Bug 14871: Extend the patrons search to search like %$term% (checkout tab)
[koha.git] / circ / circulation.pl
1 #!/usr/bin/perl
2
3 # script to execute issuing of books
4
5 # Copyright 2000-2002 Katipo Communications
6 # copyright 2010 BibLibre
7 # Copyright 2011 PTFS-Europe Ltd.
8 # Copyright 2012 software.coop and MJ Ray
9 #
10 # This file is part of Koha.
11 #
12 # Koha is free software; you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 3 of the License, or
15 # (at your option) any later version.
16 #
17 # Koha is distributed in the hope that it will be useful, but
18 # WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24
25 use strict;
26 use warnings;
27 use CGI qw ( -utf8 );
28 use DateTime;
29 use DateTime::Duration;
30 use C4::Output;
31 use C4::Print;
32 use C4::Auth qw/:DEFAULT get_session haspermission/;
33 use C4::Dates qw/format_date/;
34 use C4::Branch; # GetBranches
35 use C4::Koha;   # GetPrinter
36 use C4::Circulation;
37 use C4::Utils::DataTables::Members;
38 use C4::Members;
39 use C4::Biblio;
40 use C4::Search;
41 use MARC::Record;
42 use C4::Reserves;
43 use Koha::Holds;
44 use C4::Context;
45 use CGI::Session;
46 use C4::Members::Attributes qw(GetBorrowerAttributes);
47 use Koha::Borrower::Debarments qw(GetDebarments IsDebarred);
48 use Koha::DateUtils;
49 use Koha::Database;
50
51 use Date::Calc qw(
52   Today
53   Add_Delta_YM
54   Add_Delta_Days
55   Date_to_Days
56 );
57 use List::MoreUtils qw/uniq/;
58
59
60 #
61 # PARAMETERS READING
62 #
63 my $query = new CGI;
64
65 my $sessionID = $query->cookie("CGISESSID") ;
66 my $session = get_session($sessionID);
67
68 # branch and printer are now defined by the userenv
69 # but first we have to check if someone has tried to change them
70
71 my $branch = $query->param('branch');
72 if ($branch){
73     # update our session so the userenv is updated
74     $session->param('branch', $branch);
75     $session->param('branchname', GetBranchName($branch));
76 }
77
78 my $printer = $query->param('printer');
79 if ($printer){
80     # update our session so the userenv is updated
81     $session->param('branchprinter', $printer);
82 }
83
84 if (!C4::Context->userenv && !$branch){
85     if ($session->param('branch') eq 'NO_LIBRARY_SET'){
86         # no branch set we can't issue
87         print $query->redirect("/cgi-bin/koha/circ/selectbranchprinter.pl");
88         exit;
89     }
90 }
91
92 my $barcodes = [];
93 if ( my $barcode = $query->param('barcode') ) {
94     $barcodes = [ $barcode ];
95 } else {
96     my $filefh = $query->upload('uploadfile');
97     if ( $filefh ) {
98         while ( my $content = <$filefh> ) {
99             $content =~ s/[\r\n]*$//g;
100             push @$barcodes, $content if $content;
101         }
102     } elsif ( my $list = $query->param('barcodelist') ) {
103         push @$barcodes, split( /\s\n/, $list );
104         $barcodes = [ map { $_ =~ /^\s*$/ ? () : $_ } @$barcodes ];
105     } else {
106         @$barcodes = $query->param('barcodes');
107     }
108 }
109
110 $barcodes = [ uniq @$barcodes ];
111
112 my $template_name = q|circ/circulation.tt|;
113 my $borrowernumber = $query->param('borrowernumber');
114 my $borrower = $borrowernumber ? GetMember( borrowernumber => $borrowernumber ) : undef;
115 my $batch = $query->param('batch');
116 my $batch_allowed = 0;
117 if ( $batch && C4::Context->preference('BatchCheckouts') ) {
118     $template_name = q|circ/circulation_batch_checkouts.tt|;
119     my @batch_category_codes = split '\|', C4::Context->preference('BatchCheckoutsValidCategories');
120     if ( grep {/^$borrower->{categorycode}$/} @batch_category_codes ) {
121         $batch_allowed = 1;
122     } else {
123         $barcodes = [];
124     }
125 }
126
127 my ( $template, $loggedinuser, $cookie ) = get_template_and_user (
128     {
129         template_name   => $template_name,
130         query           => $query,
131         type            => "intranet",
132         authnotrequired => 0,
133         flagsrequired   => { circulate => 'circulate_remaining_permissions' },
134     }
135 );
136
137 my $branches = GetBranches();
138
139 my $force_allow_issue = $query->param('forceallow') || 0;
140 if (!C4::Auth::haspermission( C4::Context->userenv->{id} , { circulate => 'force_checkout' } )) {
141     $force_allow_issue = 0;
142 }
143
144 my $onsite_checkout = $query->param('onsite_checkout');
145
146 my @failedrenews = $query->param('failedrenew');    # expected to be itemnumbers
147 our %renew_failed = ();
148 for (@failedrenews) { $renew_failed{$_} = 1; }
149
150 my @failedreturns = $query->param('failedreturn');
151 our %return_failed = ();
152 for (@failedreturns) { $return_failed{$_} = 1; }
153
154 my $findborrower = $query->param('findborrower') || q{};
155 $findborrower =~ s|,| |g;
156
157 $branch  = C4::Context->userenv->{'branch'};  
158 $printer = C4::Context->userenv->{'branchprinter'};
159
160
161 # If AutoLocation is not activated, we show the Circulation Parameters to chage settings of librarian
162 if (C4::Context->preference("AutoLocation") != 1) {
163     $template->param(ManualLocation => 1);
164 }
165
166 if (C4::Context->preference("DisplayClearScreenButton")) {
167     $template->param(DisplayClearScreenButton => 1);
168 }
169
170 for my $barcode ( @$barcodes ) {
171     $barcode =~ s/^\s*|\s*$//g; # remove leading/trailing whitespace
172     $barcode = barcodedecode($barcode)
173         if( $barcode && C4::Context->preference('itemBarcodeInputFilter'));
174 }
175
176 my $stickyduedate  = $query->param('stickyduedate') || $session->param('stickyduedate');
177 my $duedatespec    = $query->param('duedatespec')   || $session->param('stickyduedate');
178 my $issueconfirmed = $query->param('issueconfirmed');
179 my $cancelreserve  = $query->param('cancelreserve');
180 my $print          = $query->param('print') || q{};
181 my $debt_confirmed = $query->param('debt_confirmed') || 0; # Don't show the debt error dialog twice
182 my $charges        = $query->param('charges') || q{};
183
184 # Check if stickyduedate is turned off
185 if ( @$barcodes ) {
186     # was stickyduedate loaded from session?
187     if ( $stickyduedate && ! $query->param("stickyduedate") ) {
188         $session->clear( 'stickyduedate' );
189         $stickyduedate  = $query->param('stickyduedate');
190         $duedatespec    = $query->param('duedatespec');
191     }
192     $session->param('auto_renew', $query->param('auto_renew'));
193 }
194 else {
195     $session->clear('auto_renew');
196 }
197
198 my ($datedue,$invalidduedate);
199
200 my $duedatespec_allow = C4::Context->preference('SpecifyDueDate');
201 if( $onsite_checkout && !$duedatespec_allow ) {
202     $datedue = output_pref({ dt => dt_from_string, dateonly => 1, dateformat => 'iso' });
203     $datedue .= ' 23:59:00';
204 } elsif( $duedatespec_allow ) {
205     if ($duedatespec) {
206         if ($duedatespec =~ C4::Dates->regexp('syspref')) {
207                 $datedue = dt_from_string($duedatespec);
208         } else {
209             $invalidduedate = 1;
210             $template->param(IMPOSSIBLE=>1, INVALID_DATE=>$duedatespec);
211         }
212     }
213 }
214
215 our $todaysdate = C4::Dates->new->output('iso');
216
217 # check and see if we should print
218 if ( @$barcodes == 0 && $print eq 'maybe' ) {
219     $print = 'yes';
220 }
221
222 my $inprocess = (@$barcodes == 0) ? '' : $query->param('inprocess');
223 if ( @$barcodes == 0 && $charges eq 'yes' ) {
224     $template->param(
225         PAYCHARGES     => 'yes',
226         borrowernumber => $borrowernumber
227     );
228 }
229
230 if ( $print eq 'yes' && $borrowernumber ne '' ) {
231     if ( C4::Context->boolean_preference('printcirculationslips') ) {
232         my $letter = IssueSlip($branch, $borrowernumber, "QUICK");
233         NetworkPrint($letter->{content});
234     }
235     $query->param( 'borrowernumber', '' );
236     $borrowernumber = '';
237 }
238
239 #
240 # STEP 2 : FIND BORROWER
241 # if there is a list of find borrowers....
242 #
243 my $message;
244 if ($findborrower) {
245     my $borrower = C4::Members::GetMember( cardnumber => $findborrower );
246     if ( $borrower ) {
247         $borrowernumber = $borrower->{borrowernumber};
248     } else {
249         my $dt_params = { iDisplayLength => -1 };
250         my $results = C4::Utils::DataTables::Members::search(
251             {
252                 searchmember => $findborrower,
253                 searchtype => 'contain',
254                 dt_params => $dt_params,
255             }
256         );
257         my $borrowers = $results->{patrons};
258         if ( scalar @$borrowers == 1 ) {
259             $borrowernumber = $borrowers->[0]->{borrowernumber};
260             $query->param( 'borrowernumber', $borrowernumber );
261             $query->param( 'barcode',           '' );
262         } elsif ( @$borrowers ) {
263             $template->param( borrowers => $borrowers );
264         } else {
265             $query->param( 'findborrower', '' );
266             $message = "'$findborrower'";
267         }
268     }
269 }
270
271 # get the borrower information.....
272 if ($borrowernumber) {
273     $borrower = GetMemberDetails( $borrowernumber, 0 );
274     my ( $od, $issue, $fines ) = GetMemberIssuesAndFines( $borrowernumber );
275
276     # Warningdate is the date that the warning starts appearing
277     my (  $today_year,   $today_month,   $today_day) = Today();
278     my ($warning_year, $warning_month, $warning_day) = split /-/, $borrower->{'dateexpiry'};
279     my (  $enrol_year,   $enrol_month,   $enrol_day) = split /-/, $borrower->{'dateenrolled'};
280     # Renew day is calculated by adding the enrolment period to today
281     my (  $renew_year,   $renew_month,   $renew_day);
282     if ($enrol_year*$enrol_month*$enrol_day>0) {
283         (  $renew_year,   $renew_month,   $renew_day) =
284         Add_Delta_YM( $enrol_year, $enrol_month, $enrol_day,
285             0 , $borrower->{'enrolmentperiod'});
286     }
287     # if the expiry date is before today ie they have expired
288     if ( !$borrower->{'dateexpiry'} || $warning_year*$warning_month*$warning_day==0
289         || Date_to_Days($today_year,     $today_month, $today_day  ) 
290          > Date_to_Days($warning_year, $warning_month, $warning_day) )
291     {
292         #borrowercard expired, no issues
293         $template->param(
294             flagged  => "1",
295             noissues => ($force_allow_issue) ? 0 : "1",
296             forceallow => $force_allow_issue,
297             expired => "1",
298             renewaldate => format_date("$renew_year-$renew_month-$renew_day")
299         );
300     }
301     # check for NotifyBorrowerDeparture
302     elsif ( C4::Context->preference('NotifyBorrowerDeparture') &&
303             Date_to_Days(Add_Delta_Days($warning_year,$warning_month,$warning_day,- C4::Context->preference('NotifyBorrowerDeparture'))) <
304             Date_to_Days( $today_year, $today_month, $today_day ) ) 
305     {
306         # borrower card soon to expire warn librarian
307         $template->param("warndeparture" => format_date($borrower->{dateexpiry}),
308         flagged       => "1",);
309         if (C4::Context->preference('ReturnBeforeExpiry')){
310             $template->param("returnbeforeexpiry" => 1);
311         }
312     }
313     $template->param(
314         overduecount => $od,
315         issuecount   => $issue,
316         finetotal    => $fines
317     );
318
319     if ( IsDebarred($borrowernumber) ) {
320         $template->param(
321             'userdebarred'    => $borrower->{debarred},
322             'debarredcomment' => $borrower->{debarredcomment},
323         );
324
325         if ( $borrower->{debarred} ne "9999-12-31" ) {
326             $template->param( 'userdebarreddate' =>
327                   C4::Dates::format_date( $borrower->{debarred} ) );
328         }
329     }
330
331 }
332
333 #
334 # STEP 3 : ISSUING
335 #
336 #
337 if (@$barcodes) {
338   my $checkout_infos;
339   for my $barcode ( @$barcodes ) {
340     my $template_params = { barcode => $barcode };
341     # always check for blockers on issuing
342     my ( $error, $question, $alerts ) =
343     CanBookBeIssued( $borrower, $barcode, $datedue , $inprocess, undef, { onsite_checkout => $onsite_checkout } );
344     my $blocker = $invalidduedate ? 1 : 0;
345
346     $template_params->{alert} = $alerts;
347
348     #  Get the item title for more information
349     my $getmessageiteminfo = GetBiblioFromItemNumber(undef,$barcode);
350     $template_params->{authvalcode_notforloan} =
351         C4::Koha::GetAuthValCode('items.notforloan', $getmessageiteminfo->{'frameworkcode'});
352
353     # Fix for bug 7494: optional checkout-time fallback search for a book
354
355     if ( $error->{'UNKNOWN_BARCODE'}
356         && C4::Context->preference("itemBarcodeFallbackSearch")
357         && not $batch
358     )
359     {
360      $template_params->{FALLBACK} = 1;
361
362         my $query = "kw=" . $barcode;
363         my ( $searcherror, $results, $total_hits ) = SimpleSearch($query);
364
365         # if multiple hits, offer options to librarian
366         if ( $total_hits > 0 ) {
367             my @options = ();
368             foreach my $hit ( @{$results} ) {
369                 my $chosen =
370                   TransformMarcToKoha( C4::Context->dbh,
371                     C4::Search::new_record_from_zebra('biblioserver',$hit) );
372
373                 # offer all barcodes individually
374                 if ( $chosen->{barcode} ) {
375                     foreach my $barcode ( sort split(/\s*\|\s*/, $chosen->{barcode}) ) {
376                         my %chosen_single = %{$chosen};
377                         $chosen_single{barcode} = $barcode;
378                         push( @options, \%chosen_single );
379                     }
380                 }
381             }
382             $template_params->{options} = \@options;
383         }
384     }
385
386     unless( $onsite_checkout and C4::Context->preference("OnSiteCheckoutsForce") ) {
387         delete $question->{'DEBT'} if ($debt_confirmed);
388         foreach my $impossible ( keys %$error ) {
389             $template_params->{$impossible} = $$error{$impossible};
390             $template_params->{IMPOSSIBLE} = 1;
391             $blocker = 1;
392         }
393     }
394     my $iteminfo = GetBiblioFromItemNumber(undef, $barcode);
395     if( !$blocker || $force_allow_issue ){
396         my $confirm_required = 0;
397         unless($issueconfirmed){
398             #  Get the item title for more information
399             $template_params->{additional_materials} = $iteminfo->{'materials'};
400             $template_params->{itemhomebranch} = $iteminfo->{'homebranch'};
401
402             # pass needsconfirmation to template if issuing is possible and user hasn't yet confirmed.
403             foreach my $needsconfirmation ( keys %$question ) {
404                 $template_params->{$needsconfirmation} = $$question{$needsconfirmation};
405                 $template_params->{getTitleMessageIteminfo} = $iteminfo->{'title'};
406                 $template_params->{getBarcodeMessageIteminfo} = $iteminfo->{'barcode'};
407                 $template_params->{NEEDSCONFIRMATION} = 1;
408                 $template_params->{onsite_checkout} = $onsite_checkout;
409                 $confirm_required = 1;
410             }
411         }
412         unless($confirm_required) {
413             my $issue = AddIssue( $borrower, $barcode, $datedue, $cancelreserve, undef, undef, { onsite_checkout => $onsite_checkout, auto_renew => $session->param('auto_renew') } );
414             $template->param( issue => $issue );
415             $session->clear('auto_renew');
416             $inprocess = 1;
417         }
418     }
419
420     # FIXME If the issue is confirmed, we launch another time GetMemberIssuesAndFines, now display the issue count after issue
421     my ( $od, $issue, $fines ) = GetMemberIssuesAndFines($borrowernumber);
422
423     if ($question->{RESERVE_WAITING} or $question->{RESERVED}){
424         $template->param(
425             reserveborrowernumber => $question->{'resborrowernumber'},
426             itembiblionumber => $getmessageiteminfo->{'biblionumber'}
427         );
428     }
429
430     $template_params->{issuecount} = $issue;
431
432     if ( $iteminfo ) {
433         $iteminfo->{subtitle} = GetRecordValue('subtitle', GetMarcBiblio($iteminfo->{biblionumber}), GetFrameworkCode($iteminfo->{biblionumber}));
434         $template_params->{item} = $iteminfo;
435     }
436     push @$checkout_infos, $template_params;
437   }
438   unless ( $batch ) {
439     $template->param( %{$checkout_infos->[0]} );
440     $template->param( barcode => $barcodes->[0] );
441   } else {
442     my $confirmation_needed = grep { $_->{NEEDSCONFIRMATION} } @$checkout_infos;
443     $template->param(
444         checkout_infos => $checkout_infos,
445         confirmation_needed => $confirmation_needed,
446     );
447   }
448 }
449
450 # reload the borrower info for the sake of reseting the flags.....
451 if ($borrowernumber) {
452     $borrower = GetMemberDetails( $borrowernumber, 0 );
453 }
454
455 ##################################################################################
456 # BUILD HTML
457 # show all reserves of this borrower, and the position of the reservation ....
458 if ($borrowernumber) {
459     my $holds = Koha::Holds->search( { borrowernumber => $borrowernumber } );
460     $template->param(
461         holds_count  => $holds->count(),
462         WaitingHolds => scalar $holds->waiting(),
463     );
464
465     $template->param( adultborrower => 1 ) if ( $borrower->{category_type} eq 'A' || $borrower->{category_type} eq 'I' );
466 }
467
468 #title
469 my $flags = $borrower->{'flags'};
470 foreach my $flag ( sort keys %$flags ) {
471     $template->param( flagged=> 1);
472     $flags->{$flag}->{'message'} =~ s#\n#<br />#g;
473     if ( $flags->{$flag}->{'noissues'} ) {
474         $template->param(
475             noissues => ($force_allow_issue) ? 0 : 'true',
476             forceallow => $force_allow_issue,
477         );
478         if ( $flag eq 'GNA' ) {
479             $template->param( gna => 'true' );
480         }
481         elsif ( $flag eq 'LOST' ) {
482             $template->param( lost => 'true' );
483         }
484         elsif ( $flag eq 'DBARRED' ) {
485             $template->param( dbarred => 'true' );
486         }
487         elsif ( $flag eq 'CHARGES' ) {
488             $template->param(
489                 charges    => 'true',
490                 chargesmsg => $flags->{'CHARGES'}->{'message'},
491                 chargesamount => $flags->{'CHARGES'}->{'amount'},
492                 charges_is_blocker => 1
493             );
494         }
495         elsif ( $flag eq 'CREDITS' ) {
496             $template->param(
497                 credits    => 'true',
498                 creditsmsg => $flags->{'CREDITS'}->{'message'},
499                 creditsamount => sprintf("%.02f", -($flags->{'CREDITS'}->{'amount'})), # from patron's pov
500             );
501         }
502     }
503     else {
504         if ( $flag eq 'CHARGES' ) {
505             $template->param(
506                 charges    => 'true',
507                 chargesmsg => $flags->{'CHARGES'}->{'message'},
508                 chargesamount => $flags->{'CHARGES'}->{'amount'},
509             );
510         }
511         elsif ( $flag eq 'CREDITS' ) {
512             $template->param(
513                 credits    => 'true',
514                 creditsmsg => $flags->{'CREDITS'}->{'message'},
515                 creditsamount => sprintf("%.02f", -($flags->{'CREDITS'}->{'amount'})), # from patron's pov
516             );
517         }
518         elsif ( $flag eq 'ODUES' ) {
519             $template->param(
520                 odues    => 'true',
521                 oduesmsg => $flags->{'ODUES'}->{'message'}
522             );
523
524             my $items = $flags->{$flag}->{'itemlist'};
525             if ( ! $query->param('module') || $query->param('module') ne 'returns' ) {
526                 $template->param( nonreturns => 'true' );
527             }
528         }
529         elsif ( $flag eq 'NOTES' ) {
530             $template->param(
531                 notes    => 'true',
532                 notesmsg => $flags->{'NOTES'}->{'message'}
533             );
534         }
535     }
536 }
537
538 my $amountold = $borrower->{flags}->{'CHARGES'}->{'message'} || 0;
539 $amountold =~ s/^.*\$//;    # remove upto the $, if any
540
541 my ( $total, $accts, $numaccts) = GetMemberAccountRecords( $borrowernumber );
542
543 if ( $borrowernumber && $borrower->{'category_type'} eq 'C') {
544     my  ( $catcodes, $labels ) =  GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
545     my $cnt = scalar(@$catcodes);
546     $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
547     $template->param( 'catcode' =>    $catcodes->[0])  if $cnt == 1;
548 }
549
550 my $lib_messages_loop = GetMessages( $borrowernumber, 'L', $branch );
551 if($lib_messages_loop){ $template->param(flagged => 1 ); }
552
553 my $bor_messages_loop = GetMessages( $borrowernumber, 'B', $branch );
554 if($bor_messages_loop){ $template->param(flagged => 1 ); }
555
556 my $fast_cataloging = 0;
557 if (defined getframeworkinfo('FA')) {
558     $fast_cataloging = 1 
559 }
560
561 if (C4::Context->preference('ExtendedPatronAttributes')) {
562     my $attributes = GetBorrowerAttributes($borrowernumber);
563     $template->param(
564         ExtendedPatronAttributes => 1,
565         extendedattributes => $attributes
566     );
567 }
568 my $view = $batch
569     ?'batch_checkout_view'
570     : 'circview';
571
572 my @relatives = GetMemberRelatives( $borrower->{'borrowernumber'} );
573 my $relatives_issues_count =
574   Koha::Database->new()->schema()->resultset('Issue')
575   ->count( { borrowernumber => \@relatives } );
576
577 my $roadtype = C4::Koha::GetAuthorisedValueByCode( 'ROADTYPE', $borrower->{streettype} );
578
579 $template->param(%$borrower);
580
581 $template->param(
582     lib_messages_loop => $lib_messages_loop,
583     bor_messages_loop => $bor_messages_loop,
584     all_messages_del  => C4::Context->preference('AllowAllMessageDeletion'),
585     findborrower      => $findborrower,
586     borrower          => $borrower,
587     borrowernumber    => $borrowernumber,
588     branch            => $branch,
589     branchname        => GetBranchName($borrower->{'branchcode'}),
590     printer           => $printer,
591     printername       => $printer,
592     was_renewed       => $query->param('was_renewed') ? 1 : 0,
593     expiry            => format_date($borrower->{'dateexpiry'}),
594     roadtype          => $roadtype,
595     amountold         => $amountold,
596     barcodes          => $barcodes,
597     stickyduedate     => $stickyduedate,
598     duedatespec       => $duedatespec,
599     message           => $message,
600     totaldue          => sprintf('%.2f', $total),
601     inprocess         => $inprocess,
602     is_child          => ($borrowernumber && $borrower->{'category_type'} eq 'C'),
603     $view             => 1,
604     batch_allowed     => $batch_allowed,
605     soundon           => C4::Context->preference("SoundOn"),
606     fast_cataloging   => $fast_cataloging,
607     CircAutoPrintQuickSlip   => C4::Context->preference("CircAutoPrintQuickSlip"),
608     activeBorrowerRelationship => (C4::Context->preference('borrowerRelationship') ne ''),
609     SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
610     AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
611     RoutingSerials => C4::Context->preference('RoutingSerials'),
612     relatives_issues_count => $relatives_issues_count,
613     relatives_borrowernumbers => \@relatives,
614 );
615
616 # save stickyduedate to session
617 if ($stickyduedate) {
618     $session->param( 'stickyduedate', $duedatespec );
619 }
620
621 my ($picture, $dberror) = GetPatronImage($borrower->{'borrowernumber'});
622 $template->param( picture => 1 ) if $picture;
623
624 # get authorised values with type of BOR_NOTES
625
626 my $canned_notes = GetAuthorisedValues("BOR_NOTES");
627
628 $template->param(
629     debt_confirmed            => $debt_confirmed,
630     SpecifyDueDate            => $duedatespec_allow,
631     CircAutocompl             => C4::Context->preference("CircAutocompl"),
632     AllowRenewalLimitOverride => C4::Context->preference("AllowRenewalLimitOverride"),
633     canned_bor_notes_loop     => $canned_notes,
634     debarments                => GetDebarments({ borrowernumber => $borrowernumber }),
635     todaysdate                => output_pref( { dt => dt_from_string()->set(hour => 23)->set(minute => 59), dateformat => 'sql' } ),
636 );
637
638 output_html_with_http_headers $query, $cookie, $template->output;