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
38 my $quicksearch = $input->param('quicksearch');
39 my $startfrom = $input->param('startfrom')||1;
40 my $resultsperpage = $input->param('resultsperpage')||C4
::Context
->preference("PatronsPerPage")||20;
42 my ($template, $loggedinuser, $cookie)
43 = get_template_and_user
({template_name
=> "members/member.tmpl",
47 flagsrequired
=> {borrowers
=> 1},
50 my $theme = $input->param('theme') || "default";
52 my $patron = $input->Vars;
53 foreach (keys %$patron){
54 delete $$patron{$_} unless($$patron{$_});
56 my @categories=C4
::Category
->all;
58 my $branches = GetBranches
;
61 foreach (sort { $branches->{$a}->{branchname
} cmp $branches->{$b}->{branchname
} } keys %$branches) {
63 $selected = 1 if $branches->{$_}->{branchcode
} eq $$patron{branchcode
};
64 my %row = ( value
=> $_,
65 selected
=> $selected,
66 branchname
=> $branches->{$_}->{branchname
},
68 push @branchloop, \
%row;
71 my %categories_dislay;
73 foreach my $category (@categories){
75 category_description
=>$$category{description
},
76 category_type
=>$$category{category_type
}
78 $categories_dislay{$$category{categorycode
}} = $hash;
80 my $AddPatronLists = C4
::Context
->preference("AddPatronLists") || '';
82 "AddPatronLists_$AddPatronLists" => "1",
84 if ($AddPatronLists=~/code/){
85 $categories[0]->{'first'}=1;
88 my $member=$input->param('member');
89 my $orderbyparams=$input->param('orderby');
92 my @orderbyelt=split(/,/,$orderbyparams);
93 push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0};
96 @orderby = ({surname
=>0},{firstname
=>0});
99 $member =~ s/,//g; #remove any commas from search string
102 my $from = ( $startfrom - 1 ) * $resultsperpage;
103 my $to = $from + $resultsperpage;
105 my ($count,$results);
106 if ($member || keys %$patron) {
107 my $searchfields = $input->param('searchfields');
108 my @searchfields = $searchfields ?
split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
110 if ( $searchfields eq "dateofbirth" ) {
111 $member = output_pref
(dt_from_string
($member), 'iso', undef, 1);
114 my $search_scope = ( $quicksearch ?
"field_start_with" : "start_with" );
115 ($results) = Search
( $member || $patron, \
@orderby, undef, undef, \
@searchfields, $search_scope );
119 for my $field ('categorycode','branchcode'){
120 next unless ($patron->{$field});
121 @
$results = grep { $_->{$field} eq $patron->{$field} } @
$results;
123 $count = scalar(@
$results);
127 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . @
$results[0]->{borrowernumber
});
132 $to=($count>$to?
$to:$count);
134 foreach my $borrower(@
$results[$from..$to-1]){
136 my ($od,$issue,$fines)=GetMemberIssuesAndFines
($$borrower{'borrowernumber'});
138 $$borrower{'dateexpiry'}= C4
::Dates
->new($$borrower{'dateexpiry'},'iso')->output('syspref');
143 (defined $categories_dislay{ $borrower->{categorycode
} }?
%{ $categories_dislay{ $borrower->{categorycode
} } }:()),
146 odissue
=> "$od/$issue",
147 fines
=> sprintf("%.2f",$fines),
148 branchname
=> $branches->{$borrower->{branchcode
}}->{branchname
},
150 push(@resultsdata, \
%row);
153 if ($$patron{categorycode
}){
154 foreach my $category (grep{$_->{categorycode
} eq $$patron{categorycode
}}@categories){
155 $$category{selected
}=1;
160 , 'orderby' => $orderbyparams
161 , 'resultsperpage' => $resultsperpage
162 , 'type'=> 'intranet');
167 map { "$_=$parameters{$_}" } (keys %parameters)
170 my @letters = map { {letter
=> $_} } ( 'A' .. 'Z');
173 letters
=> \
@letters,
174 paginationbar
=> pagination_bar
(
176 int( $count / $resultsperpage ) + ($count % $resultsperpage ?
1 : 0),
177 $startfrom, 'startfrom'
179 startfrom
=> $startfrom,
180 from
=> ($startfrom-1)*$resultsperpage+1,
182 multipage
=> ($count != $to || $startfrom!=1),
183 advsearch
=> ($$patron{categorycode
} || $$patron{branchcode
}),
184 branchloop
=>\
@branchloop,
185 categories
=>\
@categories,
187 actionname
=>basename
($0),
189 numresults
=> $count,
190 resultsloop
=> \
@resultsdata,
193 output_html_with_http_headers
$input, $cookie, $template->output;