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.
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) {
62 $selected = 1 if $patron->{branchcode} && $branches->{$_}->{branchcode} eq $patron->{branchcode};
63 my %row = ( value => $_,
64 selected => $selected,
65 branchname => $branches->{$_}->{branchname},
67 push @branchloop, \%row;
70 my %categories_dislay;
72 foreach my $category (@categories){
74 category_description=>$$category{description},
75 category_type=>$$category{category_type}
77 $categories_dislay{$$category{categorycode}} = $hash;
79 my $AddPatronLists = C4::Context->preference("AddPatronLists") || '';
81 "AddPatronLists_$AddPatronLists" => "1",
83 if ($AddPatronLists=~/code/){
84 $categories[0]->{'first'}=1;
87 my $member=$input->param('member') || '';
88 my $orderbyparams=$input->param('orderby') || '';
91 my @orderbyelt=split(/,/,$orderbyparams);
92 push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0};
95 @orderby = ({surname=>0},{firstname=>0});
98 $member =~ s/,//g; #remove any commas from search string
101 my $from = ( $startfrom - 1 ) * $resultsperpage;
102 my $to = $from + $resultsperpage;
104 my ($count,$results);
105 if ($member || keys %$patron) {
106 my $searchfields = $input->param('searchfields') || '';
107 my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
109 if ( $searchfields eq "dateofbirth" ) {
110 $member = output_pref(dt_from_string($member), 'iso', undef, 1);
113 my $searchtype = $input->param('searchtype');
115 $quicksearch ? "field_start_with"
116 : $searchtype ? $searchtype
119 ($results) = Search( $member || $patron, \@orderby, undef, undef, \@searchfields, $search_scope );
123 for my $field ('categorycode','branchcode'){
124 next unless ($patron->{$field});
125 @$results = grep { $_->{$field} eq $patron->{$field} } @$results;
127 $count = scalar(@$results);
131 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . @$results[0]->{borrowernumber});
136 $to=($count>$to?$to:$count);
138 foreach my $borrower(@$results[$from..$to-1]){
140 my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
142 $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
147 (defined $categories_dislay{ $borrower->{categorycode} }? %{ $categories_dislay{ $borrower->{categorycode} } }:()),
150 odissue => "$od/$issue",
151 fines => sprintf("%.2f",$fines),
152 branchname => $branches->{$borrower->{branchcode}}->{branchname},
154 push(@resultsdata, \%row);
157 if ($$patron{categorycode}){
158 foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
159 $$category{selected}=1;
164 , 'orderby' => $orderbyparams
165 , 'resultsperpage' => $resultsperpage
166 , 'type'=> 'intranet');
171 map { "$_=$parameters{$_}" } (keys %parameters)
174 my @letters = map { {letter => $_} } ( 'A' .. 'Z');
177 letters => \@letters,
178 paginationbar => pagination_bar(
180 int( $count / $resultsperpage ) + ($count % $resultsperpage ? 1 : 0),
181 $startfrom, 'startfrom'
183 startfrom => $startfrom,
184 from => ($startfrom-1)*$resultsperpage+1,
186 multipage => ($count != $to || $startfrom!=1),
187 advsearch => ($$patron{categorycode} || $$patron{branchcode}),
188 branchloop=>\@branchloop,
189 categories=>\@categories,
191 actionname =>basename($0),
193 numresults => $count,
194 resultsloop => \@resultsdata,
197 output_html_with_http_headers $input, $cookie, $template->output;