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