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