Bug 19940: Koha::Biblio - Remove GetBiblioItemInfosOf
[koha.git] / reserve / request.pl
1 #!/usr/bin/perl
2
3
4 #written 2/1/00 by chris@katipo.oc.nz
5 # Copyright 2000-2002 Katipo Communications
6 # Parts Copyright 2011 Catalyst IT
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23 =head1 request.pl
24
25 script to place reserves/requests
26
27 =cut
28
29 use Modern::Perl;
30
31 use CGI qw ( -utf8 );
32 use List::MoreUtils qw/uniq/;
33 use Date::Calc qw/Date_to_Days/;
34 use C4::Output;
35 use C4::Auth;
36 use C4::Reserves;
37 use C4::Biblio;
38 use C4::Items;
39 use C4::Koha;
40 use C4::Circulation;
41 use Koha::DateUtils;
42 use C4::Utils::DataTables::Members;
43 use C4::Members;
44 use C4::Search;         # enabled_staff_search_views
45
46 use Koha::Biblios;
47 use Koha::DateUtils;
48 use Koha::Checkouts;
49 use Koha::Holds;
50 use Koha::IssuingRules;
51 use Koha::Items;
52 use Koha::ItemTypes;
53 use Koha::Libraries;
54 use Koha::Patrons;
55
56 my $dbh = C4::Context->dbh;
57 my $input = new CGI;
58 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
59     {
60         template_name   => "reserve/request.tt",
61         query           => $input,
62         type            => "intranet",
63         authnotrequired => 0,
64         flagsrequired   => { reserveforothers => 'place_holds' },
65     }
66 );
67
68 my $multihold = $input->param('multi_hold');
69 $template->param(multi_hold => $multihold);
70 my $showallitems = $input->param('showallitems');
71
72 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
73
74 # Select borrowers infos
75 my $findborrower = $input->param('findborrower');
76 $findborrower = '' unless defined $findborrower;
77 $findborrower =~ s|,| |g;
78 my $borrowernumber_hold = $input->param('borrowernumber') || '';
79 my $messageborrower;
80 my $warnings;
81 my $messages;
82 my $exceeded_maxreserves;
83 my $exceeded_holds_per_record;
84
85 my $date = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
86 my $action = $input->param('action');
87 $action ||= q{};
88
89 if ( $action eq 'move' ) {
90   my $where = $input->param('where');
91   my $reserve_id = $input->param('reserve_id');
92   AlterPriority( $where, $reserve_id );
93 } elsif ( $action eq 'cancel' ) {
94   my $reserve_id = $input->param('reserve_id');
95   my $hold = Koha::Holds->find( $reserve_id );
96   $hold->cancel if $hold;
97 } elsif ( $action eq 'setLowestPriority' ) {
98   my $reserve_id = $input->param('reserve_id');
99   ToggleLowestPriority( $reserve_id );
100 } elsif ( $action eq 'toggleSuspend' ) {
101   my $reserve_id = $input->param('reserve_id');
102   my $suspend_until  = $input->param('suspend_until');
103   ToggleSuspend( $reserve_id, $suspend_until );
104 }
105
106 if ($findborrower) {
107     my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
108     if ( $patron ) {
109         $borrowernumber_hold = $patron->borrowernumber;
110     } else {
111         my $dt_params = { iDisplayLength => -1 };
112         my $results = C4::Utils::DataTables::Members::search(
113             {
114                 searchmember => $findborrower,
115                 dt_params => $dt_params,
116             }
117         );
118         my $borrowers = $results->{patrons};
119         if ( scalar @$borrowers == 1 ) {
120             $borrowernumber_hold = $borrowers->[0]->{borrowernumber};
121         } elsif ( @$borrowers ) {
122             $template->param( borrowers => $borrowers );
123         } else {
124             $messageborrower = "'$findborrower'";
125         }
126     }
127 }
128
129 my @biblionumbers = ();
130 my $biblionumbers = $input->param('biblionumbers');
131 if ($multihold) {
132     @biblionumbers = split '/', $biblionumbers;
133 } else {
134     push @biblionumbers, $input->multi_param('biblionumber');
135 }
136
137
138 # If we have the borrowernumber because we've performed an action, then we
139 # don't want to try to place another reserve.
140 if ($borrowernumber_hold && !$action) {
141     my $patron = Koha::Patrons->find( $borrowernumber_hold );
142     my $diffbranch;
143
144     # we check the reserves of the user, and if they can reserve a document
145     # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
146
147     my $reserves_count = $patron->holds->count;
148
149     my $new_reserves_count = scalar( @biblionumbers );
150
151     my $maxreserves = C4::Context->preference('maxreserves');
152     if ( $maxreserves
153         && ( $reserves_count + $new_reserves_count > $maxreserves ) )
154     {
155         my $new_reserves_allowed =
156             $maxreserves - $reserves_count > 0
157           ? $maxreserves - $reserves_count
158           : 0;
159         $warnings             = 1;
160         $exceeded_maxreserves = 1;
161         $template->param(
162             new_reserves_allowed => $new_reserves_allowed,
163             new_reserves_count   => $new_reserves_count,
164             reserves_count       => $reserves_count,
165             maxreserves          => $maxreserves,
166         );
167     }
168
169     # we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn)
170     my $expiry_date = $patron->dateexpiry;
171     my $expiry = 0; # flag set if patron account has expired
172     if ($expiry_date and $expiry_date ne '0000-00-00' and
173         Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
174         $expiry = 1;
175     }
176
177     # check if the borrower make the reserv in a different branch
178     if ( $patron->branchcode ne C4::Context->userenv->{'branch'} ) {
179         $diffbranch = 1;
180     }
181
182     my $amount_outstanding = $patron->account->balance;
183     $template->param(
184                 expiry              => $expiry,
185                 diffbranch          => $diffbranch,
186                 messages            => $messages,
187                 warnings            => $warnings,
188                 amount_outstanding  => $amount_outstanding,
189     );
190 }
191
192 $template->param( messageborrower => $messageborrower );
193
194 # FIXME launch another time GetMember perhaps until (Joubu: Why?)
195 my $patron = Koha::Patrons->find( $borrowernumber_hold );
196
197 my $logged_in_patron = Koha::Patrons->find( $borrowernumber );
198
199 my $itemdata_enumchron = 0;
200 my @biblioloop = ();
201 foreach my $biblionumber (@biblionumbers) {
202     next unless $biblionumber =~ m|^\d+$|;
203
204     my %biblioloopiter = ();
205
206     my $biblio = Koha::Biblios->find( $biblionumber );
207
208     my $force_hold_level;
209     if ( $patron ) {
210         { # CanBookBeReserved
211             my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber );
212             $canReserve //= '';
213             if ( $canReserve eq 'OK' ) {
214
215                 #All is OK and we can continue
216             }
217             elsif ( $canReserve eq 'tooManyReserves' ) {
218                 $exceeded_maxreserves = 1;
219             }
220             elsif ( $canReserve eq 'tooManyHoldsForThisRecord' ) {
221                 $exceeded_holds_per_record = 1;
222                 $biblioloopiter{$canReserve} = 1;
223             }
224             elsif ( $canReserve eq 'ageRestricted' ) {
225                 $template->param( $canReserve => 1 );
226                 $biblioloopiter{$canReserve} = 1;
227             }
228             else {
229                 $biblioloopiter{$canReserve} = 1;
230             }
231         }
232
233         # For multiple holds per record, if a patron has previously placed a hold,
234         # the patron can only place more holds of the same type. That is, if the
235         # patron placed a record level hold, all the holds the patron places must
236         # be record level. If the patron placed an item level hold, all holds
237         # the patron places must be item level
238         my $holds = Koha::Holds->search(
239             {
240                 borrowernumber => $patron->borrowernumber,
241                 biblionumber   => $biblionumber,
242                 found          => undef,
243             }
244         );
245         $force_hold_level = $holds->forced_hold_level();
246         $biblioloopiter{force_hold_level} = $force_hold_level;
247         $template->param( force_hold_level => $force_hold_level );
248
249         # For a librarian to be able to place multiple record holds for a patron for a record,
250         # we must find out what the maximum number of holds they can place for the patron is
251         my $max_holds_for_record = GetMaxPatronHoldsForRecord( $patron->borrowernumber, $biblionumber );
252         my $remaining_holds_for_record = $max_holds_for_record - $holds->count();
253         $biblioloopiter{remaining_holds_for_record} = $max_holds_for_record;
254         $template->param( max_holds_for_record => $max_holds_for_record );
255         $template->param( remaining_holds_for_record => $remaining_holds_for_record );
256
257         { # alreadypossession
258             # Check to see if patron is allowed to place holds on records where the
259             # patron already has an item from that record checked out
260             if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions')
261                 && CheckIfIssuedToPatron( $patron->borrowernumber, $biblionumber ) )
262             {
263                 $template->param( alreadypossession => 1, );
264             }
265         }
266     }
267
268
269     my $count = Koha::Holds->search( { biblionumber => $biblionumber } )->count();
270     my $totalcount = $count;
271
272     # FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
273     # make priorities options
274
275     my @optionloop;
276     for ( 1 .. $count + 1 ) {
277         push(
278              @optionloop,
279              {
280               num      => $_,
281               selected => ( $_ == $count + 1 ),
282              }
283             );
284     }
285     # adding a fixed value for priority options
286     my $fixedRank = $count+1;
287
288     my %itemnumbers_of_biblioitem;
289
290     my @hostitems = get_hostitemnumbers_of($biblionumber);
291     my @itemnumbers;
292     if (@hostitems){
293         $template->param('hostitemsflag' => 1);
294         push(@itemnumbers, @hostitems);
295     }
296
297     my $items = Koha::Items->search({ -or => { biblionumber => $biblionumber, itemnumber => { in => \@itemnumbers } } });
298
299     unless ( $items->count ) {
300         # FIXME Then why do we continue?
301         $template->param('noitems' => 1);
302         $biblioloopiter{noitems} = 1;
303     }
304
305     ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers,
306     ## when by definition all of the itemnumber have the same biblioitemnumber
307     my ( $iteminfos_of );
308     while ( my $item = $items->next ) {
309         $item = $item->unblessed;
310         my $biblioitemnumber = $item->{biblioitemnumber};
311         my $itemnumber = $item->{itemnumber};
312         push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
313         $iteminfos_of->{$itemnumber} = $item;
314     }
315
316     ## Should be same as biblionumber
317     my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
318
319     my $biblioiteminfos_of = {
320         map {
321             my $biblioitem = $_;
322             ( $biblioitem->{biblioitemnumber} => $biblioitem )
323           } @{ Koha::Biblioitems->search(
324                 { biblioitemnumber => { -in => \@biblioitemnumbers } },
325                 { select => ['biblioitemnumber', 'publicationyear', 'itemtype']}
326             )->unblessed
327           }
328     };
329
330     my $frameworkcode = GetFrameworkCode( $biblionumber );
331     my @notforloan_avs = Koha::AuthorisedValues->search_by_koha_field({ kohafield => 'items.notforloan', frameworkcode => $frameworkcode });
332     my $notforloan_label_of = { map { $_->authorised_value => $_->lib } @notforloan_avs };
333
334     my @bibitemloop;
335
336     my @available_itemtypes;
337     foreach my $biblioitemnumber (@biblioitemnumbers) {
338         my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
339         my $num_available = 0;
340         my $num_override  = 0;
341         my $hiddencount   = 0;
342
343         $biblioitem->{force_hold_level} = $force_hold_level;
344
345         if ( $biblioitem->{biblioitemnumber} ne $biblionumber ) {
346             $biblioitem->{hostitemsflag} = 1;
347         }
348
349         $biblioloopiter{description} = $biblioitem->{description};
350         $biblioloopiter{itypename}   = $biblioitem->{description};
351         if ( $biblioitem->{itemtype} ) {
352
353             $biblioitem->{description} =
354               $itemtypes->{ $biblioitem->{itemtype} }{description};
355
356             $biblioloopiter{imageurl} =
357               getitemtypeimagelocation( 'intranet',
358                 $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
359         }
360
361         foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
362             my $item = $iteminfos_of->{$itemnumber};
363
364             $item->{force_hold_level} = $force_hold_level;
365
366             unless (C4::Context->preference('item-level_itypes')) {
367                 $item->{itype} = $biblioitem->{itemtype};
368             }
369
370             $item->{itypename} = $itemtypes->{ $item->{itype} }{description};
371             $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
372             $item->{homebranch} = $item->{homebranch};
373
374             # if the holdingbranch is different than the homebranch, we show the
375             # holdingbranch of the document too
376             if ( $item->{homebranch} ne $item->{holdingbranch} ) {
377                 $item->{holdingbranch} = $item->{holdingbranch};
378             }
379
380             if($item->{biblionumber} ne $biblionumber){
381                 $item->{hostitemsflag} = 1;
382                 $item->{hosttitle} = Koha::Biblios->find( $item->{biblionumber} )->title;
383             }
384
385             # if the item is currently on loan, we display its return date and
386             # change the background color
387             my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
388             if ( $issue ) {
389                 $item->{date_due} = $issue->date_due;
390                 $item->{backgroundcolor} = 'onloan';
391             }
392
393             # checking reserve
394             my $item_object = Koha::Items->find( $itemnumber );
395             my $holds = $item_object->current_holds;
396             if ( my $first_hold = $holds->next ) {
397                 my $p = Koha::Patrons->find( $first_hold->borrowernumber );
398
399                 $item->{backgroundcolor} = 'reserved';
400                 $item->{reservedate}     = output_pref({ dt => dt_from_string( $first_hold->reservedate ), dateonly => 1 }); # FIXME Should be formatted in the template
401                 $item->{ReservedFor}     = $p;
402                 $item->{ExpectedAtLibrary}     = $first_hold->branchcode;
403                 $item->{waitingdate} = $first_hold->waitingdate;
404             }
405
406             # Management of the notforloan document
407             if ( $item->{notforloan} ) {
408                 $item->{backgroundcolor} = 'other';
409                 $item->{notforloanvalue} =
410                   $notforloan_label_of->{ $item->{notforloan} };
411             }
412
413             # Management of lost or long overdue items
414             if ( $item->{itemlost} ) {
415
416                 # FIXME localized strings should never be in Perl code
417                 $item->{message} =
418                   $item->{itemlost} == 1 ? "(lost)"
419                     : $item->{itemlost} == 2 ? "(long overdue)"
420                       : "";
421                 $item->{backgroundcolor} = 'other';
422                 if ($logged_in_patron->category->hidelostitems && !$showallitems) {
423                     $item->{hide} = 1;
424                     $hiddencount++;
425                 }
426             }
427
428             # Check the transit status
429             my ( $transfertwhen, $transfertfrom, $transfertto ) =
430               GetTransfers($itemnumber);
431
432             if ( defined $transfertwhen && $transfertwhen ne '' ) {
433                 $item->{transfertwhen} = output_pref({ dt => dt_from_string( $transfertwhen ), dateonly => 1 });
434                 $item->{transfertfrom} = $transfertfrom;
435                 $item->{transfertto} = $transfertto;
436                 $item->{nocancel} = 1;
437             }
438
439             # If there is no loan, return and transfer, we show a checkbox.
440             $item->{notforloan} ||= 0;
441
442             # if independent branches is on we need to check if the person can reserve
443             # for branches they arent logged in to
444             if ( C4::Context->preference("IndependentBranches") ) {
445                 if (! C4::Context->preference("canreservefromotherbranches")){
446                     # cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
447                     my $userenv = C4::Context->userenv;
448                     unless ( C4::Context->IsSuperLibrarian ) {
449                         $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
450                     }
451                 }
452             }
453
454             if ( $patron ) {
455                 my $patron_unblessed = $patron->unblessed;
456                 my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed);
457
458                 my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
459
460                 $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
461
462                 my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber );
463                 $item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' );
464
465                 $item->{item_level_holds} = Koha::IssuingRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
466
467                 if (
468                        !$item->{cantreserve}
469                     && !$exceeded_maxreserves
470                     && IsAvailableForItemLevelRequest($item, $patron_unblessed)
471                     && $can_item_be_reserved eq 'OK'
472                   )
473                 {
474                     $item->{available} = 1;
475                     $num_available++;
476
477                     push( @available_itemtypes, $item->{itype} );
478                 }
479                 elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
480                     # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
481                     $item->{override} = 1;
482                     $num_override++;
483
484                     push( @available_itemtypes, $item->{itype} );
485                 }
486
487                 # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
488
489                 # Show serial enumeration when needed
490                 if ($item->{enumchron}) {
491                     $itemdata_enumchron = 1;
492                 }
493             }
494
495             push @{ $biblioitem->{itemloop} }, $item;
496         }
497
498         if ( $num_override == scalar( @{ $biblioitem->{itemloop} } ) ) { # That is, if all items require an override
499             $template->param( override_required => 1 );
500         } elsif ( $num_available == 0 ) {
501             $template->param( none_available => 1 );
502             $biblioloopiter{warn} = 1;
503             $biblioloopiter{none_avail} = 1;
504         }
505         $template->param( hiddencount => $hiddencount);
506
507         push @bibitemloop, $biblioitem;
508     }
509
510     @available_itemtypes = uniq( @available_itemtypes );
511     $template->param( available_itemtypes => \@available_itemtypes );
512
513     # existingreserves building
514     my @reserveloop;
515     my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } );
516     foreach my $res (
517         sort {
518             my $a_found = $a->found() || '';
519             my $b_found = $a->found() || '';
520             $a_found cmp $b_found;
521         } @reserves
522       )
523     {
524         my $priority = $res->priority();
525         my %reserve;
526         my @optionloop;
527         for ( my $i = 1 ; $i <= $totalcount ; $i++ ) {
528             push(
529                 @optionloop,
530                 {
531                     num      => $i,
532                     selected => ( $i == $priority ),
533                 }
534             );
535         }
536
537         if ( $res->is_found() ) {
538             $reserve{'holdingbranch'} = $res->item()->holdingbranch();
539             $reserve{'biblionumber'}  = $res->item()->biblionumber();
540             $reserve{'barcodenumber'} = $res->item()->barcode();
541             $reserve{'wbrcode'}       = $res->branchcode();
542             $reserve{'itemnumber'}    = $res->itemnumber();
543             $reserve{'wbrname'}       = $res->branch()->branchname();
544
545             if ( $reserve{'holdingbranch'} eq $reserve{'wbrcode'} ) {
546
547                 # Just because the holdingbranch matches the reserve branch doesn't mean the item
548                 # has arrived at the destination, check for an open transfer for the item as well
549                 my ( $transfertwhen, $transfertfrom, $transferto ) =
550                   C4::Circulation::GetTransfers( $res->itemnumber() );
551                 if ( not $transferto or $transferto ne $res->branchcode() ) {
552                     $reserve{'atdestination'} = 1;
553                 }
554             }
555
556             # set found to 1 if reserve is waiting for patron pickup
557             $reserve{'found'}     = $res->is_found();
558             $reserve{'intransit'} = $res->is_in_transit();
559         }
560         elsif ( $res->priority() > 0 ) {
561             if ( my $item = $res->item() )  {
562                 $reserve{'itemnumber'}      = $item->id();
563                 $reserve{'barcodenumber'}   = $item->barcode();
564                 $reserve{'item_level_hold'} = 1;
565             }
566         }
567
568         $reserve{'expirationdate'} = output_pref( { dt => dt_from_string( $res->expirationdate ), dateonly => 1 } )
569           unless ( !defined( $res->expirationdate ) || $res->expirationdate eq '0000-00-00' );
570         $reserve{'date'}           = output_pref( { dt => dt_from_string( $res->reservedate ), dateonly => 1 } );
571         $reserve{'borrowernumber'} = $res->borrowernumber();
572         $reserve{'biblionumber'}   = $res->biblionumber();
573         $reserve{'patron'}         = $res->borrower;
574         $reserve{'notes'}          = $res->reservenotes();
575         $reserve{'waiting_date'}   = $res->waitingdate();
576         $reserve{'ccode'}          = $res->item() ? $res->item()->ccode() : undef;
577         $reserve{'barcode'}        = $res->item() ? $res->item()->barcode() : undef;
578         $reserve{'priority'}       = $res->priority();
579         $reserve{'lowestPriority'} = $res->lowestPriority();
580         $reserve{'optionloop'}     = \@optionloop;
581         $reserve{'suspend'}        = $res->suspend();
582         $reserve{'suspend_until'}  = $res->suspend_until();
583         $reserve{'reserve_id'}     = $res->reserve_id();
584         $reserve{itemtype}         = $res->itemtype();
585         $reserve{branchcode}       = $res->branchcode();
586
587         push( @reserveloop, \%reserve );
588     }
589
590     # get the time for the form name...
591     my $time = time();
592
593     $template->param(
594                      time        => $time,
595                      fixedRank   => $fixedRank,
596                     );
597
598     # display infos
599     $template->param(
600                      optionloop        => \@optionloop,
601                      bibitemloop       => \@bibitemloop,
602                      itemdata_enumchron => $itemdata_enumchron,
603                      date              => $date,
604                      biblionumber      => $biblionumber,
605                      findborrower      => $findborrower,
606                      title             => $biblio->title,
607                      author            => $biblio->author,
608                      holdsview => 1,
609                      C4::Search::enabled_staff_search_views,
610                     );
611
612     $biblioloopiter{biblionumber} = $biblionumber;
613     $biblioloopiter{title} = $biblio->title;
614     $biblioloopiter{rank} = $fixedRank;
615     $biblioloopiter{reserveloop} = \@reserveloop;
616
617     if (@reserveloop) {
618         $template->param( reserveloop => \@reserveloop );
619     }
620
621     push @biblioloop, \%biblioloopiter;
622 }
623
624 $template->param( biblioloop => \@biblioloop );
625 $template->param( biblionumbers => $biblionumbers );
626 $template->param( exceeded_maxreserves => $exceeded_maxreserves );
627 $template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
628
629 if ($multihold) {
630     $template->param( multi_hold => 1 );
631 }
632
633 if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
634     $template->param( reserve_in_future => 1 );
635 }
636
637 $template->param(
638     patron => $patron,
639     SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
640     AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
641 );
642
643 # printout the page
644 output_html_with_http_headers $input, $cookie, $template->output;
645
646 sub sort_borrowerlist {
647     my $borrowerslist = shift;
648     my $ref           = [];
649     push @{$ref}, sort {
650         uc( $a->{surname} . $a->{firstname} ) cmp
651           uc( $b->{surname} . $b->{firstname} )
652     } @{$borrowerslist};
653     return $ref;
654 }