From 8b987317d9f886ebe11cb05f4f3884929edffe53 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 27 Jun 2013 15:33:46 +0200 Subject: [PATCH] Bug 5904: make patron search autocompletion respect IndependentBranches Test plan: - Add a staff user foo in a library A - Add a staff user bar in a library B - log in as foo and try to search 'bar' - Switch on (Prevent) the syspref IndependentBranches - the search returns no result - log in as a superlibrarian - Check that you are allowed to search all patrons. Signed-off-by: Srdjan Signed-off-by: Kyle M Hall Passes koha-qa.pl, works as advertised. Signed-off-by: Galen Charlton (cherry picked from commit 6b72f249082fc6be8811c3dacec15648f7c5ccd9) Signed-off-by: Tomas Cohen Arazi (cherry picked from commit f01248ae55beffae61f7fed36cbe046b65b96116) Signed-off-by: Bernardo Gonzalez Kriegel (cherry picked from commit f01248ae55beffae61f7fed36cbe046b65b96116) --- circ/ysearch.pl | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/circ/ysearch.pl b/circ/ysearch.pl index 8a48c51f4b..4a3663e348 100755 --- a/circ/ysearch.pl +++ b/circ/ysearch.pl @@ -44,13 +44,23 @@ if ($auth_status ne "ok") { } my $dbh = C4::Context->dbh; -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 surname, firstname, cardnumber, address, city, zipcode, country + FROM borrowers + WHERE ( surname LIKE ? + OR firstname LIKE ? + OR cardnumber LIKE ? ) +); +if (C4::Context->preference("IndependentBranches")){ + if ( C4::Context->userenv + && (C4::Context->userenv->{flags} % 2) !=1 + && C4::Context->userenv->{'branch'} + ){ + $sql .= " AND borrowers.branchcode =" . $dbh->quote(C4::Context->userenv->{'branch'}); + } +} + +$sql .= q( ORDER BY surname, firstname LIMIT 10); my $sth = $dbh->prepare( $sql ); $sth->execute("$query%", "$query%", "$query%"); @@ -68,4 +78,4 @@ while ( my $rec = $sth->fetchrow_hashref ) { "}"; $i++; } -print "]"; \ No newline at end of file +print "]"; -- 2.39.5