Merge branch 'bug_9052' into 3.12-master
[koha.git] / members / member.pl
index e2a6ef5..d25dba9 100755 (executable)
@@ -58,7 +58,8 @@ my $branches = GetBranches;
 my @branchloop;
 
 foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
-  my $selected = 1 if $branches->{$_}->{branchcode} eq $$patron{branchcode};
+  my $selected;
+  $selected = 1 if $branches->{$_}->{branchcode} eq $$patron{branchcode};
   my %row = ( value => $_,
         selected => $selected,
         branchname => $branches->{$_}->{branchname},
@@ -94,6 +95,9 @@ else {
        @orderby = ({surname=>0},{firstname=>0});
 }
 
+my $searchfields = $input->param('searchfields');
+my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
+
 $member =~ s/,//g;   #remove any commas from search string
 $member =~ s/\*/%/g;
 
@@ -104,7 +108,7 @@ my ($count,$results);
 if ($member || keys %$patron) {
     #($results)=Search($member || $patron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"]  );
     my $search_scope = ( $quicksearch ? "field_start_with" : "start_with" );
-    ($results) = Search( $member || $patron, \@orderby, undef, undef, [ "firstname", "surname", "othernames", "cardnumber", "userid" ], $search_scope );
+    ($results) = Search( $member || $patron, \@orderby, undef, undef, \@searchfields, $search_scope );
 }
 
 if ($results) {
@@ -131,12 +135,13 @@ foreach my $borrower(@$results[$from..$to-1]){
 
   my %row = (
     count => $index++,
-       %$borrower,
-       %{$categories_dislay{$$borrower{categorycode}}},
+    %$borrower,
+    (defined $categories_dislay{ $borrower->{categorycode} }?   %{ $categories_dislay{ $borrower->{categorycode} } }:()),
     overdues => $od,
     issues => $issue,
     odissue => "$od/$issue",
     fines =>  sprintf("%.2f",$fines),
+    branchname => $branches->{$borrower->{branchcode}}->{branchname},
     );
   push(@resultsdata, \%row);
 }