Bug 9206 - Only allow place holds in records that the patron don't have in his possession
[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 ) = 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 $default = C4::Context->userenv->{branch};
69 my @values;
70 my %label_of;
71
72 foreach my $branchcode ( sort { $branches->{$a}->{branchname} cmp $branches->{$b}->{branchname} } keys %$branches ) {
73     push @values, $branchcode;
74     $label_of{$branchcode} = $branches->{$branchcode}->{branchname};
75 }
76 my $CGIbranch = CGI::scrolling_list(
77                                     -name     => 'pickup',
78                                     -id          => 'pickup',
79                                     -values   => \@values,
80                                     -default  => $default,
81                                     -labels   => \%label_of,
82                                     -size     => 1,
83                                     -multiple => 0,
84                                    );
85
86 # Select borrowers infos
87 my $findborrower = $input->param('findborrower');
88 $findborrower = '' unless defined $findborrower;
89 $findborrower =~ s|,| |g;
90 my $borrowernumber_hold = $input->param('borrowernumber') || '';
91 my $borrowerslist;
92 my $messageborrower;
93 my $warnings;
94 my $messages;
95
96 my $date = C4::Dates->today('iso');
97 my $action = $input->param('action');
98 $action ||= q{};
99
100 if ( $action eq 'move' ) {
101   my $where = $input->param('where');
102   my $borrowernumber = $input->param('borrowernumber');
103   my $biblionumber = $input->param('biblionumber');
104   AlterPriority( $where, $borrowernumber, $biblionumber );
105 } elsif ( $action eq 'cancel' ) {
106   my $borrowernumber = $input->param('borrowernumber');
107   my $biblionumber = $input->param('biblionumber');
108   CancelReserve( $biblionumber, '', $borrowernumber );
109 } elsif ( $action eq 'setLowestPriority' ) {
110   my $borrowernumber = $input->param('borrowernumber');
111   my $biblionumber   = $input->param('biblionumber');
112   ToggleLowestPriority( $borrowernumber, $biblionumber );
113 } elsif ( $action eq 'toggleSuspend' ) {
114   my $borrowernumber = $input->param('borrowernumber');
115   my $biblionumber   = $input->param('biblionumber');
116   my $suspend_until  = $input->param('suspend_until');
117   ToggleSuspend( $borrowernumber, $biblionumber, $suspend_until );
118 }
119
120 if ($findborrower) {
121     my $borrowers = Search($findborrower, 'cardnumber');
122
123     if ($borrowers && @$borrowers) {
124         if ( @$borrowers == 1 ) {
125             $borrowernumber_hold = $borrowers->[0]->{'borrowernumber'};
126         }
127         else {
128             $borrowerslist = $borrowers;
129         }
130     } else {
131         $messageborrower = "'$findborrower'";
132     }
133 }
134
135 # If we have the borrowernumber because we've performed an action, then we
136 # don't want to try to place another reserve.
137 if ($borrowernumber_hold && !$action) {
138     my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
139     my $diffbranch;
140     my @getreservloop;
141     my $count_reserv = 0;
142     my $maxreserves;
143
144 #   we check the reserves of the borrower, and if he can reserv a document
145 # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
146
147     my $number_reserves =
148       GetReserveCount( $borrowerinfo->{'borrowernumber'} );
149
150     if ( C4::Context->preference('maxreserves') && ($number_reserves >= C4::Context->preference('maxreserves')) ) {
151                 $warnings = 1;
152         $maxreserves = 1;
153     }
154
155     # we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn)
156     my $expiry_date = $borrowerinfo->{dateexpiry};
157     my $expiry = 0; # flag set if patron account has expired
158     if ($expiry_date and $expiry_date ne '0000-00-00' and
159             Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
160                 $messages = $expiry = 1;
161     }
162
163     # check if the borrower make the reserv in a different branch
164     if ( $borrowerinfo->{'branchcode'} ne C4::Context->userenv->{'branch'} ) {
165                 $messages = 1;
166         $diffbranch = 1;
167     }
168
169     $template->param(
170                 borrowernumber      => $borrowerinfo->{'borrowernumber'},
171                 borrowersurname     => $borrowerinfo->{'surname'},
172                 borrowerfirstname   => $borrowerinfo->{'firstname'},
173                 borrowerstreetaddress   => $borrowerinfo->{'address'},
174                 borrowercity        => $borrowerinfo->{'city'},
175                 borrowerphone       => $borrowerinfo->{'phone'},
176                 borrowermobile      => $borrowerinfo->{'mobile'},
177                 borrowerfax         => $borrowerinfo->{'fax'},
178                 borrowerphonepro    => $borrowerinfo->{'phonepro'},
179                 borroweremail       => $borrowerinfo->{'email'},
180                 borroweremailpro    => $borrowerinfo->{'emailpro'},
181                 borrowercategory    => $borrowerinfo->{'category'},
182                 borrowerreservs     => $count_reserv,
183                 cardnumber          => $borrowerinfo->{'cardnumber'},
184                 maxreserves         => $maxreserves,
185                 expiry              => $expiry,
186                 diffbranch          => $diffbranch,
187                                 messages            => $messages,
188                                 warnings            => $warnings
189     );
190 }
191
192 $template->param( messageborrower => $messageborrower );
193
194 my $CGIselectborrower;
195 if ($borrowerslist) {
196     my @values;
197     my %labels;
198
199     foreach my $borrower (
200         sort {
201                 uc($a->{surname}
202               . $a->{firstname}) cmp uc($b->{surname}
203               . $b->{firstname})
204         } @{$borrowerslist}
205       )
206     {
207         push @values, $borrower->{borrowernumber};
208
209         $labels{ $borrower->{borrowernumber} } = sprintf(
210             '%s, %s ... (%s - %s) ... %s',
211             $borrower->{surname} ||'',    $borrower->{firstname} || '',
212             $borrower->{cardnumber} || '', $borrower->{categorycode} || '',
213             $borrower->{address} || '',
214         );
215     }
216
217     $CGIselectborrower = CGI::scrolling_list(
218         -name     => 'borrowernumber',
219         -values   => \@values,
220         -labels   => \%labels,
221         -size     => 7,
222         -multiple => 0,
223     );
224 }
225
226 # FIXME launch another time GetMember perhaps until
227 my $borrowerinfo = GetMember( borrowernumber => $borrowernumber_hold );
228
229 my @biblionumbers = ();
230 my $biblionumbers = $input->param('biblionumbers');
231 if ($multihold) {
232     @biblionumbers = split '/', $biblionumbers;
233 } else {
234     push @biblionumbers, $input->param('biblionumber');
235 }
236
237 my $itemdata_enumchron = 0;
238 my @biblioloop = ();
239 foreach my $biblionumber (@biblionumbers) {
240
241     my %biblioloopiter = ();
242         my $maxreserves;
243
244     my $dat          = GetBiblioData($biblionumber);
245
246     unless ( CanBookBeReserved($borrowerinfo->{borrowernumber}, $biblionumber) ) {
247                 $warnings = 1;
248         $maxreserves = 1;
249     }
250     if (not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowerinfo->{borrowernumber},$biblionumber)) {
251         $warnings = 1;
252         $alreadypossession = 1;
253     }
254
255     # get existing reserves .....
256     my ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
257     my $totalcount = $count;
258     my $alreadyreserved;
259
260     foreach my $res (@$reserves) {
261         if ( defined $res->{found} && $res->{found} eq 'W' ) {
262             $count--;
263         }
264
265         if ( defined $borrowerinfo && ($borrowerinfo->{borrowernumber} eq $res->{borrowernumber}) ) {
266             $warnings = 1;
267             $alreadyreserved = 1;
268             $biblioloopiter{warn} = 1;
269             $biblioloopiter{alreadyres} = 1;
270         }
271     }
272
273     $template->param( alreadyreserved => $alreadyreserved,
274                       messages => $messages,
275                       warnings => $warnings,
276                  maxreserves=>$maxreserves,
277                      alreadypossession => $alreadypossession,
278                                           );
279
280
281     # FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
282     # make priorities options
283
284     my @optionloop;
285     for ( 1 .. $count + 1 ) {
286         push(
287              @optionloop,
288              {
289               num      => $_,
290               selected => ( $_ == $count + 1 ),
291              }
292             );
293     }
294     # adding a fixed value for priority options
295     my $fixedRank = $count+1;
296
297     my @branchcodes;
298     my %itemnumbers_of_biblioitem;
299     my @itemnumbers;
300
301     ## $items is array of 'item' table numbers
302     if (my $items = get_itemnumbers_of($biblionumber)->{$biblionumber}){
303         @itemnumbers  = @$items;
304     }
305         my @hostitems = get_hostitemnumbers_of($biblionumber);
306         if (@hostitems){
307                 $template->param('hostitemsflag' => 1);
308                 push(@itemnumbers, @hostitems);
309         }
310
311     if (!@itemnumbers) {
312         $template->param('noitems' => 1);
313         $biblioloopiter{noitems} = 1;
314     }
315
316     ## Hash of item number to 'item' table fields
317     my $iteminfos_of = GetItemInfosOf(@itemnumbers);
318
319     ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers,
320     ## when by definition all of the itemnumber have the same biblioitemnumber
321     foreach my $itemnumber (@itemnumbers) {
322         my $biblioitemnumber = $iteminfos_of->{$itemnumber}->{biblioitemnumber};
323         push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
324     }
325
326     ## Should be same as biblionumber
327     my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
328
329     my $notforloan_label_of = get_notforloan_label_of();
330
331     ## Hash of biblioitemnumber to 'biblioitem' table records
332     my $biblioiteminfos_of  = GetBiblioItemInfosOf(@biblioitemnumbers);
333
334     my @bibitemloop;
335
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->{description} =
343           $itemtypes->{ $biblioitem->{itemtype} }{description};
344         if($biblioitem->{biblioitemnumber} ne $biblionumber){
345                 $biblioitem->{hostitemsflag}=1;
346         }
347         $biblioloopiter{description} = $biblioitem->{description};
348         $biblioloopiter{itypename} = $biblioitem->{description};
349         $biblioloopiter{imageurl} =
350           getitemtypeimagelocation('intranet', $itemtypes->{$biblioitem->{itemtype}}{imageurl});
351
352         foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
353             my $item = $iteminfos_of->{$itemnumber};
354
355             unless (C4::Context->preference('item-level_itypes')) {
356                 $item->{itype} = $biblioitem->{itemtype};
357             }
358
359             $item->{itypename} = $itemtypes->{ $item->{itype} }{description};
360             $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
361             $item->{homebranchname} = $branches->{ $item->{homebranch} }{branchname};
362
363             # if the holdingbranch is different than the homebranch, we show the
364             # holdingbranch of the document too
365             if ( $item->{homebranch} ne $item->{holdingbranch} ) {
366                 $item->{holdingbranchname} =
367                   $branches->{ $item->{holdingbranch} }{branchname};
368             }
369
370                 if($item->{biblionumber} ne $biblionumber){
371                         $item->{hostitemsflag}=1;
372                         $item->{hosttitle} = GetBiblioData($item->{biblionumber})->{title};
373                 }
374                 
375             #   add information
376             $item->{itemcallnumber} = $item->{itemcallnumber};
377
378             # if the item is currently on loan, we display its return date and
379             # change the background color
380             my $issues= GetItemIssue($itemnumber);
381             if ( $issues->{'date_due'} ) {
382                 $item->{date_due} = format_sqldatetime($issues->{date_due});
383                 $item->{backgroundcolor} = 'onloan';
384             }
385
386             # checking reserve
387             my ($reservedate,$reservedfor,$expectedAt) = GetReservesFromItemnumber($itemnumber);
388             my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
389
390             if ( defined $reservedate ) {
391                 $item->{backgroundcolor} = 'reserved';
392                 $item->{reservedate}     = format_date($reservedate);
393                 $item->{ReservedForBorrowernumber}     = $reservedfor;
394                 $item->{ReservedForSurname}     = $ItemBorrowerReserveInfo->{'surname'};
395                 $item->{ReservedForFirstname}     = $ItemBorrowerReserveInfo->{'firstname'};
396                 $item->{ExpectedAtLibrary}     = $branches->{$expectedAt}{branchname};
397
398             }
399
400             # Management of the notforloan document
401             if ( $item->{notforloan} ) {
402                 $item->{backgroundcolor} = 'other';
403                 $item->{notforloanvalue} =
404                   $notforloan_label_of->{ $item->{notforloan} };
405             }
406
407             # Management of lost or long overdue items
408             if ( $item->{itemlost} ) {
409
410                 # FIXME localized strings should never be in Perl code
411                 $item->{message} =
412                   $item->{itemlost} == 1 ? "(lost)"
413                     : $item->{itemlost} == 2 ? "(long overdue)"
414                       : "";
415                 $item->{backgroundcolor} = 'other';
416                 if (GetHideLostItemsPreference($borrowernumber) && !$showallitems) {
417                     $item->{hide} = 1;
418                     $hiddencount++;
419                 }
420             }
421
422             # Check the transit status
423             my ( $transfertwhen, $transfertfrom, $transfertto ) =
424               GetTransfers($itemnumber);
425
426             if ( defined $transfertwhen && $transfertwhen ne '' ) {
427                 $item->{transfertwhen} = format_date($transfertwhen);
428                 $item->{transfertfrom} =
429                   $branches->{$transfertfrom}{branchname};
430                 $item->{transfertto} = $branches->{$transfertto}{branchname};
431                 $item->{nocancel} = 1;
432             }
433
434             # If there is no loan, return and transfer, we show a checkbox.
435             $item->{notforloan} = $item->{notforloan} || 0;
436
437             # if independent branches is on we need to check if the person can reserve
438             # for branches they arent logged in to
439             if ( C4::Context->preference("IndependantBranches") ) {
440                 if (! C4::Context->preference("canreservefromotherbranches")){
441                     # cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
442                     my $userenv = C4::Context->userenv;
443                     if ( ($userenv) && ( $userenv->{flags} % 2 != 1 ) ) {
444                         $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
445                     }
446                 }
447             }
448
449             my $branch = C4::Circulation::_GetCircControlBranch($item, $borrowerinfo);
450
451             my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
452             my $policy_holdallowed = 1;
453
454             $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
455
456             if ( $branchitemrule->{'holdallowed'} == 0 ||
457                  ( $branchitemrule->{'holdallowed'} == 1 &&
458                      $borrowerinfo->{'branchcode'} ne $item->{'homebranch'} ) ) {
459                 $policy_holdallowed = 0;
460             }
461             
462             if (
463                    $policy_holdallowed
464                 && !$item->{cantreserve}
465                 && IsAvailableForItemLevelRequest($itemnumber)
466                 && CanItemBeReserved(
467                     $borrowerinfo->{borrowernumber}, $itemnumber
468                 )
469               )
470             {
471                 $item->{available} = 1;
472                 $num_available++;
473             }
474             elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
475
476 # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
477                 $item->{override} = 1;
478                 $num_override++;
479             }
480
481             # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
482
483             # FIXME: move this to a pm
484             my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
485             $sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
486             while (my $wait_hashref = $sth2->fetchrow_hashref) {
487                 $item->{waitingdate} = format_date($wait_hashref->{waitingdate});
488             }
489
490             # Show serial enumeration when needed
491             if ($item->{enumchron}) {
492                 $itemdata_enumchron = 1;
493             }
494
495             push @{ $biblioitem->{itemloop} }, $item;
496         }
497
498         if ( $num_override == scalar( @{ $biblioitem->{itemloop} } ) ) { # That is, if all items require an override
499             $template->param( override_required => 1 );
500         } elsif ( $num_available == 0 ) {
501             $template->param( none_available => 1 );
502             $template->param( warnings => 1 );
503             $biblioloopiter{warn} = 1;
504             $biblioloopiter{none_avail} = 1;
505         }
506         $template->param( hiddencount => $hiddencount);
507
508         push @bibitemloop, $biblioitem;
509     }
510
511     # existingreserves building
512     my @reserveloop;
513     ( $count, $reserves ) = GetReservesFromBiblionumber($biblionumber,1);
514     foreach my $res ( sort {
515             my $a_found = $a->{found} || '';
516             my $b_found = $a->{found} || '';
517             $a_found cmp $b_found;
518         } @$reserves ) {
519         my %reserve;
520         my @optionloop;
521         for ( my $i = 1 ; $i <= $totalcount ; $i++ ) {
522             push(
523                  @optionloop,
524                  {
525                   num      => $i,
526                   selected => ( $i == $res->{priority} ),
527                  }
528                 );
529         }
530
531         if ( defined $res->{'found'} && $res->{'found'} eq 'W' || $res->{'found'} eq 'T' ) {
532             my $item = $res->{'itemnumber'};
533             $item = GetBiblioFromItemNumber($item,undef);
534             $reserve{'wait'}= 1;
535             $reserve{'holdingbranch'}=$item->{'holdingbranch'};
536             $reserve{'biblionumber'}=$item->{'biblionumber'};
537             $reserve{'barcodenumber'}   = $item->{'barcode'};
538             $reserve{'wbrcode'} = $res->{'branchcode'};
539             $reserve{'itemnumber'}  = $res->{'itemnumber'};
540             $reserve{'wbrname'} = $branches->{$res->{'branchcode'}}->{'branchname'};
541             if($reserve{'holdingbranch'} eq $reserve{'wbrcode'}){
542                 $reserve{'atdestination'} = 1;
543             }
544             # set found to 1 if reserve is waiting for patron pickup
545             $reserve{'found'} = 1 if $res->{'found'} eq 'W';
546             $reserve{'intransit'} = 1 if $res->{'found'} eq 'T';
547         } elsif ($res->{priority} > 0) {
548             if (defined($res->{itemnumber})) {
549                 my $item = GetItem($res->{itemnumber});
550                 $reserve{'itemnumber'}  = $res->{'itemnumber'};
551                 $reserve{'barcodenumber'}   = $item->{'barcode'};
552                 $reserve{'item_level_hold'} = 1;
553             }
554         }
555
556         #     get borrowers reserve info
557         my $reserveborrowerinfo = GetMember( borrowernumber => $res->{'borrowernumber'} );
558         if (C4::Context->preference('HidePatronName')){
559             $reserve{'hidename'} = 1;
560             $reserve{'cardnumber'} = $reserveborrowerinfo->{'cardnumber'};
561         }
562         $reserve{'expirationdate'} = format_date( $res->{'expirationdate'} )
563             unless ( !defined($res->{'expirationdate'}) || $res->{'expirationdate'} eq '0000-00-00' );
564         $reserve{'date'}           = format_date( $res->{'reservedate'} );
565         $reserve{'borrowernumber'} = $res->{'borrowernumber'};
566         $reserve{'biblionumber'}   = $res->{'biblionumber'};
567         $reserve{'borrowernumber'} = $res->{'borrowernumber'};
568         $reserve{'firstname'}      = $reserveborrowerinfo->{'firstname'};
569         $reserve{'surname'}        = $reserveborrowerinfo->{'surname'};
570         $reserve{'notes'}          = $res->{'reservenotes'};
571         $reserve{'wait'}           =
572           ( ( defined $res->{'found'} and $res->{'found'} eq 'W' ) or ( $res->{'priority'} eq '0' ) );
573         $reserve{'constrainttypea'} = ( $res->{'constrainttype'} eq 'a' );
574         $reserve{'constrainttypeo'} = ( $res->{'constrainttype'} eq 'o' );
575         $reserve{'voldesc'}         = $res->{'volumeddesc'};
576         $reserve{'ccode'}           = $res->{'ccode'};
577         $reserve{'barcode'}         = $res->{'barcode'};
578         $reserve{'priority'}    = $res->{'priority'};
579         $reserve{'lowestPriority'}    = $res->{'lowestPriority'};
580         $reserve{'branchloop'} = GetBranchesLoop($res->{'branchcode'});
581         $reserve{'optionloop'} = \@optionloop;
582         $reserve{'suspend'} = $res->{'suspend'};
583         $reserve{'suspend_until'} = $res->{'suspend_until'};
584         push( @reserveloop, \%reserve );
585     }
586
587     # get the time for the form name...
588     my $time = time();
589
590     $template->param(
591                      CGIbranch   => $CGIbranch,
592
593                      time        => $time,
594                      fixedRank   => $fixedRank,
595                     );
596
597     # display infos
598     $template->param(
599                      optionloop        => \@optionloop,
600                      bibitemloop       => \@bibitemloop,
601                      itemdata_enumchron => $itemdata_enumchron,
602                      date              => $date,
603                      biblionumber      => $biblionumber,
604                      findborrower      => $findborrower,
605                      title             => $dat->{title},
606                      author            => $dat->{author},
607                      holdsview => 1,
608                      C4::Search::enabled_staff_search_views,
609                     );
610     if (defined $borrowerinfo && exists $borrowerinfo->{'branchcode'}) {
611         $template->param(
612                      borrower_branchname => $branches->{$borrowerinfo->{'branchcode'}}->{'branchname'},
613                      borrower_branchcode => $borrowerinfo->{'branchcode'},
614         );
615     }
616     $template->param(CGIselectborrower => $CGIselectborrower) if defined $CGIselectborrower;
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( DHTMLcalendar_dateformat  => C4::Dates->DHTMLcalendar() );
633
634 if ($multihold) {
635     $template->param( multi_hold => 1 );
636 }
637
638 if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
639     $template->param( reserve_in_future => 1 );
640 }
641
642 $template->param(
643     SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
644     AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
645 );
646
647 # printout the page
648 output_html_with_http_headers $input, $cookie, $template->output;