bug fixing : Patron Search : IndependentBranches
authorPaul Poulain <paul.poulain@biblibre.com>
Tue, 5 Jan 2010 20:25:57 +0000 (21:25 +0100)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Mon, 11 Jan 2010 12:33:13 +0000 (13:33 +0100)
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
admin/systempreferences.pl
circ/ysearch.pl
installer/data/mysql/en/mandatory/sysprefs.sql
installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
installer/data/mysql/updatedatabase30.pl
kohaversion.pl

index bd9e60b..49ed0f4 100644 (file)
@@ -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 - .= <<EOT;
         }
-        $query = $query . ") OR cardnumber LIKE ? ";
+        $query = $query . " OR cardnumber LIKE ? ) ";
         push( @bind, $searchstring );
         if (C4::Context->preference('ExtendedPatronAttributes')) {
             $query .= "OR borrowernumber IN (
index 9211856..13f92f9 100755 (executable)
@@ -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";
index 136ca76..6288387 100755 (executable)
@@ -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%");
 
index f9ad18a..a67dcb6 100644 (file)
@@ -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');");
index 32628b8..5917986 100644 (file)
@@ -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');");
index 4df69dc..de57e89 100644 (file)
@@ -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)
 
index e8ea8e7..8fae535 100644 (file)
@@ -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