Merge remote branch 'kc/new/bug_6162' into kcmaster
[koha.git] / circ / returns.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #           2006 SAN-OP
5 #           2007-2010 BibLibre, Paul POULAIN
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22 =head1 returns.pl
23
24 script to execute returns of books
25
26 =cut
27
28 use strict;
29 #use warnings; FIXME - Bug 2505
30
31 use CGI;
32 use C4::Context;
33 use C4::Auth qw/:DEFAULT get_session/;
34 use C4::Output;
35 use C4::Circulation;
36 use C4::Dates qw/format_date/;
37 use Date::Calc qw/Add_Delta_Days/;
38 use C4::Calendar;
39 use C4::Print;
40 use C4::Reserves;
41 use C4::Biblio;
42 use C4::Items;
43 use C4::Members;
44 use C4::Branch; # GetBranches GetBranchName
45 use C4::Koha;   # FIXME : is it still useful ?
46 use C4::RotatingCollections;
47
48 my $query = new CGI;
49
50 if (!C4::Context->userenv){
51     my $sessionID = $query->cookie("CGISESSID");
52     my $session = get_session($sessionID);
53     if ($session->param('branch') eq 'NO_LIBRARY_SET'){
54         # no branch set we can't return
55         print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
56         exit;
57     }
58
59
60 #getting the template
61 my ( $template, $librarian, $cookie ) = get_template_and_user(
62     {
63         template_name   => "circ/returns.tmpl",
64         query           => $query,
65         type            => "intranet",
66         authnotrequired => 0,
67         flagsrequired   => { circulate => "circulate_remaining_permissions" },
68     }
69 );
70
71 #####################
72 #Global vars
73 my $branches = GetBranches();
74 my $printers = GetPrinters();
75
76 my $printer = C4::Context->userenv ? C4::Context->userenv->{'branchprinter'} : "";
77 my $overduecharges = (C4::Context->preference('finesMode') && C4::Context->preference('finesMode') ne 'off');
78
79 my $userenv_branch = C4::Context->userenv->{'branch'} || '';
80 #
81 # Some code to handle the error if there is no branch or printer setting.....
82 #
83
84 # Set up the item stack ....
85 my %returneditems;
86 my %riduedate;
87 my %riborrowernumber;
88 my @inputloop;
89 foreach ( $query->param ) {
90     my $counter;
91     if (/ri-(\d*)/) {
92         $counter = $1;
93         if ($counter > 20) {
94             next;
95         }
96     }
97     else {
98         next;
99     }
100
101     my %input;
102     my $barcode        = $query->param("ri-$counter");
103     my $duedate        = $query->param("dd-$counter");
104     my $borrowernumber = $query->param("bn-$counter");
105     $counter++;
106
107     # decode barcode    ## Didn't we already decode them before passing them back last time??
108     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
109     $barcode = barcodedecode($barcode) if(C4::Context->preference('itemBarcodeInputFilter'));
110
111     ######################
112     #Are these lines still useful ?
113     $returneditems{$counter}    = $barcode;
114     $riduedate{$counter}        = $duedate;
115     $riborrowernumber{$counter} = $borrowernumber;
116
117     #######################
118     $input{counter}        = $counter;
119     $input{barcode}        = $barcode;
120     $input{duedate}        = $duedate;
121     $input{borrowernumber} = $borrowernumber;
122     push( @inputloop, \%input );
123 }
124
125 ############
126 # Deal with the requests....
127
128 if ($query->param('WT-itemNumber')){
129         updateWrongTransfer ($query->param('WT-itemNumber'),$query->param('WT-waitingAt'),$query->param('WT-From'));
130 }
131
132 if ( $query->param('resbarcode') ) {
133     my $item           = $query->param('itemnumber');
134     my $borrowernumber = $query->param('borrowernumber');
135     my $resbarcode     = $query->param('resbarcode');
136     my $diffBranchReturned = $query->param('diffBranch');
137     my $iteminfo   = GetBiblioFromItemNumber($item);
138     # fix up item type for display
139     $iteminfo->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $iteminfo->{'itype'} : $iteminfo->{'itemtype'};
140     my $diffBranchSend = ($userenv_branch ne $diffBranchReturned) ? $diffBranchReturned : undef;
141 # diffBranchSend tells ModReserveAffect whether document is expected in this library or not,
142 # i.e., whether to apply waiting status
143     ModReserveAffect( $item, $borrowernumber, $diffBranchSend);
144 #   check if we have other reserves for this document, if we have a return send the message of transfer
145     my ( $messages, $nextreservinfo ) = GetOtherReserves($item);
146
147     my ($borr) = GetMemberDetails( $nextreservinfo, 0 );
148     my $name   = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'};
149     if ( $messages->{'transfert'} ) {
150         $template->param(
151             itemtitle      => $iteminfo->{'title'},
152             itembiblionumber => $iteminfo->{'biblionumber'},
153             iteminfo       => $iteminfo->{'author'},
154             tobranchname   => GetBranchName($messages->{'transfert'}),
155             name           => $name,
156             borrowernumber => $borrowernumber,
157             borcnum        => $borr->{'cardnumber'},
158             borfirstname   => $borr->{'firstname'},
159             borsurname     => $borr->{'surname'},
160             diffbranch     => 1,
161         );
162     }
163 }
164
165 my $borrower;
166 my $returned = 0;
167 my $messages;
168 my $issueinformation;
169 my $itemnumber;
170 my $barcode     = $query->param('barcode');
171 my $exemptfine  = $query->param('exemptfine');
172 my $dropboxmode = $query->param('dropboxmode');
173 my $dotransfer  = $query->param('dotransfer');
174 my $calendar    = C4::Calendar->new( branchcode => $userenv_branch );
175 #dropbox: get last open day (today - 1)
176 my $today       = C4::Dates->new();
177 my $today_iso   = $today->output('iso');
178 my $dropboxdate = $calendar->addDate($today, -1);
179 if ($dotransfer){
180 # An item has been returned to a branch other than the homebranch, and the librarian has chosen to initiate a transfer
181     my $transferitem = $query->param('transferitem');
182     my $tobranch     = $query->param('tobranch');
183     ModItemTransfer($transferitem, $userenv_branch, $tobranch); 
184 }
185
186 # actually return book and prepare item table.....
187 if ($barcode) {
188     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
189     $barcode = barcodedecode($barcode) if C4::Context->preference('itemBarcodeInputFilter');
190     $itemnumber = GetItemnumberFromBarcode($barcode);
191
192     if ( C4::Context->preference("InProcessingToShelvingCart") ) {
193         my $item = GetItem( $itemnumber );
194         if ( $item->{'location'} eq 'PROC' ) {
195             $item->{'location'} = 'CART';
196             ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
197         }
198     }
199
200     if ( C4::Context->preference("ReturnToShelvingCart") ) {
201         my $item = GetItem( $itemnumber );
202         $item->{'location'} = 'CART';
203         ModItem( $item, $item->{'biblionumber'}, $item->{'itemnumber'} );
204     }
205
206 #
207 # save the return
208 #
209     ( $returned, $messages, $issueinformation, $borrower ) =
210       AddReturn( $barcode, $userenv_branch, $exemptfine, $dropboxmode);     # do the return
211     my $homeorholdingbranchreturn = C4::Context->preference('HomeOrHoldingBranchReturn') or 'homebranch';
212
213     # get biblio description
214     my $biblio = GetBiblioFromItemNumber($itemnumber);
215     # fix up item type for display
216     $biblio->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $biblio->{'itype'} : $biblio->{'itemtype'};
217
218     $template->param(
219         title            => $biblio->{'title'},
220         homebranch       => $biblio->{'homebranch'},
221         homebranchname   => GetBranchName( $biblio->{$homeorholdingbranchreturn} ),
222         author           => $biblio->{'author'},
223         itembarcode      => $biblio->{'barcode'},
224         itemtype         => $biblio->{'itemtype'},
225         ccode            => $biblio->{'ccode'},
226         itembiblionumber => $biblio->{'biblionumber'},    
227     );
228
229     my %input = (
230         counter => 0,
231         first   => 1,
232         barcode => $barcode,
233     );
234
235     if ($returned) {
236         my $duedate = $issueinformation->{'date_due'};
237         $returneditems{0}      = $barcode;
238         $riborrowernumber{0}   = $borrower->{'borrowernumber'};
239         $riduedate{0}          = $duedate;
240         $input{borrowernumber} = $borrower->{'borrowernumber'};
241         $input{duedate}        = $duedate;
242         $input{return_overdue} = 1 if ($duedate and $duedate lt $today->output('iso'));
243         push( @inputloop, \%input );
244
245         if ( C4::Context->preference("FineNotifyAtCheckin") ) {
246             my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrower->{'borrowernumber'} );
247             if ($fines > 0) {
248                 $template->param( fines => sprintf("%.2f",$fines) );
249                 $template->param( fineborrowernumber => $borrower->{'borrowernumber'} );
250             }
251         }
252         
253         if (C4::Context->preference("WaitingNotifyAtCheckin") ) {
254             #Check for waiting holds
255             my @reserves = GetReservesFromBorrowernumber($borrower->{'borrowernumber'});
256             my $waiting_holds;
257             foreach my $num_res (@reserves) {
258                 if ( $num_res->{'found'} eq 'W' && $num_res->{'branchcode'} eq $userenv_branch) {
259                     $waiting_holds++;
260                 }
261             } 
262             if ($waiting_holds > 0) {
263                 $template->param(
264                     waiting_holds       => $waiting_holds,
265                     holdsborrowernumber => $borrower->{'borrowernumber'},
266                 );
267             }
268         }
269     }
270     elsif ( !$messages->{'BadBarcode'} ) {
271         $input{duedate}   = 0;
272         $returneditems{0} = $barcode;
273         $riduedate{0}     = 0;
274         if ( $messages->{'wthdrawn'} ) {
275             $input{withdrawn}      = 1;
276             $input{borrowernumber} = 'Item Cancelled';  # FIXME: should be in display layer ?
277             $riborrowernumber{0}   = 'Item Cancelled';
278         }
279         else {
280             $input{borrowernumber} = ' ';  # This seems clearly bogus.
281             $riborrowernumber{0}   = ' ';
282         }
283         push( @inputloop, \%input );
284     }
285 }
286 $template->param( inputloop => \@inputloop );
287
288 my $found    = 0;
289 my $waiting  = 0;
290 my $reserved = 0;
291
292 # new op dev : we check if the document must be returned to his homebranch directly,
293 #  if the document is transfered, we have warning message .
294
295 if ( $messages->{'WasTransfered'} ) {
296     $template->param(
297         found          => 1,
298         transfer       => 1,
299     );
300 }
301
302 if ( $messages->{'NeedsTransfer'} ){
303     $template->param(
304         found          => 1,
305         needstransfer  => 1,
306         itemnumber     => $itemnumber,
307     );
308 }
309
310 if ( $messages->{'Wrongbranch'} ){
311     $template->param(
312         wrongbranch => 1,
313     );
314 }
315
316 # case of wrong transfert, if the document wasn't transfered to the right library (according to branchtransfer (tobranch) BDD)
317
318 if ( $messages->{'WrongTransfer'} and not $messages->{'WasTransfered'}) {
319     $messages->{'WrongTransfer'} = GetBranchName( $messages->{'WrongTransfer'} );
320     $template->param(
321         WrongTransfer  => 1,
322         TransferWaitingAt => $messages->{'WrongTransfer'},
323         WrongTransferItem => $messages->{'WrongTransferItem'},
324     );
325
326     my $reserve    = $messages->{'ResFound'};
327     my $branchname = $branches->{ $reserve->{'branchcode'} }->{'branchname'};
328     my ($borr) = GetMemberDetails( $reserve->{'borrowernumber'}, 0 );
329     my $name = $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'};
330     $template->param(
331             wname           => $name,
332             wborfirstname   => $borr->{'firstname'},
333             wborsurname     => $borr->{'surname'},
334             wbortitle       => $borr->{'title'},
335             wborphone       => $borr->{'phone'},
336             wboremail       => $borr->{'email'},
337             wboraddress     => $borr->{'address'},
338             wboraddress2    => $borr->{'address2'},
339             wborcity        => $borr->{'city'},
340             wborzip         => $borr->{'zipcode'},
341             wborrowernumber => $reserve->{'borrowernumber'},
342             wborcnum        => $borr->{'cardnumber'},
343             wtransfertFrom  => $userenv_branch,
344     );
345 }
346
347 #
348 # reserve found and item arrived at the expected branch
349 #
350 if ( $messages->{'ResFound'}) {
351     my $reserve    = $messages->{'ResFound'};
352     my $branchname = $branches->{ $reserve->{'branchcode'} }->{'branchname'};
353     my ($borr) = GetMemberDetails( $reserve->{'borrowernumber'}, 0 );
354
355     if ( $reserve->{'ResFound'} eq "Waiting" or $reserve->{'ResFound'} eq "Reserved" ) {
356         if ( $reserve->{'ResFound'} eq "Waiting" ) {
357             $template->param(
358                 waiting      => ($userenv_branch eq $reserve->{'branchcode'} ? 1 : 0 ),
359             );
360         } elsif ( $reserve->{'ResFound'} eq "Reserved" ) {
361             $template->param(
362                 intransit    => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
363                 transfertodo => ($userenv_branch eq $reserve->{'branchcode'} ? 0 : 1 ),
364                 resbarcode   => $barcode,
365                 reserved     => 1,
366             );
367         }
368
369         # same params for Waiting or Reserved
370         $template->param(
371             found          => 1,
372             currentbranch  => $branches->{$userenv_branch}->{'branchname'},
373             destbranchname => $branches->{ $reserve->{'branchcode'} }->{'branchname'},
374             name           => $borr->{'surname'} . ", " . $borr->{'title'} . " " . $borr->{'firstname'},
375             borfirstname   => $borr->{'firstname'},
376             borsurname     => $borr->{'surname'},
377             bortitle       => $borr->{'title'},
378             borphone       => $borr->{'phone'},
379             boremail       => $borr->{'email'},
380             boraddress     => $borr->{'address'},
381             boraddress2    => $borr->{'address2'},
382             borcity        => $borr->{'city'},
383             borzip         => $borr->{'zipcode'},
384             borcnum        => $borr->{'cardnumber'},
385             debarred       => $borr->{'debarred'},
386             gonenoaddress  => $borr->{'gonenoaddress'},
387             barcode        => $barcode,
388             destbranch     => $reserve->{'branchcode'},
389             borrowernumber => $reserve->{'borrowernumber'},
390             itemnumber     => $reserve->{'itemnumber'},
391             reservenotes   => $reserve->{'reservenotes'},
392         );
393     } # else { ; }  # error?
394 }
395
396 # Error Messages
397 my @errmsgloop;
398 foreach my $code ( keys %$messages ) {
399     my %err;
400     my $exit_required_p = 0;
401     if ( $code eq 'BadBarcode' ) {
402         $err{badbarcode} = 1;
403         $err{msg}        = $messages->{'BadBarcode'};
404     }
405     elsif ( $code eq 'NotIssued' ) {
406         $err{notissued} = 1;
407         $err{msg} = $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
408     }
409     elsif ( $code eq 'WasLost' ) {
410         $err{waslost} = 1;
411     }
412     elsif ( $code eq 'ResFound' ) {
413         ;    # FIXME... anything to do here?
414     }
415     elsif ( $code eq 'WasReturned' ) {
416         ;    # FIXME... anything to do here?
417     }
418     elsif ( $code eq 'WasTransfered' ) {
419         ;    # FIXME... anything to do here?
420     }
421     elsif ( $code eq 'wthdrawn' ) {
422         $err{withdrawn} = 1;
423         $exit_required_p = 1;
424     }
425     elsif ( ( $code eq 'IsPermanent' ) && ( not $messages->{'ResFound'} ) ) {
426         if ( $messages->{'IsPermanent'} ne $userenv_branch ) {
427             $err{ispermanent} = 1;
428             $err{msg}         =
429               $branches->{ $messages->{'IsPermanent'} }->{'branchname'};
430         }
431     }
432     elsif ( $code eq 'WrongTransfer' ) {
433         ;    # FIXME... anything to do here?
434     }
435     elsif ( $code eq 'WrongTransferItem' ) {
436         ;    # FIXME... anything to do here?
437     }
438     elsif ( $code eq 'NeedsTransfer' ) {
439     }
440     elsif ( $code eq 'Wrongbranch' ) {
441     }
442
443     else {
444         die "Unknown error code $code";    # note we need all the (empty) elsif's above, or we die.
445         # This forces the issue of staying in sync w/ Circulation.pm
446     }
447     if (%err) {
448         push( @errmsgloop, \%err );
449     }
450     last if $exit_required_p;
451 }
452 $template->param( errmsgloop => \@errmsgloop );
453
454 # patrontable ....
455 if ($borrower) {
456     my $flags = $borrower->{'flags'};
457     my @flagloop;
458     my $flagset;
459     foreach my $flag ( sort keys %$flags ) {
460         my %flaginfo;
461         unless ($flagset) { $flagset = 1; }
462         $flaginfo{redfont} = ( $flags->{$flag}->{'noissues'} );
463         $flaginfo{flag}    = $flag;
464         if ( $flag eq 'CHARGES' ) {
465             $flaginfo{msg}            = $flag;
466             $flaginfo{charges}        = 1;
467             $flaginfo{chargeamount}   = $flags->{$flag}->{amount};
468             $flaginfo{borrowernumber} = $borrower->{borrowernumber};
469         }
470         elsif ( $flag eq 'WAITING' ) {
471             $flaginfo{msg}     = $flag;
472             $flaginfo{waiting} = 1;
473             my @waitingitemloop;
474             my $items = $flags->{$flag}->{'itemlist'};
475             foreach my $item (@$items) {
476                 my $biblio = GetBiblioFromItemNumber( $item->{'itemnumber'});
477                 push @waitingitemloop, {
478                     biblionum => $biblio->{'biblionumber'},
479                     barcode   => $biblio->{'barcode'},
480                     title     => $biblio->{'title'},
481                     brname    => $branches->{ $biblio->{'holdingbranch'} }->{'branchname'},
482                 };
483             }
484             $flaginfo{itemloop} = \@waitingitemloop;
485         }
486         elsif ( $flag eq 'ODUES' ) {
487             my $items = $flags->{$flag}->{'itemlist'};
488             my @itemloop;
489             foreach my $item ( sort { $a->{'date_due'} cmp $b->{'date_due'} }
490                 @$items )
491             {
492                 my $biblio = GetBiblioFromItemNumber( $item->{'itemnumber'});
493                 push @itemloop, {
494                     duedate   => format_date($item->{'date_due'}),
495                     biblionum => $biblio->{'biblionumber'},
496                     barcode   => $biblio->{'barcode'},
497                     title     => $biblio->{'title'},
498                     brname    => $branches->{ $biblio->{'holdingbranch'} }->{'branchname'},
499                 };
500             }
501             $flaginfo{itemloop} = \@itemloop;
502             $flaginfo{overdue}  = 1;
503         }
504         else {
505             $flaginfo{other} = 1;
506             $flaginfo{msg}   = $flags->{$flag}->{'message'};
507         }
508         push( @flagloop, \%flaginfo );
509     }
510     $template->param(
511         flagset          => $flagset,
512         flagloop         => \@flagloop,
513         riborrowernumber => $borrower->{'borrowernumber'},
514         riborcnum        => $borrower->{'cardnumber'},
515         riborsurname     => $borrower->{'surname'},
516         ribortitle       => $borrower->{'title'},
517         riborfirstname   => $borrower->{'firstname'}
518     );
519 }
520
521 #set up so only the last 8 returned items display (make for faster loading pages)
522 my $returned_counter = ( C4::Context->preference('numReturnedItemsToShow') ) ? C4::Context->preference('numReturnedItemsToShow') : 8;
523 my $count = 0;
524 my @riloop;
525 foreach ( sort { $a <=> $b } keys %returneditems ) {
526     my %ri;
527     if ( $count++ < $returned_counter ) {
528         my $bar_code = $returneditems{$_};
529         my $duedate = $riduedate{$_};
530         if ($duedate) {
531             my @tempdate = split( /-/, $duedate );
532             $ri{year}  = $tempdate[0];
533             $ri{month} = $tempdate[1];
534             $ri{day}   = $tempdate[2];
535             $ri{duedate} = format_date($duedate);
536             my ($b)      = GetMemberDetails( $riborrowernumber{$_}, 0 );
537             $ri{return_overdue} = 1 if ($duedate lt $today->output('iso'));
538             $ri{borrowernumber} = $b->{'borrowernumber'};
539             $ri{borcnum}        = $b->{'cardnumber'};
540             $ri{borfirstname}   = $b->{'firstname'};
541             $ri{borsurname}     = $b->{'surname'};
542             $ri{bortitle}       = $b->{'title'};
543             $ri{bornote}        = $b->{'borrowernotes'};
544             $ri{borcategorycode}= $b->{'categorycode'};
545         }
546         else {
547             $ri{borrowernumber} = $riborrowernumber{$_};
548         }
549
550         #        my %ri;
551         my $biblio = GetBiblioFromItemNumber(GetItemnumberFromBarcode($bar_code));
552         # fix up item type for display
553         $biblio->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $biblio->{'itype'} : $biblio->{'itemtype'};
554         $ri{itembiblionumber} = $biblio->{'biblionumber'};
555         $ri{itemtitle}        = $biblio->{'title'};
556         $ri{itemauthor}       = $biblio->{'author'};
557         $ri{itemcallnumber}   = $biblio->{'itemcallnumber'};
558         $ri{itemtype}         = $biblio->{'itemtype'};
559         $ri{itemnote}         = $biblio->{'itemnotes'};
560         $ri{ccode}            = $biblio->{'ccode'};
561         $ri{itemnumber}       = $biblio->{'itemnumber'};
562         $ri{barcode}          = $bar_code;
563     }
564     else {
565         last;
566     }
567     push @riloop, \%ri;
568 }
569
570 $template->param(
571     riloop         => \@riloop,
572     genbrname      => $branches->{$userenv_branch}->{'branchname'},
573     genprname      => $printers->{$printer}->{'printername'},
574     branchname     => $branches->{$userenv_branch}->{'branchname'},
575     printer        => $printer,
576     errmsgloop     => \@errmsgloop,
577     exemptfine     => $exemptfine,
578     dropboxmode    => $dropboxmode,
579     dropboxdate    => $dropboxdate->output(),
580     overduecharges => $overduecharges,
581     soundon        => C4::Context->preference("SoundOn"),
582 );
583
584 ### Comment out rotating collections for now to allow it a little more time to bake
585 ### for 3.4; in particular, must ensure that it doesn't fight with transfers required
586 ### to fill hold requests
587 ### -- Galen Charlton 2010-10-06
588 #my $itemnumber = GetItemnumberFromBarcode( $query->param('barcode') );
589 #if ( $itemnumber ) {
590 #   my ( $holdingBranch, $collectionBranch ) = GetCollectionItemBranches( $itemnumber );
591 #    if ( ! ( $holdingBranch eq $collectionBranch ) ) {
592 #        $template->param(
593 #          collectionItemNeedsTransferred => 1,
594 #          collectionBranch => GetBranchName($collectionBranch),
595 #        );
596 #    }
597 #}                                                                                                            
598
599 # actually print the page!
600 output_html_with_http_headers $query, $cookie, $template->output;