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
35 my $quicksearch = $input->param('quicksearch');
36 my $startfrom = $input->param('startfrom')||1;
37 my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
39 my ($template, $loggedinuser, $cookie);
41 ($template, $loggedinuser, $cookie)
42 = get_template_and_user({template_name => "members/member-quicksearch-results.tmpl",
46 flagsrequired => {borrowers => 1},
49 ($template, $loggedinuser, $cookie)
50 = get_template_and_user({template_name => "members/member.tmpl",
54 flagsrequired => {borrowers => 1},
57 my $theme = $input->param('theme') || "default";
59 my $patron = $input->Vars;
60 foreach (keys %$patron){
61 delete $$patron{$_} unless($$patron{$_});
64 my @categories=C4::Category->all;
65 my $branches=(defined $$patron{branchcode}?GetBranchesLoop($$patron{branchcode}):GetBranchesLoop());
67 my %categories_dislay;
69 foreach my $category (@categories){
71 category_description=>$$category{description},
72 category_type=>$$category{category_type}
74 $categories_dislay{$$category{categorycode}} = $hash;
77 "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
79 if (C4::Context->preference("AddPatronLists")=~/code/){
80 $categories[0]->{'first'}=1;
83 my $member=$input->param('member');
84 my $orderby=$input->param('orderby');
85 $orderby = "surname,firstname" unless $orderby;
86 $member =~ s/,//g; #remove any commas from search string
91 if (C4::Context->preference("IndependantBranches")){
92 if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=1 && C4::Context->userenv->{'branch'}){
93 $$patron{branchcode}=C4::Context->userenv->{'branch'} unless (C4::Context->userenv->{'branch'} eq "insecure");
96 $$patron{firstname}.="\%" if ($$patron{firstname});
97 $$patron{surname}.="\%" if ($$patron{surname});
100 push @searchpatron, $member if ($member);
101 push @searchpatron, $patron if (keys %$patron);
102 my $from= ($startfrom-1)*$resultsperpage;
103 my $to=$from+$resultsperpage;
104 #($results)=Search(\@searchpatron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"] ) if (@searchpatron);
105 ($results)=Search(\@searchpatron,{surname=>1,firstname=>1},undef,undef,["firstname","surname","email","othernames","cardnumber"],"start_with" ) if (@searchpatron);
107 $count =scalar(@$results);
110 my $to=($count>$to?$to:$count);
112 foreach my $borrower(@$results[$from..$to-1]){
114 my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
116 $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
121 %{$categories_dislay{$$borrower{categorycode}}},
124 odissue => "$od/$issue",
125 fines => sprintf("%.2f",$fines),
127 push(@resultsdata, \%row);
130 if ($$patron{branchcode}){
131 foreach my $branch (grep{$_->{value} eq $$patron{branchcode}}@$branches){
132 $$branch{selected}=1;
135 if ($$patron{categorycode}){
136 foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
137 $$category{selected}=1;
142 , 'orderby' => $orderby
143 , 'resultsperpage' => $resultsperpage
144 , 'type'=> 'intranet');
149 map { "$_=$parameters{$_}" } (keys %parameters)
153 paginationbar => pagination_bar(
154 $base_url, int( $count / $resultsperpage ) + 1,
155 $startfrom, 'startfrom'
157 startfrom => $startfrom,
158 from => ($startfrom-1)*$resultsperpage+1,
160 multipage => ($count != $to+1 || $startfrom!=1),
163 branchloop=>$branches,
164 categoryloop=>\@categories,
170 actionname =>basename($0),
172 numresults => $count,
173 resultsloop => \@resultsdata,
176 output_html_with_http_headers $input, $cookie, $template->output;