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