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