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