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