4 #script to do a borrower enquiry/bring up borrower details etc
5 #written 20/12/99 by chris@katipo.co.nz
8 # Copyright 2000-2002 Katipo Communications
9 # Copyright 2010 BibLibre
11 # This file is part of Koha.
13 # Koha is free software; you can redistribute it and/or modify it under the
14 # terms of the GNU General Public License as published by the Free Software
15 # Foundation; either version 2 of the License, or (at your option) any later
18 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
19 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
20 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along
23 # with Koha; if not, write to the Free Software Foundation, Inc.,
24 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #use warnings; FIXME - Bug 2505
37 my $quicksearch = $input->param('quicksearch');
38 my $startfrom = $input->param('startfrom')||1;
39 my $resultsperpage = $input->param('resultsperpage')||C4
::Context
->preference("PatronsPerPage")||20;
41 my ($template, $loggedinuser, $cookie)
42 = get_template_and_user
({template_name
=> "members/member.tmpl",
46 flagsrequired
=> {borrowers
=> 1},
49 my $theme = $input->param('theme') || "default";
51 my $patron = $input->Vars;
52 foreach (keys %$patron){
53 delete $$patron{$_} unless($$patron{$_});
55 my @categories=C4
::Category
->all;
57 my $branches = GetBranches
;
60 foreach (sort { $branches->{$a}->{branchname
} cmp $branches->{$b}->{branchname
} } keys %$branches) {
61 my $selected = 1 if $branches->{$_}->{branchcode
} eq $$patron{branchcode
};
62 my %row = ( value
=> $_,
63 selected
=> $selected,
64 branchname
=> $branches->{$_}->{branchname
},
66 push @branchloop, \
%row;
69 my %categories_dislay;
71 foreach my $category (@categories){
73 category_description
=>$$category{description
},
74 category_type
=>$$category{category_type
}
76 $categories_dislay{$$category{categorycode
}} = $hash;
78 my $AddPatronLists = C4
::Context
->preference("AddPatronLists") || '';
80 "AddPatronLists_$AddPatronLists" => "1",
82 if ($AddPatronLists=~/code/){
83 $categories[0]->{'first'}=1;
86 my $member=$input->param('member');
87 my $orderbyparams=$input->param('orderby');
90 my @orderbyelt=split(/,/,$orderbyparams);
91 push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0};
94 @orderby = ({surname
=>0},{firstname
=>0});
97 my $searchfields = $input->param('searchfields');
98 my @searchfields = $searchfields ?
split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
100 $member =~ s/,//g; #remove any commas from search string
103 my $from = ( $startfrom - 1 ) * $resultsperpage;
104 my $to = $from + $resultsperpage;
106 my ($count,$results);
107 if ($member || keys %$patron) {
108 #($results)=Search($member || $patron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"] );
109 my $search_scope = ( $quicksearch ?
"field_start_with" : "start_with" );
110 ($results) = Search
( $member || $patron, \
@orderby, undef, undef, \
@searchfields, $search_scope );
114 for my $field ('categorycode','branchcode'){
115 next unless ($patron->{$field});
116 @
$results = grep { $_->{$field} eq $patron->{$field} } @
$results;
118 $count = scalar(@
$results);
122 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . @
$results[0]->{borrowernumber
});
127 $to=($count>$to?
$to:$count);
129 foreach my $borrower(@
$results[$from..$to-1]){
131 my ($od,$issue,$fines)=GetMemberIssuesAndFines
($$borrower{'borrowernumber'});
133 $$borrower{'dateexpiry'}= C4
::Dates
->new($$borrower{'dateexpiry'},'iso')->output('syspref');
138 %{$categories_dislay{$$borrower{categorycode
}}},
141 odissue
=> "$od/$issue",
142 fines
=> sprintf("%.2f",$fines),
144 push(@resultsdata, \
%row);
147 if ($$patron{categorycode
}){
148 foreach my $category (grep{$_->{categorycode
} eq $$patron{categorycode
}}@categories){
149 $$category{selected
}=1;
154 , 'orderby' => $orderbyparams
155 , 'resultsperpage' => $resultsperpage
156 , 'type'=> 'intranet');
161 map { "$_=$parameters{$_}" } (keys %parameters)
164 my @letters = map { {letter
=> $_} } ( 'A' .. 'Z');
167 letters
=> \
@letters,
168 paginationbar
=> pagination_bar
(
170 int( $count / $resultsperpage ) + ($count % $resultsperpage ?
1 : 0),
171 $startfrom, 'startfrom'
173 startfrom
=> $startfrom,
174 from
=> ($startfrom-1)*$resultsperpage+1,
176 multipage
=> ($count != $to || $startfrom!=1),
177 advsearch
=> ($$patron{categorycode
} || $$patron{branchcode
}),
178 branchloop
=>\
@branchloop,
179 categories
=>\
@categories,
181 actionname
=>basename
($0),
183 numresults
=> $count,
184 resultsloop
=> \
@resultsdata,
187 output_html_with_http_headers
$input, $cookie, $template->output;