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