-#($results)=Search(\@searchpatron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"] ) if (@searchpatron);
-my $search_scope = ( $quicksearch ? "field_start_with" : "start_with" );
-($results) = Search( \@searchpatron, \@orderby, undef, undef, [ "firstname", "surname", "othernames", "cardnumber", "userid" ], $search_scope ) if (@searchpatron);
+my ($count,$results);
+if ($member || keys %$patron) {
+ my $searchfields = $input->param('searchfields') || '';
+ my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
+
+ if ( $searchfields eq "dateofbirth" ) {
+ $member = output_pref({dt => dt_from_string($member), dateformat => 'iso', dateonly => 1});
+ }
+
+ my $searchtype = $input->param('searchtype');
+ my $search_scope =
+ $quicksearch ? "field_start_with"
+ : $searchtype ? $searchtype
+ : "start_with";
+
+ ($results) = Search( $member || $patron, \@orderby, undef, undef, \@searchfields, $search_scope );
+}
+
+if ($add_to_patron_list) {
+ my $patron_list;
+
+ if ( $add_to_patron_list eq 'new' ) {
+ $patron_list = AddPatronList( { name => $new_patron_list } );
+ }
+ else {
+ $patron_list =
+ [ GetPatronLists( { patron_list_id => $add_to_patron_list } ) ]->[0];
+ }
+
+ if ( $add_to_patron_list_which eq 'all' ) {
+ @borrowernumbers = map { $_->{borrowernumber} } @$results;
+ }
+
+ my @patrons_added_to_list = AddPatronsToList( { list => $patron_list, borrowernumbers => \@borrowernumbers } );
+
+ $template->param(
+ patron_list => $patron_list,
+ patrons_added_to_list => \@patrons_added_to_list,
+ )
+}