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 with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
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);
42 ($template, $loggedinuser, $cookie)
43 = get_template_and_user({template_name => "members/member-quicksearch-results.tmpl",
47 flagsrequired => {borrowers => 1},
50 ($template, $loggedinuser, $cookie)
51 = get_template_and_user({template_name => "members/member.tmpl",
55 flagsrequired => {borrowers => 1},
58 my $theme = $input->param('theme') || "default";
60 my $patron = $input->Vars;
61 foreach (keys %$patron){
62 delete $$patron{$_} unless($$patron{$_});
65 my @categories=C4::Category->all;
66 my $branches=(defined $$patron{branchcode}?GetBranchesLoop($$patron{branchcode}):GetBranchesLoop());
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=>1},{firstname=>1});
94 warn Data::Dumper::Dumper(@orderby);
95 $member =~ s/,//g; #remove any commas from search string
101 push @searchpatron, $member if ($member);
102 push @searchpatron, $patron if (keys %$patron);
103 my $from= ($startfrom-1)*$resultsperpage;
104 my $to=$from+$resultsperpage;
105 #($results)=Search(\@searchpatron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"] ) if (@searchpatron);
106 my $search_scope=($quicksearch?"field_start_with":"start_with");
107 ($results)=Search(\@searchpatron,\@orderby,undef,undef,["firstname","surname","email","othernames","cardnumber","userid"],$search_scope ) if (@searchpatron);
109 $count =scalar(@$results);
112 my $to=($count>$to?$to:$count);
114 foreach my $borrower(@$results[$from..$to-1]){
116 my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
118 $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
123 %{$categories_dislay{$$borrower{categorycode}}},
126 odissue => "$od/$issue",
127 fines => sprintf("%.2f",$fines),
129 push(@resultsdata, \%row);
132 if ($$patron{branchcode}){
133 foreach my $branch (grep{$_->{value} eq $$patron{branchcode}}@$branches){
134 $$branch{selected}=1;
137 if ($$patron{categorycode}){
138 foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
139 $$category{selected}=1;
144 , 'orderby' => $orderbyparams
145 , 'resultsperpage' => $resultsperpage
146 , 'type'=> 'intranet');
151 map { "$_=$parameters{$_}" } (keys %parameters)
155 paginationbar => pagination_bar(
156 $base_url, int( $count / $resultsperpage ) + 1,
157 $startfrom, 'startfrom'
159 startfrom => $startfrom,
160 from => ($startfrom-1)*$resultsperpage+1,
162 multipage => ($count != $to+1 || $startfrom!=1),
165 branchloop=>$branches,
166 categoryloop=>\@categories,
172 actionname =>basename($0),
174 numresults => $count,
175 resultsloop => \@resultsdata,
178 output_html_with_http_headers $input, $cookie, $template->output;