Bug 17453: Add exceptions
[koha.git] / opac / opac-reserve.pl
1 #!/usr/bin/perl
2
3 # Copyright Katipo Communications 2002
4 # Copyright Koha Development team 2012
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use Modern::Perl;
22
23 use CGI qw ( -utf8 );
24 use C4::Auth;    # checkauth, getborrowernumber.
25 use C4::Koha;
26 use C4::Circulation;
27 use C4::Reserves;
28 use C4::Biblio;
29 use C4::Items;
30 use C4::Output;
31 use C4::Context;
32 use C4::Members;
33 use C4::Overdues;
34 use C4::Debug;
35 use Koha::DateUtils;
36 use Koha::Libraries;
37 use Koha::Patrons;
38 use Date::Calc qw/Today Date_to_Days/;
39 use List::MoreUtils qw/uniq/;
40
41 my $maxreserves = C4::Context->preference("maxreserves");
42
43 my $query = new CGI;
44
45 # if RequestOnOpac (for placing holds) is disabled, leave immediately
46 if ( ! C4::Context->preference('RequestOnOpac') ) {
47     print $query->redirect("/cgi-bin/koha/errors/404.pl");
48     exit;
49 }
50
51 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
52     {
53         template_name   => "opac-reserve.tt",
54         query           => $query,
55         type            => "opac",
56         authnotrequired => 0,
57         debug           => 1,
58     }
59 );
60
61 my ($show_holds_count, $show_priority);
62 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
63     m/holds/o and $show_holds_count = 1;
64     m/priority/ and $show_priority = 1;
65 }
66
67 sub get_out {
68         output_html_with_http_headers(shift,shift,shift); # $query, $cookie, $template->output;
69         exit;
70 }
71
72 # get borrower information ....
73 my ( $borr ) = GetMember( borrowernumber => $borrowernumber );
74 my $patron = Koha::Patrons->find( $borrowernumber );
75
76 my $can_place_hold_if_available_at_pickup = C4::Context->preference('OPACHoldsIfAvailableAtPickup');
77 unless ( $can_place_hold_if_available_at_pickup ) {
78     my @patron_categories = split '\|', C4::Context->preference('OPACHoldsIfAvailableAtPickupExceptions');
79     if ( @patron_categories ) {
80         $can_place_hold_if_available_at_pickup = grep /$borr->{categorycode}/, @patron_categories;
81     }
82 }
83
84 # check if this user can place a reserve, -1 means use sys pref, 0 means dont block, 1 means block
85 if ( $patron->category->effective_BlockExpiredPatronOpacActions ) {
86
87     if ( $patron->is_expired ) {
88
89         # cannot reserve, their card has expired and the rules set mean this is not allowed
90         $template->param( message => 1, expired_patron => 1 );
91         get_out( $query, $cookie, $template->output );
92     }
93 }
94
95 # Pass through any reserve charge
96 my $reservefee = $patron->category->reservefee;
97 if ( $reservefee > 0){
98     $template->param( RESERVE_CHARGE => sprintf("%.2f",$reservefee));
99 }
100
101 my $itemTypes = GetItemTypes();
102
103 # There are two ways of calling this script, with a single biblio num
104 # or multiple biblio nums.
105 my $biblionumbers = $query->param('biblionumbers');
106 my $reserveMode = $query->param('reserve_mode');
107 if ($reserveMode && ($reserveMode eq 'single')) {
108     my $bib = $query->param('single_bib');
109     $biblionumbers = "$bib/";
110 }
111 if (! $biblionumbers) {
112     $biblionumbers = $query->param('biblionumber');
113 }
114
115 if ((! $biblionumbers) && (! $query->param('place_reserve'))) {
116     $template->param(message=>1, no_biblionumber=>1);
117     &get_out($query, $cookie, $template->output);
118 }
119
120 # Pass the numbers to the page so they can be fed back
121 # when the hold is confirmed. TODO: Not necessary?
122 $template->param( biblionumbers => $biblionumbers );
123
124 # Each biblio number is suffixed with '/', e.g. "1/2/3/"
125 my @biblionumbers = split /\//, $biblionumbers;
126 if (($#biblionumbers < 0) && (! $query->param('place_reserve'))) {
127     # TODO: New message?
128     $template->param(message=>1, no_biblionumber=>1);
129     &get_out($query, $cookie, $template->output);
130 }
131
132
133 # pass the pickup branch along....
134 my $branch = $query->param('branch') || $borr->{'branchcode'} || C4::Context->userenv->{branch} || '' ;
135 $template->param( branch => $branch );
136
137 # Is the person allowed to choose their branch
138 my $OPACChooseBranch = (C4::Context->preference("OPACAllowUserToChooseBranch")) ? 1 : 0;
139
140 $template->param( choose_branch => $OPACChooseBranch);
141
142 #
143 #
144 # Build hashes of the requested biblio(item)s and items.
145 #
146 #
147
148 my %biblioDataHash; # Hash of biblionumber to biblio/biblioitems record.
149 my %itemInfoHash; # Hash of itemnumber to item info.
150 foreach my $biblioNumber (@biblionumbers) {
151
152     my $biblioData = GetBiblioData($biblioNumber);
153     $biblioDataHash{$biblioNumber} = $biblioData;
154
155     my @itemInfos = GetItemsInfo($biblioNumber);
156
157     my $marcrecord= GetMarcBiblio($biblioNumber);
158
159     # flag indicating existence of at least one item linked via a host record
160     my $hostitemsflag;
161     # adding items linked via host biblios
162     my @hostitemInfos = GetHostItemsInfo($marcrecord);
163     if (@hostitemInfos){
164         $hostitemsflag =1;
165         push (@itemInfos,@hostitemInfos);
166     }
167
168     $biblioData->{itemInfos} = \@itemInfos;
169     foreach my $itemInfo (@itemInfos) {
170         $itemInfoHash{$itemInfo->{itemnumber}} = $itemInfo;
171     }
172
173     # Compute the priority rank.
174     my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblioNumber, all_dates => 1 });
175     my $rank = scalar( @$reserves );
176     $biblioData->{reservecount} = 1;    # new reserve
177     foreach my $res (@{$reserves}) {
178         my $found = $res->{found};
179         if ( $found && $found eq 'W' ) {
180             $rank--;
181         }
182         else {
183             $biblioData->{reservecount}++;
184         }
185     }
186     $biblioData->{rank} = $rank + 1;
187 }
188
189 #
190 #
191 # If this is the second time through this script, it
192 # means we are carrying out the hold request, possibly
193 # with a specific item for each biblionumber.
194 #
195 #
196 if ( $query->param('place_reserve') ) {
197     my $reserve_cnt = 0;
198     if ($maxreserves) {
199         $reserve_cnt = GetReservesFromBorrowernumber( $borrowernumber );
200     }
201
202     # List is composed of alternating biblio/item/branch
203     my $selectedItems = $query->param('selecteditems');
204
205     if ($query->param('reserve_mode') eq 'single') {
206         # This indicates non-JavaScript mode, so there was
207         # only a single biblio number selected.
208         my $bib = $query->param('single_bib');
209         my $item = $query->param("checkitem_$bib");
210         if ($item eq 'any') {
211             $item = '';
212         }
213         my $branch = $query->param('branch');
214         $selectedItems = "$bib/$item/$branch/";
215     }
216
217     $selectedItems =~ s!/$!!;
218     my @selectedItems = split /\//, $selectedItems, -1;
219
220     # Make sure there is a biblionum/itemnum/branch triplet for each item.
221     # The itemnum can be 'any', meaning next available.
222     my $selectionCount = @selectedItems;
223     if (($selectionCount == 0) || (($selectionCount % 3) != 0)) {
224         $template->param(message=>1, bad_data=>1);
225         &get_out($query, $cookie, $template->output);
226     }
227
228     my $failed_holds = 0;
229     while (@selectedItems) {
230         my $biblioNum = shift(@selectedItems);
231         my $itemNum   = shift(@selectedItems);
232         my $branch    = shift(@selectedItems);    # i.e., branch code, not name
233
234         my $canreserve = 0;
235
236         my $singleBranchMode = Koha::Libraries->search->count == 1;
237         if ( $singleBranchMode || !$OPACChooseBranch )
238         {    # single branch mode or disabled user choosing
239             $branch = $borr->{'branchcode'};
240         }
241
242 #item may belong to a host biblio, if yes change biblioNum to hosts bilbionumber
243         if ( $itemNum ne '' ) {
244             my $hostbiblioNum = GetBiblionumberFromItemnumber($itemNum);
245             if ( $hostbiblioNum ne $biblioNum ) {
246                 $biblioNum = $hostbiblioNum;
247             }
248         }
249
250         my $biblioData = $biblioDataHash{$biblioNum};
251         my $found;
252
253         # Check for user supplied reserve date
254         my $startdate;
255         if (   C4::Context->preference('AllowHoldDateInFuture')
256             && C4::Context->preference('OPACAllowHoldDateInFuture') )
257         {
258             $startdate = $query->param("reserve_date_$biblioNum");
259         }
260
261         my $expiration_date = $query->param("expiration_date_$biblioNum");
262
263       # If a specific item was selected and the pickup branch is the same as the
264       # holdingbranch, force the value $rank and $found.
265         my $rank = $biblioData->{rank};
266         if ( $itemNum ne '' ) {
267             $canreserve = 1 if CanItemBeReserved( $borrowernumber, $itemNum ) eq 'OK';
268             $rank = '0' unless C4::Context->preference('ReservesNeedReturns');
269             my $item = GetItem($itemNum);
270             if ( $item->{'holdingbranch'} eq $branch ) {
271                 $found = 'W'
272                   unless C4::Context->preference('ReservesNeedReturns');
273             }
274         }
275         else {
276             $canreserve = 1 if CanBookBeReserved( $borrowernumber, $biblioNum ) eq 'OK';
277
278             # Inserts a null into the 'itemnumber' field of 'reserves' table.
279             $itemNum = undef;
280         }
281         my $notes = $query->param('notes_'.$biblioNum)||'';
282
283         if (   $maxreserves
284             && $reserve_cnt >= $maxreserves )
285         {
286             $canreserve = 0;
287         }
288
289         unless ( $can_place_hold_if_available_at_pickup ) {
290             $canreserve = 0 if Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch })->count;
291         }
292
293         my $itemtype = $query->param('itemtype') || undef;
294         $itemtype = undef if $itemNum;
295
296         # Here we actually do the reserveration. Stage 3.
297         if ($canreserve) {
298             my $reserve_id = AddReserve(
299                 $branch,          $borrowernumber, $biblioNum,
300                 [$biblioNum],     $rank,           $startdate,
301                 $expiration_date, $notes,          $biblioData->{title},
302                 $itemNum,         $found,          $itemtype,
303             );
304             $failed_holds++ unless $reserve_id;
305             ++$reserve_cnt;
306         }
307     }
308
309     print $query->redirect("/cgi-bin/koha/opac-user.pl?" . ( $failed_holds ? "failed_holds=$failed_holds" : q|| ) . "#opac-user-holds");
310     exit;
311 }
312
313 #
314 #
315 # Here we check that the borrower can actually make reserves Stage 1.
316 #
317 #
318 my $noreserves     = 0;
319 my $maxoutstanding = C4::Context->preference("maxoutstanding");
320 $template->param( noreserve => 1 ) unless $maxoutstanding;
321 my ( $amountoutstanding ) = GetMemberAccountRecords($borrowernumber);
322 if ( $amountoutstanding && ($amountoutstanding > $maxoutstanding) ) {
323     my $amount = sprintf "%.02f", $amountoutstanding;
324     $template->param( message => 1 );
325     $noreserves = 1;
326     $template->param( too_much_oweing => $amount );
327 }
328
329 if ( $borr->{gonenoaddress} && ($borr->{gonenoaddress} == 1) ) {
330     $noreserves = 1;
331     $template->param(
332         message => 1,
333         GNA     => 1
334     );
335 }
336
337 if ( $borr->{lost} && ($borr->{lost} == 1) ) {
338     $noreserves = 1;
339     $template->param(
340         message => 1,
341         lost    => 1
342     );
343 }
344
345 if ( Koha::Patrons->find( $borrowernumber )->is_debarred ) {
346     $noreserves = 1;
347     $template->param(
348         message          => 1,
349         debarred         => 1,
350         debarred_comment => $borr->{debarredcomment},
351         debarred_date    => $borr->{debarred},
352     );
353 }
354
355 my @reserves = GetReservesFromBorrowernumber( $borrowernumber );
356 my $reserves_count = scalar(@reserves);
357 $template->param( RESERVES => \@reserves );
358 if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
359     $template->param( message => 1 );
360     $noreserves = 1;
361     $template->param( too_many_reserves => scalar(@reserves));
362 }
363
364 unless ( $noreserves ) {
365     my $requested_reserves_count = scalar( @biblionumbers );
366     if ( $maxreserves && ( $reserves_count + $requested_reserves_count > $maxreserves ) ) {
367         $template->param( new_reserves_allowed => $maxreserves - $reserves_count );
368     }
369 }
370
371 unless ($noreserves) {
372     $template->param( select_item_types => 1 );
373 }
374
375
376 #
377 #
378 # Build the template parameters that will show the info
379 # and items for each biblionumber.
380 #
381 #
382 my $notforloan_label_of = get_notforloan_label_of();
383
384 my $biblioLoop = [];
385 my $numBibsAvailable = 0;
386 my $itemdata_enumchron = 0;
387 my $anyholdable = 0;
388 my $itemLevelTypes = C4::Context->preference('item-level_itypes');
389 $template->param('item_level_itypes' => $itemLevelTypes);
390
391 foreach my $biblioNum (@biblionumbers) {
392
393     my @not_available_at = ();
394     my $record = GetMarcBiblio($biblioNum);
395     # Init the bib item with the choices for branch pickup
396     my %biblioLoopIter;
397
398     # Get relevant biblio data.
399     my $biblioData = $biblioDataHash{$biblioNum};
400     if (! $biblioData) {
401         $template->param(message=>1, bad_biblionumber=>$biblioNum);
402         &get_out($query, $cookie, $template->output);
403     }
404
405     $biblioLoopIter{biblionumber} = $biblioData->{biblionumber};
406     $biblioLoopIter{title} = $biblioData->{title};
407     $biblioLoopIter{subtitle} = GetRecordValue('subtitle', $record, GetFrameworkCode($biblioData->{biblionumber}));
408     $biblioLoopIter{author} = $biblioData->{author};
409     $biblioLoopIter{rank} = $biblioData->{rank};
410     $biblioLoopIter{reservecount} = $biblioData->{reservecount};
411     $biblioLoopIter{already_reserved} = $biblioData->{already_reserved};
412     $biblioLoopIter{mandatorynotes}=0; #FIXME: For future use
413
414     if (!$itemLevelTypes && $biblioData->{itemtype}) {
415         $biblioLoopIter{translated_description} = $itemTypes->{$biblioData->{itemtype}}{translated_description};
416         $biblioLoopIter{imageurl} = getitemtypeimagesrc() . "/". $itemTypes->{$biblioData->{itemtype}}{imageurl};
417     }
418
419     foreach my $itemInfo (@{$biblioData->{itemInfos}}) {
420         if ($itemLevelTypes && $itemInfo->{itype}) {
421             $itemInfo->{translated_description} = $itemTypes->{$itemInfo->{itype}}{translated_description};
422             $itemInfo->{imageurl} = getitemtypeimagesrc() . "/". $itemTypes->{$itemInfo->{itype}}{imageurl};
423         }
424
425         if (!$itemInfo->{'notforloan'} && !($itemInfo->{'itemnotforloan'} > 0)) {
426             $biblioLoopIter{forloan} = 1;
427         }
428     }
429
430     $biblioLoopIter{itemLoop} = [];
431     my $numCopiesAvailable = 0;
432     my $numCopiesOPACAvailable = 0;
433     foreach my $itemInfo (@{$biblioData->{itemInfos}}) {
434         my $itemNum = $itemInfo->{itemnumber};
435         my $itemLoopIter = {};
436
437         $itemLoopIter->{itemnumber} = $itemNum;
438         $itemLoopIter->{barcode} = $itemInfo->{barcode};
439         $itemLoopIter->{homeBranchName} = $itemInfo->{homebranch};
440         $itemLoopIter->{callNumber} = $itemInfo->{itemcallnumber};
441         $itemLoopIter->{enumchron} = $itemInfo->{enumchron};
442         $itemLoopIter->{copynumber} = $itemInfo->{copynumber};
443         if ($itemLevelTypes) {
444             $itemLoopIter->{translated_description} = $itemInfo->{translated_description};
445             $itemLoopIter->{itype} = $itemInfo->{itype};
446             $itemLoopIter->{imageurl} = $itemInfo->{imageurl};
447         }
448
449         # If the holdingbranch is different than the homebranch, we show the
450         # holdingbranch of the document too.
451         if ( $itemInfo->{homebranch} ne $itemInfo->{holdingbranch} ) {
452             $itemLoopIter->{holdingBranchName} = $itemInfo->{holdingbranch};
453         }
454
455         # If the item is currently on loan, we display its return date and
456         # change the background color.
457         my $issues= GetItemIssue($itemNum);
458         if ( $issues->{'date_due'} ) {
459             $itemLoopIter->{dateDue} = output_pref({ dt => dt_from_string($issues->{date_due}, 'sql'), as_due_date => 1 });
460             $itemLoopIter->{backgroundcolor} = 'onloan';
461         }
462
463         # checking reserve
464         my ($reservedate,$reservedfor,$expectedAt,undef,$wait) = GetReservesFromItemnumber($itemNum);
465         my $ItemBorrowerReserveInfo = GetMember( borrowernumber => $reservedfor );
466
467         # the item could be reserved for this borrower vi a host record, flag this
468         $reservedfor //= '';
469
470         if ( defined $reservedate ) {
471             $itemLoopIter->{backgroundcolor} = 'reserved';
472             $itemLoopIter->{reservedate}     = output_pref({ dt => dt_from_string($reservedate), dateonly => 1 });
473             $itemLoopIter->{ReservedForBorrowernumber} = $reservedfor;
474             $itemLoopIter->{ReservedForSurname}        = $ItemBorrowerReserveInfo->{'surname'};
475             $itemLoopIter->{ReservedForFirstname}      = $ItemBorrowerReserveInfo->{'firstname'};
476             $itemLoopIter->{ExpectedAtLibrary}         = $expectedAt;
477             #waiting status
478             $itemLoopIter->{waitingdate} = $wait;
479         }
480
481         $itemLoopIter->{notforloan} = $itemInfo->{notforloan};
482         $itemLoopIter->{itemnotforloan} = $itemInfo->{itemnotforloan};
483
484         # Management of the notforloan document
485         if ( $itemLoopIter->{notforloan} || $itemLoopIter->{itemnotforloan}) {
486             $itemLoopIter->{backgroundcolor} = 'other';
487             $itemLoopIter->{notforloanvalue} =
488               $notforloan_label_of->{ $itemLoopIter->{notforloan} };
489         }
490
491         # Management of lost or long overdue items
492         if ( $itemInfo->{itemlost} ) {
493
494             # FIXME localized strings should never be in Perl code
495             $itemLoopIter->{message} =
496                 $itemInfo->{itemlost} == 1 ? "(lost)"
497               : $itemInfo->{itemlost} == 2 ? "(long overdue)"
498               : "";
499             $itemInfo->{backgroundcolor} = 'other';
500         }
501
502         # Check of the transfered documents
503         my ( $transfertwhen, $transfertfrom, $transfertto ) =
504           GetTransfers($itemNum);
505         if ( $transfertwhen && ($transfertwhen ne '') ) {
506             $itemLoopIter->{transfertwhen} = output_pref({ dt => dt_from_string($transfertwhen), dateonly => 1 });
507             $itemLoopIter->{transfertfrom} = $transfertfrom;
508             $itemLoopIter->{transfertto} = $transfertto;
509             $itemLoopIter->{nocancel} = 1;
510         }
511
512         # if the items belongs to a host record, show link to host record
513         if ( $itemInfo->{biblionumber} ne $biblioNum ) {
514             $biblioLoopIter{hostitemsflag}    = 1;
515             $itemLoopIter->{hostbiblionumber} = $itemInfo->{biblionumber};
516             $itemLoopIter->{hosttitle}        = GetBiblioData( $itemInfo->{biblionumber} )->{title};
517         }
518
519         # If there is no loan, return and transfer, we show a checkbox.
520         $itemLoopIter->{notforloan} = $itemLoopIter->{notforloan} || 0;
521
522         my $branch = GetReservesControlBranch( $itemInfo, $borr );
523
524         my $policy_holdallowed = !$itemLoopIter->{already_reserved};
525         $policy_holdallowed &&=
526             IsAvailableForItemLevelRequest($itemInfo,$borr) &&
527             CanItemBeReserved($borrowernumber,$itemNum) eq 'OK';
528
529         if ($policy_holdallowed) {
530             if ( my $hold_allowed = OPACItemHoldsAllowed( $itemInfo, $borr ) ) {
531                 $itemLoopIter->{available} = 1;
532                 $numCopiesOPACAvailable++;
533                 $biblioLoopIter{force_hold} = 1 if $hold_allowed eq 'F';
534             }
535             $numCopiesAvailable++;
536
537             unless ( $can_place_hold_if_available_at_pickup ) {
538                 push @not_available_at, $itemInfo->{holdingbranch};
539             }
540         }
541
542         $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemTypes->{ $itemInfo->{itype} }{imageurl} );
543
544     # Show serial enumeration when needed
545         if ($itemLoopIter->{enumchron}) {
546             $itemdata_enumchron = 1;
547         }
548
549         push @{$biblioLoopIter{itemLoop}}, $itemLoopIter;
550     }
551     $template->param( itemdata_enumchron => $itemdata_enumchron );
552
553     if ($numCopiesAvailable > 0) {
554         $numBibsAvailable++;
555         $biblioLoopIter{bib_available} = 1;
556         $biblioLoopIter{holdable} = 1;
557         $biblioLoopIter{itemholdable} = 1 if $numCopiesOPACAvailable;
558     }
559     if ($biblioLoopIter{already_reserved}) {
560         $biblioLoopIter{holdable} = undef;
561         $biblioLoopIter{itemholdable} = undef;
562     }
563     if(not C4::Context->preference('AllowHoldsOnPatronsPossessions') and CheckIfIssuedToPatron($borrowernumber,$biblioNum)) {
564         $biblioLoopIter{holdable} = undef;
565         $biblioLoopIter{already_patron_possession} = 1;
566     }
567
568     if ( $biblioLoopIter{holdable} ) {
569         @not_available_at = uniq @not_available_at;
570         $biblioLoopIter{not_available_at} = \@not_available_at ;
571     }
572
573     unless ( $can_place_hold_if_available_at_pickup ) {
574         @not_available_at = uniq @not_available_at;
575         $biblioLoopIter{not_available_at} = \@not_available_at ;
576         # The record is not holdable is not available at any of the libraries
577         if ( Koha::Libraries->search->count == @not_available_at ) {
578             $biblioLoopIter{holdable} = 0;
579         }
580     }
581
582     $biblioLoopIter{holdable} &&= CanBookBeReserved($borrowernumber,$biblioNum) eq 'OK';
583
584     # For multiple holds per record, if a patron has previously placed a hold,
585     # the patron can only place more holds of the same type. That is, if the
586     # patron placed a record level hold, all the holds the patron places must
587     # be record level. If the patron placed an item level hold, all holds
588     # the patron places must be item level
589     my $forced_hold_level = Koha::Holds->search(
590         {
591             borrowernumber => $borrowernumber,
592             biblionumber   => $biblioNum,
593             found          => undef,
594         }
595     )->forced_hold_level();
596     if ($forced_hold_level) {
597         $biblioLoopIter{force_hold}   = 1 if $forced_hold_level eq 'item';
598         $biblioLoopIter{itemholdable} = 0 if $forced_hold_level eq 'record';
599     }
600
601
602     push @$biblioLoop, \%biblioLoopIter;
603
604     $anyholdable = 1 if $biblioLoopIter{holdable};
605 }
606
607
608 if ( $numBibsAvailable == 0 || $anyholdable == 0) {
609     $template->param( none_available => 1 );
610 }
611
612 my $show_notes=C4::Context->preference('OpacHoldNotes');
613 $template->param(OpacHoldNotes=>$show_notes);
614
615 # display infos
616 $template->param(bibitemloop => $biblioLoop);
617 # can set reserve date in future
618 if (
619     C4::Context->preference( 'AllowHoldDateInFuture' ) &&
620     C4::Context->preference( 'OPACAllowHoldDateInFuture' )
621     ) {
622     $template->param(
623             reserve_in_future         => 1,
624     );
625 }
626
627 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };