Handle non-latin1 charsets
[koha.git] / moremember.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # script to do a borrower enquiry/bring up borrower details etc
6 # Displays all the details about a borrower
7 # written 20/12/99 by chris@katipo.co.nz
8 # last modified 21/1/2000 by chris@katipo.co.nz
9 # modified 31/1/2001 by chris@katipo.co.nz
10 #   to not allow items on request to be renewed
11 #
12 # needs html removed and to use the C4::Output more, but its tricky
13 #
14
15
16 # Copyright 2000-2002 Katipo Communications
17 #
18 # This file is part of Koha.
19 #
20 # Koha is free software; you can redistribute it and/or modify it under the
21 # terms of the GNU General Public License as published by the Free Software
22 # Foundation; either version 2 of the License, or (at your option) any later
23 # version.
24 #
25 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
26 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
27 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
28 #
29 # You should have received a copy of the GNU General Public License along with
30 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
31 # Suite 330, Boston, MA  02111-1307 USA
32
33 use strict;
34 use C4::Auth;
35 use C4::Context;
36 use C4::Output;
37 use C4::Charset;
38 use CGI;
39 use C4::Search;
40 use Date::Manip;
41 use C4::Reserves2;
42 use C4::Circulation::Renewals2;
43 use C4::Circulation::Circ2;
44 use C4::Koha;
45 use HTML::Template;
46
47 my $dbh = C4::Context->dbh;
48
49 my $input = new CGI;
50
51 my ($template, $loggedinuser, $cookie)
52     = get_template_and_user({template_name => "members/moremember.tmpl",
53                              query => $input,
54                              type => "intranet",
55                              authnotrequired => 0,
56                              flagsrequired => {borrowers => 1},
57                              debug => 1,
58                              });
59
60 my $bornum=$input->param('bornum');
61
62 #start the page and read in includes
63
64 my $data=borrdata('',$bornum);
65
66 $data->{'dateenrolled'} = slashifyDate($data->{'dateenrolled'});
67 $data->{'expiry'} = slashifyDate($data->{'expiry'});
68 $data->{'dateofbirth'} = slashifyDate($data->{'dateofbirth'});
69
70 $data->{'ethnicity'} = fixEthnicity($data->{'ethnicity'});
71
72 if ($data->{'categorycode'} eq 'C'){
73     my $data2=borrdata('',$data->{'guarantor'});
74     $data->{'streetaddress'}=$data2->{'streetaddress'};
75     $data->{'city'}=$data2->{'city'};
76     $data->{'physstreet'}=$data2->{'phystreet'};
77     $data->{'streetcity'}=$data2->{'streetcity'};
78     $data->{'phone'}=$data2->{'phone'};
79     $data->{'phoneday'}=$data2->{'phoneday'};
80 }
81
82
83 if ($data->{'ethnicity'} || $data->{'ethnotes'}) {
84         $template->param(printethnicityline => 1);
85 }
86
87 if ($data->{'categorycode'} ne 'C'){
88   $template->param(isguarantee => 1);
89   # FIXME
90   # It looks like the $i is only being returned to handle walking through
91   # the array, which is probably better done as a foreach loop.
92   #
93   my ($count,$guarantees)=findguarantees($data->{'borrowernumber'});
94   my @guaranteedata;
95   for (my $i=0;$i<$count;$i++){
96     push (@guaranteedata, {borrowernumber => $guarantees->[$i]->{'borrowernumber'},
97                            cardnumber => $guarantees->[$i]->{'cardnumber'}});
98   }
99   $template->param(guaranteeloop => \@guaranteedata);
100
101 } else {
102   my ($guarantor)=findguarantor($data->{'borrowernumber'});
103   unless ($guarantor->{'borrowernumber'} == 0){
104     $template->param(guarantorborrowernumber => $guarantor->{'borrowernumber'}, guarantorcardnumber => $guarantor->{'cardnumber'});
105   }
106 }
107
108 my %bor;
109 $bor{'borrowernumber'}=$bornum;
110
111 # FIXME
112 # it looks like $numaccts is a temp variable and that the
113 # for (my $i;$i<$numaccts;$i++)
114 # can be turned into a foreach loop instead
115 #
116 my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);
117 #if ($numaccts > 10){
118 #  $numaccts=10;
119 #}
120 my @accountdata;
121 for (my$i=0;$i<$numaccts;$i++){
122   my $amount= $accts->[$i]{'amount'} + 0.00;
123   my $amount2= $accts->[$i]{'amountoutstanding'} + 0.00;
124   my %row = %$accts->[$i];
125   if ($amount2 != 0){
126     my $item=" &nbsp; ";
127     $row{'date'} = slashifyDate($accts->[$i]{'date'});
128
129     if ($accts->[$i]{'accounttype'} ne 'Res'){
130       #get item data
131       #$item=
132     }
133
134     # FIXME
135     # why set this variable if it's not going to be used?
136     #
137     my $env;
138     if ($accts->[$i]{'accounttype'} ne 'Res'){
139       my $iteminfo=C4::Circulation::Circ2::getiteminformation($env,$accts->[$i]->{'itemnumber'},'');
140    # FIXME, seems to me $iteminfo gets not defined
141       %row = (%row , %$iteminfo) if $iteminfo;
142     }
143   }
144   push (@accountdata, \%row);
145 }
146
147 my ($count,$issue)=borrissues($bornum);
148 my $today=ParseDate('today');
149 my @issuedata;
150 for (my $i=0;$i<$count;$i++){
151   my $datedue=ParseDate($issue->[$i]{'date_due'});
152   $issue->[$i]{'date_due'} = slashifyDate($issue->[$i]{'date_due'});
153   my %row = %{$issue->[$i]};
154   if ($datedue < $today){
155     $row{'red'}=1; #print "<font color=red>";
156   }
157   #find the charge for an item
158   # FIXME - This is expecting
159   # &C4::Circulation::Renewals2::calc_charges, but it's getting
160   # &C4::Circulation::Circ2::calc_charges, which only returns one
161   # element, so itemtype isn't being set.
162   # But &C4::Circulation::Renewals2::calc_charges doesn't appear to
163   # return the correct item type either (or a properly-formatted
164   # charge, for that matter).
165   my ($charge,$itemtype)=calc_charges(undef,$dbh,$issue->[$i]{'itemnumber'},$bornum);
166   $row{'itemtype'}=$itemtype;
167   $row{'charge'}=$charge;
168
169   #check item is not reserved
170   my ($restype,$reserves)=CheckReserves($issue->[$i]{'itemnumber'});
171   if ($restype){
172     print "<TD><a href=/cgi-bin/koha/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
173 #  } elsif ($issue->[$i]->{'renewals'} > 0) {
174 #      print "<TD>Previously Renewed - no renewals</td></tr>";
175   } else {
176     $row{'norenew'}=0;
177   }
178   push (@issuedata, \%row);
179 }
180
181 my ($rescount,$reserves)=FindReserves('',$bornum); #From C4::Reserves2
182
183 # FIXME
184 # does it make sense to turn this into a foreach my $i (0..$rescount)
185 # kind of loop?
186 #
187 my @reservedata;
188 for (my $i=0;$i<$rescount;$i++){
189   $reserves->[$i]{'reservedate2'} = slashifyDate($reserves->[$i]{'reservedate'});
190   my $restitle;
191   my %row = %$reserves->[$i];
192   if ($reserves->[$i]{'constrainttype'} eq 'o'){
193     $restitle=getreservetitle($reserves->[$i]{'biblionumber'},$reserves->[$i]{'borrowernumber'},$reserves->[$i]{'reservedate'},$reserves->[$i]{'timestamp'});
194     %row =  (%row , %$restitle);
195   }
196   push (@reservedata, \%row);
197 }
198
199 $template->param($data);
200 $template->param(
201                  bornum          => $bornum,
202                  accountloop     => \@accountdata,
203                  issueloop       => \@issuedata,
204                  reserveloop     => \@reservedata);
205
206 print $input->header(
207     -type => guesstype($template->output),
208     -cookie => $cookie
209 ),$template->output;