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.
35 use Koha::List::Patron;
38 my $quicksearch = $input->param('quicksearch') || '';
39 my $startfrom = $input->param('startfrom') || 1;
40 my $resultsperpage = $input->param('resultsperpage') || C4::Context->preference("PatronsPerPage") || 20;
42 my ($template, $loggedinuser, $cookie)
43 = get_template_and_user({template_name => "members/member.tmpl",
47 flagsrequired => {borrowers => 1},
50 my $theme = $input->param('theme') || "default";
52 my $add_to_patron_list = $input->param('add_to_patron_list');
53 my $add_to_patron_list_which = $input->param('add_to_patron_list_which');
54 my $new_patron_list = $input->param('new_patron_list');
55 my @borrowernumbers = $input->param('borrowernumber');
57 'add_to_patron_list', 'add_to_patron_list_which',
58 'new_patron_list', 'borrowernumber',
61 my $patron = $input->Vars;
62 foreach (keys %$patron){
63 delete $$patron{$_} unless($$patron{$_});
65 my @categories=C4::Category->all;
67 my $branches = GetBranches;
70 foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
72 $selected = 1 if $patron->{branchcode} && $branches->{$_}->{branchcode} eq $patron->{branchcode};
73 my %row = ( value => $_,
74 selected => $selected,
75 branchname => $branches->{$_}->{branchname},
77 push @branchloop, \%row;
80 my %categories_dislay;
82 foreach my $category (@categories){
84 category_description=>$$category{description},
85 category_type=>$$category{category_type}
87 $categories_dislay{$$category{categorycode}} = $hash;
89 my $AddPatronLists = C4::Context->preference("AddPatronLists") || '';
91 "AddPatronLists_$AddPatronLists" => "1",
93 if ($AddPatronLists=~/code/){
94 $categories[0]->{'first'}=1;
97 my $member=$input->param('member') || '';
98 my $orderbyparams=$input->param('orderby') || '';
101 my @orderbyelt=split(/,/,$orderbyparams);
102 push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0};
105 @orderby = ({surname=>0},{firstname=>0});
108 $member =~ s/,//g; #remove any commas from search string
111 my $from = ( $startfrom - 1 ) * $resultsperpage;
112 my $to = $from + $resultsperpage;
114 my ($count,$results);
115 if ($member || keys %$patron) {
116 my $searchfields = $input->param('searchfields') || '';
117 my @searchfields = $searchfields ? split( ',', $searchfields ) : ( "firstname", "surname", "othernames", "cardnumber", "userid", "email" );
119 if ( $searchfields eq "dateofbirth" ) {
120 $member = output_pref({dt => dt_from_string($member), dateformat => 'iso', dateonly => 1});
123 my $searchtype = $input->param('searchtype');
125 $quicksearch ? "field_start_with"
126 : $searchtype ? $searchtype
129 ($results) = Search( $member || $patron, \@orderby, undef, undef, \@searchfields, $search_scope );
132 if ($add_to_patron_list) {
135 if ( $add_to_patron_list eq 'new' ) {
136 $patron_list = AddPatronList( { name => $new_patron_list } );
140 [ GetPatronLists( { patron_list_id => $add_to_patron_list } ) ]->[0];
143 if ( $add_to_patron_list_which eq 'all' ) {
144 @borrowernumbers = map { $_->{borrowernumber} } @$results;
147 my @patrons_added_to_list = AddPatronsToList( { list => $patron_list, borrowernumbers => \@borrowernumbers } );
150 patron_list => $patron_list,
151 patrons_added_to_list => \@patrons_added_to_list,
156 for my $field ('categorycode','branchcode'){
157 next unless ($patron->{$field});
158 @$results = grep { $_->{$field} eq $patron->{$field} } @$results;
160 $count = scalar(@$results);
166 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . @$results[0]->{borrowernumber});
171 $to=($count>$to?$to:$count);
173 foreach my $borrower(@$results[$from..$to-1]){
175 my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
177 $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
182 (defined $categories_dislay{ $borrower->{categorycode} }? %{ $categories_dislay{ $borrower->{categorycode} } }:()),
185 odissue => "$od/$issue",
186 fines => sprintf("%.2f",$fines),
187 branchname => $branches->{$borrower->{branchcode}}->{branchname},
189 push(@resultsdata, \%row);
192 if ($$patron{categorycode}){
193 foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
194 $$category{selected}=1;
199 , 'orderby' => $orderbyparams
200 , 'resultsperpage' => $resultsperpage
201 , 'type'=> 'intranet');
206 map { "$_=$parameters{$_}" } (keys %parameters)
209 my @letters = map { {letter => $_} } ( 'A' .. 'Z');
213 letters => \@letters,
214 paginationbar => pagination_bar(
216 int( $count / $resultsperpage ) + ( $count % $resultsperpage ? 1 : 0 ),
220 startfrom => $startfrom,
221 from => ( $startfrom - 1 ) * $resultsperpage + 1,
223 multipage => ( $count != $to || $startfrom != 1 ),
224 advsearch => ( $$patron{categorycode} || $$patron{branchcode} ),
225 branchloop => \@branchloop,
226 categories => \@categories,
228 actionname => basename($0),
229 numresults => $count,
230 resultsloop => \@resultsdata,
231 results_per_page => $resultsperpage,
233 search_parameters => \%parameters,
234 patron_lists => [ GetPatronLists() ],
237 output_html_with_http_headers $input, $cookie, $template->output;