Bug 13890 - Switch from full serials permission to 'routing' permission for reorderin...
[srvgit] / serials / member-search.pl
index 549067a..9ae769b 100755 (executable)
@@ -1,5 +1,7 @@
 #!/usr/bin/perl
 
+# Parts copyright Catalyst IT 2010
+#
 # This file is part of Koha.
 #
 # Koha is free software; you can redistribute it and/or modify it under the
@@ -11,9 +13,9 @@
 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 =head1 member-search.pl
 
@@ -23,7 +25,7 @@ Member Search.pl script used to search for members to add to a routing list
 
 use strict;
 use warnings;
-use CGI;
+use CGI qw ( -utf8 );
 use C4::Auth;       # get_template_and_user
 use C4::Output;
 use C4::Members;    # BornameSearch
@@ -43,15 +45,17 @@ foreach (keys %$patron){
 
 my @categories=C4::Category->all;
 my $branches=(defined $$patron{branchcode}?GetBranchesLoop($$patron{branchcode}):GetBranchesLoop());
+my $subscriptionid = $cgi->param('subscriptionid');
+my $searchstring   = $cgi->param('member');
 
 my %categories_dislay;
 my ($template, $loggedinuser, $cookie);
     ($template, $loggedinuser, $cookie)
-    = get_template_and_user({template_name => "serials/member-search.tmpl",
+    = get_template_and_user({template_name => "serials/member-search.tt",
                  query => $cgi,
                  type => "intranet",
                  authnotrequired => 0,
-                 flagsrequired => {borrowers => 1},
+                 flagsrequired => { serials => 'routing' },
                  });
 
 foreach my $category (@categories){
@@ -78,10 +82,13 @@ if (defined $member) {
 
 my ($count,$results);
 
-if (C4::Context->preference("IndependantBranches")){
-   if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=1 && C4::Context->userenv->{'branch'}){
-        $$patron{branchcode}=C4::Context->userenv->{'branch'} unless (C4::Context->userenv->{'branch'} eq "insecure");
-   }
+if ( C4::Context->preference("IndependentBranches") ) {
+    if (   C4::Context->userenv
+        && !C4::Context->IsSuperLibrarian()
+        && C4::Context->userenv->{'branch'} )
+    {
+        $$patron{branchcode} = C4::Context->userenv->{'branch'};
+    }
 }
 $$patron{firstname}.="\%" if ($$patron{firstname});
 $$patron{surname}.="\%" if ($$patron{surname});
@@ -108,18 +115,20 @@ my @resultsdata;
 $to=($count>$to?$to:$count);
 my $index=$from;
 foreach my $borrower(@$results[$from..$to-1]){
-  #find out stats
-
-  $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
-
-  my %row = (
-    count => $index++,
-       %$borrower,
-       %{$categories_dislay{$$borrower{categorycode}}},
-    );
-  push(@resultsdata, \%row);
+    # find out stats
+    $borrower->{'dateexpiry'}= C4::Dates->new($borrower->{'dateexpiry'},'iso')->output('syspref');
+    if ($categories_dislay{$borrower->{'categorycode'}}){
+        my %row = (
+           count => $index++,
+           %$borrower,
+           %{$categories_dislay{$$borrower{categorycode}}},
+       );
+       push(@resultsdata, \%row);
+    }
+    else {
+        warn $borrower->{'cardnumber'} ." has a bad category code of " . $borrower->{'categorycode'} ."\n";
+    }
 }
-
 if ($$patron{branchcode}){
        foreach my $branch (grep{$_->{value} eq $$patron{branchcode}}@$branches){
                $$branch{selected}=1;