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