MT1109 , follow-up to 888cde546e5c62d71f312755f4a1dbc8631626eb
[koha.git] / members / member.pl
blob9192be8ae61c8088d4b3a49f2843048d4df064f6
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
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
15 # version.
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
25 use strict;
26 use C4::Auth;
27 use C4::Output;
28 use CGI;
29 use C4::Members;
30 use C4::Branch;
31 use C4::Category;
33 my $input = new CGI;
34 my $quicksearch = $input->param('quicksearch');
35 my $startfrom = $input->param('startfrom')||1;
36 my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
38 my ($template, $loggedinuser, $cookie);
39 if($quicksearch){
40 ($template, $loggedinuser, $cookie)
41 = get_template_and_user({template_name => "members/member-quicksearch-results.tmpl",
42 query => $input,
43 type => "intranet",
44 authnotrequired => 0,
45 flagsrequired => {borrowers => 1},
46 debug => 1,
47 });
48 } else {
49 ($template, $loggedinuser, $cookie)
50 = get_template_and_user({template_name => "members/member.tmpl",
51 query => $input,
52 type => "intranet",
53 authnotrequired => 0,
54 flagsrequired => {borrowers => 1},
55 debug => 1,
56 });
58 my $theme = $input->param('theme') || "default";
61 $template->param(
62 "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
64 if (C4::Context->preference("AddPatronLists")=~/code/){
65 my $categories=GetBorrowercategoryList;
66 $categories->[0]->{'first'}=1;
67 $template->param(categories=>$categories);
69 # only used if allowthemeoverride is set
70 #my %tmpldata = pathtotemplate ( template => 'member.tmpl', theme => $theme, language => 'fi' );
71 # FIXME - Error-checking
72 #my $template = HTML::Template->new( filename => $tmpldata{'path'},
73 # die_on_bad_params => 0,
74 # loop_context_vars => 1 );
76 my $member=$input->param('member');
77 my $orderby=$input->param('orderby');
78 $orderby = "surname,firstname" unless $orderby;
79 $member =~ s/,//g; #remove any commas from search string
80 $member =~ s/\*/%/g;
82 my ($count,$results);
84 my $patron = $input->Vars;
85 foreach (keys %$patron){
86 delete $$patron{$_} unless($$patron{$_});
88 ($results)=Search($patron,{surname=>1,firstname=>1}) if (keys %$patron);
89 $count =scalar(@$results);
90 use YAML;
91 warn Dump($results);
92 unless ($count){
93 if(length($member) == 1)
95 ($count,$results)=SearchMember($member,$orderby,"simple");
97 else
99 ($count,$results)=SearchMember($member,$orderby,"advanced");
103 my @resultsdata;
104 my $to=($count>($startfrom*$resultsperpage)?$startfrom*$resultsperpage:$count);
105 for (my $i=($startfrom-1)*$resultsperpage; $i < $to; $i++){
106 #find out stats
107 my ($od,$issue,$fines)=GetMemberIssuesAndFines($results->[$i]{'borrowernumber'});
109 $$results[$i]{'dateexpiry'}= C4::Dates->new($results->[$i]{'dateexpiry'},'iso')->output('syspref');
111 my %row = (
112 count => $i+1,
113 %{$results->[$i]},
114 overdues => $od,
115 issues => $issue,
116 odissue => "$od/$issue",
117 fines => sprintf("%.2f",$fines),
119 push(@resultsdata, \%row);
121 my $base_url =
122 'member.pl?&amp;'
123 . join(
124 '&amp;',
125 map { $_->{term} . '=' . $_->{val} } (
126 { term => 'member', val => $member},
127 { term => 'orderby', val => $orderby },
128 { term => 'resultsperpage', val => $resultsperpage },
129 { term => 'type', val => 'intranet' },
133 my @categories=C4::Category->all;
134 $template->param(
135 paginationbar => pagination_bar(
136 $base_url, int( $count / $resultsperpage ) + 1,
137 $startfrom, 'startfrom'
139 startfrom => $startfrom,
140 from => ($startfrom-1)*$resultsperpage+1,
141 to => $to,
142 multipage => ($count != $to || $startfrom!=1),
143 branchloop=>GetBranchesLoop(),
144 categoryloop=>\@categories,
147 $template->param(
148 searching => "1",
149 member => $member,
150 numresults => $count,
151 resultsloop => \@resultsdata,
154 output_html_with_http_headers $input, $cookie, $template->output;