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
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along
22 # with Koha; if not, write to the Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #use warnings; FIXME - Bug 2505
36 my $quicksearch = $input->param('quicksearch');
37 my $startfrom = $input->param('startfrom')||1;
38 my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
40 my ($template, $loggedinuser, $cookie)
41 = get_template_and_user({template_name => "members/member.tmpl",
45 flagsrequired => {borrowers => 1},
48 my $theme = $input->param('theme') || "default";
50 my $patron = $input->Vars;
51 foreach (keys %$patron){
52 delete $$patron{$_} unless($$patron{$_});
54 my @categories=C4::Category->all;
56 my $branches = GetBranches;
59 foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
60 my $selected = 1 if $branches->{$_}->{branchcode} eq $$patron{branchcode};
61 my %row = ( value => $_,
62 selected => $selected,
63 branchname => $branches->{$_}->{branchname},
65 push @branchloop, \%row;
68 my %categories_dislay;
70 foreach my $category (@categories){
72 category_description=>$$category{description},
73 category_type=>$$category{category_type}
75 $categories_dislay{$$category{categorycode}} = $hash;
78 "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
80 if (C4::Context->preference("AddPatronLists")=~/code/){
81 $categories[0]->{'first'}=1;
84 my $member=$input->param('member');
85 my $orderbyparams=$input->param('orderby');
88 my @orderbyelt=split(/,/,$orderbyparams);
89 push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0};
92 @orderby = ({surname=>0},{firstname=>0});
96 $member =~ s/^.*%B60198321(\d{10})\d&.*$/S$1/ && warn "JMBAG: $1";
97 $member =~ s/,//g; #remove any commas from search string
100 my ($count,$results);
103 push @searchpatron, $member if ($member);
104 push @searchpatron, $patron if (keys %$patron);
105 my $from= ($startfrom-1)*$resultsperpage;
106 my $to=$from+$resultsperpage;
107 #($results)=Search(\@searchpatron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"] ) if (@searchpatron);
108 my $search_scope=($quicksearch?"field_start_with":"contain");
109 ($results)=Search(\@searchpatron,\@orderby,undef,undef,["firstname","surname","email","othernames","cardnumber","userid"],$search_scope ) if (@searchpatron);
111 $count =scalar(@$results);
114 $to=($count>$to?$to:$count);
116 foreach my $borrower(@$results[$from..$to-1]){
118 my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
120 $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
125 %{$categories_dislay{$$borrower{categorycode}}},
128 odissue => "$od/$issue",
129 fines => sprintf("%.2f",$fines),
131 push(@resultsdata, \%row);
134 if ($$patron{categorycode}){
135 foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
136 $$category{selected}=1;
141 , 'orderby' => $orderbyparams
142 , 'resultsperpage' => $resultsperpage
143 , 'type'=> 'intranet');
148 map { "$_=$parameters{$_}" } (keys %parameters)
151 my @letters = map { {letter => $_} } ( 'A' .. 'Z');
154 letters => \@letters,
155 paginationbar => pagination_bar(
157 int( $count / $resultsperpage ) + ($count % $resultsperpage ? 1 : 0),
158 $startfrom, 'startfrom'
160 startfrom => $startfrom,
161 from => ($startfrom-1)*$resultsperpage+1,
163 multipage => ($count != $to || $startfrom!=1),
164 advsearch => ($$patron{categorycode} || $$patron{branchcode}),
165 branchloop=>\@branchloop,
166 categories=>\@categories,
168 actionname =>basename($0),
170 numresults => $count,
171 resultsloop => \@resultsdata,
174 output_html_with_http_headers $input, $cookie, $template->output;