Bug 7057: CheckReserves uses GetMemberDetails unnecessarily
[koha.git] / members / member.pl
blobe2a6ef54dd2c4e5467e9964dde3af7c3bf4453d4
1 #!/usr/bin/perl
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
16 # version.
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.
26 use strict;
27 #use warnings; FIXME - Bug 2505
28 use C4::Auth;
29 use C4::Output;
30 use CGI;
31 use C4::Members;
32 use C4::Branch;
33 use C4::Category;
34 use File::Basename;
36 my $input = new CGI;
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",
43 query => $input,
44 type => "intranet",
45 authnotrequired => 0,
46 flagsrequired => {borrowers => 1},
47 });
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;
58 my @branchloop;
60 foreach (sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches) {
61 my $selected = 1 if $branches->{$_}->{branchcode} eq $$patron{branchcode};
62 my %row = ( value => $_,
63 selected => $selected,
64 branchname => $branches->{$_}->{branchname},
66 push @branchloop, \%row;
69 my %categories_dislay;
71 foreach my $category (@categories){
72 my $hash={
73 category_description=>$$category{description},
74 category_type=>$$category{category_type}
76 $categories_dislay{$$category{categorycode}} = $hash;
78 my $AddPatronLists = C4::Context->preference("AddPatronLists") || '';
79 $template->param(
80 "AddPatronLists_$AddPatronLists" => "1",
82 if ($AddPatronLists=~/code/){
83 $categories[0]->{'first'}=1;
86 my $member=$input->param('member');
87 my $orderbyparams=$input->param('orderby');
88 my @orderby;
89 if ($orderbyparams){
90 my @orderbyelt=split(/,/,$orderbyparams);
91 push @orderby, {$orderbyelt[0]=>$orderbyelt[1]||0};
93 else {
94 @orderby = ({surname=>0},{firstname=>0});
97 $member =~ s/,//g; #remove any commas from search string
98 $member =~ s/\*/%/g;
100 my $from = ( $startfrom - 1 ) * $resultsperpage;
101 my $to = $from + $resultsperpage;
103 my ($count,$results);
104 if ($member || keys %$patron) {
105 #($results)=Search($member || $patron,{surname=>1,firstname=>1},[$from,$to],undef,["firstname","surname","email","othernames"] );
106 my $search_scope = ( $quicksearch ? "field_start_with" : "start_with" );
107 ($results) = Search( $member || $patron, \@orderby, undef, undef, [ "firstname", "surname", "othernames", "cardnumber", "userid" ], $search_scope );
110 if ($results) {
111 for my $field ('categorycode','branchcode'){
112 next unless ($patron->{$field});
113 @$results = grep { $_->{$field} eq $patron->{$field} } @$results;
115 $count = scalar(@$results);
118 if($count == 1){
119 print $input->redirect("/cgi-bin/koha/members/moremember.pl?borrowernumber=" . @$results[0]->{borrowernumber});
120 exit;
123 my @resultsdata;
124 $to=($count>$to?$to:$count);
125 my $index=$from;
126 foreach my $borrower(@$results[$from..$to-1]){
127 #find out stats
128 my ($od,$issue,$fines)=GetMemberIssuesAndFines($$borrower{'borrowernumber'});
130 $$borrower{'dateexpiry'}= C4::Dates->new($$borrower{'dateexpiry'},'iso')->output('syspref');
132 my %row = (
133 count => $index++,
134 %$borrower,
135 %{$categories_dislay{$$borrower{categorycode}}},
136 overdues => $od,
137 issues => $issue,
138 odissue => "$od/$issue",
139 fines => sprintf("%.2f",$fines),
141 push(@resultsdata, \%row);
144 if ($$patron{categorycode}){
145 foreach my $category (grep{$_->{categorycode} eq $$patron{categorycode}}@categories){
146 $$category{selected}=1;
149 my %parameters=
150 ( %$patron
151 , 'orderby' => $orderbyparams
152 , 'resultsperpage' => $resultsperpage
153 , 'type'=> 'intranet');
154 my $base_url =
155 'member.pl?&'
156 . join(
157 '&',
158 map { "$_=$parameters{$_}" } (keys %parameters)
161 my @letters = map { {letter => $_} } ( 'A' .. 'Z');
163 $template->param(
164 letters => \@letters,
165 paginationbar => pagination_bar(
166 $base_url,
167 int( $count / $resultsperpage ) + ($count % $resultsperpage ? 1 : 0),
168 $startfrom, 'startfrom'
170 startfrom => $startfrom,
171 from => ($startfrom-1)*$resultsperpage+1,
172 to => $to,
173 multipage => ($count != $to || $startfrom!=1),
174 advsearch => ($$patron{categorycode} || $$patron{branchcode}),
175 branchloop=>\@branchloop,
176 categories=>\@categories,
177 searching => "1",
178 actionname =>basename($0),
179 %$patron,
180 numresults => $count,
181 resultsloop => \@resultsdata,
184 output_html_with_http_headers $input, $cookie, $template->output;