Bug 24412: (follow-up) prevent request.pl from failing
[koha.git] / opac / opac-reserve.pl
blobb0ed08868950669b566118b957fcc61c06b67873
1 #!/usr/bin/perl
3 # Copyright Katipo Communications 2002
4 # Copyright Koha Development team 2012
6 # This file is part of Koha.
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.
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.
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>.
21 use Modern::Perl;
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;
36 use Koha::AuthorisedValues;
37 use Koha::Biblios;
38 use Koha::DateUtils;
39 use Koha::CirculationRules;
40 use Koha::Items;
41 use Koha::ItemTypes;
42 use Koha::Checkouts;
43 use Koha::Libraries;
44 use Koha::Patrons;
45 use Date::Calc qw/Today Date_to_Days/;
46 use List::MoreUtils qw/uniq/;
48 my $maxreserves = C4::Context->preference("maxreserves");
50 my $query = CGI->new;
52 # if RequestOnOpac (for placing holds) is disabled, leave immediately
53 if ( ! C4::Context->preference('RequestOnOpac') ) {
54 print $query->redirect("/cgi-bin/koha/errors/404.pl");
55 exit;
58 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
60 template_name => "opac-reserve.tt",
61 query => $query,
62 type => "opac",
63 debug => 1,
67 my ($show_holds_count, $show_priority);
68 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
69 m/holds/o and $show_holds_count = 1;
70 m/priority/ and $show_priority = 1;
73 my $patron = Koha::Patrons->find( $borrowernumber );
75 my $can_place_hold_if_available_at_pickup = C4::Context->preference('OPACHoldsIfAvailableAtPickup');
76 unless ( $can_place_hold_if_available_at_pickup ) {
77 my @patron_categories = split '\|', C4::Context->preference('OPACHoldsIfAvailableAtPickupExceptions');
78 if ( @patron_categories ) {
79 my $categorycode = $patron->categorycode;
80 $can_place_hold_if_available_at_pickup = grep { $_ eq $categorycode } @patron_categories;
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 ) {
87 if ( $patron->is_expired ) {
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 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
92 exit;
96 # Pass through any reserve charge
97 my $reservefee = $patron->category->reservefee;
98 if ( $reservefee > 0){
99 $template->param( RESERVE_CHARGE => $reservefee);
102 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
104 # There are two ways of calling this script, with a single biblio num
105 # or multiple biblio nums.
106 my $biblionumbers = $query->param('biblionumbers');
107 my $reserveMode = $query->param('reserve_mode');
108 if ($reserveMode && ($reserveMode eq 'single')) {
109 my $bib = $query->param('single_bib');
110 $biblionumbers = "$bib/";
112 if (! $biblionumbers) {
113 $biblionumbers = $query->param('biblionumber');
116 if ((! $biblionumbers) && (! $query->param('place_reserve'))) {
117 $template->param(message=>1, no_biblionumber=>1);
118 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
119 exit;
122 # Pass the numbers to the page so they can be fed back
123 # when the hold is confirmed. TODO: Not necessary?
124 $template->param( biblionumbers => $biblionumbers );
126 # Each biblio number is suffixed with '/', e.g. "1/2/3/"
127 my @biblionumbers = split /\//, $biblionumbers;
128 if (($#biblionumbers < 0) && (! $query->param('place_reserve'))) {
129 # TODO: New message?
130 $template->param(message=>1, no_biblionumber=>1);
131 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
132 exit;
136 # pass the pickup branch along....
137 my $branch = $query->param('branch') || $patron->branchcode || C4::Context->userenv->{branch} || '' ;
138 $template->param( branch => $branch );
142 # Build hashes of the requested biblio(item)s and items.
146 my %biblioDataHash; # Hash of biblionumber to biblio/biblioitems record.
147 my %itemInfoHash; # Hash of itemnumber to item info.
148 foreach my $biblioNumber (@biblionumbers) {
150 my $biblioData = GetBiblioData($biblioNumber);
151 $biblioDataHash{$biblioNumber} = $biblioData;
153 my @itemInfos = GetItemsInfo($biblioNumber);
155 my $marcrecord= GetMarcBiblio({ biblionumber => $biblioNumber });
157 # flag indicating existence of at least one item linked via a host record
158 my $hostitemsflag;
159 # adding items linked via host biblios
160 my @hostitemInfos = GetHostItemsInfo($marcrecord);
161 if (@hostitemInfos){
162 $hostitemsflag =1;
163 push (@itemInfos,@hostitemInfos);
166 $biblioData->{itemInfos} = \@itemInfos;
167 foreach my $itemInfo (@itemInfos) {
168 $itemInfoHash{$itemInfo->{itemnumber}} = $itemInfo;
171 # Compute the priority rank.
172 my $biblio = Koha::Biblios->find( $biblioNumber );
173 $biblioData->{object} = $biblio;
174 my $holds = $biblio->holds;
175 my $rank = $holds->count;
176 $biblioData->{reservecount} = 1; # new reserve
177 while ( my $hold = $holds->next ) {
178 if ( $hold->is_waiting ) {
179 $rank--;
181 else {
182 $biblioData->{reservecount}++;
185 $biblioData->{rank} = $rank + 1;
190 # If this is the second time through this script, it
191 # means we are carrying out the hold request, possibly
192 # with a specific item for each biblionumber.
195 if ( $query->param('place_reserve') ) {
196 my $reserve_cnt = 0;
197 if ($maxreserves) {
198 $reserve_cnt = $patron->holds->count;
201 # List is composed of alternating biblio/item/branch
202 my $selectedItems = $query->param('selecteditems');
204 if ($query->param('reserve_mode') eq 'single') {
205 # This indicates non-JavaScript mode, so there was
206 # only a single biblio number selected.
207 my $bib = $query->param('single_bib');
208 my $item = $query->param("checkitem_$bib");
209 if ($item eq 'any') {
210 $item = '';
212 my $branch = $query->param('branch');
213 $selectedItems = "$bib/$item/$branch/";
216 $selectedItems =~ s!/$!!;
217 my @selectedItems = split /\//, $selectedItems, -1;
219 # Make sure there is a biblionum/itemnum/branch triplet for each item.
220 # The itemnum can be 'any', meaning next available.
221 my $selectionCount = @selectedItems;
222 if (($selectionCount == 0) || (($selectionCount % 3) != 0)) {
223 $template->param(message=>1, bad_data=>1);
224 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
225 exit;
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
234 my $canreserve = 0;
236 my $singleBranchMode = Koha::Libraries->search->count == 1;
237 if ( $singleBranchMode || ! C4::Context->preference("OPACAllowUserToChooseBranch") )
238 { # single branch mode or disabled user choosing
239 $branch = $patron->branchcode;
242 # When choosing a specific item, the default pickup library should be dictated by the default hold policy
243 if ( ! C4::Context->preference("OPACAllowUserToChooseBranch") && $itemNum ) {
244 my $item = Koha::Items->find( $itemNum );
245 my $type = $item->effective_itemtype;
246 my $rule = GetBranchItemRule( $patron->branchcode, $type );
248 if ( $rule->{hold_fulfillment_policy} eq 'any' ) {
249 $branch = $patron->branchcode;
250 } else {
251 my $policy = $rule->{hold_fulfillment_policy};
252 $branch = $item->$policy;
256 #item may belong to a host biblio, if yes change biblioNum to hosts bilbionumber
257 if ( $itemNum ne '' ) {
258 my $item = Koha::Items->find( $itemNum );
259 my $hostbiblioNum = $item->biblio->biblionumber;
260 if ( $hostbiblioNum ne $biblioNum ) {
261 $biblioNum = $hostbiblioNum;
265 my $biblioData = $biblioDataHash{$biblioNum};
266 my $found;
268 # Check for user supplied reserve date
269 my $startdate;
270 if ( C4::Context->preference('AllowHoldDateInFuture')
271 && C4::Context->preference('OPACAllowHoldDateInFuture') )
273 $startdate = $query->param("reserve_date_$biblioNum");
276 my $expiration_date = $query->param("expiration_date_$biblioNum");
278 my $rank = $biblioData->{rank};
279 if ( $itemNum ne '' ) {
280 $canreserve = 1 if CanItemBeReserved( $borrowernumber, $itemNum, $branch )->{status} eq 'OK';
282 else {
283 $canreserve = 1 if CanBookBeReserved( $borrowernumber, $biblioNum, $branch )->{status} eq 'OK';
285 # Inserts a null into the 'itemnumber' field of 'reserves' table.
286 $itemNum = undef;
288 my $notes = $query->param('notes_'.$biblioNum)||'';
290 if ( $maxreserves
291 && $reserve_cnt >= $maxreserves )
293 $canreserve = 0;
296 unless ( $can_place_hold_if_available_at_pickup ) {
297 my $items_in_this_library = Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch });
298 my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
299 my $nb_of_items_unavailable = $items_in_this_library->search({ -or => { lost => { '!=' => 0 }, damaged => { '!=' => 0 }, } });
300 if ( $items_in_this_library->count > $nb_of_items_issued + $nb_of_items_unavailable ) {
301 $canreserve = 0
305 my $itemtype = $query->param('itemtype') || undef;
306 $itemtype = undef if $itemNum;
308 # Here we actually do the reserveration. Stage 3.
309 if ($canreserve) {
310 my $reserve_id = AddReserve(
312 branchcode => $branch,
313 borrowernumber => $borrowernumber,
314 biblionumber => $biblioNum,
315 priority => $rank,
316 reservation_date => $startdate,
317 expiration_date => $expiration_date,
318 notes => $notes,
319 title => $biblioData->{title},
320 itemnumber => $itemNum,
321 found => $found,
322 itemtype => $itemtype,
325 $failed_holds++ unless $reserve_id;
326 ++$reserve_cnt;
330 print $query->redirect("/cgi-bin/koha/opac-user.pl?" . ( $failed_holds ? "failed_holds=$failed_holds" : q|| ) . "#opac-user-holds");
331 exit;
336 # Here we check that the borrower can actually make reserves Stage 1.
339 my $noreserves = 0;
340 my $maxoutstanding = C4::Context->preference("maxoutstanding");
341 $template->param( noreserve => 1 ) unless $maxoutstanding;
342 my $amountoutstanding = $patron->account->balance;
343 if ( $amountoutstanding && ($amountoutstanding > $maxoutstanding) ) {
344 my $amount = sprintf "%.02f", $amountoutstanding;
345 $template->param( message => 1 );
346 $noreserves = 1;
347 $template->param( too_much_oweing => $amount );
350 if ( $patron->gonenoaddress && ($patron->gonenoaddress == 1) ) {
351 $noreserves = 1;
352 $template->param(
353 message => 1,
354 GNA => 1
358 if ( $patron->lost && ($patron->lost == 1) ) {
359 $noreserves = 1;
360 $template->param(
361 message => 1,
362 lost => 1
366 if ( $patron->is_debarred ) {
367 $noreserves = 1;
368 $template->param(
369 message => 1,
370 debarred => 1,
371 debarred_comment => $patron->debarredcomment,
372 debarred_date => $patron->debarred,
376 my $holds = $patron->holds;
377 my $reserves_count = $holds->count;
378 $template->param( RESERVES => $holds->unblessed );
379 if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
380 $template->param( message => 1 );
381 $noreserves = 1;
382 $template->param( too_many_reserves => $holds->count );
385 unless ( $noreserves ) {
386 my $requested_reserves_count = scalar( @biblionumbers );
387 if ( $maxreserves && ( $reserves_count + $requested_reserves_count > $maxreserves ) ) {
388 $template->param( new_reserves_allowed => $maxreserves - $reserves_count );
392 unless ($noreserves) {
393 $template->param( select_item_types => 1 );
399 # Build the template parameters that will show the info
400 # and items for each biblionumber.
404 my $biblioLoop = [];
405 my $numBibsAvailable = 0;
406 my $itemdata_enumchron = 0;
407 my $itemdata_ccode = 0;
408 my $anyholdable = 0;
409 my $itemLevelTypes = C4::Context->preference('item-level_itypes');
410 my $pickup_locations = Koha::Libraries->search({ pickup_location => 1 });
411 $template->param('item_level_itypes' => $itemLevelTypes);
413 foreach my $biblioNum (@biblionumbers) {
415 # Init the bib item with the choices for branch pickup
416 my %biblioLoopIter;
418 # Get relevant biblio data.
419 my $biblioData = $biblioDataHash{$biblioNum};
420 if (! $biblioData) {
421 $template->param(message=>1, bad_biblionumber=>$biblioNum);
422 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
423 exit;
426 my @not_available_at = ();
427 my $biblio = $biblioData->{object};
428 foreach my $library ( $pickup_locations->as_list ) {
429 push( @not_available_at, $library->branchcode ) unless $biblio->can_be_transferred({ to => $library });
432 my $frameworkcode = GetFrameworkCode( $biblioData->{biblionumber} );
433 $biblioLoopIter{biblionumber} = $biblioData->{biblionumber};
434 $biblioLoopIter{title} = $biblioData->{title};
435 $biblioLoopIter{subtitle} = $biblioData->{'subtitle'};
436 $biblioLoopIter{medium} = $biblioData->{medium};
437 $biblioLoopIter{part_number} = $biblioData->{part_number};
438 $biblioLoopIter{part_name} = $biblioData->{part_name};
439 $biblioLoopIter{author} = $biblioData->{author};
440 $biblioLoopIter{rank} = $biblioData->{rank};
441 $biblioLoopIter{reservecount} = $biblioData->{reservecount};
442 $biblioLoopIter{already_reserved} = $biblioData->{already_reserved};
443 $biblioLoopIter{reqholdnotes}=0; #TODO: For future use
445 if (!$itemLevelTypes && $biblioData->{itemtype}) {
446 $biblioLoopIter{translated_description} = $itemtypes->{$biblioData->{itemtype}}{translated_description};
447 $biblioLoopIter{imageurl} = getitemtypeimagesrc() . "/". $itemtypes->{$biblioData->{itemtype}}{imageurl};
450 foreach my $itemInfo (@{$biblioData->{itemInfos}}) {
451 if ($itemLevelTypes && $itemInfo->{itype}) {
452 $itemInfo->{translated_description} = $itemtypes->{$itemInfo->{itype}}{translated_description};
453 $itemInfo->{imageurl} = getitemtypeimagesrc() . "/". $itemtypes->{$itemInfo->{itype}}{imageurl};
456 if (!$itemInfo->{'notforloan'} && !($itemInfo->{'itemnotforloan'} > 0)) {
457 $biblioLoopIter{forloan} = 1;
461 my @notforloan_avs = Koha::AuthorisedValues->search_by_koha_field({ kohafield => 'items.notforloan', frameworkcode => $frameworkcode });
462 my $notforloan_label_of = { map { $_->authorised_value => $_->opac_description } @notforloan_avs };
464 $biblioLoopIter{itemLoop} = [];
465 my $numCopiesAvailable = 0;
466 my $numCopiesOPACAvailable = 0;
467 foreach my $itemInfo (@{$biblioData->{itemInfos}}) {
468 my $itemNum = $itemInfo->{itemnumber};
469 my $item = Koha::Items->find( $itemNum );
470 my $itemLoopIter = {};
472 $itemLoopIter->{itemnumber} = $itemNum;
473 $itemLoopIter->{barcode} = $itemInfo->{barcode};
474 $itemLoopIter->{homeBranchName} = $itemInfo->{homebranch};
475 $itemLoopIter->{callNumber} = $itemInfo->{itemcallnumber};
476 $itemLoopIter->{enumchron} = $itemInfo->{enumchron};
477 $itemLoopIter->{ccode} = $itemInfo->{ccode};
478 $itemLoopIter->{copynumber} = $itemInfo->{copynumber};
479 if ($itemLevelTypes) {
480 $itemLoopIter->{translated_description} = $itemInfo->{translated_description};
481 $itemLoopIter->{itype} = $itemInfo->{itype};
482 $itemLoopIter->{imageurl} = $itemInfo->{imageurl};
485 # If the holdingbranch is different than the homebranch, we show the
486 # holdingbranch of the document too.
487 if ( $itemInfo->{homebranch} ne $itemInfo->{holdingbranch} ) {
488 $itemLoopIter->{holdingBranchName} = $itemInfo->{holdingbranch};
491 # If the item is currently on loan, we display its return date and
492 # change the background color.
493 my $issue = Koha::Checkouts->find( { itemnumber => $itemNum } );
494 if ( $issue ) {
495 $itemLoopIter->{dateDue} = output_pref({ dt => dt_from_string($issue->date_due, 'sql'), as_due_date => 1 });
496 $itemLoopIter->{backgroundcolor} = 'onloan';
499 # checking reserve
500 my $holds = $item->current_holds;
502 if ( my $first_hold = $holds->next ) {
503 $itemLoopIter->{backgroundcolor} = 'reserved';
504 $itemLoopIter->{reservedate} = output_pref({ dt => dt_from_string($first_hold->reservedate), dateonly => 1 }); # FIXME Should be formatted in the template
505 $itemLoopIter->{ExpectedAtLibrary} = $first_hold->branchcode;
506 $itemLoopIter->{waitingdate} = $first_hold->waitingdate;
509 $itemLoopIter->{notforloan} = $itemInfo->{notforloan};
510 $itemLoopIter->{itemnotforloan} = $itemInfo->{itemnotforloan};
512 # Management of the notforloan document
513 if ( $itemLoopIter->{notforloan} || $itemLoopIter->{itemnotforloan}) {
514 $itemLoopIter->{backgroundcolor} = 'other';
515 $itemLoopIter->{notforloanvalue} =
516 $notforloan_label_of->{ $itemLoopIter->{notforloan} };
519 # Management of lost or long overdue items
520 if ( $itemInfo->{itemlost} ) {
522 # FIXME localized strings should never be in Perl code
523 $itemLoopIter->{message} =
524 $itemInfo->{itemlost} == 1 ? "(lost)"
525 : $itemInfo->{itemlost} == 2 ? "(long overdue)"
526 : "";
527 $itemInfo->{backgroundcolor} = 'other';
530 # Check of the transferred documents
531 my ( $transfertwhen, $transfertfrom, $transfertto ) =
532 GetTransfers($itemNum);
533 if ( $transfertwhen && ($transfertwhen ne '') ) {
534 $itemLoopIter->{transfertwhen} = output_pref({ dt => dt_from_string($transfertwhen), dateonly => 1 });
535 $itemLoopIter->{transfertfrom} = $transfertfrom;
536 $itemLoopIter->{transfertto} = $transfertto;
537 $itemLoopIter->{nocancel} = 1;
540 # if the items belongs to a host record, show link to host record
541 if ( $itemInfo->{biblionumber} ne $biblioNum ) {
542 $biblioLoopIter{hostitemsflag} = 1;
543 $itemLoopIter->{hostbiblionumber} = $itemInfo->{biblionumber};
544 $itemLoopIter->{hosttitle} = Koha::Biblios->find( $itemInfo->{biblionumber} )->title;
547 # If there is no loan, return and transfer, we show a checkbox.
548 $itemLoopIter->{notforloan} = $itemLoopIter->{notforloan} || 0;
550 my $patron_unblessed = $patron->unblessed;
551 my $branch = GetReservesControlBranch( $itemInfo, $patron_unblessed );
553 my $policy_holdallowed = !$itemLoopIter->{already_reserved};
554 $policy_holdallowed &&=
555 IsAvailableForItemLevelRequest($item, $patron) &&
556 CanItemBeReserved( $borrowernumber, $itemNum )->{status} eq 'OK';
558 if ($policy_holdallowed) {
559 my $opac_hold_policy = Koha::CirculationRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
560 if ( $opac_hold_policy ne 'N' ) { # If Y or F
561 $itemLoopIter->{available} = 1;
562 $numCopiesOPACAvailable++;
563 $biblioLoopIter{force_hold} = 1 if $opac_hold_policy eq 'F';
565 $numCopiesAvailable++;
567 unless ( $can_place_hold_if_available_at_pickup ) {
568 my $items_in_this_library = Koha::Items->search({ biblionumber => $itemInfo->{biblionumber}, holdingbranch => $itemInfo->{holdingbranch} });
569 my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
570 if ( $items_in_this_library->count > $nb_of_items_issued ) {
571 push @not_available_at, $itemInfo->{holdingbranch};
576 $itemLoopIter->{imageurl} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itemInfo->{itype} }{imageurl} );
578 # Show serial enumeration when needed
579 if ($itemLoopIter->{enumchron}) {
580 $itemdata_enumchron = 1;
582 # Show collection when needed
583 if ($itemLoopIter->{ccode}) {
584 $itemdata_ccode = 1;
587 push @{$biblioLoopIter{itemLoop}}, $itemLoopIter;
589 $template->param(
590 itemdata_enumchron => $itemdata_enumchron,
591 itemdata_ccode => $itemdata_ccode,
594 if ($numCopiesAvailable > 0) {
595 $numBibsAvailable++;
596 $biblioLoopIter{bib_available} = 1;
597 $biblioLoopIter{holdable} = 1;
598 $biblioLoopIter{itemholdable} = 1 if $numCopiesOPACAvailable;
600 if ($biblioLoopIter{already_reserved}) {
601 $biblioLoopIter{holdable} = undef;
602 $biblioLoopIter{itemholdable} = undef;
604 if ( $biblioLoopIter{holdable} ) {
605 @not_available_at = uniq @not_available_at;
606 $biblioLoopIter{not_available_at} = \@not_available_at ;
609 unless ( $can_place_hold_if_available_at_pickup ) {
610 @not_available_at = uniq @not_available_at;
611 $biblioLoopIter{not_available_at} = \@not_available_at ;
612 # The record is not holdable is not available at any of the libraries
613 if ( Koha::Libraries->search->count == @not_available_at ) {
614 $biblioLoopIter{holdable} = 0;
618 my $status = CanBookBeReserved( $borrowernumber, $biblioNum )->{status};
619 $biblioLoopIter{holdable} &&= $status eq 'OK';
620 $biblioLoopIter{already_patron_possession} = $status eq 'alreadypossession';
622 # For multiple holds per record, if a patron has previously placed a hold,
623 # the patron can only place more holds of the same type. That is, if the
624 # patron placed a record level hold, all the holds the patron places must
625 # be record level. If the patron placed an item level hold, all holds
626 # the patron places must be item level
627 my $forced_hold_level = Koha::Holds->search(
629 borrowernumber => $borrowernumber,
630 biblionumber => $biblioNum,
631 found => undef,
633 )->forced_hold_level();
634 if ($forced_hold_level) {
635 $biblioLoopIter{force_hold} = 1 if $forced_hold_level eq 'item';
636 $biblioLoopIter{itemholdable} = 0 if $forced_hold_level eq 'record';
637 $biblioLoopIter{forced_hold_level} = $forced_hold_level;
641 push @$biblioLoop, \%biblioLoopIter;
643 $anyholdable = 1 if $biblioLoopIter{holdable};
646 unless ($pickup_locations->count) {
647 $numBibsAvailable = 0;
648 $anyholdable = 0;
649 $template->param(
650 message => 1,
651 no_pickup_locations => 1
655 if ( $numBibsAvailable == 0 || $anyholdable == 0) {
656 $template->param( none_available => 1 );
659 if (scalar @biblionumbers > 1) {
660 $template->param( multi_hold => 1);
663 my $show_notes=C4::Context->preference('OpacHoldNotes');
664 $template->param(OpacHoldNotes=>$show_notes);
666 # display infos
667 $template->param(bibitemloop => $biblioLoop);
668 # can set reserve date in future
669 if (
670 C4::Context->preference( 'AllowHoldDateInFuture' ) &&
671 C4::Context->preference( 'OPACAllowHoldDateInFuture' )
673 $template->param(
674 reserve_in_future => 1,
678 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };