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