Added PODs.
[koha.git] / moremember.pl
1 #!/usr/bin/perl
2
3 # script to do a borrower enquiry/bring up borrower details etc
4 # Displays all the details about a borrower
5 # written 20/12/99 by chris@katipo.co.nz
6 # last modified 21/1/2000 by chris@katipo.co.nz
7 # modified 31/1/2001 by chris@katipo.co.nz 
8 #   to not allow items on request to be renewed
9 #
10 # needs html removed and to use the C4::Output more, but its tricky
11 #
12
13
14 # Copyright 2000-2002 Katipo Communications
15 #
16 # This file is part of Koha.
17 #
18 # Koha is free software; you can redistribute it and/or modify it under the
19 # terms of the GNU General Public License as published by the Free Software
20 # Foundation; either version 2 of the License, or (at your option) any later
21 # version.
22 #
23 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
24 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
25 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
26 #
27 # You should have received a copy of the GNU General Public License along with
28 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
29 # Suite 330, Boston, MA  02111-1307 USA
30
31 use strict;
32 use C4::Output;
33 use CGI;
34 use C4::Search;
35 use Date::Manip;
36 use C4::Reserves2;
37 use C4::Circulation::Renewals2;
38 use C4::Circulation::Circ2;
39 use C4::Koha;
40 use C4::Database;
41
42 my $dbh=C4Connect;
43
44 my $input = new CGI;
45 my $bornum=$input->param('bornum');
46
47
48 print $input->header;
49
50 #start the page and read in includes
51 print startpage();
52 print startmenu('member');
53 my $data=borrdata('',$bornum);
54
55
56 $data->{'dateenrolled'} = slashifyDate($data->{'dateenrolled'});
57 $data->{'expiry'} = slashifyDate($data->{'expiry'});
58 $data->{'dateofbirth'} = slashifyDate($data->{'dateofbirth'});
59
60 $data->{'ethnicity'} = fixEthnicity($data->{'ethnicity'});
61
62 print <<printend
63 <FONT SIZE=6><em>$data->{'firstname'} $data->{'surname'}</em></FONT><P>
64 <p>
65 <form action=/cgi-bin/koha/jmemberentry.pl method=post>
66 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 align=left width=270>
67 <TR VALIGN=TOP>
68 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>MEMBERSHIP RECORD</TD></TR>
69 <tr VALIGN=TOP  >       
70 <TD>
71 <p align=right><INPUT TYPE="image" name="submit"  VALUE="add-child" height=42  WIDTH=120 BORDER=0 src="/images/add-child.gif">          
72 <input type=hidden name=type value=Add>
73 <input type=hidden name=bornum value=$data->{'borrowernumber'}>
74 </form>
75 </P><br>
76 <FONT SIZE=2  face="arial, helvetica">$data->{'title'} $data->{'othernames'}  $data->{'surname'} ($data->{'firstname'}, $data->{'initials'})<p>
77
78 Card Number: $data->{'cardnumber'}<BR>
79 printend
80 ;
81 if ($data->{'categorycode'} eq 'C'){
82     my $data2=borrdata('',$data->{'guarantor'});
83     $data->{'streetaddress'}=$data2->{'streetaddress'};
84     $data->{'city'}=$data2->{'city'};
85     $data->{'physstreet'}=$data2->{'phystreet'};
86     $data->{'streetcity'}=$data2->{'streetcity'};
87     $data->{'phone'}=$data2->{'phone'};
88     $data->{'phoneday'}=$data2->{'phoneday'};
89 }
90 my $ethnicityline='';
91 if ($data->{'ethnicity'} || $data->{'ethnotes'}) {
92         $ethnicityline="Ethnicity: $data->{'ethnicity'}, $data->{'ethnotes'}<br>";
93 }
94 print <<printend
95 Postal Address: $data->{'streetaddress'}, $data->{'city'}<BR>
96 Home Address: $data->{'physstreet'}, $data->{'streetcity'}<BR>
97 Phone (Home): $data->{'phone'}<BR>
98 Phone (Daytime): $data->{'phoneday'}<BR>
99 Fax: $data->{'faxnumber'}<BR>
100 E-mail: <a href="mailto:$data->{'emailaddress'}">$data->{'emailaddress'}</a><br>
101 Textmessaging:$data->{'textmessaging'}<p>
102 Membership Number: $data->{'borrowernumber'}<BR>
103 Membership: $data->{'categorycode'}<BR>
104 Area: $data->{'area'}<BR>
105 Fee:$30/year, Paid<BR>
106 Joined: $data->{'dateenrolled'},  Expires: $data->{'expiry'} <BR>
107 Joining Branch: $data->{'homebranch'}<P>
108 $ethnicityline
109 DoB: $data->{'dateofbirth'}<BR>
110 Sex: $data->{'sex'}<P>
111
112 Alternative Contact:$data->{'contactname'}<BR>
113 Phone: $data->{'altphone'}<BR>
114 Relationship: $data->{'altrelationship'}<BR>
115 Notes: $data->{'altnotes'}<P>
116 printend
117 ;
118
119 if ($data->{'categorycode'} ne 'C'){
120   print " Guarantees:";
121   # FIXME
122   # It looks like the $i is only being returned to handle walking through
123   # the array, which is probably better done as a foreach loop.
124   #
125   my ($count,$guarantees)=findguarantees($data->{'borrowernumber'});
126   for (my $i=0;$i<$count;$i++){
127     print "<A HREF=\"/cgi-bin/koha/moremember.pl?bornum=$guarantees->[$i]->{'borrowernumber'}\">$guarantees->[$i]->{'cardnumber'}</a><br>";
128   }
129 } else {
130   print "Guarantor:";
131   my ($guarantor)=findguarantor($data->{'borrowernumber'});
132   if ($guarantor->{'borrowernumber'} == 0){
133       print "no guarantor<br>";
134   } else {
135     print "<A HREF=\"/cgi-bin/koha/moremember.pl?bornum=$guarantor->{'borrowernumber'}\">$guarantor->{'cardnumber'}</a><br>";
136   }
137 }
138 print <<printend
139
140
141 <P>
142
143 General Notes: <!--<A HREF="popbox.html" onclick="messenger(200,250,'Form that lets you add to and delete notes.'); return false">-->
144 $data->{'borrowernotes'}<!--</a>-->
145 <p align=right>
146 <form action=/cgi-bin/koha/memberentry.pl method=post>
147 <input type=hidden name=bornum value=$bornum>
148 <INPUT TYPE="image" name="modify"  VALUE="modify" height=42  WIDTH=93 BORDER=0 src="/images/modify-mem.gif"> 
149
150 <INPUT TYPE="image" name="delete"  VALUE="delete" height=42  WIDTH=93 BORDER=0 src="/images/delete-mem.gif"> 
151 </p>
152
153 </TD>
154 </TR>
155 </TABLE>
156 </FORM>
157 <img src="/images/holder.gif" width=16 height=800 align=left>
158 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
159 <TR VALIGN=TOP>
160 <td  bgcolor="99cc33" background="/images/background-mem.gif" colspan=4><B>FINES & CHARGES</TD></TR>
161 printend
162 ;
163 my %bor;
164 $bor{'borrowernumber'}=$bornum;
165
166 # FIXME
167 # it looks like $numaccts is a temp variable and that the 
168 # for (my $i;$i<$numaccts;$i+++) 
169 # can be turned into a foreach loop instead
170 #
171 my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);
172 #if ($numaccts > 10){
173 #  $numaccts=10;
174 #}
175 for (my$i=0;$i<$numaccts;$i++){
176 #if ($accts->[$i]{'accounttype'} ne 'Pay'){
177   my $amount= $accts->[$i]{'amount'} + 0.00;
178     my $amount2= $accts->[$i]{'amountoutstanding'} + 0.00;
179   if ($amount2 != 0){
180     print "<tr VALIGN=TOP  >";
181     my $item=" &nbsp; ";
182     
183     $accts->[$i]{'date'} = slashifyDate($accts->[$i]{'date'});
184
185     if ($accts->[$i]{'accounttype'} ne 'Res'){
186     #get item data
187     #$item=
188     }
189     print "<td>$accts->[$i]{'date'}</td>";
190 #  print "<TD>$accts->[$i]{'accounttype'}</td>";
191     print "<TD>";
192
193     # FIXME
194     # why set this variable if it's not going to be used?
195     #
196     my $env;
197     if ($accts->[$i]{'accounttype'} ne 'Res'){
198       my $iteminfo=C4::Circulation::Circ2::getiteminformation($env,$accts->[$i]->{'itemnumber'},'');
199       print "<a href=/cgi-bin/koha/moredetail.pl?itemnumber=$accts->[$i]->{'itemnumber'}&bib=$iteminfo->{'biblionumber'}&bi=$iteminfo->{'biblioitemnumber'}>$accts->[$i]->{'description'} $accts->[$i]{'title'}</a>";
200     }
201     print "</td>
202     <TD>$amount</td><td>$amount2</td>
203     </tr>";
204   }
205 }
206 print <<printend
207
208 <tr VALIGN=TOP  >
209 <TD colspan=3 align=right>
210 <nobr>
211 <a href=/cgi-bin/koha/boraccount.pl?bornum=$bornum><img height=42  WIDTH=187 BORDER=0 src="/images/view-account.gif"></a>
212 <a href=/cgi-bin/koha/pay.pl?bornum=$bornum><img height=42  WIDTH=187 BORDER=0 src="/images/pay-fines.gif"></a></nobr>
213 </td>
214
215 </tr>
216
217
218 </table>
219
220 <p>
221 <form action="renewscript.pl" method=post>
222 <input type=hidden name=bornum value=$bornum>
223 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
224
225 <TR VALIGN=TOP>
226
227 <td  bgcolor="99cc33" background="/images/background-mem.gif" colspan=6><B>ITEMS CURRENTLY ON ISSUE</b></TD>
228 </TR>
229
230 <TR VALIGN=TOP>
231 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Title</b></TD>
232 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Due</b></TD>
233 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Itemtype</b></TD>
234 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Charge</b></TD>
235 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Renew</b></TD>
236 </TR>
237 printend
238 ;
239 my ($count,$issue)=borrissues($bornum);
240 my $today=ParseDate('today');
241 for (my $i=0;$i<$count;$i++){
242   print "<tr VALIGN=TOP  >
243   <TD>";
244     my $datedue=ParseDate($issue->[$i]{'date_due'});
245
246   $issue->[$i]{'date_due'} = slashifyDate($issue->[$i]{'date_due'});
247
248   if ($datedue < $today){  
249     print "<font color=red>";
250   }
251   print "$issue->[$i]{'title'} 
252   <a href=/cgi-bin/koha/moredetail.pl?item=$issue->[$i]->{'itemnumber'}&bib=$issue->[$i]->{'biblionumber'}&bi=$issue->[$i]->{'biblioitemnumber'}>
253   $issue->[$i]{'barcode'}</a></td>
254   <TD>$issue->[$i]{'date_due'}</td>";
255   #find the charge for an item
256   my ($charge,$itemtype)=calc_charges(undef,$dbh,$issue->[$i]{'itemnumber'},$bornum);
257   print "<TD>$itemtype</td>";
258   print "<TD>$charge</td>";
259
260 #  if ($datedue < $today){
261 #    print "<td>Overdue</td>";
262 #  } else {
263 #    print "<td> &nbsp; </td>";
264 #  }
265   #check item is not reserved
266   my ($rescount,$reserves)=Findgroupreserve($issue->[$i]{'biblioitemnumber'},$issue->[$i]{'biblionumber'});
267   if ($rescount >0){
268     print "<TD><a href=/cgi-bin/koha/request.pl?bib=$issue->[$i]{'biblionumber'}>On Request - no renewals</a></td></tr>";
269 #  } elsif ($issue->[$i]->{'renewals'} > 0) {
270 #      print "<TD>Previously Renewed - no renewals</td></tr>";
271   } else {
272     print "<TD>";
273   
274     print "<input type=radio name=\"renew_item_$issue->[$i]{'itemnumber'}\" value=y>Y
275     <input type=radio name=\"renew_item_$issue->[$i]{'itemnumber'}\" value=n>N</td>
276     </tr>
277     ";
278   }
279 }
280 print <<printend
281
282 <tr VALIGN=TOP  >
283 <TD colspan=5 align=right>
284 <INPUT TYPE="image" name="submit"  VALUE="update" height=42  WIDTH=187 BORDER=0 src="/images/update-renewals.gif">
285 </td>
286 </form>
287 </tr>
288
289
290 </table>
291
292
293 <P>
294
295 <TABLE  CELLSPACING=0  CELLPADDING=5 border=1 >
296
297 <TR VALIGN=TOP>
298
299 <td  bgcolor="99cc33" background="/images/background-mem.gif" colspan=5><B>ITEMS REQUESTED</b></TD>
300 </TR>
301
302 <TR VALIGN=TOP>
303
304 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Title</b></TD>
305 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Requested</b></TD>
306
307
308
309
310 <td  bgcolor="99cc33" background="/images/background-mem.gif"><B>Remove</b></TD>
311 </TR>
312 <form action=/cgi-bin/koha/modrequest.pl method=post>
313 <input type=hidden name=from value=borrower>
314 printend
315 ;
316
317 my ($rescount,$reserves)=FindReserves('',$bornum); #From C4::Reserves2
318
319 # FIXME
320 # does it make sense to turn this into a foreach my $i (0..$rescount) 
321 # kind of loop? 
322 #
323 for (my $i=0;$i<$rescount;$i++){
324   $reserves->[$i]{'reservedate2'} = slashifyDate($reserves->[$i]{'reservedate'});
325   my $restitle;
326   if ($reserves->[$i]{'constrainttype'} eq 'o'){
327       $restitle=getreservetitle($reserves->[$i]{'biblionumber'},$reserves->[$i]{'borrowernumber'},$reserves->[$i]{'reservedate'},$reserves->[$i]{'timestamp'});
328   } 
329   print "<tr VALIGN=TOP  >
330   <TD><a href=\"/cgi-bin/koha/request.pl?bib=$reserves->[$i]{'biblionumber'}\">$reserves->[$i]{'btitle'}</a> $restitle->{'volumeddesc'} $restitle->{'itemtype'}</td>
331   <TD>$reserves->[$i]{'reservedate2'}</td>
332   <input type=hidden name=biblio value=$reserves->[$i]{'biblionumber'}>
333   <input type=hidden name=borrower value=$bornum>
334
335   <TD><select name=\"rank-request\">
336   <option value=n>No
337   <option value=del>Yes
338   </select>
339   </tr>
340   ";
341 }
342 print <<printend
343
344 <tr VALIGN=TOP  >
345 <TD colspan=5 align=right>
346 <INPUT TYPE="image" name="submit"  VALUE="update" height=42  WIDTH=187 BORDER=0 src="/images/cancel-requests.gif"></td>
347 </tr>
348 </table>
349 </form>
350 <p align=right>
351 <a href=/cgi-bin/koha/readingrec.pl?bornum=$bornum><img height=42  WIDTH=187 BORDER=0 src="/images/reading-record.gif"></a>
352 </p>
353 printend
354 ;
355
356
357 print endmenu('member');
358 print endpage();
359
360
361 $dbh->disconnect;