Bug 17799: MARC bibliographic frameworks breadcrumbs broken for Default framework
[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 strict;
30 use warnings;
31 use C4::Branch;
32 use CGI qw ( -utf8 );
33 use List::MoreUtils qw/uniq/;
34 use Date::Calc qw/Date_to_Days/;
35 use C4::Output;
36 use C4::Auth;
37 use C4::Reserves;
38 use C4::Biblio;
39 use C4::Items;
40 use C4::Koha;
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 use Koha::DateUtils;
47 use Koha::Borrower::Debarments qw(IsDebarred);
48
49 my $dbh = C4::Context->dbh;
50 my $input = new CGI;
51 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
52     {
53         template_name   => "reserve/request.tt",
54         query           => $input,
55         type            => "intranet",
56         authnotrequired => 0,
57         flagsrequired   => { reserveforothers => 'place_holds' },
58     }
59 );
60
61 my $multihold = $input->param('multi_hold');
62 $template->param(multi_hold => $multihold);
63 my $showallitems = $input->param('showallitems');
64
65 # get Branches and Itemtypes
66 my $branches = GetBranches();
67 my $itemtypes = GetItemTypes();
68
69 my $userbranch = '';
70 if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
71     $userbranch = C4::Context->userenv->{'branch'};
72 }
73
74
75 # Select borrowers infos
76 my $findborrower = $input->param('findborrower');
77 $findborrower = '' unless defined $findborrower;
78 $findborrower =~ s|,| |g;
79 my $borrowernumber_hold = $input->param('borrowernumber') || '';
80 my $messageborrower;
81 my $warnings;
82 my $messages;
83 my $exceeded_maxreserves;
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   AlterPriority( $where, $reserve_id );
93 } elsif ( $action eq 'cancel' ) {
94   my $reserve_id = $input->param('reserve_id');
95   CancelReserve({ reserve_id => $reserve_id });
96 } elsif ( $action eq 'setLowestPriority' ) {
97   my $reserve_id = $input->param('reserve_id');
98   ToggleLowestPriority( $reserve_id );
99 } elsif ( $action eq 'toggleSuspend' ) {
100   my $reserve_id = $input->param('reserve_id');
101   my $suspend_until  = $input->param('suspend_until');
102   ToggleSuspend( $reserve_id, $suspend_until );
103 }
104
105 if ($findborrower) {
106     my $borrower = C4::Members::GetMember( cardnumber => $findborrower );
107     if ( $borrower ) {
108         $borrowernumber_hold = $borrower->{borrowernumber};
109     } else {
110         my $dt_params = { iDisplayLength => -1 };
111         my $results = C4::Utils::DataTables::Members::search(
112             {
113                 searchmember => $findborrower,
114                 dt_params => $dt_params,
115             }
116         );
117         my $borrowers = $results->{patrons};
118         if ( scalar @$borrowers == 1 ) {
119             $borrowernumber_hold = $borrowers->[0]->{borrowernumber};
120         } elsif ( @$borrowers ) {
121             $template->param( borrowers => $borrowers );
122         } else {
123             $messageborrower = "'$findborrower'";
124         }
125     }
126 }
127
128 my @biblionumbers = ();
129 my $biblionumbers = $input->param('biblionumbers');
130 if ($multihold) {
131     @biblionumbers = split '/', $biblionumbers;
132 } else {
133     push @biblionumbers, $input->multi_param('biblionumber');
134 }
135
136
137 # If we have the borrowernumber because we've performed an action, then we
138 # don't want to try to place another reserve.
139 if ($borrowernumber_hold && !$action) {
140     my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
141     my $diffbranch;
142
143     # we check the reserves of the borrower, and if he can reserv a document
144     # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
145
146     my $reserves_count =
147       GetReserveCount( $borrowerinfo->{'borrowernumber'} );
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 = $borrowerinfo->{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 ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) {
179         $diffbranch = 1;
180     }
181
182     $template->param(
183                 borrowernumber      => $borrowerinfo->{'borrowernumber'},
184                 borrowersurname     => $borrowerinfo->{'surname'},
185                 borrowerfirstname   => $borrowerinfo->{'firstname'},
186                 borrowerstreetaddress   => $borrowerinfo->{'address'},
187                 borrowercity        => $borrowerinfo->{'city'},
188                 borrowerphone       => $borrowerinfo->{'phone'},
189                 borrowermobile      => $borrowerinfo->{'mobile'},
190                 borrowerfax         => $borrowerinfo->{'fax'},
191                 borrowerphonepro    => $borrowerinfo->{'phonepro'},
192                 borroweremail       => $borrowerinfo->{'email'},
193                 borroweremailpro    => $borrowerinfo->{'emailpro'},
194                 borrowercategory    => $borrowerinfo->{'category'},
195                 cardnumber          => $borrowerinfo->{'cardnumber'},
196                 expiry              => $expiry,
197                 diffbranch          => $diffbranch,
198                 messages            => $messages,
199                 warnings            => $warnings,
200                 restricted          => IsDebarred($borrowerinfo->{'borrowernumber'}),
201                 amount_outstanding  => GetMemberAccountRecords($borrowerinfo->{borrowernumber}),
202     );
203 }
204
205 $template->param( messageborrower => $messageborrower );
206
207 # FIXME launch another time GetMember perhaps until
208 my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
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 'ageRestricted' ) {
229         $template->param( $canReserve => 1 );
230         $biblioloopiter{$canReserve} = 1;
231     }
232     else {
233         $biblioloopiter{$canReserve} = 1;
234     }
235
236     my $alreadypossession;
237     if (not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowerinfo->{borrowernumber},$biblionumber)) {
238         $alreadypossession = 1;
239     }
240
241     # get existing reserves .....
242     my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
243     my $count = scalar( @$reserves );
244     my $totalcount = $count;
245     my $holds_count = 0;
246     my $alreadyreserved = 0;
247
248     foreach my $res (@$reserves) {
249         if ( defined $res->{found} ) { # found can be 'W' or 'T'
250             $count--;
251         }
252
253         if ( defined $borrowerinfo && defined($borrowerinfo->{borrowernumber}) && ($borrowerinfo->{borrowernumber} eq $res->{borrowernumber}) ) {
254             $holds_count++;
255         }
256     }
257
258     if ( $holds_count ) {
259             $alreadyreserved = 1;
260             $biblioloopiter{warn} = 1;
261             $biblioloopiter{alreadyres} = 1;
262     }
263
264     $template->param(
265         alreadyreserved => $alreadyreserved,
266         alreadypossession => $alreadypossession,
267     );
268
269     # FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
270     # make priorities options
271
272     my @optionloop;
273     for ( 1 .. $count + 1 ) {
274         push(
275              @optionloop,
276              {
277               num      => $_,
278               selected => ( $_ == $count + 1 ),
279              }
280             );
281     }
282     # adding a fixed value for priority options
283     my $fixedRank = $count+1;
284
285     my %itemnumbers_of_biblioitem;
286     my @itemnumbers;
287
288     ## $items is array of 'item' table numbers
289     if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
290         @itemnumbers  = @$items;
291     }
292     my @hostitems = get_hostitemnumbers_of($biblionumber);
293     if (@hostitems){
294         $template->param('hostitemsflag' => 1);
295         push(@itemnumbers, @hostitems);
296     }
297
298     if (!@itemnumbers) {
299         $template->param('noitems' => 1);
300         $biblioloopiter{noitems} = 1;
301     }
302
303     ## Hash of item number to 'item' table fields
304     my $iteminfos_of = GetItemInfosOf(@itemnumbers);
305
306     ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers,
307     ## when by definition all of the itemnumber have the same biblioitemnumber
308     foreach my $itemnumber (@itemnumbers) {
309         my $biblioitemnumber = $iteminfos_of->{$itemnumber}->{biblioitemnumber};
310         push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
311     }
312
313     ## Should be same as biblionumber
314     my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
315
316     my $notforloan_label_of = get_notforloan_label_of();
317
318     ## Hash of biblioitemnumber to 'biblioitem' table records
319     my $biblioiteminfos_of  = GetBiblioItemInfosOf(@biblioitemnumbers);
320
321     my @bibitemloop;
322
323     foreach my $biblioitemnumber (@biblioitemnumbers) {
324         my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
325         my $num_available = 0;
326         my $num_override  = 0;
327         my $hiddencount   = 0;
328
329         if ( $biblioitem->{biblioitemnumber} ne $biblionumber ) {
330             $biblioitem->{hostitemsflag} = 1;
331         }
332
333         $biblioloopiter{description} = $biblioitem->{description};
334         $biblioloopiter{itypename}   = $biblioitem->{description};
335         if ( $biblioitem->{itemtype} ) {
336
337             $biblioitem->{description} =
338               $itemtypes->{ $biblioitem->{itemtype} }{description};
339
340             $biblioloopiter{imageurl} =
341               getitemtypeimagelocation( 'intranet',
342                 $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
343         }
344
345         foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
346             my $item = $iteminfos_of->{$itemnumber};
347
348             unless (C4::Context->preference('item-level_itypes')) {
349                 $item->{itype} = $biblioitem->{itemtype};
350             }
351
352             $item->{itypename} = $itemtypes->{ $item->{itype} }{description};
353             $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
354             $item->{homebranchname} = $branches->{ $item->{homebranch} }{branchname};
355
356             # if the holdingbranch is different than the homebranch, we show the
357             # holdingbranch of the document too
358             if ( $item->{homebranch} ne $item->{holdingbranch} ) {
359                 $item->{holdingbranchname} =
360                   $branches->{ $item->{holdingbranch} }{branchname};
361             }
362
363                 if($item->{biblionumber} ne $biblionumber){
364                         $item->{hostitemsflag}=1;
365                         $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
366                 }
367                 
368             # if the item is currently on loan, we display its return date and
369             # change the background color
370             my $issues= GetItemIssue($itemnumber);
371             if ( $issues->{'date_due'} ) {
372                 $item->{date_due} = $issues->{date_due_sql};
373                 $item->{backgroundcolor} = 'onloan';
374             }
375
376             # checking reserve
377             my ($reservedate,$reservedfor,$expectedAt,$reserve_id,$wait) = GetReservesFromItemnumber($itemnumber);
378             if ( defined $reservedate ) {
379                 my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
380
381                 $item->{backgroundcolor} = 'reserved';
382                 $item->{reservedate}     = output_pref({ dt => dt_from_string( $reservedate ), dateonly => 1 });
383                 $item->{ReservedForBorrowernumber}     = $reservedfor;
384                 $item->{ReservedForSurname}     = $ItemBorrowerReserveInfo->{'surname'};
385                 $item->{ReservedForFirstname}     = $ItemBorrowerReserveInfo->{'firstname'};
386                 $item->{ExpectedAtLibrary}     = $branches->{$expectedAt}{branchname};
387                 $item->{waitingdate} = $wait;
388             }
389
390             # Management of the notforloan document
391             if ( $item->{notforloan} ) {
392                 $item->{backgroundcolor} = 'other';
393                 $item->{notforloanvalue} =
394                   $notforloan_label_of->{ $item->{notforloan} };
395             }
396
397             # Management of lost or long overdue items
398             if ( $item->{itemlost} ) {
399
400                 # FIXME localized strings should never be in Perl code
401                 $item->{message} =
402                   $item->{itemlost} == 1 ? "(lost)"
403                     : $item->{itemlost} == 2 ? "(long overdue)"
404                       : "";
405                 $item->{backgroundcolor} = 'other';
406                 if (GetHideLostItemsPreference($borrowernumber) && !$showallitems) {
407                     $item->{hide} = 1;
408                     $hiddencount++;
409                 }
410             }
411
412             # Check the transit status
413             my ( $transfertwhen, $transfertfrom, $transfertto ) =
414               GetTransfers($itemnumber);
415
416             if ( defined $transfertwhen && $transfertwhen ne '' ) {
417                 $item->{transfertwhen} = output_pref({ dt => dt_from_string( $transfertwhen ), dateonly => 1 });
418                 $item->{transfertfrom} =
419                   $branches->{$transfertfrom}{branchname};
420                 $item->{transfertto} = $branches->{$transfertto}{branchname};
421                 $item->{nocancel} = 1;
422             }
423
424             # If there is no loan, return and transfer, we show a checkbox.
425             $item->{notforloan} ||= 0;
426
427             # if independent branches is on we need to check if the person can reserve
428             # for branches they arent logged in to
429             if ( C4::Context->preference("IndependentBranches") ) {
430                 if (! C4::Context->preference("canreservefromotherbranches")){
431                     # cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
432                     my $userenv = C4::Context->userenv;
433                     unless ( C4::Context->IsSuperLibrarian ) {
434                         $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
435                     }
436                 }
437             }
438
439             my $branch = C4::Circulation::_GetCircControlBranch($item, $borrowerinfo);
440
441             my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
442
443             $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
444
445             if (
446                    !$item->{cantreserve}
447                 && !$exceeded_maxreserves
448                 && IsAvailableForItemLevelRequest($item, $borrowerinfo)
449                 && CanItemBeReserved(
450                     $borrowerinfo->{borrowernumber}, $itemnumber
451                 ) eq 'OK'
452               )
453             {
454                 $item->{available} = 1;
455                 $num_available++;
456             }
457             elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
458                 # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
459                 $item->{override} = 1;
460                 $num_override++;
461             }
462
463             # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
464
465             # Show serial enumeration when needed
466             if ($item->{enumchron}) {
467                 $itemdata_enumchron = 1;
468             }
469
470             push @{ $biblioitem->{itemloop} }, $item;
471         }
472
473         if ( $num_override == scalar( @{ $biblioitem->{itemloop} } ) ) { # That is, if all items require an override
474             $template->param( override_required => 1 );
475         } elsif ( $num_available == 0 ) {
476             $template->param( none_available => 1 );
477             $biblioloopiter{warn} = 1;
478             $biblioloopiter{none_avail} = 1;
479         }
480         $template->param( hiddencount => $hiddencount);
481
482         push @bibitemloop, $biblioitem;
483     }
484
485     # existingreserves building
486     my @reserveloop;
487     $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
488     foreach my $res ( sort {
489             my $a_found = $a->{found} || '';
490             my $b_found = $a->{found} || '';
491             $a_found cmp $b_found;
492         } @$reserves ) {
493         my %reserve;
494         my @optionloop;
495         for ( my $i = 1 ; $i <= $totalcount ; $i++ ) {
496             push(
497                  @optionloop,
498                  {
499                   num      => $i,
500                   selected => ( $i == $res->{priority} ),
501                  }
502                 );
503         }
504
505         if ( defined $res->{'found'} && ($res->{'found'} eq 'W' || $res->{'found'} eq 'T' )) {
506             my $item = $res->{'itemnumber'};
507             $item = GetBiblioFromItemNumber($item,undef);
508             $reserve{'wait'}= 1;
509             $reserve{'holdingbranch'}=$item->{'holdingbranch'};
510             $reserve{'biblionumber'}=$item->{'biblionumber'};
511             $reserve{'barcodenumber'}   = $item->{'barcode'};
512             $reserve{'wbrcode'} = $res->{'branchcode'};
513             $reserve{'itemnumber'}  = $res->{'itemnumber'};
514             $reserve{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
515             if($reserve{'holdingbranch'} eq $reserve{'wbrcode'}){
516                 # Just because the holdingbranch matches the reserve branch doesn't mean the item
517                 # has arrived at the destination, check for an open transfer for the item as well
518                 my ( $transfertwhen, $transfertfrom, $transferto ) = C4::Circulation::GetTransfers( $res->{itemnumber} );
519                 if ( not $transferto or $transferto ne $res->{branchcode} ) {
520                     $reserve{'atdestination'} = 1;
521                 }
522             }
523             # set found to 1 if reserve is waiting for patron pickup
524             $reserve{'found'} = 1 if $res->{'found'} eq 'W';
525             $reserve{'intransit'} = 1 if $res->{'found'} eq 'T';
526         } elsif ($res->{priority} > 0) {
527             if (defined($res->{itemnumber})) {
528                 my $item = GetItem($res->{itemnumber});
529                 $reserve{'itemnumber'}  = $res->{'itemnumber'};
530                 $reserve{'barcodenumber'}   = $item->{'barcode'};
531                 $reserve{'item_level_hold'} = 1;
532             }
533         }
534
535         #     get borrowers reserve info
536         my $reserveborrowerinfo = GetMember( borrowernumber => $res->{'borrowernumber'} );
537         if (C4::Context->preference('HidePatronName')){
538             $reserve{'hidename'} = 1;
539             $reserve{'cardnumber'} = $reserveborrowerinfo->{'cardnumber'};
540         }
541         $reserve{'expirationdate'} = output_pref({ dt => dt_from_string( $res->{'expirationdate'} ), dateonly => 1 })
542             unless ( !defined($res->{'expirationdate'}) || $res->{'expirationdate'} eq '0000-00-00' );
543         $reserve{'date'}           = output_pref({ dt => dt_from_string( $res->{'reservedate'} ), dateonly => 1 });
544         $reserve{'borrowernumber'} = $res->{'borrowernumber'};
545         $reserve{'biblionumber'}   = $res->{'biblionumber'};
546         $reserve{'borrowernumber'} = $res->{'borrowernumber'};
547         $reserve{'firstname'}      = $reserveborrowerinfo->{'firstname'};
548         $reserve{'surname'}        = $reserveborrowerinfo->{'surname'};
549         $reserve{'notes'}          = $res->{'reservenotes'};
550         $reserve{'wait'}           =
551           ( ( defined $res->{'found'} and $res->{'found'} eq 'W' ) or ( $res->{'priority'} eq '0' ) );
552         $reserve{'voldesc'}         = $res->{'volumeddesc'};
553         $reserve{'ccode'}           = $res->{'ccode'};
554         $reserve{'barcode'}         = $res->{'barcode'};
555         $reserve{'priority'}    = $res->{'priority'};
556         $reserve{'lowestPriority'}    = $res->{'lowestPriority'};
557         $reserve{'optionloop'} = \@optionloop;
558         $reserve{'suspend'} = $res->{'suspend'};
559         $reserve{'suspend_until'} = $res->{'suspend_until'};
560         $reserve{'reserve_id'} = $res->{'reserve_id'};
561
562         if ( C4::Context->preference('IndependentBranches') && $flags->{'superlibrarian'} != 1 ) {
563               $reserve{'branchloop'} = [ GetBranchDetail($res->{'branchcode'}) ];
564         } else {
565               $reserve{'branchloop'} = GetBranchesLoop($res->{'branchcode'});
566         }
567
568         push( @reserveloop, \%reserve );
569     }
570
571     # get the time for the form name...
572     my $time = time();
573
574     $template->param(
575                      branchloop  => GetBranchesLoop($userbranch),
576                      time        => $time,
577                      fixedRank   => $fixedRank,
578                     );
579
580     # display infos
581     $template->param(
582                      optionloop        => \@optionloop,
583                      bibitemloop       => \@bibitemloop,
584                      itemdata_enumchron => $itemdata_enumchron,
585                      date              => $date,
586                      biblionumber      => $biblionumber,
587                      findborrower      => $findborrower,
588                      title             => $dat->{title},
589                      author            => $dat->{author},
590                      holdsview => 1,
591                      C4::Search::enabled_staff_search_views,
592                     );
593     if (defined $borrowerinfo && exists $borrowerinfo->{'branchcode'}) {
594         $template->param(
595                      borrower_branchname => $branches->{$borrowerinfo->{'branchcode'}}->{'branchname'},
596                      borrower_branchcode => $borrowerinfo->{'branchcode'},
597         );
598     }
599
600     $biblioloopiter{biblionumber} = $biblionumber;
601     $biblioloopiter{title} = $dat->{title};
602     $biblioloopiter{rank} = $fixedRank;
603     $biblioloopiter{reserveloop} = \@reserveloop;
604
605     if (@reserveloop) {
606         $template->param( reserveloop => \@reserveloop );
607     }
608
609     push @biblioloop, \%biblioloopiter;
610 }
611
612 $template->param( biblioloop => \@biblioloop );
613 $template->param( biblionumbers => $biblionumbers );
614 $template->param( exceeded_maxreserves => $exceeded_maxreserves );
615
616 if ($multihold) {
617     $template->param( multi_hold => 1 );
618 }
619
620 if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
621     $template->param( reserve_in_future => 1 );
622 }
623
624 $template->param(
625     SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
626     AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
627 );
628
629 # printout the page
630 output_html_with_http_headers $input, $cookie, $template->output;
631
632 sub sort_borrowerlist {
633     my $borrowerslist = shift;
634     my $ref           = [];
635     push @{$ref}, sort {
636         uc( $a->{surname} . $a->{firstname} ) cmp
637           uc( $b->{surname} . $b->{firstname} )
638     } @{$borrowerslist};
639     return $ref;
640 }