-my $sql = qq(SELECT surname, firstname, cardnumber, address, city, zipcode, country
- FROM borrowers
- WHERE surname LIKE ?
- OR firstname LIKE ?
- OR cardnumber LIKE ?
- ORDER BY surname, firstname
- LIMIT 10);
+my $sql = q(
+ SELECT borrowernumber, surname, firstname, cardnumber, address, city, zipcode, country
+ FROM borrowers
+ WHERE ( surname LIKE ?
+ OR firstname LIKE ?
+ OR cardnumber LIKE ? )
+);
+if ( C4::Context->preference("IndependentBranches")
+ && C4::Context->userenv
+ && !C4::Context->IsSuperLibrarian()
+ && C4::Context->userenv->{'branch'} )
+{
+ $sql .= " AND borrowers.branchcode ="
+ . $dbh->quote( C4::Context->userenv->{'branch'} );
+}
+
+$sql .= q( ORDER BY surname, firstname LIMIT 10);