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