Implemented fixes for bug 170
[koha.git] / circ / circulation.pl
1 #!/usr/bin/perl
2 # Please use 8-character tabs for this file (indents are every 4 characters)
3
4 #written 8/5/2002 by Finlay
5 #script to execute issuing of books
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 CGI;
27 use C4::Circulation::Circ2;
28 use C4::Search;
29 use C4::Output;
30 use C4::Print;
31 use DBI;
32 use C4::Auth;
33
34 my $query=new CGI;
35 my ($loggedinuser, $sessioncookie, $sessionID) = checkauth($query);
36
37
38 my %env;
39 my $headerbackgroundcolor='#99cc33';
40 my $circbackgroundcolor='#ffffcc';      # FIXME - Never used
41 my $circbackgroundcolor='white';        # FIXME - Never used
42 my $linecolor1='#ffffcc';
43 my $linecolor2='white';
44 my $backgroundimage="/images/background-mem.gif";
45
46 my $branches = getbranches();
47 my $printers = getprinters(\%env);
48
49 my $query = new CGI;
50
51 my $branch = getbranch($query, $branches);
52 my $printer = getprinter($query, $printers);
53
54
55 #set up cookie.....
56 my $info = '';
57 my $branchcookie;
58 my $printercookie;
59 if ($query->param('setcookies')) {
60     $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
61     $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
62 }
63
64 $env{'branchcode'}=$branch;
65 $env{'printer'}=$printer;
66 $env{'queue'}=$printer;
67
68 my @datearr = localtime(time());
69 my $tday = localtime(time());           # FIXME - Unused
70 #warn "today: $tday \n";
71 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
72 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
73 #warn $todaysdate;
74
75
76 my $message;
77 my $borrowerslist;
78 # if there is a list of find borrowers....
79 my $findborrower = $query->param('findborrower');
80 if ($findborrower) {
81     my ($borrowers, $flags) = findborrower(\%env, $findborrower);
82     my @borrowers=@$borrowers;
83     if ($#borrowers == -1) {
84         $query->param('findborrower', '');
85         $message =  "No borrower matched '$findborrower'";
86     } elsif ($#borrowers == 0) {
87         $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
88         $query->param('barcode','');
89     } else {
90         $borrowerslist = \@borrowers;
91     }
92 }
93
94 my $borrowernumber = $query->param('borrnumber');
95 my $bornum = $query->param('borrnumber');
96 # check and see if we should print
97 my $print=$query->param('print');
98 my $barcode = $query->param('barcode');
99 if ($barcode eq ''  && $print eq 'maybe'){
100     $print = 'yes';
101 }
102 if ($print eq 'yes' && $borrowernumber ne ''){
103     printslip(\%env,$borrowernumber);
104     $query->param('borrnumber','');
105     $borrowernumber='';
106 }
107
108
109
110 # get the borrower information.....
111 my $borrower;
112 my $flags;
113 if ($borrowernumber) {
114     ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
115 }
116
117 # get the responses to any questions.....
118 my %responses;
119 foreach (sort $query->param) {
120     if ($_ =~ /response-(\d*)/) {
121         $responses{$1} = $query->param($_);
122     }
123 }
124 if (my $qnumber = $query->param('questionnumber')) {
125     $responses{$qnumber} = $query->param('answer');
126 }
127
128
129
130 my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer);
131
132 my $year=$query->param('year');
133 my $month=$query->param('month');
134 my $day=$query->param('day');
135
136 # if the barcode is set
137 if ($barcode) {
138     $barcode = cuecatbarcodedecode($barcode);
139     my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
140
141     unless ($invalidduedate) {
142         $env{'datedue'}=$datedue;
143         my @time=localtime(time);
144         my $date= (1900+$time[5])."-".($time[4]+1)."-".$time[3];
145         ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer, $message)
146                      = issuebook(\%env, $borrower, $barcode, \%responses, $date);
147     }
148 }
149
150 # reload the borrower info for the sake of reseting the flags.....
151 if ($borrowernumber) {
152     ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
153 }
154
155
156 ##################################################################################
157 # HTML code....
158
159
160 my $rejectedtext;
161 if ($rejected) {
162     if ($rejected == -1) {
163     } else {
164         $rejectedtext = << "EOF";
165 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
166 <tr><th><font color=black size=5>Error Issuing Book</font></th></tr>
167 <tr><td><font color=red size=5>$rejected</font></td></tr>
168 </table>
169 <br>
170 EOF
171     }
172 }
173
174 my $selectborrower;
175 if ($borrowerslist) {
176     $selectborrower = <<"EOF";
177 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
178 <input type=hidden name=branch value=$branch>
179 <input type=hidden name=printer value=$printer>
180 <table border=1 cellspacing=0 cellpadding=5 bgcolor="#dddddd">
181 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
182 <font color=black><b>Select a borrower</b></font></th></tr>\n
183 <tr><td align=center>
184 <select name=borrnumber size=7>
185 EOF
186     foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
187         $selectborrower .= <<"EOF";
188 <option value=$_->{'borrowernumber'}>$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})
189 EOF
190     }
191     $selectborrower .= <<"EOF";
192 </select><br>
193 <input type=submit>
194 </td></tr></table>
195 EOF
196 }
197
198 # title....
199 my $title = <<"EOF";
200 <table align="right"><tr><td>
201 <a href=circulation.pl?borrnumber=$borrowernumber&branch=$branch&printer=$printer&print=yes>
202 <img src="/images/button-next-borrower.gif" width="171" height="42" border="0" alt="Next Borrower"></a> &nbsp
203 <a href=returns.pl>
204 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
205 &nbsp<a href=branchtransfers.pl><img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Transfers"></a>
206 </td></tr></table>
207 <FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
208 <b>Branch:</b> $branches->{$branch}->{'branchname'} &nbsp
209 <b>Printer:</b> $printers->{$printer}->{'printername'} <br>
210 <a href=selectbranchprinter.pl>Change Settings</a></td>
211 <input type=hidden name=branch value=$branch>
212 <input type=hidden name=printer value=$printer>
213 <p>
214 EOF
215
216 my $titlenoborrower = <<"EOF";
217 <table align="right"><tr><td>
218 <a href=returns.pl>
219 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
220 &nbsp<a href=branchtransfers.pl><img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Transfers"></a>
221 </td></tr></table>
222 <FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
223 <b>Branch:</b> $branches->{$branch}->{'branchname'} &nbsp
224 <b>Printer:</b> $printers->{$printer}->{'printername'} <br>
225 <a href=selectbranchprinter.pl>Change Settings</a></td>
226 <input type=hidden name=branch value=$branch>
227 <input type=hidden name=printer value=$printer>
228 <p>
229 EOF
230
231
232
233 my $cardnumberinput = << "EOF";
234 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
235 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
236 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
237 <font color=black><b>Enter borrower card number<br> or partial last name</b></font></td></tr>
238 <tr><td><input name=findborrower></td></tr>
239   <input type=hidden name=branch value=$branch>
240 <input type=hidden name=printer value=$printer>
241 </table>
242 </form>
243 EOF
244
245 my $responsesform = '';
246 foreach (keys %responses) {
247     $responsesform.="<input type=hidden name=response-$_ value=$responses{$_}>\n";
248 }
249 my $questionform;
250 if ($question) {
251     my $stickyduedate=$query->param('stickyduedate');
252     $questionform = <<"EOF";
253 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
254 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
255 <font size=+2 color=red><b>Issuing Question</b></font></th></tr>
256 <tr><td><table border=0 cellpadding=10><tr><td>
257 Attempting to issue $iteminformation->{'title'}
258 by $iteminformation->{'author'} to $borrower->{'firstname'} $borrower->{'surname'}.
259 <p>
260 $question
261 </td></tr></table></td></tr>
262 <tr><td align=center>
263 <table border=0>
264 <tr><td>
265 <form method=get>
266 <input type=hidden name=borrnumber value=$borrowernumber>
267 <input type=hidden name=barcode value=$barcode>
268 <input type=hidden name=questionnumber value=$questionnumber>
269 <input type=hidden name=day value=$day>
270 <input type=hidden name=month value=$month>
271 <input type=hidden name=year value=$year>
272 <input type=hidden name=stickyduedate value=$stickyduedate>
273 <input type=hidden name=branch value=$branch>
274 <input type=hidden name=printer value=$printer>
275 $responsesform
276 <input type=hidden name=answer value=Y>
277 <input type=submit value=Yes>
278 </form>
279 </td>
280 <td>
281 <form method=get>
282 <input type=hidden name=borrnumber value=$borrowernumber>
283 <input type=hidden name=barcode value=$barcode>
284 <input type=hidden name=questionnumber value=$questionnumber>
285 <input type=hidden name=day value=$day>
286 <input type=hidden name=month value=$month>
287 <input type=hidden name=year value=$year>
288 <input type=hidden name=stickyduedate value=$stickyduedate>
289 <input type=hidden name=branch value=$branch>
290 <input type=hidden name=printer value=$printer>
291 $responsesform
292 <input type=hidden name=answer value=N>
293 <input type=submit value=No>
294 </form>
295 </td>
296 </tr>
297 </table>
298 </td></tr>
299 </table>
300 </td></tr>
301 </table>
302 EOF
303 }
304
305
306 # Barcode entry box, with hidden inputs attached....
307 my $counter = 1;
308 my $dayoptions = '';
309 my $monthoptions = '';
310 my $yearoptions = '';
311 for (my $i=1; $i<32; $i++) {
312     my $selected='';
313     if (($query->param('stickyduedate')) && ($day==$i)) {
314         $selected='selected';
315     }
316     $dayoptions.="<option value=$i $selected>$i";
317 }
318 foreach (('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) {
319     my $selected='';
320     if (($query->param('stickyduedate')) && ($month==$counter)) {
321         $selected='selected';
322     }
323     $monthoptions.="<option value=$counter $selected>$_";
324     $counter++;
325 }
326 for (my $i=$datearr[5]+1900; $i<$datearr[5]+1905; $i++) {
327     my $selected='';
328     if (($query->param('stickyduedate')) && ($year==$i)) {
329         $selected='selected';
330     }
331     $yearoptions.="<option value=$i $selected>$i";
332 }
333 my $selected='';
334 ($query->param('stickyduedate')) && ($selected='checked');
335
336
337 my $barcodeentrytext = <<"EOF";
338 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
339 <table border=1 cellpadding=5>
340 <tr>
341 <td align=center valign=top>
342 <table border=0 cellspacing=0 cellpadding=5>
343 <tr><th align=center background=$backgroundimage>
344 <font color=black><b>Enter Book Barcode</b></font></th></tr>
345 <tr><td align=center>
346 <table border=0>
347 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td><td><input type=submit value=Issue></td></tr>
348 <tr><td colspan=3 align=center>
349 <table border=0 cellpadding=0 cellspacing=0>
350 <tr><td>
351 <select name=day><option value=0>Day$dayoptions</select>
352 </td><td>
353 <select name=month><option value=0>Month$monthoptions</select>
354 </td><td>
355 <select name=year><option value=0>Year$yearoptions</select>
356 </td></tr>
357 </table>
358 <input type=checkbox name=stickyduedate $selected> Sticky Due Date
359 </td></tr>
360 </table>
361 <input type=hidden name=borrnumber value=$borrowernumber>
362 <input type=hidden name=branch value=$branch>
363 <input type=hidden name=printer value=$printer>
364 <input type=hidden name=print value=maybe>
365 EOF
366 if ($flags->{'CHARGES'}){
367     $barcodeentrytext.="<input type=hidden name=charges value=yes>";
368 }
369 my $amountold=$flags->{'CHARGES'}->{'message'};
370 my @temp=split(/\$/,$amountold);
371 $amountold=$temp[1];
372 $barcodeentrytext.="<input type=hidden name=oldamount value=$amountold>";
373 $barcodeentrytext.=<<"EOF";
374 </td></tr></table>
375 </td></tr></table>
376 </form>
377 EOF
378
379
380 # collect the messages and put into message table....
381 my $messagetable;
382 if ($message) {
383     $messagetable = << "EOF";
384 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
385 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
386 <tr><td> $message </td></tr></table>
387 EOF
388 }
389
390
391
392 # make the issued books table.....
393 my $todaysissues='';
394 my $previssues='';
395 if ($borrower) {
396     my @todaysissues;
397     my @previousissues;
398     my $issueslist = getissues($borrower);
399     foreach my $it (keys %$issueslist) {
400         my $issuedate = $issueslist->{$it}->{'timestamp'};
401         $issuedate = substr($issuedate, 0, 8);
402         if ($todaysdate == $issuedate) {
403             push @todaysissues, $issueslist->{$it};
404         } else {
405             push @previousissues, $issueslist->{$it};
406         }
407     }
408     my $tcolor = '';
409     my $pcolor = '';
410     foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
411         my $dd = $book->{'date_due'};
412         my $datedue = $book->{'date_due'};
413         #convert to nz style dates
414         #this should be set with some kinda config variable
415         my @tempdate=split(/-/,$dd);
416         $dd="$tempdate[2]/$tempdate[1]/$tempdate[0]";
417         $datedue=~s/-//g;
418         if ($datedue < $todaysdate) {
419             $dd="<font color=red>$dd</font>\n";
420         }
421         ($tcolor eq $linecolor1) ? ($tcolor=$linecolor2) : ($tcolor=$linecolor1);
422         $todaysissues .=<< "EOF";
423 <tr><td bgcolor=$tcolor align=center>$dd</td>
424 <td bgcolor=$tcolor align=center>
425 <a href=/cgi-bin/koha/detail.pl?bib=$book->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$book->{'barcode'}</a></td>
426 <td bgcolor=$tcolor>$book->{'title'}</td>
427 <td bgcolor=$tcolor>$book->{'author'}</td>
428 <td bgcolor=$tcolor align=center>$book->{'dewey'} $book->{'subclass'}</td></tr>
429 EOF
430     }
431     # FIXME - For small and private libraries, it'd be nice if this
432     # table included a "Return" link next to each book, so that you
433     # don't have to remember the book's bar code and type it in on the
434     # "Returns" page.
435     foreach my $book (sort {$a->{'date_due'} cmp $b->{'date_due'}} @previousissues){
436         my $dd = $book->{'date_due'};
437         my $datedue = $book->{'date_due'};
438         #convert to nz style dates
439         #this should be set with some kinda config variable
440         my @tempdate=split(/-/,$dd);
441         $dd="$tempdate[2]/$tempdate[1]/$tempdate[0]";
442         $datedue=~s/-//g;
443         if ($datedue < $todaysdate) {
444             $dd="<font color=red>$dd</font>\n";
445         }
446         ($pcolor eq $linecolor1) ? ($pcolor=$linecolor2) : ($pcolor=$linecolor1);
447         $previssues .= << "EOF";
448 <tr><td bgcolor=$pcolor align=center>$dd</td>
449 <td bgcolor=$pcolor align=center>
450 <a href=/cgi-bin/koha/detail.pl?bib=$book->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$book->{'barcode'}</a></td>
451 <td bgcolor=$pcolor>$book->{'title'}</td>
452 <td bgcolor=$pcolor>$book->{'author'}</td>
453 <td bgcolor=$pcolor align=center>$book->{'dewey'} $book->{'subclass'}</td></tr>
454 EOF
455     }
456 }
457
458 my $issuedbookstable;
459 if ($todaysissues) {
460     $issuedbookstable .= <<"EOF";
461 <table border=1 cellpadding=5 cellspacing=0 width=80%>
462 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
463 <b>Todays Issues</b></font></th></tr>
464 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
465 $todaysissues
466 </table>
467 EOF
468 }
469 if ($previssues) {
470     $issuedbookstable .= <<"EOF";
471 <table border=1 cellpadding=5 cellspacing=0 width=80%>
472 <tr><th colspan=5 bgcolor=$headerbackgroundcolor background=$backgroundimage><font color=black>
473 <b>Previous Issues</b></font></th></tr>
474 <tr><th>Due Date</th><th>Bar Code</th><th>Title</th><th>Author</th><th>Class</th></tr>
475 $previssues
476 </table>
477 EOF
478 }
479
480
481
482
483
484 # actually print the page!
485
486
487 if ($branchcookie && $printercookie) {
488     print $query->header(-type=>'text/html',-expires=>'now', -cookie=>[$branchcookie,$printercookie,$sessioncookie]);
489 } else {
490     print $query->header(-cookie=>[$sessioncookie]);
491 }
492
493 print startpage();
494 my @inp=startmenu('circulation');
495 if ($query->param('barcode') eq '' && $query->param('charges') eq 'yes'){
496     my $count=@inp;
497      for (my $i=0;$i<$count;$i++){
498          $inp[$i]=~ s/onLoad=focusinput\(\)/onLoad=focusinput\(\)\;messenger\(\"\/cgi-bin\/koha\/pay.pl?bornum=$bornum\",700,600\)\;window1.focus\(\)/;
499      }
500 }
501
502 print @inp;
503
504
505 #print startmenu('circulation');
506 if ($borrower) {
507     print $title;
508 } else {
509     print $titlenoborrower;
510 }
511
512
513 print $info;
514
515 if ($question) {
516     print $questionform;
517 }
518
519 print $rejectedtext;
520 print $messagetable;
521
522
523 unless ($borrower) {
524     if ($borrowerslist) {
525         print $selectborrower;
526     } else {
527         print $cardnumberinput;
528     }
529 }
530
531
532
533 if ($borrower) {
534     my ($patrontable, $flaginfotable) = patrontable($borrower);
535     print $patrontable;
536     print $flaginfotable;
537     print $barcodeentrytext;
538     print "<p clear=all><br><br>";
539     print $issuedbookstable;
540 }
541
542
543
544
545 print endmenu('circulation');
546 print endpage();
547
548
549 ####################################################################
550 # Extra subroutines,,,
551
552 sub cuecatbarcodedecode {
553     my ($barcode) = @_;
554     chomp($barcode);
555     my @fields = split(/\./,$barcode);
556     my @results = map(decode($_), @fields[1..$#fields]);
557     if ($#results == 2){
558         return $results[2];
559     } else {
560         return $barcode;
561     }
562 }
563
564 sub fixdate {
565     my ($year, $month, $day) = @_;
566     my $invalidduedate;
567     my $date;
568     if (($year eq 0) && ($month eq 0) && ($year eq 0)) {
569         $env{'datedue'}='';
570     } else {
571         if (($year eq 0) || ($month eq 0) || ($year eq 0)) {
572             $invalidduedate="Invalid Due Date Specified. Book was not issued.<p>\n";
573         } else {
574             if (($day>30) && (($month==4) || ($month==6) || ($month==9) || ($month==11))) {
575                 $invalidduedate = "Invalid Due Date Specified. Book was not issued. Only 30 days in $month month.<p>\n";
576             } elsif (($day > 29) && ($month == 2)) {
577                 $invalidduedate="Invalid Due Date Specified. Book was not issued.  Never that many days in February!<p>\n";
578             } elsif (($month == 2) && ($day > 28) && (($year%4) && ((!($year%100) || ($year%400))))) {
579                 $invalidduedate="Invalid Due Date Specified. Book was not issued.  $year is not a leap year.<p>\n";
580             } else {
581                 $date="$year-$month-$day";
582             }
583         }
584     }
585     return ($date, $invalidduedate);
586 }
587
588
589 sub patrontable {
590     my ($borrower) = @_;
591     my $flags = $borrower->{'flags'};
592     my $flaginfotable='';
593     my $flaginfotext='';
594     my $flag;
595     my $color='';
596     foreach $flag (sort keys %$flags) {
597         ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
598         $flags->{$flag}->{'message'}=~s/\n/<br>/g;
599         if ($flags->{$flag}->{'noissues'}) {
600             if ($flag eq 'CHARGES') {
601                 $flaginfotext.="<tr><td valign=top><font color=red>$flag</font></td><td bgcolor=$color><b>$flags->{$flag}->{'message'}</b> <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'} onClick=\"openWindow(this, 'Payment', 480,640)\">Payment</a></td></tr>\n";
602             } else {
603                 $flaginfotext.="<tr><td valign=top><font color=red>$flag</font></td><td bgcolor=$color>$flags->{$flag}->{'message'}</td></tr>\n";
604             }
605         } else {
606             if ($flag eq 'CHARGES') {
607                 $flaginfotext.="<tr><td valign=top>$flag</td><td> $flags->{$flag}->{'message'} <a href=/cgi-bin/koha/pay.pl?bornum=$borrower->{'borrowernumber'} onClick=\"openWindow(this, 'Payment', 480,640)\">Payment</a></td></tr>\n";
608             } elsif ($flag eq 'WAITING') {
609                 my $itemswaiting='';
610                 my $items=$flags->{$flag}->{'itemlist'};
611                 foreach my $item (@$items) {
612                     my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
613                     $itemswaiting.="<a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$iteminformation->{'barcode'}</a> $iteminformation->{'title'} ($branches->{$iteminformation->{'holdingbranch'}}->{'branchname'})<br>\n";
614                 }
615                 $flaginfotext.="<tr><td valign=top>$flag</td><td>$itemswaiting</td></tr>\n";
616             } elsif ($flag eq 'ODUES') {
617                 my $items=$flags->{$flag}->{'itemlist'};
618                 my $itemswaiting="<table border=1 cellspacing=0 cellpadding=2>\n";
619                 my $currentcolor=$color;
620                 {
621                     my $color=$currentcolor;
622                     foreach my $item (@$items) {
623                         ($color eq $linecolor1) ? ($color=$linecolor2) : ($color=$linecolor1);
624                         my ($iteminformation) = getiteminformation(\%env, $item->{'itemnumber'}, 0);
625                         $itemswaiting.="<tr><td><font color=red>$iteminformation->{'date_due'}</font></td><td bgcolor=$color><a href=/cgi-bin/koha/detail.pl?bib=$iteminformation->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$iteminformation->{'barcode'}</a></td><td>$iteminformation->{'title'}</td></tr>\n";
626                     }
627                 }
628                 $itemswaiting.="</table>\n";
629                 if ($query->param('module') ne 'returns'){
630                   $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}, See below</td></tr>\n";
631                 } else {
632                   $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
633                 }
634             } else {
635                 $flaginfotext.="<tr><td valign=top>$flag</td><td>$flags->{$flag}->{'message'}</td></tr>\n";
636             }
637         }
638     }
639     ($flaginfotext) && ($flaginfotext="<tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><b>Flags</b></td></tr>$flaginfotext\n");
640     $flaginfotext.="</table>";
641     my $patrontable= << "EOF";
642 <br><p>
643     <table border=1 cellpadding=5 cellspacing=0 align=right>
644     <tr><td bgcolor=$headerbackgroundcolor background=$backgroundimage colspan=2><font color=black><b>Patron Information</b></font></td></tr>
645     <tr><td colspan=2>
646     <a href=/cgi-bin/koha/moremember.pl?bornum=$borrower->{'borrowernumber'} onClick="openWindow(this,'Member', 480, 640)">$borrower->{'cardnumber'}</a> $borrower->{'surname'}, $borrower->{'title'} $borrower->{'firstname'}<br>$borrower->{'streetaddress'} $borrower->{'city'} Cat: $borrower->{'categorycode'} </td></tr>
647 EOF
648     return($patrontable, $flaginfotext);
649 }
650
651
652 # FIXME - This clashes with &C4::Print::printslip
653 sub printslip {
654     my ($env,$borrowernumber)=@_;
655     my ($borrower, $flags) = getpatroninformation($env,$borrowernumber,0);
656     $env->{'todaysissues'}=1;
657     my ($borrowerissues) = currentissues($env, $borrower);
658     $env->{'nottodaysissues'}=1;
659     $env->{'todaysissues'}=0;
660     my ($borroweriss2)=currentissues($env, $borrower);
661     $env->{'nottodaysissues'}=0;
662     my $i=0;
663     my @issues;
664     foreach (sort {$a <=> $b} keys %$borrowerissues) {
665         $issues[$i]=$borrowerissues->{$_};
666         my $dd=$issues[$i]->{'date_due'};
667 #       warn $_,$dd;
668         #convert to nz style dates
669         #this should be set with some kinda config variable
670         my @tempdate=split(/-/,$dd);
671         $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
672         $i++;
673     }
674     foreach (sort {$a <=> $b} keys %$borroweriss2) {
675         $issues[$i]=$borroweriss2->{$_};
676         my $dd=$issues[$i]->{'date_due'};
677 #       warn $_,$dd;
678         #convert to nz style dates
679         #this should be set with some kinda config variable
680         my @tempdate=split(/-/,$dd);
681         $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
682         $i++;
683     }
684     remoteprint($env,\@issues,$borrower);
685 }
686
687 # Local Variables:
688 # tab-width: 8
689 # End: