[Koha-patches] [PATCH 5/5] bug fixing : Patron Search : IndependentBranches
Henri-Damien LAURENT
henridamien.laurent at biblibre.com
Thu May 27 22:03:40 CEST 2010
Porting feature from 3.0 to 3.2
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 +++++-
installer/data/mysql/en/mandatory/sysprefs.sql | 2 +-
.../1-Obligatoire/unimarc_standard_systemprefs.sql | 1 +
installer/data/mysql/updatedatabase.pl | 9 ++++++
kohaversion.pl | 2 +-
7 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/C4/Members.pm b/C4/Members.pm
index 30e9f2d..d04f665 100644
--- a/C4/Members.pm
+++ b/C4/Members.pm
@@ -156,7 +156,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
@@ -180,8 +180,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("IndependentBranchPatron") && !$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 );
@@ -191,8 +203,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} % 2 !=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");
}
}
@@ -204,8 +216,8 @@ sub SearchMember {
@data = split( ' ', $searchstring );
$count = @data;
$query .= " WHERE ";
- if (C4::Context->preference("IndependantBranches") && !$showallbranches){
- if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=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");
}
}
@@ -228,7 +240,7 @@ sub SearchMember {
# FIXME - .= <<EOT;
}
- $query = $query . ") OR cardnumber LIKE ? ";
+ $query = $query . " OR cardnumber LIKE ? ) ";
push( @bind, $searchstring );
$query .= "order by $orderby";
diff --git a/admin/systempreferences.pl b/admin/systempreferences.pl
index f7f71b9..94bc53e 100755
--- a/admin/systempreferences.pl
+++ b/admin/systempreferences.pl
@@ -86,6 +86,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 f8fc52a..5d4442b 100755
--- a/circ/ysearch.pl
+++ b/circ/ysearch.pl
@@ -46,8 +46,14 @@ my $sql = qq(SELECT surname, firstname, cardnumber, address, city, zipcode, coun
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 4161959..31d7d91 100644
--- a/installer/data/mysql/en/mandatory/sysprefs.sql
+++ b/installer/data/mysql/en/mandatory/sysprefs.sql
@@ -287,4 +287,4 @@ INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanatio
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ILS-DI','0','Enables ILS-DI services at OPAC.','','YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ILS-DI:Authorized_IPs','','.','Restricts usage of ILS-DI to some IPs','Free');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OverduesBlockCirc','noblock','When checking out an item should overdues block checkout, generate a confirmation dialogue, or allow checkout','noblock|confirmation|block','Choice');
-INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('DisplayMultiPlaceHold','1','Display the ability to place multiple holds or not','','YesNo');
+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 59e04b3..a9aaf38 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
@@ -288,3 +288,4 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'PrintNoticesMaxLines', '0', '', 'If greater than 0, sets the maximum number of lines an overdue notice will print. If the number of items is greater than this number, the notice will end with a warning asking the borrower to check their online account for a full list of overdue items.', 'Integer' );
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('ILS-DI','0','Active les services ILS-DI Ã l''OPAC.','','YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('OverduesBlockCirc','noblock','When checking out an item should overdues block checkout, generate a confirmation dialogue, or allow checkout','noblock|confirmation|block','Choice');
+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/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 5925895..5f03126 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -3640,6 +3640,15 @@ INSERT INTO permissions (module_bit, code, description) VALUES
}
+
+$DBversion = "3.01.00.138";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("INSERT INTO systempreferences SET variable='IndependentBranchPatron',value=0");
+
+ print "Upgrade to $DBversion done (IndependentBranchPatron syspref added)\n";
+ SetVersion ($DBversion);
+}
+
=item DropAllForeignKeys($table)
Drop all foreign keys of the table $table
diff --git a/kohaversion.pl b/kohaversion.pl
index e7972f8..8da986b 100644
--- a/kohaversion.pl
+++ b/kohaversion.pl
@@ -10,7 +10,7 @@
use strict;
sub kohaversion {
- our $VERSION = '3.01.00.137';
+ our $VERSION = '3.01.00.138';
# version needs to be set this way
# so that it can be picked up by Makefile.PL
# during install
--
1.7.0.4
More information about the Koha-patches
mailing list