From 8758e8d0e853dd4936ef45d125259f63bd794ef7 Mon Sep 17 00:00:00 2001 From: Paul Poulain Date: Tue, 5 Jan 2010 21:25:57 +0100 Subject: [PATCH] bug fixing : Patron Search : IndependentBranches When Independant Branches is set, some library expect not to see the patrons of other library Adding a new systempreference : IndependentBranchPatron in order to be able to restrict Patron search to the library of the current user and not change the current behaviour of IndependantBranches patron search --- C4/Members.pm | 28 +++++++++++++------ admin/systempreferences.pl | 1 + circ/ysearch.pl | 10 +++++-- .../data/mysql/en/mandatory/sysprefs.sql | 1 + .../unimarc_standard_systemprefs.sql | 1 + installer/data/mysql/updatedatabase30.pl | 7 +++++ kohaversion.pl | 2 +- 7 files changed, 39 insertions(+), 11 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index bd9e60b299..49ed0f4059 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -148,7 +148,7 @@ name. C<$filter> is assumed to be a list of elements to filter results on -C<$showallbranches> is used in IndependantBranches Context to display all branches results. +C<$showallbranches> is used in IndependentBranchPatron Context to display all branches results. C<&SearchMember> returns a two-element list. C<$borrowers> is a reference-to-array; each element is a reference-to-hash, whose keys @@ -173,8 +173,20 @@ sub SearchMember { $query = "SELECT * FROM borrowers LEFT JOIN categories ON borrowers.categorycode=categories.categorycode "; - my $sth = $dbh->prepare("$query WHERE cardnumber = ?"); - $sth->execute($searchstring); + my (@where_string, @bind_params); + push @where_string, "cardnumber=?"; + push @bind_params, $searchstring; + if (C4::Context->preference("IndependantBranchPatron") && !$showallbranches){ + if (C4::Context->userenv && (C4::Context->userenv->{flags} % 2) !=1 && C4::Context->userenv->{'branch'}){ + unless (C4::Context->userenv->{'branch'} eq "insecure"){ + push @where_string,"borrowers.branchcode =?"; + push @bind_params,C4::Context->userenv->{'branch'}; + } + } + } + my $sth = $dbh->prepare("$query WHERE ".join(" AND ", @where_string)); + + $sth->execute(@bind_params); my $data = $sth->fetchall_arrayref({}); if (@$data){ return ( scalar(@$data), $data ); @@ -185,8 +197,8 @@ sub SearchMember { { $query .= ($category_type ? " AND category_type = ".$dbh->quote($category_type) : ""); $query .= " WHERE (surname LIKE ? OR cardnumber like ?) "; - if (C4::Context->preference("IndependantBranches") && !$showallbranches){ - if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){ + if (C4::Context->preference("IndependentBranchPatron") && !$showallbranches){ + if (C4::Context->userenv && (C4::Context->userenv->{flags} % 2) !=1 && C4::Context->userenv->{'branch'}){ $query.=" AND borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'}) unless (C4::Context->userenv->{'branch'} eq "insecure"); } } @@ -198,8 +210,8 @@ sub SearchMember { @data = split( ' ', $searchstring ); $count = @data; $query .= " WHERE "; - if (C4::Context->preference("IndependantBranches") && !$showallbranches){ - if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){ + if (C4::Context->preference("IndependentBranchPatron") && !$showallbranches){ + if (C4::Context->userenv && (C4::Context->userenv->{flags} %2 )!=1 && C4::Context->userenv->{'branch'}){ $query.=" borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'})." AND " unless (C4::Context->userenv->{'branch'} eq "insecure"); } } @@ -222,7 +234,7 @@ sub SearchMember { # FIXME - .= <preference('ExtendedPatronAttributes')) { $query .= "OR borrowernumber IN ( diff --git a/admin/systempreferences.pl b/admin/systempreferences.pl index 92118567c7..13f92f91eb 100755 --- a/admin/systempreferences.pl +++ b/admin/systempreferences.pl @@ -80,6 +80,7 @@ $tabsysprefs{FrameworksLoaded} = "Admin"; $tabsysprefs{libraryAddress} = "Admin"; $tabsysprefs{delimiter} = "Admin"; $tabsysprefs{IndependantBranches} = "Admin"; +$tabsysprefs{IndependentBranchPatron}= "Admin"; $tabsysprefs{insecure} = "Admin"; $tabsysprefs{KohaAdmin} = "Admin"; $tabsysprefs{KohaAdminEmailAddress} = "Admin"; diff --git a/circ/ysearch.pl b/circ/ysearch.pl index 136ca76f7b..628838748e 100755 --- a/circ/ysearch.pl +++ b/circ/ysearch.pl @@ -45,8 +45,14 @@ my $sql = qq(SELECT surname, firstname, cardnumber, address, city, zipcode FROM borrowers WHERE surname LIKE ? OR firstname LIKE ? - OR cardnumber LIKE ? - ORDER BY surname, firstname); + OR cardnumber LIKE ?); +if (C4::Context->preference("IndependentBranchPatron")){ + if (C4::Context->userenv && (C4::Context->userenv->{flags} % 2) !=1 && C4::Context->userenv->{'branch'}){ + $sql.=" AND borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'}) unless (C4::Context->userenv->{'branch'} eq "insecure"); + } +} + +$sql .= qq( ORDER BY surname, firstname); my $sth = $dbh->prepare( $sql ); $sth->execute("$query%", "$query%", "$query%"); diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql index f9ad18a954..a67dcb6024 100644 --- a/installer/data/mysql/en/mandatory/sysprefs.sql +++ b/installer/data/mysql/en/mandatory/sysprefs.sql @@ -226,3 +226,4 @@ INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ( INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonCoverImages', '0', 'Display cover images on OPAC from Amazon Web Services','','YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ReadingHistory', '0', 'If on display reading history for user', NULL, 'YesNo'); INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ReceiveBackIssues', '5', 'Number of Previous journals to display when on subscription detail', '', ''); +INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('IndependentBranchPatron',0,'If ON, librarian patron search can only be done on patron of same library as librarian',NULL,'YesNo');"); diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql index 32628b8a10..59179868db 100644 --- a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql +++ b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql @@ -222,3 +222,4 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewISBD','1','Affiche la vue ISBD à l\'intranet','','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Affiche la vue labeled MARC','','YesNo'); INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Affiche la vue MARC','','YesNo'); +INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('IndependentBranchPatron','0','Si activé, Le bibliothécaire ne recherche les lecteurs que dans SA bibliothèque',NULL,'YesNo');"); diff --git a/installer/data/mysql/updatedatabase30.pl b/installer/data/mysql/updatedatabase30.pl index 4df69dc493..de57e89ca7 100644 --- a/installer/data/mysql/updatedatabase30.pl +++ b/installer/data/mysql/updatedatabase30.pl @@ -713,6 +713,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = "3.00.06.004"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('IndependentBranchPatron','0','If ON, librarian patron search can only be done on patron of same library as librarian',NULL,'YesNo');"); + print "Upgrade to $DBversion done (Add IndependentBranchPatron system preference to be able to limit patron search to librarian's Library)\n"; + SetVersion ($DBversion); +} + =item DropAllForeignKeys($table) diff --git a/kohaversion.pl b/kohaversion.pl index e8ea8e7f59..8fae5356b4 100644 --- a/kohaversion.pl +++ b/kohaversion.pl @@ -10,7 +10,7 @@ use strict; sub kohaversion { - our $VERSION = '3.00.06.003'; + our $VERSION = '3.00.06.004'; # version needs to be set this way # so that it can be picked up by Makefile.PL # during install -- 2.20.1