bug 3464: Takes columns country and B_country of table borrowers into account in...
[koha.git] / members / member.pl
1 #!/usr/bin/perl
2
3
4 #script to do a borrower enquiry/bring up borrower details etc
5 #written 20/12/99 by chris@katipo.co.nz
6
7
8 # Copyright 2000-2002 Katipo Communications
9 #
10 # This file is part of Koha.
11 #
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.
16 #
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.
20 #
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
24
25 use strict;
26 use C4::Auth;
27 use C4::Output;
28 use CGI;
29 use C4::Members;
30
31
32 my $input = new CGI;
33 my $quicksearch = $input->param('quicksearch');
34 my $startfrom = $input->param('startfrom')||1;
35 my $resultsperpage = $input->param('resultsperpage')||C4::Context->preference("PatronsPerPage")||20;
36
37 my ($template, $loggedinuser, $cookie);
38 if($quicksearch){
39     ($template, $loggedinuser, $cookie)
40     = get_template_and_user({template_name => "members/member-quicksearch-results.tmpl",
41                  query => $input,
42                  type => "intranet",
43                  authnotrequired => 0,
44                  flagsrequired => {borrowers => 1},
45                  debug => 1,
46                  });
47 } else {
48     ($template, $loggedinuser, $cookie)
49     = get_template_and_user({template_name => "members/member.tmpl",
50                  query => $input,
51                  type => "intranet",
52                  authnotrequired => 0,
53                  flagsrequired => {borrowers => 1},
54                  debug => 1,
55                  });
56 }
57 my $theme = $input->param('theme') || "default";
58
59
60 $template->param( 
61         "AddPatronLists_".C4::Context->preference("AddPatronLists")=> "1",
62             );
63 if (C4::Context->preference("AddPatronLists")=~/code/){
64     my $categories=GetBorrowercategoryList;
65     $categories->[0]->{'first'}=1;
66     $template->param(categories=>$categories);  
67 }  
68             # only used if allowthemeoverride is set
69 #my %tmpldata = pathtotemplate ( template => 'member.tmpl', theme => $theme, language => 'fi' );
70     # FIXME - Error-checking
71 #my $template = HTML::Template->new( filename => $tmpldata{'path'},
72 #                   die_on_bad_params => 0,
73 #                   loop_context_vars => 1 );
74
75 my $member=$input->param('member');
76 my $orderby=$input->param('orderby');
77 $orderby = "surname,firstname" unless $orderby;
78 $member =~ s/,//g;   #remove any commas from search string
79 $member =~ s/\*/%/g;
80
81 my ($count,$results);
82
83 if(length($member) == 1)
84 {
85     ($count,$results)=SearchMember($member,$orderby,"simple");
86 }
87 else
88 {
89     ($count,$results)=SearchMember($member,$orderby,"advanced");
90 }
91
92
93 my @resultsdata;
94 my $to=($count>($startfrom*$resultsperpage)?$startfrom*$resultsperpage:$count);
95 for (my $i=($startfrom-1)*$resultsperpage; $i < $to; $i++){
96   #find out stats
97   my ($od,$issue,$fines)=GetMemberIssuesAndFines($results->[$i]{'borrowernumber'});
98
99   my %row = (
100     count => $i+1,
101     borrowernumber => $results->[$i]{'borrowernumber'},
102     cardnumber => $results->[$i]{'cardnumber'},
103     surname => $results->[$i]{'surname'},
104     firstname => $results->[$i]{'firstname'},
105     categorycode => $results->[$i]{'categorycode'},
106     category_type => $results->[$i]{'category_type'},
107     category_description => $results->[$i]{'description'},
108     address => $results->[$i]{'address'},
109         address2 => $results->[$i]{'address2'},
110     city => $results->[$i]{'city'},
111         zipcode => $results->[$i]{'zipcode'},
112         country => $results->[$i]{'country'},
113     branchcode => $results->[$i]{'branchcode'},
114     overdues => $od,
115     issues => $issue,
116     odissue => "$od/$issue",
117     fines =>  sprintf("%.2f",$fines),
118     borrowernotes => $results->[$i]{'borrowernotes'},
119     sort1 => $results->[$i]{'sort1'},
120     sort2 => $results->[$i]{'sort2'},
121     dateexpiry => C4::Dates->new($results->[$i]{'dateexpiry'},'iso')->output('syspref'),
122     );
123   push(@resultsdata, \%row);
124 }
125 my $base_url =
126     'member.pl?&amp;'
127   . join(
128     '&amp;',
129     map { $_->{term} . '=' . $_->{val} } (
130         { term => 'member', val => $member},
131         { term => 'orderby', val => $orderby },
132         { term => 'resultsperpage', val => $resultsperpage },
133         { term => 'type',           val => 'intranet' },
134     )
135   );
136
137 $template->param(
138     paginationbar => pagination_bar(
139         $base_url,  int( $count / $resultsperpage ) + 1,
140         $startfrom, 'startfrom'
141     ),
142     startfrom => $startfrom,
143     from      => ($startfrom-1)*$resultsperpage+1,  
144     to        => $to,
145     multipage => ($count != $to || $startfrom!=1),
146 );
147
148 $template->param( 
149         searching       => "1",
150         member          => $member,
151         numresults      => $count,
152         resultsloop     => \@resultsdata,
153             );
154
155 output_html_with_http_headers $input, $cookie, $template->output;