# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-use strict;
-#use warnings; FIXME - Bug 2505
+use Modern::Perl;
use C4::Auth;
use C4::Output;
use CGI;
use C4::Members;
use C4::Branch;
use C4::Category;
+use Koha::DateUtils;
use File::Basename;
my $input = new CGI;
-my $quicksearch = $input->param('quicksearch');
-my $startfrom = $input->param('startfrom')||1;
-my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
+my $quicksearch = $input->param('quicksearch') || '';
+my $startfrom = $input->param('startfrom') || 1;
+my $resultsperpage = $input->param('resultsperpage') || C4::Context->preference("PatronsPerPage") || 20;
my ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "members/member.tmpl",
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 $patron->{branchcode} && $branches->{$_}->{branchcode} eq $patron->{branchcode};
my %row = ( value => $_,
selected => $selected,
branchname => $branches->{$_}->{branchname},
};
$categories_dislay{$$category{categorycode}} = $hash;
}
+my $AddPatronLists = C4::Context->preference("AddPatronLists") || '';
$template->param(
- "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
+ "AddPatronLists_$AddPatronLists" => "1",
);
-if (C4::Context->preference("AddPatronLists")=~/code/){
+if ($AddPatronLists=~/code/){
$categories[0]->{'first'}=1;
}
-my $member=$input->param('member');
-my $orderbyparams=$input->param('orderby');
+my $member=$input->param('member') || '';
+my $orderbyparams=$input->param('orderby') || '';
my @orderby;
if ($orderbyparams){
my @orderbyelt=split(/,/,$orderbyparams);
$member =~ s/,//g; #remove any commas from search string
$member =~ s/\*/%/g;
-my ($count,$results);
-
-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);
-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_from_string($member), 'iso', undef, 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 ($results) {
for my $field ('categorycode','branchcode'){
@$results = grep { $_->{$field} eq $patron->{$field} } @$results;
}
$count = scalar(@$results);
+} else {
+ $count = 0;
+}
+
+if($count == 1){
+ print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . @$results[0]->{borrowernumber});
+ exit;
}
+
my @resultsdata;
$to=($count>$to?$to:$count);
my $index=$from;
foreach my $borrower(@$results[$from..$to-1]){
#find out stats
my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
-
+ $fines ||= 0;
$$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
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);
}