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.
34 use Koha
::List
::Patron
;
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 $add_to_patron_list = $input->param('add_to_patron_list');
52 my $add_to_patron_list_which = $input->param('add_to_patron_list_which');
53 my $new_patron_list = $input->param('new_patron_list');
54 my @borrowernumbers = $input->param('borrowernumber');
56 'add_to_patron_list', 'add_to_patron_list_which',
57 'new_patron_list', 'borrowernumber',
60 my $patron = $input->Vars;
61 foreach (keys %$patron){
62 delete $$patron{$_} unless($$patron{$_});
64 my @categories=C4
::Category
->all;
66 my $branches = GetBranches
;
69 foreach (sort { $branches->{$a}->{branchname
} cmp $branches->{$b}->{branchname
} } keys %$branches) {
71 $selected = 1 if $patron->{branchcode
} && $branches->{$_}->{branchcode
} eq $patron->{branchcode
};
72 my %row = ( value
=> $_,
73 selected
=> $selected,
74 branchname
=> $branches->{$_}->{branchname
},
76 push @branchloop, \
%row;
79 my %categories_dislay;
81 foreach my $category (@categories){
83 category_description
=>$$category{description
},
84 category_type
=>$$category{category_type
}
86 $categories_dislay{$$category{categorycode
}} = $hash;
88 my $AddPatronLists = C4
::Context
->preference("AddPatronLists") || '';
90 "AddPatronLists_$AddPatronLists" => "1",
92 if ($AddPatronLists=~/code/){
93 $categories[0]->{'first'}=1;
96 my $member=$input->param('member') || '';
97 my $orderbyparams=$input->param('orderby') || '';
100 my @orderbyelt=split(/,/,$orderbyparams);
101 push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0};
104 @orderby = ({surname
=>0},{firstname
=>0});
107 $member =~ s/,//g; #remove any commas from search string
110 my $from = ( $startfrom - 1 ) * $resultsperpage;
111 my $to = $from + $resultsperpage;
113 my ($count,$results);
114 if ($member || keys %$patron) {
115 my $searchfields = $input->param('searchfields') || '';
116 my @searchfields = $searchfields ?
split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
118 if ( $searchfields eq "dateofbirth" ) {
119 $member = output_pref
({dt
=> dt_from_string
($member), dateformat
=> 'iso', dateonly
=> 1});
122 my $searchtype = $input->param('searchtype');
124 $quicksearch ?
"field_start_with"
125 : $searchtype ?
$searchtype
128 ($results) = Search
( $member || $patron, \
@orderby, undef, undef, \
@searchfields, $search_scope );
131 if ($add_to_patron_list) {
134 if ( $add_to_patron_list eq 'new' ) {
135 $patron_list = AddPatronList
( { name
=> $new_patron_list } );
139 [ GetPatronLists
( { patron_list_id
=> $add_to_patron_list } ) ]->[0];
142 if ( $add_to_patron_list_which eq 'all' ) {
143 @borrowernumbers = map { $_->{borrowernumber
} } @
$results;
146 my @patrons_added_to_list = AddPatronsToList
( { list
=> $patron_list, borrowernumbers
=> \
@borrowernumbers } );
149 patron_list
=> $patron_list,
150 patrons_added_to_list
=> \
@patrons_added_to_list,
155 for my $field ('categorycode','branchcode'){
156 next unless ($patron->{$field});
157 @
$results = grep { $_->{$field} eq $patron->{$field} } @
$results;
159 $count = scalar(@
$results);
165 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . @
$results[0]->{borrowernumber
});
170 $to=($count>$to?
$to:$count);
172 foreach my $borrower(@
$results[$from..$to-1]){
174 my ($od,$issue,$fines)=GetMemberIssuesAndFines
($$borrower{'borrowernumber'});
176 $$borrower{'dateexpiry'}= C4
::Dates
->new($$borrower{'dateexpiry'},'iso')->output('syspref');
181 (defined $categories_dislay{ $borrower->{categorycode
} }?
%{ $categories_dislay{ $borrower->{categorycode
} } }:()),
184 odissue
=> "$od/$issue",
185 fines
=> sprintf("%.2f",$fines),
186 branchname
=> $branches->{$borrower->{branchcode
}}->{branchname
},
188 push(@resultsdata, \
%row);
191 if ($$patron{categorycode
}){
192 foreach my $category (grep{$_->{categorycode
} eq $$patron{categorycode
}}@categories){
193 $$category{selected
}=1;
198 , 'orderby' => $orderbyparams
199 , 'resultsperpage' => $resultsperpage
200 , 'type'=> 'intranet');
205 map { "$_=$parameters{$_}" } (keys %parameters)
208 my @letters = map { {letter
=> $_} } ( 'A' .. 'Z');
212 letters
=> \
@letters,
213 paginationbar
=> pagination_bar
(
215 int( $count / $resultsperpage ) + ( $count % $resultsperpage ?
1 : 0 ),
219 startfrom
=> $startfrom,
220 from
=> ( $startfrom - 1 ) * $resultsperpage + 1,
222 multipage
=> ( $count != $to || $startfrom != 1 ),
223 advsearch
=> ( $$patron{categorycode
} || $$patron{branchcode
} ),
224 branchloop
=> \
@branchloop,
225 categories
=> \
@categories,
227 numresults
=> $count,
228 resultsloop
=> \
@resultsdata,
229 results_per_page
=> $resultsperpage,
231 search_parameters
=> \
%parameters,
232 patron_lists
=> [ GetPatronLists
() ],
235 output_html_with_http_headers
$input, $cookie, $template->output;