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 $member =~ s/,//g; #remove any commas from search string
100 my $from = ( $startfrom - 1 ) * $resultsperpage;
101 my $to = $from + $resultsperpage;
103 my ($count,$results);
104 if ($member || keys %$patron) {
105 #($results)=Search($member || $patron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"] );
106 my $search_scope = ( $quicksearch ? "field_start_with" : "start_with" );
107 ($results) = Search( $member || $patron, \@orderby, undef, undef, [ "firstname", "surname", "othernames", "cardnumber", "userid" ], $search_scope );
111 for my $field ('categorycode','branchcode'){
112 next unless ($patron->{$field});
113 @$results = grep { $_->{$field} eq $patron->{$field} } @$results;
115 $count = scalar(@$results);
119 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . @$results[0]->{borrowernumber});
124 $to=($count>$to?$to:$count);
126 foreach my $borrower(@$results[$from..$to-1]){
128 my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
130 $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
135 %{$categories_dislay{$$borrower{categorycode}}},
138 odissue => "$od/$issue",
139 fines => sprintf("%.2f",$fines),
141 push(@resultsdata, \%row);
144 if ($$patron{categorycode}){
145 foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
146 $$category{selected}=1;
151 , 'orderby' => $orderbyparams
152 , 'resultsperpage' => $resultsperpage
153 , 'type'=> 'intranet');
158 map { "$_=$parameters{$_}" } (keys %parameters)
161 my @letters = map { {letter => $_} } ( 'A' .. 'Z');
164 letters => \@letters,
165 paginationbar => pagination_bar(
167 int( $count / $resultsperpage ) + ($count % $resultsperpage ? 1 : 0),
168 $startfrom, 'startfrom'
170 startfrom => $startfrom,
171 from => ($startfrom-1)*$resultsperpage+1,
173 multipage => ($count != $to || $startfrom!=1),
174 advsearch => ($$patron{categorycode} || $$patron{branchcode}),
175 branchloop=>\@branchloop,
176 categories=>\@categories,
178 actionname =>basename($0),
180 numresults => $count,
181 resultsloop => \@resultsdata,
184 output_html_with_http_headers $input, $cookie, $template->output;