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