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