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