Bug 15533 [QA Followup] - Itemtype limit missing from tables
[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 strict;
30 use warnings;
31 use C4::Branch;
32 use CGI qw ( -utf8 );
33 use List::MoreUtils qw/uniq/;
34 use Date::Calc qw/Date_to_Days/;
35 use C4::Output;
36 use C4::Auth;
37 use C4::Reserves;
38 use C4::Biblio;
39 use C4::Items;
40 use C4::Koha;
41 use C4::Circulation;
42 use Koha::DateUtils;
43 use C4::Utils::DataTables::Members;
44 use C4::Members;
45 use C4::Search;         # enabled_staff_search_views
46 use Koha::DateUtils;
47 use Koha::Patron::Debarments qw(IsDebarred);
48 use Koha::Holds;
49 use Koha::Libraries;
50
51 my $dbh = C4::Context->dbh;
52 my $input = new CGI;
53 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
54     {
55         template_name   => "reserve/request.tt",
56         query           => $input,
57         type            => "intranet",
58         authnotrequired => 0,
59         flagsrequired   => { reserveforothers => 'place_holds' },
60     }
61 );
62
63 my $multihold = $input->param('multi_hold');
64 $template->param(multi_hold => $multihold);
65 my $showallitems = $input->param('showallitems');
66
67 # get Branches and Itemtypes
68 my $branches = GetBranches();
69 my $itemtypes = GetItemTypes();
70
71 my $userbranch = '';
72 if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
73     $userbranch = C4::Context->userenv->{'branch'};
74 }
75
76
77 # Select borrowers infos
78 my $findborrower = $input->param('findborrower');
79 $findborrower = '' unless defined $findborrower;
80 $findborrower =~ s|,| |g;
81 my $borrowernumber_hold = $input->param('borrowernumber') || '';
82 my $messageborrower;
83 my $warnings;
84 my $messages;
85 my $exceeded_maxreserves;
86
87 my $date = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
88 my $action = $input->param('action');
89 $action ||= q{};
90
91 if ( $action eq 'move' ) {
92   my $where = $input->param('where');
93   my $reserve_id = $input->param('reserve_id');
94   AlterPriority( $where, $reserve_id );
95 } elsif ( $action eq 'cancel' ) {
96   my $reserve_id = $input->param('reserve_id');
97   CancelReserve({ reserve_id => $reserve_id });
98 } elsif ( $action eq 'setLowestPriority' ) {
99   my $reserve_id = $input->param('reserve_id');
100   ToggleLowestPriority( $reserve_id );
101 } elsif ( $action eq 'toggleSuspend' ) {
102   my $reserve_id = $input->param('reserve_id');
103   my $suspend_until  = $input->param('suspend_until');
104   ToggleSuspend( $reserve_id, $suspend_until );
105 }
106
107 if ($findborrower) {
108     my $borrower = C4::Members::GetMember( cardnumber => $findborrower );
109     if ( $borrower ) {
110         $borrowernumber_hold = $borrower->{borrowernumber};
111     } else {
112         my $dt_params = { iDisplayLength => -1 };
113         my $results = C4::Utils::DataTables::Members::search(
114             {
115                 searchmember => $findborrower,
116                 dt_params => $dt_params,
117             }
118         );
119         my $borrowers = $results->{patrons};
120         if ( scalar @$borrowers == 1 ) {
121             $borrowernumber_hold = $borrowers->[0]->{borrowernumber};
122         } elsif ( @$borrowers ) {
123             $template->param( borrowers => $borrowers );
124         } else {
125             $messageborrower = "'$findborrower'";
126         }
127     }
128 }
129
130 my @biblionumbers = ();
131 my $biblionumbers = $input->param('biblionumbers');
132 if ($multihold) {
133     @biblionumbers = split '/', $biblionumbers;
134 } else {
135     push @biblionumbers, $input->multi_param('biblionumber');
136 }
137
138
139 # If we have the borrowernumber because we've performed an action, then we
140 # don't want to try to place another reserve.
141 if ($borrowernumber_hold && !$action) {
142     my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
143     my $diffbranch;
144
145     # we check the reserves of the borrower, and if he can reserv a document
146     # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
147
148     my $reserves_count =
149       GetReserveCount( $borrowerinfo->{'borrowernumber'} );
150
151     my $new_reserves_count = scalar( @biblionumbers );
152
153     my $maxreserves = C4::Context->preference('maxreserves');
154     if ( $maxreserves
155         && ( $reserves_count + $new_reserves_count > $maxreserves ) )
156     {
157         my $new_reserves_allowed =
158             $maxreserves - $reserves_count > 0
159           ? $maxreserves - $reserves_count
160           : 0;
161         $warnings             = 1;
162         $exceeded_maxreserves = 1;
163         $template->param(
164             new_reserves_allowed => $new_reserves_allowed,
165             new_reserves_count   => $new_reserves_count,
166             reserves_count       => $reserves_count,
167             maxreserves          => $maxreserves,
168         );
169     }
170
171     # we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn)
172     my $expiry_date = $borrowerinfo->{dateexpiry};
173     my $expiry = 0; # flag set if patron account has expired
174     if ($expiry_date and $expiry_date ne '0000-00-00' and
175         Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
176         $expiry = 1;
177     }
178
179     # check if the borrower make the reserv in a different branch
180     if ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) {
181         $diffbranch = 1;
182     }
183
184     $template->param(
185                 borrowernumber      => $borrowerinfo->{'borrowernumber'},
186                 borrowersurname     => $borrowerinfo->{'surname'},
187                 borrowerfirstname   => $borrowerinfo->{'firstname'},
188                 borrowerstreetaddress   => $borrowerinfo->{'address'},
189                 borrowercity        => $borrowerinfo->{'city'},
190                 borrowerphone       => $borrowerinfo->{'phone'},
191                 borrowermobile      => $borrowerinfo->{'mobile'},
192                 borrowerfax         => $borrowerinfo->{'fax'},
193                 borrowerphonepro    => $borrowerinfo->{'phonepro'},
194                 borroweremail       => $borrowerinfo->{'email'},
195                 borroweremailpro    => $borrowerinfo->{'emailpro'},
196                 borrowercategory    => $borrowerinfo->{'category'},
197                 cardnumber          => $borrowerinfo->{'cardnumber'},
198                 expiry              => $expiry,
199                 diffbranch          => $diffbranch,
200                 messages            => $messages,
201                 warnings            => $warnings,
202                 restricted          => IsDebarred($borrowerinfo->{'borrowernumber'}),
203                 amount_outstanding  => GetMemberAccountRecords($borrowerinfo->{borrowernumber}),
204     );
205 }
206
207 $template->param( messageborrower => $messageborrower );
208
209 # FIXME launch another time GetMember perhaps until
210 my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
211
212 my $itemdata_enumchron = 0;
213 my @biblioloop = ();
214 foreach my $biblionumber (@biblionumbers) {
215
216     my %biblioloopiter = ();
217
218     my $dat = GetBiblioData($biblionumber);
219
220     my $canReserve = CanBookBeReserved( $borrowerinfo->{borrowernumber}, $biblionumber );
221     $canReserve //= '';
222     if ( $canReserve eq 'OK' ) {
223
224         #All is OK and we can continue
225     }
226     elsif ( $canReserve eq 'tooManyReserves' ) {
227         $exceeded_maxreserves = 1;
228     }
229     elsif ( $canReserve eq 'ageRestricted' ) {
230         $template->param( $canReserve => 1 );
231         $biblioloopiter{$canReserve} = 1;
232     }
233     else {
234         $biblioloopiter{$canReserve} = 1;
235     }
236
237     my $alreadypossession;
238     if (not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowerinfo->{borrowernumber},$biblionumber)) {
239         $alreadypossession = 1;
240     }
241
242     # get existing reserves .....
243     my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
244     my $count = scalar( @$reserves );
245     my $totalcount = $count;
246     my $holds_count = 0;
247     my $alreadyreserved = 0;
248
249     foreach my $res (@$reserves) {
250         if ( defined $res->{found} ) { # found can be 'W' or 'T'
251             $count--;
252         }
253
254         if ( defined $borrowerinfo && defined($borrowerinfo->{borrowernumber}) && ($borrowerinfo->{borrowernumber} eq $res->{borrowernumber}) ) {
255             $holds_count++;
256         }
257     }
258
259     if ( $holds_count ) {
260             $alreadyreserved = 1;
261             $biblioloopiter{warn} = 1;
262             $biblioloopiter{alreadyres} = 1;
263     }
264
265     $template->param(
266         alreadyreserved => $alreadyreserved,
267         alreadypossession => $alreadypossession,
268     );
269
270     # FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
271     # make priorities options
272
273     my @optionloop;
274     for ( 1 .. $count + 1 ) {
275         push(
276              @optionloop,
277              {
278               num      => $_,
279               selected => ( $_ == $count + 1 ),
280              }
281             );
282     }
283     # adding a fixed value for priority options
284     my $fixedRank = $count+1;
285
286     my %itemnumbers_of_biblioitem;
287     my @itemnumbers;
288
289     ## $items is array of 'item' table numbers
290     if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
291         @itemnumbers  = @$items;
292     }
293     my @hostitems = get_hostitemnumbers_of($biblionumber);
294     if (@hostitems){
295         $template->param('hostitemsflag' => 1);
296         push(@itemnumbers, @hostitems);
297     }
298
299     if (!@itemnumbers) {
300         $template->param('noitems' => 1);
301         $biblioloopiter{noitems} = 1;
302     }
303
304     ## Hash of item number to 'item' table fields
305     my $iteminfos_of = GetItemInfosOf(@itemnumbers);
306
307     ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers,
308     ## when by definition all of the itemnumber have the same biblioitemnumber
309     foreach my $itemnumber (@itemnumbers) {
310         my $biblioitemnumber = $iteminfos_of->{$itemnumber}->{biblioitemnumber};
311         push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
312     }
313
314     ## Should be same as biblionumber
315     my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
316
317     my $notforloan_label_of = get_notforloan_label_of();
318
319     ## Hash of biblioitemnumber to 'biblioitem' table records
320     my $biblioiteminfos_of  = GetBiblioItemInfosOf(@biblioitemnumbers);
321
322     my @bibitemloop;
323
324     my @available_itemtypes;
325     foreach my $biblioitemnumber (@biblioitemnumbers) {
326         my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
327         my $num_available = 0;
328         my $num_override  = 0;
329         my $hiddencount   = 0;
330
331         if ( $biblioitem->{biblioitemnumber} ne $biblionumber ) {
332             $biblioitem->{hostitemsflag} = 1;
333         }
334
335         $biblioloopiter{description} = $biblioitem->{description};
336         $biblioloopiter{itypename}   = $biblioitem->{description};
337         if ( $biblioitem->{itemtype} ) {
338
339             $biblioitem->{description} =
340               $itemtypes->{ $biblioitem->{itemtype} }{description};
341
342             $biblioloopiter{imageurl} =
343               getitemtypeimagelocation( 'intranet',
344                 $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
345         }
346
347         foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
348             my $item = $iteminfos_of->{$itemnumber};
349
350             unless (C4::Context->preference('item-level_itypes')) {
351                 $item->{itype} = $biblioitem->{itemtype};
352             }
353
354             $item->{itypename} = $itemtypes->{ $item->{itype} }{description};
355             $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
356             $item->{homebranchname} = $branches->{ $item->{homebranch} }{branchname};
357
358             # if the holdingbranch is different than the homebranch, we show the
359             # holdingbranch of the document too
360             if ( $item->{homebranch} ne $item->{holdingbranch} ) {
361                 $item->{holdingbranchname} =
362                   $branches->{ $item->{holdingbranch} }{branchname};
363             }
364
365                 if($item->{biblionumber} ne $biblionumber){
366                         $item->{hostitemsflag}=1;
367                         $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
368                 }
369                 
370             # if the item is currently on loan, we display its return date and
371             # change the background color
372             my $issues= GetItemIssue($itemnumber);
373             if ( $issues->{'date_due'} ) {
374                 $item->{date_due} = $issues->{date_due_sql};
375                 $item->{backgroundcolor} = 'onloan';
376             }
377
378             # checking reserve
379             my ($reservedate,$reservedfor,$expectedAt,$reserve_id,$wait) = GetReservesFromItemnumber($itemnumber);
380             if ( defined $reservedate ) {
381                 my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
382
383                 $item->{backgroundcolor} = 'reserved';
384                 $item->{reservedate}     = output_pref({ dt => dt_from_string( $reservedate ), dateonly => 1 });
385                 $item->{ReservedForBorrowernumber}     = $reservedfor;
386                 $item->{ReservedForSurname}     = $ItemBorrowerReserveInfo->{'surname'};
387                 $item->{ReservedForFirstname}     = $ItemBorrowerReserveInfo->{'firstname'};
388                 $item->{ExpectedAtLibrary}     = $branches->{$expectedAt}{branchname};
389                 $item->{waitingdate} = $wait;
390             }
391
392             # Management of the notforloan document
393             if ( $item->{notforloan} ) {
394                 $item->{backgroundcolor} = 'other';
395                 $item->{notforloanvalue} =
396                   $notforloan_label_of->{ $item->{notforloan} };
397             }
398
399             # Management of lost or long overdue items
400             if ( $item->{itemlost} ) {
401
402                 # FIXME localized strings should never be in Perl code
403                 $item->{message} =
404                   $item->{itemlost} == 1 ? "(lost)"
405                     : $item->{itemlost} == 2 ? "(long overdue)"
406                       : "";
407                 $item->{backgroundcolor} = 'other';
408                 if (GetHideLostItemsPreference($borrowernumber) && !$showallitems) {
409                     $item->{hide} = 1;
410                     $hiddencount++;
411                 }
412             }
413
414             # Check the transit status
415             my ( $transfertwhen, $transfertfrom, $transfertto ) =
416               GetTransfers($itemnumber);
417
418             if ( defined $transfertwhen && $transfertwhen ne '' ) {
419                 $item->{transfertwhen} = output_pref({ dt => dt_from_string( $transfertwhen ), dateonly => 1 });
420                 $item->{transfertfrom} =
421                   $branches->{$transfertfrom}{branchname};
422                 $item->{transfertto} = $branches->{$transfertto}{branchname};
423                 $item->{nocancel} = 1;
424             }
425
426             # If there is no loan, return and transfer, we show a checkbox.
427             $item->{notforloan} ||= 0;
428
429             # if independent branches is on we need to check if the person can reserve
430             # for branches they arent logged in to
431             if ( C4::Context->preference("IndependentBranches") ) {
432                 if (! C4::Context->preference("canreservefromotherbranches")){
433                     # cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
434                     my $userenv = C4::Context->userenv;
435                     unless ( C4::Context->IsSuperLibrarian ) {
436                         $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
437                     }
438                 }
439             }
440
441             my $branch = C4::Circulation::_GetCircControlBranch($item, $borrowerinfo);
442
443             my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
444
445             $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
446
447             if (
448                    !$item->{cantreserve}
449                 && !$exceeded_maxreserves
450                 && IsAvailableForItemLevelRequest($item, $borrowerinfo)
451                 && CanItemBeReserved(
452                     $borrowerinfo->{borrowernumber}, $itemnumber
453                 ) eq 'OK'
454               )
455             {
456                 $item->{available} = 1;
457                 $num_available++;
458
459                 push( @available_itemtypes, $item->{itype} );
460             }
461             elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
462                 # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
463                 $item->{override} = 1;
464                 $num_override++;
465             }
466
467             # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
468
469             # Show serial enumeration when needed
470             if ($item->{enumchron}) {
471                 $itemdata_enumchron = 1;
472             }
473
474             push @{ $biblioitem->{itemloop} }, $item;
475         }
476
477         if ( $num_override == scalar( @{ $biblioitem->{itemloop} } ) ) { # That is, if all items require an override
478             $template->param( override_required => 1 );
479         } elsif ( $num_available == 0 ) {
480             $template->param( none_available => 1 );
481             $biblioloopiter{warn} = 1;
482             $biblioloopiter{none_avail} = 1;
483         }
484         $template->param( hiddencount => $hiddencount);
485
486         push @bibitemloop, $biblioitem;
487     }
488
489     @available_itemtypes = uniq( @available_itemtypes );
490     $template->param( available_itemtypes => \@available_itemtypes );
491
492     # existingreserves building
493     my @reserveloop;
494     my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } );
495     foreach my $res (
496         sort {
497             my $a_found = $a->found() || '';
498             my $b_found = $a->found() || '';
499             $a_found cmp $b_found;
500         } @reserves
501       )
502     {
503         my %reserve;
504         my @optionloop;
505         for ( my $i = 1 ; $i <= $totalcount ; $i++ ) {
506             push(
507                 @optionloop,
508                 {
509                     num      => $i,
510                     selected => ( $i == $res->priority() ),
511                 }
512             );
513         }
514
515         if ( $res->is_found() ) {
516             $reserve{'holdingbranch'} = $res->item()->holdingbranch();
517             $reserve{'biblionumber'}  = $res->item()->biblionumber();
518             $reserve{'barcodenumber'} = $res->item()->barcode();
519             $reserve{'wbrcode'}       = $res->branchcode();
520             $reserve{'itemnumber'}    = $res->itemnumber();
521             $reserve{'wbrname'}       = $res->branch()->branchname();
522
523             if ( $reserve{'holdingbranch'} eq $reserve{'wbrcode'} ) {
524
525                 # Just because the holdingbranch matches the reserve branch doesn't mean the item
526                 # has arrived at the destination, check for an open transfer for the item as well
527                 my ( $transfertwhen, $transfertfrom, $transferto ) =
528                   C4::Circulation::GetTransfers( $res->itemnumber() );
529                 if ( not $transferto or $transferto ne $res->branchcode() ) {
530                     $reserve{'atdestination'} = 1;
531                 }
532             }
533
534             # set found to 1 if reserve is waiting for patron pickup
535             $reserve{'found'}     = $res->is_found();
536             $reserve{'intransit'} = $res->is_in_transit();
537         }
538         elsif ( $res->priority() > 0 ) {
539             if ( my $item = $res->item() )  {
540                 $reserve{'itemnumber'}      = $item->id();
541                 $reserve{'barcodenumber'}   = $item->barcode();
542                 $reserve{'item_level_hold'} = 1;
543             }
544         }
545
546         #     get borrowers reserve info
547         if ( C4::Context->preference('HidePatronName') ) {
548             $reserve{'hidename'}   = 1;
549             $reserve{'cardnumber'} = $res->borrower()->cardnumber();
550         }
551         $reserve{'expirationdate'} = output_pref( { dt => dt_from_string( $res->expirationdate ), dateonly => 1 } )
552           unless ( !defined( $res->expirationdate ) || $res->expirationdate eq '0000-00-00' );
553         $reserve{'date'}           = output_pref( { dt => dt_from_string( $res->reservedate ), dateonly => 1 } );
554         $reserve{'borrowernumber'} = $res->borrowernumber();
555         $reserve{'biblionumber'}   = $res->biblionumber();
556         $reserve{'borrowernumber'} = $res->borrowernumber();
557         $reserve{'firstname'}      = $res->borrower()->firstname();
558         $reserve{'surname'}        = $res->borrower()->surname();
559         $reserve{'notes'}          = $res->reservenotes();
560         $reserve{'waiting_date'}   = $res->waitingdate();
561         $reserve{'waiting_until'}  = $res->is_waiting() ? $res->waiting_expires_on() : undef;
562         $reserve{'ccode'}          = $res->item() ? $res->item()->ccode() : undef;
563         $reserve{'barcode'}        = $res->item() ? $res->item()->barcode() : undef;
564         $reserve{'priority'}       = $res->priority();
565         $reserve{'lowestPriority'} = $res->lowestPriority();
566         $reserve{'optionloop'}     = \@optionloop;
567         $reserve{'suspend'}        = $res->suspend();
568         $reserve{'suspend_until'}  = $res->suspend_until();
569         $reserve{'reserve_id'}     = $res->reserve_id();
570         $reserve{itemtype}         = $res->itemtype();
571
572         if ( C4::Context->preference('IndependentBranches') && $flags->{'superlibrarian'} != 1 ) {
573             $reserve{'branchloop'} = [ Koha::Libraries->find( $res->branchcode() ) ];
574         }
575         else {
576             $reserve{'branchloop'} = GetBranchesLoop( $res->branchcode() );
577         }
578
579         push( @reserveloop, \%reserve );
580     }
581
582     # get the time for the form name...
583     my $time = time();
584
585     $template->param(
586                      branchloop  => GetBranchesLoop($userbranch),
587                      time        => $time,
588                      fixedRank   => $fixedRank,
589                     );
590
591     # display infos
592     $template->param(
593                      optionloop        => \@optionloop,
594                      bibitemloop       => \@bibitemloop,
595                      itemdata_enumchron => $itemdata_enumchron,
596                      date              => $date,
597                      biblionumber      => $biblionumber,
598                      findborrower      => $findborrower,
599                      title             => $dat->{title},
600                      author            => $dat->{author},
601                      holdsview => 1,
602                      C4::Search::enabled_staff_search_views,
603                     );
604     if (defined $borrowerinfo && exists $borrowerinfo->{'branchcode'}) {
605         $template->param(
606                      borrower_branchname => $branches->{$borrowerinfo->{'branchcode'}}->{'branchname'},
607                      borrower_branchcode => $borrowerinfo->{'branchcode'},
608         );
609     }
610
611     $biblioloopiter{biblionumber} = $biblionumber;
612     $biblioloopiter{title} = $dat->{title};
613     $biblioloopiter{rank} = $fixedRank;
614     $biblioloopiter{reserveloop} = \@reserveloop;
615
616     if (@reserveloop) {
617         $template->param( reserveloop => \@reserveloop );
618     }
619
620     push @biblioloop, \%biblioloopiter;
621 }
622
623 $template->param( biblioloop => \@biblioloop );
624 $template->param( biblionumbers => $biblionumbers );
625 $template->param( exceeded_maxreserves => $exceeded_maxreserves );
626
627 if ($multihold) {
628     $template->param( multi_hold => 1 );
629 }
630
631 if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
632     $template->param( reserve_in_future => 1 );
633 }
634
635 $template->param(
636     SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
637     AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
638 );
639
640 # printout the page
641 output_html_with_http_headers $input, $cookie, $template->output;
642
643 sub sort_borrowerlist {
644     my $borrowerslist = shift;
645     my $ref           = [];
646     push @{$ref}, sort {
647         uc( $a->{surname} . $a->{firstname} ) cmp
648           uc( $b->{surname} . $b->{firstname} )
649     } @{$borrowerslist};
650     return $ref;
651 }