Bug 10080 - Change system pref IndependantBranches to IndependentBranches
[koha.git] / reserve / request.pl
1 #!/usr/bin/perl
2
3
4 #writen 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 under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along
20 # with Koha; if not, write to the Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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;
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 C4::Dates qw/format_date/;
43 use C4::Members;
44 use C4::Search;         # enabled_staff_search_views
45 use Koha::DateUtils;
46
47 my $dbh = C4::Context->dbh;
48 my $sth;
49 my $input = new CGI;
50 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
51     {
52         template_name   => "reserve/request.tmpl",
53         query           => $input,
54         type            => "intranet",
55         authnotrequired => 0,
56         flagsrequired   => { reserveforothers => 'place_holds' },
57     }
58 );
59
60 my $multihold = $input->param('multi_hold');
61 $template->param(multi_hold => $multihold);
62 my $showallitems = $input->param('showallitems');
63
64 # get Branches and Itemtypes
65 my $branches = GetBranches();
66 my $itemtypes = GetItemTypes();
67
68 my $userbranch = '';
69 if (C4::Context->userenv && C4::Context->userenv->{'branch'}) {
70     $userbranch = C4::Context->userenv->{'branch'};
71 }
72
73
74 # Select borrowers infos
75 my $findborrower = $input->param('findborrower');
76 $findborrower = '' unless defined $findborrower;
77 $findborrower =~ s|,| |g;
78 my $borrowernumber_hold = $input->param('borrowernumber') || '';
79 my $borrowerslist;
80 my $messageborrower;
81 my $warnings;
82 my $messages;
83
84 my $date = C4::Dates->today('iso');
85 my $action = $input->param('action');
86 $action ||= q{};
87
88 if ( $action eq 'move' ) {
89   my $where = $input->param('where');
90   my $borrowernumber = $input->param('borrowernumber');
91   my $biblionumber = $input->param('biblionumber');
92   AlterPriority( $where, $borrowernumber, $biblionumber );
93 } elsif ( $action eq 'cancel' ) {
94   my $borrowernumber = $input->param('borrowernumber');
95   my $biblionumber = $input->param('biblionumber');
96   CancelReserve( $biblionumber, '', $borrowernumber );
97 } elsif ( $action eq 'setLowestPriority' ) {
98   my $borrowernumber = $input->param('borrowernumber');
99   my $biblionumber   = $input->param('biblionumber');
100   ToggleLowestPriority( $borrowernumber, $biblionumber );
101 } elsif ( $action eq 'toggleSuspend' ) {
102   my $borrowernumber = $input->param('borrowernumber');
103   my $biblionumber   = $input->param('biblionumber');
104   my $suspend_until  = $input->param('suspend_until');
105   ToggleSuspend( $borrowernumber, $biblionumber, $suspend_until );
106 }
107
108 if ($findborrower) {
109     my $borrowers = Search($findborrower, 'cardnumber');
110
111     if ($borrowers && @$borrowers) {
112         if ( @$borrowers == 1 ) {
113             $borrowernumber_hold = $borrowers->[0]->{'borrowernumber'};
114         }
115         else {
116             $borrowerslist = $borrowers;
117         }
118     } else {
119         $messageborrower = "'$findborrower'";
120     }
121 }
122
123 # If we have the borrowernumber because we've performed an action, then we
124 # don't want to try to place another reserve.
125 if ($borrowernumber_hold && !$action) {
126     my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
127     my $diffbranch;
128     my @getreservloop;
129     my $count_reserv = 0;
130     my $maxreserves;
131
132 #   we check the reserves of the borrower, and if he can reserv a document
133 # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
134
135     my $number_reserves =
136       GetReserveCount( $borrowerinfo->{'borrowernumber'} );
137
138     if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) {
139                 $warnings = 1;
140         $maxreserves = 1;
141     }
142
143     # we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn)
144     my $expiry_date = $borrowerinfo->{dateexpiry};
145     my $expiry = 0; # flag set if patron account has expired
146     if ($expiry_date and $expiry_date ne '0000-00-00' and
147             Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
148                 $messages = $expiry = 1;
149     }
150
151     # check if the borrower make the reserv in a different branch
152     if ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) {
153                 $messages = 1;
154         $diffbranch = 1;
155     }
156
157     $template->param(
158                 borrowernumber      => $borrowerinfo->{'borrowernumber'},
159                 borrowersurname     => $borrowerinfo->{'surname'},
160                 borrowerfirstname   => $borrowerinfo->{'firstname'},
161                 borrowerstreetaddress   => $borrowerinfo->{'address'},
162                 borrowercity        => $borrowerinfo->{'city'},
163                 borrowerphone       => $borrowerinfo->{'phone'},
164                 borrowermobile      => $borrowerinfo->{'mobile'},
165                 borrowerfax         => $borrowerinfo->{'fax'},
166                 borrowerphonepro    => $borrowerinfo->{'phonepro'},
167                 borroweremail       => $borrowerinfo->{'email'},
168                 borroweremailpro    => $borrowerinfo->{'emailpro'},
169                 borrowercategory    => $borrowerinfo->{'category'},
170                 borrowerreservs     => $count_reserv,
171                 cardnumber          => $borrowerinfo->{'cardnumber'},
172                 maxreserves         => $maxreserves,
173                 expiry              => $expiry,
174                 diffbranch          => $diffbranch,
175                                 messages            => $messages,
176                                 warnings            => $warnings
177     );
178 }
179
180 $template->param( messageborrower => $messageborrower );
181
182 my $CGIselectborrower;
183 if ($borrowerslist) {
184     my @values;
185     my %labels;
186
187     foreach my $borrower (
188         sort {
189                 uc($a->{surname}
190               . $a->{firstname}) cmp uc($b->{surname}
191               . $b->{firstname})
192         } @{$borrowerslist}
193       )
194     {
195         push @values, $borrower->{borrowernumber};
196
197         $labels{ $borrower->{borrowernumber} } = sprintf(
198             '%s, %s ... (%s - %s) ... %s',
199             $borrower->{surname} ||'',    $borrower->{firstname} || '',
200             $borrower->{cardnumber} || '', $borrower->{categorycode} || '',
201             $borrower->{address} || '',
202         );
203     }
204
205     $CGIselectborrower = CGI::scrolling_list(
206         -name     => 'borrowernumber',
207         -values   => \@values,
208         -labels   => \%labels,
209         -size     => 7,
210         -multiple => 0,
211     );
212 }
213
214 # FIXME launch another time GetMember perhaps until
215 my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
216
217 my @biblionumbers = ();
218 my $biblionumbers = $input->param('biblionumbers');
219 if ($multihold) {
220     @biblionumbers = split '/', $biblionumbers;
221 } else {
222     push @biblionumbers, $input->param('biblionumber');
223 }
224
225 my $itemdata_enumchron = 0;
226 my @biblioloop = ();
227 foreach my $biblionumber (@biblionumbers) {
228
229     my %biblioloopiter = ();
230         my $maxreserves;
231
232     my $dat          = GetBiblioData($biblionumber);
233
234     unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) {
235                 $warnings = 1;
236         $maxreserves = 1;
237     }
238
239     my $alreadypossession;
240     if (not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowerinfo->{borrowernumber},$biblionumber)) {
241         $warnings = 1;
242         $alreadypossession = 1;
243     }
244
245     # get existing reserves .....
246     my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
247     my $totalcount = $count;
248     my $alreadyreserved;
249
250     foreach my $res (@$reserves) {
251         if ( defined $res->{found} && $res->{found} eq 'W' ) {
252             $count--;
253         }
254
255         if ( defined $borrowerinfo && ($borrowerinfo->{borrowernumber} eq $res->{borrowernumber}) ) {
256             $warnings = 1;
257             $alreadyreserved = 1;
258             $biblioloopiter{warn} = 1;
259             $biblioloopiter{alreadyres} = 1;
260         }
261     }
262
263     $template->param( alreadyreserved => $alreadyreserved,
264                       messages => $messages,
265                       warnings => $warnings,
266                  maxreserves=>$maxreserves,
267                      alreadypossession => $alreadypossession,
268                                           );
269
270
271     # FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
272     # make priorities options
273
274     my @optionloop;
275     for ( 1 .. $count + 1 ) {
276         push(
277              @optionloop,
278              {
279               num      => $_,
280               selected => ( $_ == $count + 1 ),
281              }
282             );
283     }
284     # adding a fixed value for priority options
285     my $fixedRank = $count+1;
286
287     my @branchcodes;
288     my %itemnumbers_of_biblioitem;
289     my @itemnumbers;
290
291     ## $items is array of 'item' table numbers
292     if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
293         @itemnumbers  = @$items;
294     }
295         my @hostitems = get_hostitemnumbers_of($biblionumber);
296         if (@hostitems){
297                 $template->param('hostitemsflag' => 1);
298                 push(@itemnumbers, @hostitems);
299         }
300
301     if (!@itemnumbers) {
302         $template->param('noitems' => 1);
303         $biblioloopiter{noitems} = 1;
304     }
305
306     ## Hash of item number to 'item' table fields
307     my $iteminfos_of = GetItemInfosOf(@itemnumbers);
308
309     ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers,
310     ## when by definition all of the itemnumber have the same biblioitemnumber
311     foreach my $itemnumber (@itemnumbers) {
312         my $biblioitemnumber = $iteminfos_of->{$itemnumber}->{biblioitemnumber};
313         push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
314     }
315
316     ## Should be same as biblionumber
317     my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
318
319     my $notforloan_label_of = get_notforloan_label_of();
320
321     ## Hash of biblioitemnumber to 'biblioitem' table records
322     my $biblioiteminfos_of  = GetBiblioItemInfosOf(@biblioitemnumbers);
323
324     my @bibitemloop;
325
326     foreach my $biblioitemnumber (@biblioitemnumbers) {
327         my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
328         my $num_available = 0;
329         my $num_override  = 0;
330         my $hiddencount   = 0;
331
332         $biblioitem->{description} =
333           $itemtypes->{ $biblioitem->{itemtype} }{description};
334         if($biblioitem->{biblioitemnumber} ne $biblionumber){
335                 $biblioitem->{hostitemsflag}=1;
336         }
337         $biblioloopiter{description} = $biblioitem->{description};
338         $biblioloopiter{itypename} = $biblioitem->{description};
339         $biblioloopiter{imageurl} =
340           getitemtypeimagelocation('intranet', $itemtypes->{$biblioitem->{itemtype}}{imageurl});
341
342         foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
343             my $item = $iteminfos_of->{$itemnumber};
344
345             unless (C4::Context->preference('item-level_itypes')) {
346                 $item->{itype} = $biblioitem->{itemtype};
347             }
348
349             $item->{itypename} = $itemtypes->{ $item->{itype} }{description};
350             $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
351             $item->{homebranchname} = $branches->{ $item->{homebranch} }{branchname};
352
353             # if the holdingbranch is different than the homebranch, we show the
354             # holdingbranch of the document too
355             if ( $item->{homebranch} ne $item->{holdingbranch} ) {
356                 $item->{holdingbranchname} =
357                   $branches->{ $item->{holdingbranch} }{branchname};
358             }
359
360                 if($item->{biblionumber} ne $biblionumber){
361                         $item->{hostitemsflag}=1;
362                         $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
363                 }
364                 
365             #   add information
366             $item->{itemcallnumber} = $item->{itemcallnumber};
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} = format_sqldatetime($issues->{date_due});
373                 $item->{backgroundcolor} = 'onloan';
374             }
375
376             # checking reserve
377             my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemnumber);
378             my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
379
380             if ( defined $reservedate ) {
381                 $item->{backgroundcolor} = 'reserved';
382                 $item->{reservedate}     = format_date($reservedate);
383                 $item->{ReservedForBorrowernumber}     = $reservedfor;
384                 $item->{ReservedForSurname}     = $ItemBorrowerReserveInfo->{'surname'};
385                 $item->{ReservedForFirstname}     = $ItemBorrowerReserveInfo->{'firstname'};
386                 $item->{ExpectedAtLibrary}     = $branches->{$expectedAt}{branchname};
387
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} = format_date($transfertwhen);
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} = $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                     if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) {
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             my $policy_holdallowed = 1;
443
444             $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
445
446             if ( $branchitemrule->{'holdallowed'} == 0 ||
447                  ( $branchitemrule->{'holdallowed'} == 1 &&
448                      $borrowerinfo->{'branchcode'} ne $item->{'homebranch'} ) ) {
449                 $policy_holdallowed = 0;
450             }
451             
452             if (
453                    $policy_holdallowed
454                 && !$item->{cantreserve}
455                 && IsAvailableForItemLevelRequest($itemnumber)
456                 && CanItemBeReserved(
457                     $borrowerinfo->{borrowernumber}, $itemnumber
458                 )
459               )
460             {
461                 $item->{available} = 1;
462                 $num_available++;
463             }
464             elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
465
466 # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
467                 $item->{override} = 1;
468                 $num_override++;
469             }
470
471             # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
472
473             # FIXME: move this to a pm
474             my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
475             $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
476             while (my $wait_hashref = $sth2->fetchrow_hashref) {
477                 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
478             }
479
480             # Show serial enumeration when needed
481             if ($item->{enumchron}) {
482                 $itemdata_enumchron = 1;
483             }
484
485             push @{ $biblioitem->{itemloop} }, $item;
486         }
487
488         if ( $num_override == scalar( @{ $biblioitem->{itemloop} } ) ) { # That is, if all items require an override
489             $template->param( override_required => 1 );
490         } elsif ( $num_available == 0 ) {
491             $template->param( none_available => 1 );
492             $template->param( warnings => 1 );
493             $biblioloopiter{warn} = 1;
494             $biblioloopiter{none_avail} = 1;
495         }
496         $template->param( hiddencount => $hiddencount);
497
498         push @bibitemloop, $biblioitem;
499     }
500
501     # existingreserves building
502     my @reserveloop;
503     ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
504     foreach my $res ( sort {
505             my $a_found = $a->{found} || '';
506             my $b_found = $a->{found} || '';
507             $a_found cmp $b_found;
508         } @$reserves ) {
509         my %reserve;
510         my @optionloop;
511         for ( my $i = 1 ; $i <= $totalcount ; $i++ ) {
512             push(
513                  @optionloop,
514                  {
515                   num      => $i,
516                   selected => ( $i == $res->{priority} ),
517                  }
518                 );
519         }
520
521         if ( defined $res->{'found'} && $res->{'found'} eq 'W' || $res->{'found'} eq 'T' ) {
522             my $item = $res->{'itemnumber'};
523             $item = GetBiblioFromItemNumber($item,undef);
524             $reserve{'wait'}= 1;
525             $reserve{'holdingbranch'}=$item->{'holdingbranch'};
526             $reserve{'biblionumber'}=$item->{'biblionumber'};
527             $reserve{'barcodenumber'}   = $item->{'barcode'};
528             $reserve{'wbrcode'} = $res->{'branchcode'};
529             $reserve{'itemnumber'}  = $res->{'itemnumber'};
530             $reserve{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
531             if($reserve{'holdingbranch'} eq $reserve{'wbrcode'}){
532                 $reserve{'atdestination'} = 1;
533             }
534             # set found to 1 if reserve is waiting for patron pickup
535             $reserve{'found'} = 1 if $res->{'found'} eq 'W';
536             $reserve{'intransit'} = 1 if $res->{'found'} eq 'T';
537         } elsif ($res->{priority} > 0) {
538             if (defined($res->{itemnumber})) {
539                 my $item = GetItem($res->{itemnumber});
540                 $reserve{'itemnumber'}  = $res->{'itemnumber'};
541                 $reserve{'barcodenumber'}   = $item->{'barcode'};
542                 $reserve{'item_level_hold'} = 1;
543             }
544         }
545
546         #     get borrowers reserve info
547         my $reserveborrowerinfo = GetMember( borrowernumber => $res->{'borrowernumber'} );
548         if (C4::Context->preference('HidePatronName')){
549             $reserve{'hidename'} = 1;
550             $reserve{'cardnumber'} = $reserveborrowerinfo->{'cardnumber'};
551         }
552         $reserve{'expirationdate'} = format_date( $res->{'expirationdate'} )
553             unless ( !defined($res->{'expirationdate'}) || $res->{'expirationdate'} eq '0000-00-00' );
554         $reserve{'date'}           = format_date( $res->{'reservedate'} );
555         $reserve{'borrowernumber'} = $res->{'borrowernumber'};
556         $reserve{'biblionumber'}   = $res->{'biblionumber'};
557         $reserve{'borrowernumber'} = $res->{'borrowernumber'};
558         $reserve{'firstname'}      = $reserveborrowerinfo->{'firstname'};
559         $reserve{'surname'}        = $reserveborrowerinfo->{'surname'};
560         $reserve{'notes'}          = $res->{'reservenotes'};
561         $reserve{'wait'}           =
562           ( ( defined $res->{'found'} and $res->{'found'} eq 'W' ) or ( $res->{'priority'} eq '0' ) );
563         $reserve{'constrainttypea'} = ( $res->{'constrainttype'} eq 'a' );
564         $reserve{'constrainttypeo'} = ( $res->{'constrainttype'} eq 'o' );
565         $reserve{'voldesc'}         = $res->{'volumeddesc'};
566         $reserve{'ccode'}           = $res->{'ccode'};
567         $reserve{'barcode'}         = $res->{'barcode'};
568         $reserve{'priority'}    = $res->{'priority'};
569         $reserve{'lowestPriority'}    = $res->{'lowestPriority'};
570         $reserve{'optionloop'} = \@optionloop;
571         $reserve{'suspend'} = $res->{'suspend'};
572         $reserve{'suspend_until'} = $res->{'suspend_until'};
573
574         if ( C4::Context->preference('IndependantBranches') && $flags->{'superlibrarian'} != 1 ) {
575               $reserve{'branchloop'} = [ GetBranchDetail($res->{'branchcode'}) ];
576         } else {
577               $reserve{'branchloop'} = GetBranchesLoop($res->{'branchcode'});
578         }
579
580         push( @reserveloop, \%reserve );
581     }
582
583     # get the time for the form name...
584     my $time = time();
585
586     $template->param(
587                      branchloop  => GetBranchesLoop($userbranch),
588                      time        => $time,
589                      fixedRank   => $fixedRank,
590                     );
591
592     # display infos
593     $template->param(
594                      optionloop        => \@optionloop,
595                      bibitemloop       => \@bibitemloop,
596                      itemdata_enumchron => $itemdata_enumchron,
597                      date              => $date,
598                      biblionumber      => $biblionumber,
599                      findborrower      => $findborrower,
600                      title             => $dat->{title},
601                      author            => $dat->{author},
602                      holdsview => 1,
603                      C4::Search::enabled_staff_search_views,
604                     );
605     if (defined $borrowerinfo && exists $borrowerinfo->{'branchcode'}) {
606         $template->param(
607                      borrower_branchname => $branches->{$borrowerinfo->{'branchcode'}}->{'branchname'},
608                      borrower_branchcode => $borrowerinfo->{'branchcode'},
609         );
610     }
611     $template->param(CGIselectborrower => $CGIselectborrower) if defined $CGIselectborrower;
612
613     $biblioloopiter{biblionumber} = $biblionumber;
614     $biblioloopiter{title} = $dat->{title};
615     $biblioloopiter{rank} = $fixedRank;
616     $biblioloopiter{reserveloop} = \@reserveloop;
617
618     if (@reserveloop) {
619         $template->param( reserveloop => \@reserveloop );
620     }
621
622     push @biblioloop, \%biblioloopiter;
623 }
624
625 $template->param( biblioloop => \@biblioloop );
626 $template->param( biblionumbers => $biblionumbers );
627
628 if ($multihold) {
629     $template->param( multi_hold => 1 );
630 }
631
632 if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
633     $template->param( reserve_in_future => 1 );
634 }
635
636 $template->param(
637     SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
638     AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
639 );
640
641 # printout the page
642 output_html_with_http_headers $input, $cookie, $template->output;