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
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
$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 );
{
$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");
}
}
@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");
}
}
# FIXME - .= <<EOT;
}
- $query = $query . ") OR cardnumber LIKE ? ";
+ $query = $query . " OR cardnumber LIKE ? ) ";
push( @bind, $searchstring );
if (C4::Context->preference('ExtendedPatronAttributes')) {
$query .= "OR borrowernumber IN (
$tabsysprefs{libraryAddress} = "Admin";
$tabsysprefs{delimiter} = "Admin";
$tabsysprefs{IndependantBranches} = "Admin";
+$tabsysprefs{IndependentBranchPatron}= "Admin";
$tabsysprefs{insecure} = "Admin";
$tabsysprefs{KohaAdmin} = "Admin";
$tabsysprefs{KohaAdminEmailAddress} = "Admin";
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%");
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');");
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');");
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)
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