start of release notes for 3.2
[koha.git] / serials / member-search.pl
index 6e26a07..2d9a031 100755 (executable)
@@ -11,9 +11,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
 
@@ -38,7 +38,7 @@ my $startfrom = $cgi->param('startfrom')||1;
 
 my $patron = $cgi->Vars;
 foreach (keys %$patron){
-       delete $$patron{$_} unless($$patron{$_}); 
+    delete $$patron{$_} unless($$patron{$_});
 }
 
 my @categories=C4::Category->all;
@@ -61,18 +61,20 @@ foreach my $category (@categories){
                         };
        $categories_dislay{$$category{categorycode}} = $hash;
 }
-$template->param( 
+$template->param(
         "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
             );
 if (C4::Context->preference("AddPatronLists")=~/code/){
     $categories[0]->{'first'}=1;
-}  
+}
 
 my $member=$cgi->param('member');
 my $orderby=$cgi->param('orderby');
 $orderby = "surname,firstname" unless $orderby;
-$member =~ s/,//g;   #remove any commas from search string
-$member =~ s/\*/%/g;
+if (defined $member) {
+    $member =~ s/,//g;   #remove any commas from search string
+    $member =~ s/\*/%/g;
+}
 
 my ($count,$results);
 
@@ -86,16 +88,24 @@ $$patron{surname}.="\%" if ($$patron{surname});
 
 my @searchpatron;
 push @searchpatron, $member if ($member);
-push @searchpatron, $patron if (keys %$patron);
-my $from= ($startfrom-1)*$resultsperpage;
-my $to=$from+$resultsperpage;
- #($results)=Search(\@searchpatron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"]  ) if (@searchpatron);
- ($results)=Search(\@searchpatron,{surname=>1,firstname=>1},undef,undef,["firstname","surname","email","othernames","cardnumber"],"start_with"  ) if (@searchpatron);
-if ($results){
-       $count =scalar(@$results);
+push @searchpatron, $patron if ( keys %$patron );
+my $from = ( $startfrom - 1 ) * $resultsperpage;
+my $to   = $from + $resultsperpage;
+if (@searchpatron) {
+    ($results) = Search(
+        \@searchpatron,
+        [ { surname => 0 }, { firstname => 0 } ],
+        undef,
+        undef,
+        [ "firstname", "surname", "email", "othernames", "cardnumber" ],
+        "start_with"
+    );
+}
+if ($results) {
+    $count = scalar(@$results);
 }
 my @resultsdata;
-my $to=($count>$to?$to:$count);
+$to=($count>$to?$to:$count);
 my $index=$from;
 foreach my $borrower(@$results[$from..$to-1]){
   #find out stats
@@ -121,10 +131,10 @@ if ($$patron{categorycode}){
        }
 }
 my %parameters=
-        (  %$patron
-               , 'orderby'                     => $orderby 
-               , 'resultsperpage'      => $resultsperpage 
-        , 'type'=> 'intranet'); 
+(  %{$patron},
+    'orderby' => $orderby,
+    'resultsperpage' => $resultsperpage,
+    'type'=> 'intranet');
 my $base_url =
     'member-search.pl?&'
   . join(
@@ -138,7 +148,7 @@ $template->param(
         $startfrom, 'startfrom'
     ),
     startfrom => $startfrom,
-    from      => ($startfrom-1)*$resultsperpage+1,  
+    from      => ($startfrom-1)*$resultsperpage+1,
     to        => $to,
     multipage => ($count != $to+1 || $startfrom!=1),
 );
@@ -148,7 +158,7 @@ $template->param(
 );
 
 
-$template->param( 
+$template->param(
         searching       => "1",
                actionname              => basename($0),
                %$patron,