Fix for bug 1515
[koha.git] / circ / circulation.pl
1 #!/usr/bin/perl
2
3 # Please use 8-character tabs for this file (indents are every 4 characters)
4
5 # written 8/5/2002 by Finlay
6 # script to execute issuing of books
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::Output;
28 use C4::Print;
29 use C4::Auth qw/:DEFAULT get_session/;
30 use C4::Dates qw/format_date/;
31 use C4::Branch; # GetBranches
32 use C4::Koha;   # GetPrinter
33 use C4::Circulation;
34 use C4::Members;
35 use C4::Biblio;
36 use C4::Reserves;
37 use C4::Context;
38 use CGI::Session;
39
40 use Date::Calc qw(
41   Today
42   Today_and_Now
43   Add_Delta_YM
44   Add_Delta_Days
45   Date_to_Days
46 );
47
48
49 #
50 # PARAMETERS READING
51 #
52 my $query = new CGI;
53
54 # new op dev the branch and the printer are now defined by the userenv
55 # but first we have to check if someone has tried to change them
56
57 my $branch = $query->param('branch');
58 if ($branch){
59     # update our session so the userenv is updated
60     my $dbh=C4::Context->dbh;
61     my $sessionID = $query->cookie("CGISESSID") ;
62     my $session = get_session($sessionID);
63     $session->param('branch',$branch);
64     my $branchname = GetBranchName($branch);
65     $session->param('branchname',$branchname);
66 }
67
68 my $printer = $query->param('printer');
69 if ($printer){
70     # update our session so the userenv is updated
71         my $dbh=C4::Context->dbh;
72         my $sessionID = $query->cookie("CGISESSID") ;
73         my $session = get_session($sessionID);
74         $session->param('branchprinter',$printer);
75
76 }
77
78
79 my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
80     {
81         template_name   => 'circ/circulation.tmpl',
82         query           => $query,
83         type            => "intranet",
84         authnotrequired => 0,
85         flagsrequired   => { circulate => 1 },
86     }
87 );
88 my $branches = GetBranches();
89
90 my $printers = GetPrinters();
91
92 my @failedrenews = $query->param('failedrenew');
93 my @renew_failed;
94 for (@failedrenews) { $renew_failed[$_] = 1; } 
95
96 my $findborrower = $query->param('findborrower');
97 $findborrower =~ s|,| |g;
98 #$findborrower =~ s|'| |g;
99 my $borrowernumber = $query->param('borrowernumber');
100
101 $branch  = C4::Context->userenv->{'branch'};    
102 $printer = C4::Context->userenv->{'branchprinter'};
103
104
105 # If Autolocated is not activated, we show the Circulation Parameters to chage settings of librarian
106     if (C4::Context->preference("AutoLocation") ne 1)
107         {
108             $template->param(
109             ManualLocation => 1,
110             );
111         }
112
113 my $barcode        = $query->param('barcode') || '';
114
115 # strip whitespace
116 $barcode =~ s/\s*//g;
117
118 my $year           = $query->param('year');
119 my $month          = $query->param('month');
120 my $day            = $query->param('day');
121 my $stickyduedate  = $query->param('stickyduedate');
122 my $duedatespec    = $query->param('duedatespec');
123 my $issueconfirmed = $query->param('issueconfirmed');
124 my $cancelreserve  = $query->param('cancelreserve');
125 my $organisation   = $query->param('organisations');
126 my $print          = $query->param('print');
127 my $newexpiry = $query->param('dateexpiry');
128
129 #set up cookie.....
130 # my $branchcookie;
131 # my $printercookie;
132 # if ($query->param('setcookies')) {
133 #     $branchcookie = $query->cookie(-name=>'branch', -value=>"$branch", -expires=>'+1y');
134 #     $printercookie = $query->cookie(-name=>'printer', -value=>"$printer", -expires=>'+1y');
135 # }
136 #
137
138 my ($datedue,$invalidduedate);
139 if ($duedatespec) {
140         $datedue =  C4::Dates->new($duedatespec);
141         $invalidduedate=1 unless $datedue;
142 }
143
144 #if (defined($year)) {
145 #        $duedatespec = "$year-$month-$day";
146 #} else {
147 #        ($year, $month, $day) = ($duedatespec) ? split /-/, $duedatespec : (0,0,0);
148 #}
149
150 my @datearr = localtime();
151
152 # FIXME - Could just use POSIX::strftime("%Y%m%d", localtime);
153 my $todaysdate =
154     ( 1900 + $datearr[5] )
155   . sprintf( "%0.2d", ( $datearr[4] + 1 ) )
156   . sprintf( "%0.2d", ( $datearr[3] ) );
157
158 # check and see if we should print
159 if ( $barcode eq '' && $print eq 'maybe' ) {
160     $print = 'yes';
161 }
162
163 my $inprocess = ($barcode eq '') ? '' : $query->param('inprocess');
164
165 if ( $barcode eq '' && $query->param('charges') eq 'yes' ) {
166     $template->param(
167         PAYCHARGES     => 'yes',
168         borrowernumber => $borrowernumber
169     );
170 }
171
172 if ( $print eq 'yes' && $borrowernumber ne '' ) {
173     printslip( $borrowernumber );
174     $query->param( 'borrowernumber', '' );
175     $borrowernumber = '';
176 }
177
178 #
179 # STEP 2 : FIND BORROWER
180 # if there is a list of find borrowers....
181 #
182 my $borrowerslist;
183 my $message;
184 if ($findborrower) {
185     my ( $count, $borrowers ) =
186       SearchMember($findborrower, 'cardnumber', 'web' );
187     my @borrowers = @$borrowers;
188     if ( $#borrowers == -1 ) {
189         $query->param( 'findborrower', '' );
190         $message = "'$findborrower'";
191     }
192     elsif ( $#borrowers == 0 ) {
193         $query->param( 'borrowernumber', $borrowers[0]->{'borrowernumber'} );
194         $query->param( 'barcode',           '' );
195         $borrowernumber = $borrowers[0]->{'borrowernumber'};
196     }
197     else {
198         $borrowerslist = \@borrowers;
199     }
200 }
201
202 # get the borrower information.....
203 my $borrower;
204 my @lines;
205 if ($borrowernumber) {
206     $borrower = GetMemberDetails( $borrowernumber, 0 );
207     my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
208
209     # Warningdate is the date that the warning starts appearing
210     my ( $today_year,   $today_month,   $today_day )   = Today();
211     my ( $warning_year, $warning_month, $warning_day ) = split /-/,
212       $borrower->{'dateexpiry'};
213     my ( $enrol_year, $enrol_month, $enrol_day ) = split /-/,
214       $borrower->{'dateenrolled'};
215     # Renew day is calculated by adding the enrolment period to today
216     my ( $renew_year, $renew_month, $renew_day ) =
217       Add_Delta_YM( $enrol_year, $enrol_month, $enrol_day,
218         0 , $borrower->{'enrolmentperiod'}) if ($enrol_year*$enrol_month*$enrol_day>0);
219     # if the expiry date is before today ie they have expired
220     if ( $warning_year*$warning_month*$warning_day==0 
221       || Date_to_Days( $today_year, $today_month, $today_day ) 
222          > Date_to_Days( $warning_year, $warning_month, $warning_day ) )
223     {
224         #borrowercard expired, no issues
225         $template->param(
226                         flagged => "1",
227             noissues       => "1",
228             expired => format_date($borrower->{dateexpiry}),
229             renewaldate   => format_date("$renew_year-$renew_month-$renew_day")
230         );
231     }
232     # check for NotifyBorrowerDeparture
233         elsif ( C4::Context->preference('NotifyBorrowerDeparture') &&
234                 Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
235                 Date_to_Days( $today_year, $today_month, $today_day ) ) 
236         {
237                 # borrower card soon to expire warn librarian
238                 $template->param("warndeparture" => format_date($borrower->{dateexpiry}),
239                         flagged       => "1",);
240         }
241     $template->param(
242         overduecount => $od,
243         issuecount   => $issue,
244         finetotal    => $fines
245     );
246 }
247
248 #
249 # STEP 3 : ISSUING
250 #
251 #
252
253 if ($barcode) {
254    # $barcode = cuecatbarcodedecode($barcode);
255     
256         if ($issueconfirmed) {
257         AddIssue( $borrower, $barcode, $datedue, $cancelreserve );
258         $inprocess = 1;
259     }
260     else {
261         my ( $error, $question ) =
262           CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess );
263         my $noerror    = 1;
264         my $noquestion = 1;
265 #         Get the item title for more information
266         my $getmessageiteminfo  = GetBiblioFromItemNumber(undef,$barcode);
267     
268         foreach my $impossible ( keys %$error ) {
269             $template->param(
270                 $impossible => $$error{$impossible},
271                 IMPOSSIBLE  => 1
272             );
273             $noerror = 0;
274         }
275         foreach my $needsconfirmation ( keys %$question ) {
276             $template->param(
277                 $needsconfirmation => $$question{$needsconfirmation},
278                 getTitleMessageIteminfo => $getmessageiteminfo->{'title'},
279                 NEEDSCONFIRMATION  => 1
280             );
281             $noquestion = 0;
282         }
283         $template->param(
284                          itemhomebranch => $getmessageiteminfo->{'homebranch'} ,                     
285                          duedatespec => $duedatespec,
286         );
287         if ( $noerror && ( $noquestion || $issueconfirmed ) ) {
288             AddIssue( $borrower, $barcode, $datedue );
289             $inprocess = 1;
290         }
291     }
292     
293 # FIXME If the issue is confirmed, we launch another time borrdata2, now display the issue count after issue 
294         my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
295         $template->param(
296         issuecount   => $issue,
297         );
298 }
299
300 # reload the borrower info for the sake of reseting the flags.....
301 if ($borrowernumber) {
302     $borrower = GetMemberDetails( $borrowernumber, 0 );
303 }
304
305 ##################################################################################
306 # BUILD HTML
307 # show all reserves of this borrower, and the position of the reservation ....
308 if ($borrowernumber) {
309
310     # new op dev
311     # now we show the status of the borrower's reservations
312     my @borrowerreserv = GetReservesFromBorrowernumber($borrowernumber );
313     my @reservloop;
314     my @WaitingReserveLoop;
315     
316     foreach my $num_res (@borrowerreserv) {
317         my %getreserv;
318         my %getWaitingReserveInfo;
319         my $getiteminfo  = GetBiblioFromItemNumber( $num_res->{'itemnumber'} );
320         my $itemtypeinfo = getitemtypeinfo( (C4::Context->preference('item-level_itype')) ? $getiteminfo->{'itype'} : $getiteminfo->{'itemtype'} );
321         my ( $transfertwhen, $transfertfrom, $transfertto ) =
322           GetTransfers( $num_res->{'itemnumber'} );
323
324         $getreserv{waiting}       = 0;
325         $getreserv{transfered}    = 0;
326         $getreserv{nottransfered} = 0;
327
328         $getreserv{reservedate}    = format_date( $num_res->{'reservedate'} );
329         $getreserv{title}          = $getiteminfo->{'title'};
330         $getreserv{itemtype}       = $itemtypeinfo->{'description'};
331         $getreserv{author}         = $getiteminfo->{'author'};
332         $getreserv{barcodereserv}  = $getiteminfo->{'barcode'};
333         $getreserv{itemcallnumber} = $getiteminfo->{'itemcallnumber'};
334                 $getreserv{biblionumber}   = $getiteminfo->{'biblionumber'};
335
336         #         check if we have a waiting status for reservations
337         if ( $num_res->{'found'} eq 'W' ) {
338             $getreserv{color}   = 'reserved';
339             $getreserv{waiting} = 1;
340 #     genarate information displaying only waiting reserves
341         $getWaitingReserveInfo{title}        = $getiteminfo->{'title'};
342         $getWaitingReserveInfo{biblionumber}   = $getiteminfo->{'biblionumber'};
343         $getWaitingReserveInfo{itemtype}    = $itemtypeinfo->{'description'};
344         $getWaitingReserveInfo{author}        = $getiteminfo->{'author'};
345         $getWaitingReserveInfo{reservedate}    = format_date( $num_res->{'reservedate'} );
346         if ($getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} ) {
347         $getWaitingReserveInfo{waitingat}    = GetBranchName( $num_res->{'branchcode'} );
348         }
349     
350         }
351         #         check transfers with the itemnumber foud in th reservation loop
352         if ($transfertwhen) {
353             $getreserv{color}      = 'transfered';
354             $getreserv{transfered} = 1;
355             $getreserv{datesent}   = format_date($transfertwhen);
356             $getreserv{frombranch} = GetBranchName($transfertfrom);
357         }
358
359         if ( ( $getiteminfo->{'holdingbranch'} ne $num_res->{'branchcode'} )
360             and not $transfertwhen )
361         {
362             $getreserv{nottransfered}   = 1;
363             $getreserv{nottransferedby} =
364               GetBranchName( $getiteminfo->{'holdingbranch'} );
365         }
366
367 #         if we don't have a reserv on item, we put the biblio infos and the waiting position
368         if ( $getiteminfo->{'title'} eq '' ) {
369             my $getbibinfo = GetBiblioData( $num_res->{'biblionumber'} );
370             my $getbibtype = getitemtypeinfo( $getbibinfo->{'itemtype'} );  # fixme - we should have item-level reserves here ?
371             $getreserv{color}           = 'inwait';
372             $getreserv{title}           = $getbibinfo->{'title'};
373             $getreserv{waitingposition} = $num_res->{'priority'};
374             $getreserv{nottransfered}   = 0;
375             $getreserv{itemtype}        = $getbibtype->{'description'};
376             $getreserv{author}          = $getbibinfo->{'author'};
377             $getreserv{itemcallnumber}  = '----------';
378                 $getreserv{biblionumber}    = $num_res->{'biblionumber'};
379         }
380         push( @reservloop, \%getreserv );
381
382 #         if we have a reserve waiting, initiate waitingreserveloop
383         if ($getreserv{waiting} eq 1) {
384         push (@WaitingReserveLoop, \%getWaitingReserveInfo)
385         }
386       
387     }
388
389     # return result to the template
390     $template->param( 
391         countreserv => scalar @reservloop,
392         reservloop  => \@reservloop ,
393         WaitingReserveLoop  => \@WaitingReserveLoop,
394     );
395 }
396
397 # make the issued books table.
398 my $todaysissues = '';
399 my $previssues   = '';
400 my @todaysissues;
401 my @previousissues;
402 my $allowborrow;
403 ## ADDED BY JF: new itemtype issuingrules counter stuff
404 my $issued_itemtypes_loop;
405 my $issued_itemtypes_count;
406 my $issued_itemtypes_allowed_count;    # hashref with total allowed by itemtype
407 my $issued_itemtypes_remaining;        # hashref with remaining
408 my $issued_itemtypes_flags;            #hashref that stores flags
409 my @issued_itemtypes_count_loop;
410
411 if ($borrower) {
412
413 # get each issue of the borrower & separate them in todayissues & previous issues
414     my ($countissues,$issueslist) = GetPendingIssues($borrower->{'borrowernumber'});
415
416     # split in 2 arrays for today & previous
417     foreach my $it ( @$issueslist ) {
418         my $issuedate = $it->{'issuedate'};
419         $issuedate =~ s/-//g;
420         $issuedate = substr( $issuedate, 0, 8 );
421                 ($it->{'charge'}, $it->{'itemtype_charge'}) = GetIssuingCharges(
422                                                 $it->{'itemnumber'}, $borrower->{'borrowernumber'}
423                 );
424                 $it->{'charge'} = sprintf("%.2f", $it->{'charge'});
425         ($it->{'can_renew'}, $it->{'can_renew_error'}) = CanBookBeRenewed( 
426                                                 $borrower->{'borrowernumber'},$it->{'itemnumber'}
427                 );
428                 my ($restype, $reserves) = CheckReserves($it->{'itemnumber'});
429                 ($restype) and $it->{'can_renew'} = 0;
430
431                 $it->{'dd'} = format_date($it->{'date_due'});
432         my $datedue = $it->{'date_due'};
433         $datedue =~ s/-//g;
434                 $it->{'od'} = ($datedue < $todaysdate) ? 1 : 0 ;
435         ($it->{'author'} eq '') and $it->{'author'} = ' ';
436         $it->{'renew_failed'} = $renew_failed[$it->{'itemnumber'}];
437         # ADDED BY JF: NEW ITEMTYPE COUNT DISPLAY
438         $issued_itemtypes_count->{ $it->{'itemtype'} }++;
439
440         if ( $todaysdate == $issuedate ) {
441             push @todaysissues, $it;
442         } else {
443             push @previousissues, $it;
444         }
445     }
446         if (C4::Context->preference("todaysIssuesDefaultSortOrder") eq 'asc'){
447                 @todaysissues   = sort { $a->{'timestamp'} cmp $b->{'timestamp'} } @todaysissues;
448         }
449         else {
450                 @todaysissues   = sort { $b->{'timestamp'} cmp $a->{'timestamp'} } @todaysissues;
451         }
452         if (C4::Context->preference("previousIssuesDefaultSortOrder") eq 'asc'){
453                 @previousissues = sort { $a->{'date_due' } cmp $b->{'date_due' } } @previousissues;
454         }
455         else {
456                 @previousissues = sort { $b->{'date_due' } cmp $a->{'date_due' } } @previousissues;
457         }
458     my $i = 1;
459         foreach my $book (@todaysissues) {
460         $book->{'togglecolor'} = (++$i % 2) ? 0 : 1 ;
461     }
462     $i = 1;
463         foreach my $book (@previousissues) {
464         $book->{'togglecolor'} = (++$i % 2) ? 0 : 1 ;
465     }
466 }
467
468 #### ADDED BY JF FOR COUNTS BY ITEMTYPE RULES
469 # FIXME: This should utilize all the issuingrules options rather than just the defaults
470 # and it should be moved to a module
471 my $dbh = C4::Context->dbh;
472
473 # how many of each is allowed?
474 my $issueqty_sth = $dbh->prepare( "
475 SELECT itemtypes.description AS description,issuingrules.itemtype,maxissueqty
476 FROM issuingrules
477   LEFT JOIN itemtypes ON (itemtypes.itemtype=issuingrules.itemtype)
478   WHERE categorycode=?
479 " );
480 #my @issued_itemtypes_count;  # huh?
481 $issueqty_sth->execute("*");
482
483 while ( my $data = $issueqty_sth->fetchrow_hashref() ) {
484
485     # subtract how many of each this borrower has
486     $data->{'count'} = $issued_itemtypes_count->{ $data->{'description'} };  
487     $data->{'left'}  =
488       ( $data->{'maxissueqty'} -
489           $issued_itemtypes_count->{ $data->{'description'} } );
490
491     # can't have a negative number of remaining
492     if ( $data->{'left'} < 0 ) { $data->{'left'} = "0" }
493     $data->{'flag'} = 1 unless ( $data->{'maxissueqty'} > $data->{'count'} );
494     unless ( ( $data->{'maxissueqty'} < 1 )
495         || ( $data->{'itemtype'} eq "*" )
496         || ( $data->{'itemtype'} eq "CIRC" ) )
497     {
498         push @issued_itemtypes_count_loop, $data;
499     }
500 }
501 $issued_itemtypes_loop = \@issued_itemtypes_count_loop;
502
503 #### / JF
504
505 my @values;
506 my %labels;
507 my $CGIselectborrower;
508 if ($borrowerslist) {
509     foreach (
510         sort {
511                 lc $a->{'surname'}
512               . lc $a->{'firstname'} cmp lc $b->{'surname'}
513               . lc $b->{'firstname'}
514         } @$borrowerslist
515       )
516     {
517         push @values, $_->{'borrowernumber'};
518         $labels{ $_->{'borrowernumber'} } =
519 "$_->{'surname'}, $_->{'firstname'} ... ($_->{'cardnumber'} - $_->{'categorycode'}) ...  $_->{'address'} ";
520     }
521     $CGIselectborrower = CGI::scrolling_list(
522         -name     => 'borrowernumber',
523                 -class     => 'focus',
524                 -id          => 'borrowernumber',
525         -values   => \@values,
526         -labels   => \%labels,
527         -size     => 7,
528         -tabindex => '',
529         -multiple => 0
530     );
531 }
532
533 #title
534 my $flags = $borrower->{'flags'};
535 my $flag;
536
537 foreach $flag ( sort keys %$flags ) {
538     $template->param( flagged=> 1);
539     $flags->{$flag}->{'message'} =~ s/\n/<br>/g;
540     if ( $flags->{$flag}->{'noissues'} ) {
541         $template->param(
542             flagged  => 1,
543             noissues => 'true',
544         );
545         if ( $flag eq 'GNA' ) {
546             $template->param( gna => 'true' );
547         }
548         if ( $flag eq 'LOST' ) {
549             $template->param( lost => 'true' );
550         }
551         if ( $flag eq 'DBARRED' ) {
552             $template->param( dbarred => 'true' );
553         }
554         if ( $flag eq 'CHARGES' ) {
555             $template->param(
556                 charges    => 'true',
557                 chargesmsg => $flags->{'CHARGES'}->{'message'}
558             );
559         }
560         if ( $flag eq 'CREDITS' ) {
561             $template->param(
562                 credits    => 'true',
563                 creditsmsg => $flags->{'CREDITS'}->{'message'}
564             );
565         }
566     }
567     else {
568         if ( $flag eq 'CHARGES' ) {
569             $template->param(
570                 charges    => 'true',
571                 flagged    => 1,
572                 chargesmsg => $flags->{'CHARGES'}->{'message'}
573             );
574         }
575         if ( $flag eq 'CREDITS' ) {
576             $template->param(
577                 credits    => 'true',
578                 creditsmsg => $flags->{'CREDITS'}->{'message'}
579             );
580         }
581         if ( $flag eq 'ODUES' ) {
582             $template->param(
583                 odues    => 'true',
584                 flagged  => 1,
585                 oduesmsg => $flags->{'ODUES'}->{'message'}
586             );
587
588             my $items = $flags->{$flag}->{'itemlist'};
589 # useless ???
590 #             {
591 #                 my @itemswaiting;
592 #                 foreach my $item (@$items) {
593 #                     my ($iteminformation) =
594 #                         getiteminformation( $item->{'itemnumber'}, 0 );
595 #                     push @itemswaiting, $iteminformation;
596 #                 }
597 #             }
598             if ( $query->param('module') ne 'returns' ) {
599                 $template->param( nonreturns => 'true' );
600             }
601         }
602         if ( $flag eq 'NOTES' ) {
603             $template->param(
604                 notes    => 'true',
605                 flagged  => 1,
606                 notesmsg => $flags->{'NOTES'}->{'message'}
607             );
608         }
609     }
610 }
611
612 my $amountold = $borrower->{flags}->{'CHARGES'}->{'message'} || 0;
613 my @temp = split( /\$/, $amountold );
614
615 my $CGIorganisations;
616 my $member_of_institution;
617 if ( C4::Context->preference("memberofinstitution") ) {
618     my $organisations = get_institutions();
619     my @orgs;
620     my %org_labels;
621     foreach my $organisation ( keys %$organisations ) {
622         push @orgs, $organisation;
623         $org_labels{$organisation} =
624           $organisations->{$organisation}->{'surname'};
625     }
626     $member_of_institution = 1;
627     $CGIorganisations      = CGI::popup_menu(
628         -id     => 'organisations',
629         -name   => 'organisations',
630         -labels => \%org_labels,
631         -values => \@orgs,
632     );
633 }
634
635 $amountold = $temp[1];
636
637 my $borrowercategory = GetBorrowercategory( $borrower->{'categorycode'} );
638 my $category_type = $borrowercategory->{'category_type'};
639 ( $template->param( adultborrower => 1 ) ) if ( $category_type eq 'A' );
640
641 $template->param(
642     issued_itemtypes_count_loop => $issued_itemtypes_loop,
643     findborrower                => $findborrower,
644     borrower                    => $borrower,
645     borrowernumber              => $borrowernumber,
646     branch                      => $branch,
647     printer                     => $printer,
648     printername                 => $printer,
649     firstname                   => $borrower->{'firstname'},
650     surname                     => $borrower->{'surname'},
651         dateexpiry => format_date($newexpiry),
652     expiry                      =>
653       $borrower->{'dateexpiry'},    #format_date($borrower->{'dateexpiry'}),
654     categorycode      => $borrower->{'categorycode'},
655     address     => $borrower->{'address'},
656     address2     => $borrower->{'address2'},
657     email      => $borrower->{'email'},
658         emailpro           => $borrower->{'emailpro'},
659     borrowernotes     => $borrower->{'borrowernotes'},
660     city              => $borrower->{'city'},
661     phone             => $borrower->{'phone'} || $borrower->{'mobile'},
662     cardnumber        => $borrower->{'cardnumber'},
663     amountold         => $amountold,
664     barcode           => $barcode,
665     stickyduedate     => $stickyduedate,
666     message           => $message,
667     CGIselectborrower => $CGIselectborrower,
668     todayissues       => \@todaysissues,
669     previssues        => \@previousissues,
670     inprocess         => $inprocess,
671     memberofinstution => $member_of_institution,
672     CGIorganisations  => $CGIorganisations,
673         circview => 1,
674         
675 );
676
677 # set return date if stickyduedate
678 if ($stickyduedate) {
679     $template->param(
680         duedatespec => $duedatespec,
681     );
682 }
683
684 #if ($branchcookie) {
685 #$cookie=[$cookie, $branchcookie, $printercookie];
686 #}
687
688 $template->param(
689     SpecifyDueDate           => C4::Context->preference("SpecifyDueDate"),
690     CircAutocompl            => C4::Context->preference("CircAutocompl") ,
691     DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
692 );
693 output_html_with_http_headers $query, $cookie, $template->output;