]> git.koha-community.org Git - koha.git/blob - circ/circulation.pl
dosearch.pl replaces search.pl for the new templated opac. I thought it should have...
[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';
40 my $circbackgroundcolor='white';
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 #set up cookie.....
57 my $info = '';
58 my $branchcookie;
59 my $printercookie;
60 if ($query->param('setcookies')) {
61     $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
62     $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
63 }
64
65 $env{'branchcode'}=$branch;
66 $env{'printer'}=$printer;
67 $env{'queue'}=$printer;
68
69 my @datearr = localtime(time());
70 my $tday = localtime(time());
71 warn "today: $tday \n";
72 my $todaysdate = (1900+$datearr[5]).sprintf ("%0.2d", ($datearr[4]+1)).sprintf ("%0.2d", ($datearr[3]));
73 #warn $todaysdate;
74
75
76 my $message;
77 my $borrowerslist;
78 # if there is a list of find borrowers....
79 my $findborrower = $query->param('findborrower');
80 if ($findborrower) {
81     my ($borrowers, $flags) = findborrower(\%env, $findborrower);
82     my @borrowers=@$borrowers;
83     if ($#borrowers == -1) {
84         $query->param('findborrower', '');
85         $message =  "No borrower matched '$findborrower'";
86     } elsif ($#borrowers == 0) {
87         $query->param('borrnumber', $borrowers[0]->{'borrowernumber'});
88         $query->param('barcode','');
89     } else {
90         $borrowerslist = \@borrowers;
91     }
92 }
93
94 my $borrowernumber = $query->param('borrnumber');    
95 my $bornum = $query->param('borrnumber');    
96 # check and see if we should print
97 my $print=$query->param('print');
98 my $barcode = $query->param('barcode');
99 if ($barcode eq ''  && $print eq 'maybe'){
100     $print = 'yes';
101 }
102 if ($print eq 'yes' && $borrowernumber ne ''){
103     printslip(\%env,$borrowernumber);    
104     $query->param('borrnumber','');
105     $borrowernumber='';
106 }
107     
108
109
110 # get the currently issued books......
111 my $borrower;
112 my $flags;
113 if ($borrowernumber) {
114     ($borrower, $flags) = getpatroninformation(\%env,$borrowernumber,0);
115 }
116
117 # get the responses to any questions.....
118 my %responses;
119 foreach (sort $query->param) {
120     if ($_ =~ /response-(\d*)/) {
121         $responses{$1} = $query->param($_);
122     }
123 }
124 if (my $qnumber = $query->param('questionnumber')) {
125     $responses{$qnumber} = $query->param('answer');
126 }
127
128
129 # if the barcode is set
130 my ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer);
131
132 my $year=$query->param('year');
133 my $month=$query->param('month');
134 my $day=$query->param('day');
135
136
137 if ($barcode) {
138     $barcode = cuecatbarcodedecode($barcode);
139     my ($datedue, $invalidduedate) = fixdate($year, $month, $day);
140
141
142     unless ($invalidduedate) {
143         $env{'datedue'}=$datedue;
144         my @time=localtime(time);
145         my $date= (1900+$time[5])."-".($time[4]+1)."-".$time[3];
146         ($iteminformation, $duedate, $rejected, $question, $questionnumber, $defaultanswer, $message) 
147                      = issuebook(\%env, $borrower, $barcode, \%responses, $date);
148     }
149 }
150
151
152
153
154 ##################################################################################
155 # HTML code....
156
157
158 my $rejectedtext;
159 if ($rejected) {
160     if ($rejected == -1) {
161     } else {
162         $rejectedtext = << "EOF";
163 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
164 <tr><th><font color=black size=5>Error Issuing Book</font></th></tr>
165 <tr><td><font color=red size=5>$rejected</font></td></tr>
166 </table>
167 <br>
168 EOF
169     }
170 }
171
172 my $selectborrower;
173 if ($borrowerslist) {
174     $selectborrower = <<"EOF";
175 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
176 <input type=hidden name=branch value=$branch>
177 <input type=hidden name=printer value=$printer>
178 <table border=1 cellspacing=0 cellpadding=5 bgcolor="#dddddd">
179 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
180 <font color=black><b>Select a borrower</b></font></th></tr>\n
181 <tr><td align=center>
182 <select name=borrnumber size=7>
183 EOF
184     foreach (sort {$a->{'surname'}.$a->{'firstname'} cmp $b->{'surname'}.$b->{'firstname'}} @$borrowerslist){
185         $selectborrower .= <<"EOF";
186 <option value=$_->{'borrowernumber'}>$_->{'surname'}, $_->{'firstname'} ($_->{'cardnumber'})
187 EOF
188     }
189     $selectborrower .= <<"EOF";
190 </select><br>
191 <input type=submit>
192 </td></tr></table>
193 EOF
194 }
195
196 # title....
197 my $title = <<"EOF";
198 <table align="right"><tr><td>
199 <a href=circulation.pl?borrnumber=$borrowernumber&branch=$branch&printer=$printer&print=yes>
200 <img src="/images/button-next-borrower.gif" width="171" height="42" border="0" alt="Next Borrower"></a> &nbsp
201 <a href=returns.pl>
202 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
203 &nbsp<a href=branchtransfers.pl><img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Transfers"></a>
204 </td></tr></table>
205 <FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
206 <b>Branch:</b> $branches->{$branch}->{'branchname'} &nbsp 
207 <b>Printer:</b> $printers->{$printer}->{'printername'} <br>
208 <a href=selectbranchprinter.pl>Change Settings</a></td>
209 <input type=hidden name=branch value=$branch>
210 <input type=hidden name=printer value=$printer>
211 <p>
212 EOF
213
214 my $titlenoborrower = <<"EOF";
215 <table align="right"><tr><td>
216 <a href=returns.pl>
217 <img src="/images/button-returns.gif" width="110" height="42" border="0" alt="Returns"></a>
218 &nbsp<a href=branchtransfers.pl><img src="/images/button-transfers.gif" width="127" height="42" border="0" alt="Transfers"></a>
219 </td></tr></table>
220 <FONT SIZE=6><em>Circulation: Issues</em></FONT><br>
221 <b>Branch:</b> $branches->{$branch}->{'branchname'} &nbsp 
222 <b>Printer:</b> $printers->{$printer}->{'printername'} <br>
223 <a href=selectbranchprinter.pl>Change Settings</a></td>
224 <input type=hidden name=branch value=$branch>
225 <input type=hidden name=printer value=$printer>
226 <p>
227 EOF
228
229
230
231 my $cardnumberinput = << "EOF";
232 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
233 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
234 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
235 <font color=black><b>Enter borrower card number<br> or partial last name</b></font></td></tr>
236 <tr><td><input name=findborrower></td></tr>
237   <input type=hidden name=branch value=$branch>
238 <input type=hidden name=printer value=$printer>
239 </table>
240 </form>
241 EOF
242
243 my $responsesform = '';
244 foreach (keys %responses) {
245     $responsesform.="<input type=hidden name=response-$_ value=$responses{$_}>\n";
246 }
247 my $questionform;
248 if ($question) {
249     my $stickyduedate=$query->param('stickyduedate');
250     $questionform = <<"EOF";
251 <table border=1 cellpadding=5 cellspacing=0 bgcolor="#dddddd">
252 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage>
253 <font color=black><b>Issuing Question</b></font></th></tr>
254 <tr><td><table border=0 cellpadding=10><tr><td> 
255 Attempting to issue $iteminformation->{'title'} 
256 by $iteminformation->{'author'} to $borrower->{'firstname'} $borrower->{'surname'}.
257 <p>
258 $question
259 </td></tr></table></td></tr>
260 <tr><td align=center>
261 <table border=0>
262 <tr><td>
263 <form method=get>
264 <input type=hidden name=borrnumber value=$borrowernumber>
265 <input type=hidden name=barcode value=$barcode>
266 <input type=hidden name=questionnumber value=$questionnumber>
267 <input type=hidden name=day value=$day>
268 <input type=hidden name=month value=$month>
269 <input type=hidden name=year value=$year>
270 <input type=hidden name=stickyduedate value=$stickyduedate>
271 <input type=hidden name=branch value=$branch>
272 <input type=hidden name=printer value=$printer>
273 $responsesform
274 <input type=hidden name=answer value=Y>
275 <input type=submit value=Yes>
276 </form>
277 </td>
278 <td>
279 <form method=get>
280 <input type=hidden name=borrnumber value=$borrowernumber>
281 <input type=hidden name=barcode value=$barcode>
282 <input type=hidden name=questionnumber value=$questionnumber>
283 <input type=hidden name=day value=$day>
284 <input type=hidden name=month value=$month>
285 <input type=hidden name=year value=$year>
286 <input type=hidden name=stickyduedate value=$stickyduedate>
287 <input type=hidden name=branch value=$branch>
288 <input type=hidden name=printer value=$printer>
289 $responsesform
290 <input type=hidden name=answer value=N>
291 <input type=submit value=No>
292 </form>
293 </td>
294 </tr>
295 </table>
296 </td></tr>
297 </table>
298 </td></tr>
299 </table>
300 EOF
301 }
302
303
304 # Barcode entry box, with hidden inputs attached....
305 my $counter = 1;
306 my $dayoptions = '';
307 my $monthoptions = '';
308 my $yearoptions = '';
309 for (my $i=1; $i<32; $i++) {
310     my $selected='';
311     if (($query->param('stickyduedate')) && ($day==$i)) {
312         $selected='selected';
313     }
314     $dayoptions.="<option value=$i $selected>$i";
315 }
316 foreach (('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')) {
317     my $selected='';
318     if (($query->param('stickyduedate')) && ($month==$counter)) {
319         $selected='selected';
320     }
321     $monthoptions.="<option value=$counter $selected>$_";
322     $counter++;
323 }
324 for (my $i=$datearr[5]+1900; $i<$datearr[5]+1905; $i++) {
325     my $selected='';
326     if (($query->param('stickyduedate')) && ($year==$i)) {
327         $selected='selected';
328     }
329     $yearoptions.="<option value=$i $selected>$i";
330 }
331 my $selected='';
332 ($query->param('stickyduedate')) && ($selected='checked');
333
334
335 my $barcodeentrytext = <<"EOF";
336 <form method=post action=/cgi-bin/koha/circ/circulation.pl>
337 <table border=1 cellpadding=5>
338 <tr>
339 <td align=center valign=top>
340 <table border=0 cellspacing=0 cellpadding=5>
341 <tr><th align=center background=$backgroundimage>
342 <font color=black><b>Enter Book Barcode</b></font></th></tr>
343 <tr><td align=center>
344 <table border=0>
345 <tr><td>Item Barcode:</td><td><input name=barcode size=10></td><td><input type=submit value=Issue></td></tr>
346 <tr><td colspan=3 align=center>
347 <table border=0 cellpadding=0 cellspacing=0>
348 <tr><td>
349 <select name=day><option value=0>Day$dayoptions</select>
350 </td><td>
351 <select name=month><option value=0>Month$monthoptions</select>
352 </td><td>
353 <select name=year><option value=0>Year$yearoptions</select>
354 </td></tr>
355 </table>
356 <input type=checkbox name=stickyduedate $selected> Sticky Due Date
357 </td></tr>
358 </table>
359 <input type=hidden name=borrnumber value=$borrowernumber>
360 <input type=hidden name=branch value=$branch>
361 <input type=hidden name=printer value=$printer>
362 <input type=hidden name=print value=maybe>
363 EOF
364 if ($flags->{'CHARGES'}){
365     $barcodeentrytext.="<input type=hidden name=charges value=yes>";
366 }
367 my $amountold=$flags->{'CHARGES'}->{'message'};
368 my @temp=split(/\$/,$amountold);
369 $amountold=$temp[1];
370 $barcodeentrytext.="<input type=hidden name=oldamount value=$amountold>";
371 $barcodeentrytext.=<<"EOF";
372 </td></tr></table>
373 </td></tr></table>
374 </form>
375 EOF
376
377
378 # collect the messages and put into message table....
379 my $messagetable;
380 if ($message) {
381     $messagetable = << "EOF";
382 <table border=1 cellpadding=5 cellspacing=0 bgcolor='#dddddd'>
383 <tr><th bgcolor=$headerbackgroundcolor background=$backgroundimage><font>Messages</font></th></tr>
384 <tr><td> $message </td></tr></table>
385 EOF
386
387 }
388
389
390
391 # make the issued books table.....
392 my $todaysissues='';
393 my $previssues='';
394 if ($borrower) {
395     my @todaysissues;
396     my @previousissues;
397     my $issueslist = getissues($borrower);
398     foreach my $it (keys %$issueslist) {
399         my $issuedate = $issueslist->{$it}->{'timestamp'};
400         $issuedate = substr($issuedate, 0, 8);
401         if ($todaysdate == $issuedate) {
402             push @todaysissues, $issueslist->{$it};
403         } else {
404             push @previousissues, $issueslist->{$it};
405         }
406     }
407     my $tcolor = '';
408     my $pcolor = '';
409     foreach my $book (sort {$b->{'timestamp'} <=> $a->{'timestamp'}} @todaysissues){
410         my $dd = $book->{'date_due'};
411         my $datedue = $book->{'date_due'};
412         #convert to nz style dates
413         #this should be set with some kinda config variable         
414         my @tempdate=split(/-/,$dd);
415         $dd="$tempdate[2]/$tempdate[1]/$tempdate[0]";
416         $datedue=~s/-//g;
417         if ($datedue < $todaysdate) {
418             $dd="<font color=red>$dd</font>\n";
419         }
420         ($tcolor eq $linecolor1) ? ($tcolor=$linecolor2) : ($tcolor=$linecolor1);
421         $todaysissues .=<< "EOF";
422 <tr><td bgcolor=$tcolor align=center>$dd</td>
423 <td bgcolor=$tcolor align=center>
424 <a href=/cgi-bin/koha/detail.pl?bib=$book->{'biblionumber'}&type=intra onClick=\"openWindow(this, 'Item', 480, 640)\">$book->{'barcode'}</a></td>
425 <td bgcolor=$tcolor>$book->{'title'}</td>
426 <td bgcolor=$tcolor>$book->{'author'}</td>
427 <td bgcolor=$tcolor align=center>$book->{'dewey'} $book->{'subclass'}</td></tr>
428 EOF
429     } 
430     foreach my $book (sort {$a->{'due_date'} <=> $b->{'due_date'}} @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,$sessioncookie]);
484 } else {
485     print $query->header(-cookie=>[$sessioncookie]);
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
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 keys %$borrowerissues) {
660         $issues[$i]=$borrowerissues->{$_};
661         my $dd=$issues[$i]->{'date_due'};
662         #convert to nz style dates
663         #this should be set with some kinda config variable
664         my @tempdate=split(/-/,$dd);
665         $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
666         $i++;
667     }
668     foreach (sort keys %$borroweriss2) {
669         $issues[$i]=$borroweriss2->{$_};
670         my $dd=$issues[$i]->{'date_due'};
671         #convert to nz style dates
672         #this should be set with some kinda config variable
673         my @tempdate=split(/-/,$dd);
674         $issues[$i]->{'date_due'}="$tempdate[2]/$tempdate[1]/$tempdate[0]";
675         $i++;
676     }
677     remoteprint($env,\@issues,$borrower);
678 }