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