Bug 34478: Changes for opac-reserve
[koha.git] / opac / opac-reserve.pl
1 #!/usr/bin/perl
2
3
4 # Copyright Katipo Communications 2002
5 # Copyright Koha Development team 2012
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21
22 use Modern::Perl;
23
24 use CGI qw ( -utf8 );
25 use C4::Auth qw( get_template_and_user );
26 use C4::Koha qw( getitemtypeimagelocation getitemtypeimagesrc );
27 use C4::Circulation qw( GetBranchItemRule );
28 use C4::Reserves qw( CanItemBeReserved CanBookBeReserved AddReserve IsAvailableForItemLevelRequest GetReserveFee );
29 use C4::Biblio qw( GetBiblioData GetFrameworkCode );
30 use C4::Output qw( output_html_with_http_headers );
31 use C4::Context;
32 use C4::Members;
33 use C4::Overdues;
34
35 use Koha::AuthorisedValues;
36 use Koha::Biblios;
37 use Koha::CirculationRules;
38 use Koha::Items;
39 use Koha::ItemTypes;
40 use Koha::Checkouts;
41 use Koha::Libraries;
42 use Koha::Patrons;
43 use List::MoreUtils qw( uniq );
44
45 my $maxreserves = C4::Context->preference("maxreserves");
46
47 my $query = CGI->new;
48 my $op    = $query->param('op') // q{};
49
50 # if OPACHoldRequests (for placing holds) is disabled, leave immediately
51 if ( ! C4::Context->preference('OPACHoldRequests') ) {
52     print $query->redirect("/cgi-bin/koha/errors/404.pl");
53     exit;
54 }
55
56 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
57     {
58         template_name   => "opac-reserve.tt",
59         query           => $query,
60         type            => "opac",
61     }
62 );
63
64 my $patron = Koha::Patrons->find( $borrowernumber, { prefetch => ['categorycode'] } );
65 my $category = $patron->category;
66
67 my $can_place_hold_if_available_at_pickup = C4::Context->preference('OPACHoldsIfAvailableAtPickup');
68 unless ( $can_place_hold_if_available_at_pickup ) {
69     my @patron_categories = split ',', C4::Context->preference('OPACHoldsIfAvailableAtPickupExceptions');
70     if ( @patron_categories ) {
71         my $categorycode = $patron->categorycode;
72         $can_place_hold_if_available_at_pickup = grep { $_ eq $categorycode } @patron_categories;
73     }
74 }
75
76 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
77
78 # There are two ways of calling this script, with a single biblio num
79 # or multiple biblio nums.
80 my $biblionumbers = $query->param('biblionumbers');
81 my $reserveMode = $query->param('reserve_mode');
82 if ($reserveMode && ($reserveMode eq 'single')) {
83     my $bib = $query->param('single_bib');
84     $biblionumbers = "$bib/";
85 }
86 if (! $biblionumbers) {
87     $biblionumbers = $query->param('biblionumber');
88 }
89
90 if ( !$biblionumbers && $op ne 'cud-place_reserve' ) {
91     $template->param( message => 1, no_biblionumber => 1 );
92     output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
93     exit;
94 }
95
96 # Pass the numbers to the page so they can be fed back
97 # when the hold is confirmed. TODO: Not necessary?
98 $template->param( biblionumbers => $biblionumbers );
99
100 # Each biblio number is suffixed with '/', e.g. "1/2/3/"
101 my @biblionumbers = split /\//, $biblionumbers;
102 if ( $#biblionumbers < 0 && $op ne 'cud-place_reserve' ) {
103     # TODO: New message?
104     $template->param(message=>1, no_biblionumber=>1);
105     output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
106     exit;
107 }
108
109 #
110 #
111 # Here we check that the borrower can actually make reserves Stage 1.
112 #
113 #
114 my $noreserves     = 0;
115 if ( $category->effective_BlockExpiredPatronOpacActions ) {
116     if ( $patron->is_expired ) {
117         # cannot reserve, their card has expired and the rules set mean this is not allowed
118         $noreserves = 1;
119         $template->param( message => 1, expired_patron => 1 );
120     }
121 }
122
123 my $maxoutstanding = C4::Context->preference("maxoutstanding");
124 my $amountoutstanding = $patron->account->balance;
125 if ( $amountoutstanding && ($amountoutstanding > $maxoutstanding) ) {
126     my $amount = sprintf "%.02f", $amountoutstanding;
127     $template->param( message => 1 );
128     $noreserves = 1;
129     $template->param( too_much_oweing => $amount );
130 }
131
132 if ( $patron->gonenoaddress && ($patron->gonenoaddress == 1) ) {
133     $noreserves = 1;
134     $template->param(
135         message => 1,
136         GNA     => 1
137     );
138 }
139
140 if ( $patron->lost && ($patron->lost == 1) ) {
141     $noreserves = 1;
142     $template->param(
143         message => 1,
144         lost    => 1
145     );
146 }
147
148 if ( $patron->is_debarred ) {
149     $noreserves = 1;
150     $template->param(
151         message          => 1,
152         debarred         => 1,
153         debarred_comment => $patron->debarredcomment,
154         debarred_date    => $patron->debarred,
155     );
156 }
157
158 my $holds = $patron->holds;
159 my $reserves_count = $holds->count;
160 $template->param( RESERVES => $holds->unblessed );
161 if ( $maxreserves && ( $reserves_count >= $maxreserves ) ) {
162     $template->param( message => 1 );
163     $noreserves = 1;
164     $template->param( too_many_reserves => $holds->count );
165 }
166
167 if( $noreserves ){
168     output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
169     exit;
170 }
171
172
173 # pass the pickup branch along....
174 my $branch = $query->param('branch') || $patron->branchcode || C4::Context->userenv->{branch} || '' ;
175 $template->param( branch => $branch );
176
177 #
178 #
179 # Here we are carrying out the hold request, possibly
180 # with a specific item for each biblionumber.
181 #
182 #
183 if ( $op eq 'cud-place_reserve' ) {
184     my $reserve_cnt = 0;
185     if ($maxreserves) {
186         $reserve_cnt = $patron->holds->count;
187     }
188
189     # List is composed of alternating biblio/item/branch
190     my $selectedItems = $query->param('selecteditems');
191
192     if ($query->param('reserve_mode') eq 'single') {
193         # This indicates non-JavaScript mode, so there was
194         # only a single biblio number selected.
195         my $bib = $query->param('single_bib');
196         my $item = $query->param("checkitem_$bib");
197         if ($item eq 'any') {
198             $item = '';
199         }
200         my $branch = $query->param('branch');
201         $selectedItems = "$bib/$item/$branch/";
202     }
203
204     $selectedItems =~ s!/$!!;
205     my @selectedItems = split /\//, $selectedItems, -1;
206
207     # Make sure there is a biblionum/itemnum/branch triplet for each item.
208     # The itemnum can be 'any', meaning next available.
209     my $selectionCount = @selectedItems;
210     if (($selectionCount == 0) || (($selectionCount % 3) != 0)) {
211         $template->param(message=>1, bad_data=>1);
212         output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
213         exit;
214     }
215
216     my @failed_holds;
217     while (@selectedItems) {
218         my $biblioNum = shift(@selectedItems);
219         my $itemNum   = shift(@selectedItems);
220         my $branch    = shift(@selectedItems);    # i.e., branch code, not name
221
222         my $canreserve = 0;
223
224         my $singleBranchMode = Koha::Libraries->search->count == 1;
225         if ( $singleBranchMode || ! C4::Context->preference("OPACAllowUserToChooseBranch") )
226         {    # single branch mode or disabled user choosing
227             $branch = $patron->branchcode;
228         }
229
230         # FIXME We shouldn't need to fetch the item here
231         my $item = $itemNum ? Koha::Items->find( $itemNum ) : undef;
232         # When choosing a specific item, the default pickup library should be dictated by the default hold policy
233         if ( ! C4::Context->preference("OPACAllowUserToChooseBranch") && $item ) {
234             my $type                    = $item->effective_itemtype;
235             my $reserves_control_branch = Koha::Policy::Holds->holds_control_library( $item, $patron );
236             my $rule                    = GetBranchItemRule( $reserves_control_branch, $type );
237
238             if ( $rule->{hold_fulfillment_policy} eq 'any' || $rule->{hold_fulfillment_policy} eq 'patrongroup' ) {
239                 $branch = $patron->branchcode;
240             } elsif ( $rule->{hold_fulfillment_policy} eq 'holdgroup' ){
241                 $branch = $item->homebranch;
242             } else {
243                 my $policy = $rule->{hold_fulfillment_policy};
244                 $branch = $item->$policy;
245             }
246         }
247
248         # if we have an item, we are placing the hold on the item's bib, in case of analytics
249         if ( $item ) {
250             $biblioNum = $item->biblionumber;
251         }
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 $patron_expiration_date = $query->param("expiration_date_$biblioNum");
262
263         my $itemtype = $query->param('itemtype') || undef;
264         $itemtype = undef if $itemNum;
265
266         my $biblio = Koha::Biblios->find($biblioNum);
267         my $rank = $biblio->holds->search( { found => [ { "!=" => "W" }, undef ] } )->count + 1;
268         if ( $item ) {
269             my $status = CanItemBeReserved( $patron, $item, $branch, { get_from_cache => 1 } )->{status};
270             if( $status eq 'OK' ){
271                 $canreserve = 1;
272             } else {
273                 push @failed_holds, $status;
274             }
275
276         }
277         else {
278             my $status = CanBookBeReserved( $borrowernumber, $biblioNum, $branch, { itemtype => $itemtype } )->{status};
279             if( $status eq 'OK'){
280                 $canreserve = 1;
281             } else {
282                 push @failed_holds, $status;
283             }
284
285             # Inserts a null into the 'itemnumber' field of 'reserves' table.
286             $itemNum = undef;
287         }
288         my $notes = $query->param('notes_'.$biblioNum)||'';
289         my $item_group_id = $query->param("item_group_id_$biblioNum") || undef;
290
291         if (   $maxreserves
292             && $reserve_cnt >= $maxreserves )
293         {
294             push @failed_holds, 'tooManyReserves';
295             $canreserve = 0;
296         }
297
298         unless ( $can_place_hold_if_available_at_pickup ) {
299             my $items_in_this_library = Koha::Items->search({ biblionumber => $biblioNum, holdingbranch => $branch });
300             my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
301             my $nb_of_items_unavailable = $items_in_this_library->search({ -or => { lost => { '!=' => 0 }, damaged => { '!=' => 0 }, } });
302             if ( $items_in_this_library->count > $nb_of_items_issued + $nb_of_items_unavailable ) {
303                 $canreserve = 0;
304                 push @failed_holds, 'items_available';
305             }
306         }
307
308         # Here we actually do the reserveration. Stage 3.
309         if ($canreserve) {
310             my $reserve_id = AddReserve(
311                 {
312                     branchcode       => $branch,
313                     borrowernumber   => $borrowernumber,
314                     biblionumber     => $biblioNum,
315                     priority         => $rank,
316                     reservation_date => $startdate,
317                     expiration_date  => $patron_expiration_date,
318                     notes            => $notes,
319                     title            => $biblio->title,
320                     itemnumber       => $itemNum,
321                     found            => undef,
322                     itemtype         => $itemtype,
323                     item_group_id    => $item_group_id,
324                 }
325             );
326             if( $reserve_id ){
327                 ++$reserve_cnt;
328             } else {
329                 push @failed_holds, 'not_placed';
330             }
331         }
332     }
333
334     print $query->redirect("/cgi-bin/koha/opac-user.pl?" . ( @failed_holds ? "failed_holds=" . join('|',@failed_holds) : q|| ) . "&opac-user-holds=1");
335     exit;
336 }
337
338 #
339 #
340 # Build hashes of the requested biblio(item)s and items.
341 #
342 #
343
344 my %biblioDataHash; # Hash of biblionumber to biblio/biblioitems record.
345 foreach my $biblioNumber (@biblionumbers) {
346
347     my $biblioData = GetBiblioData($biblioNumber);
348     $biblioDataHash{$biblioNumber} = $biblioData;
349
350     my $biblio = Koha::Biblios->find( $biblioNumber );
351     next unless $biblio;
352
353     my $items = Koha::Items->search_ordered(
354         [
355             'me.biblionumber' => $biblioNumber,
356             'me.itemnumber' => {
357                 -in => [
358                     $biblio->host_items->get_column('itemnumber')
359                 ]
360             }
361         ],
362         { prefetch => [ 'issue', 'homebranch', 'holdingbranch' ] }
363     )->filter_by_visible_in_opac({ patron => $patron });
364
365     $biblioData->{items} = [$items->as_list]; # FIXME Potentially a lot in memory here!
366
367     # Compute the priority rank.
368     $biblioData->{object} = $biblio;
369     my $reservecount = $biblio->holds->search({ found => [ {"!=" => "W"},undef] })->count;
370     $biblioData->{reservecount} = $reservecount;
371     $biblioData->{rank} = $reservecount + 1;
372 }
373
374
375 my $requested_reserves_count = scalar( @biblionumbers );
376 if ( $maxreserves && ( $reserves_count + $requested_reserves_count > $maxreserves ) ) {
377     $template->param( new_reserves_allowed => $maxreserves - $reserves_count );
378 }
379
380 $template->param( select_item_types => 1 );
381
382
383 #
384 #
385 # Build the template parameters that will show the info
386 # and items for each biblionumber.
387 #
388 #
389
390 my $biblioLoop = [];
391 my $numBibsAvailable = 0;
392 my $itemdata_enumchron = 0;
393 my $itemdata_ccode = 0;
394 my $anyholdable = 0;
395 my $itemLevelTypes = C4::Context->preference('item-level_itypes');
396 my $pickup_locations = Koha::Libraries->search({ pickup_location => 1 });
397 $template->param('item_level_itypes' => $itemLevelTypes);
398
399 my $patron_unblessed = $patron->unblessed;
400 foreach my $biblioNum (@biblionumbers) {
401
402     # Init the bib item with the choices for branch pickup
403     my %biblioLoopIter;
404
405     # Get relevant biblio data.
406     my $biblioData = $biblioDataHash{$biblioNum};
407     if (! $biblioData) {
408         $template->param(message=>1, bad_biblionumber=>$biblioNum);
409         output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };
410         exit;
411     }
412
413     my @not_available_at = ();
414     my $biblio = $biblioData->{object};
415     foreach my $library ( $pickup_locations->as_list ) {
416         push( @not_available_at, $library->branchcode ) unless $biblio->can_be_transferred({ to => $library });
417     }
418
419     my $frameworkcode = GetFrameworkCode( $biblioData->{biblionumber} );
420     $biblioLoopIter{biblionumber} = $biblioData->{biblionumber};
421     $biblioLoopIter{title} = $biblioData->{title};
422     $biblioLoopIter{subtitle} = $biblioData->{'subtitle'};
423     $biblioLoopIter{medium} = $biblioData->{medium};
424     $biblioLoopIter{part_number} = $biblioData->{part_number};
425     $biblioLoopIter{part_name} = $biblioData->{part_name};
426     $biblioLoopIter{author} = $biblioData->{author};
427     $biblioLoopIter{rank} = $biblioData->{rank};
428     $biblioLoopIter{reservecount} = $biblioData->{reservecount};
429     $biblioLoopIter{already_reserved} = $biblioData->{already_reserved};
430     $biblioLoopIter{object} = $biblio;
431
432     if (!$itemLevelTypes && $biblioData->{itemtype}) {
433         $biblioLoopIter{translated_description} = $itemtypes->{$biblioData->{itemtype}}{translated_description};
434         $biblioLoopIter{imageurl} = getitemtypeimagesrc() . "/". $itemtypes->{$biblioData->{itemtype}}{imageurl};
435     }
436
437
438
439     $biblioLoopIter{itemLoop} = [];
440     my $numCopiesAvailable = 0;
441     my $numCopiesOPACAvailable = 0;
442     # iterating through all items first to check if any of them available
443     # to pass this value further inside down to IsAvailableForItemLevelRequest to
444     # it's complicated logic to analyse.
445     # (before this loop was inside that sub loop so it was O(n^2) )
446     foreach my $item (@{$biblioData->{items}}) {
447
448         my $item_info = $item->unblessed;
449         $item_info->{holding_branch} = $item->holding_branch;
450         $item_info->{home_branch}    = $item->home_branch;
451         if ($itemLevelTypes) {
452             my $itemtype = $item->itemtype;
453             $item_info->{'imageurl'} = getitemtypeimagelocation( 'opac',
454                 $itemtypes->{ $itemtype->itemtype }->{'imageurl'} );
455             $item_info->{'translated_description'} =
456               $itemtypes->{ $itemtype->itemtype }->{translated_description};
457         }
458
459         # checking for holds
460         my $holds = $item->current_holds;
461         if ( my $first_hold = $holds->next ) {
462             $item_info->{first_hold} = $first_hold;
463         }
464
465         $item_info->{checkout} = $item->checkout;
466
467         # Check of the transferred documents
468         my $transfer = $item->get_transfer;
469         if ( $transfer && $transfer->in_transit ) {
470             $item_info->{transfertwhen} = $transfer->datesent;
471             $item_info->{transfertfrom} = $transfer->frombranch;
472             $item_info->{transfertto} = $transfer->tobranch;
473             $item_info->{nocancel} = 1;
474         }
475
476         # if the items belongs to a host record, show link to host record
477         if ( $item_info->{biblionumber} ne $biblioNum ) {
478             $item_info->{hostbiblionumber} = $item->biblionumber;
479             $item_info->{hosttitle}        = Koha::Biblios->find( $item_info->{biblionumber} )->title;
480         }
481
482         my $branch = Koha::Policy::Holds->holds_control_library( $item, $patron );
483
484         my $policy_holdallowed =
485             CanItemBeReserved( $patron, $item, undef, { get_from_cache => 1 } )->{status} eq 'OK' &&
486             IsAvailableForItemLevelRequest($item, $patron, undef);
487
488         if ($policy_holdallowed) {
489             my $opac_hold_policy = Koha::CirculationRules->get_opacitemholds_policy( { item => $item, patron => $patron } );
490             if ( $opac_hold_policy ne 'N' ) { # If Y or F
491                 $item_info->{available} = 1;
492                 $numCopiesOPACAvailable++;
493                 $biblioLoopIter{force_hold} = 1 if $opac_hold_policy eq 'F';
494             }
495             $numCopiesAvailable++;
496
497             unless ( $can_place_hold_if_available_at_pickup ) {
498                 my $items_in_this_library = Koha::Items->search({ biblionumber => $item->biblionumber, holdingbranch => $item->holdingbranch, notforloan => 0 });
499                 my $nb_of_items_issued = $items_in_this_library->search({ 'issue.itemnumber' => { not => undef }}, { join => 'issue' })->count;
500                 if ( $items_in_this_library->count > $nb_of_items_issued ) {
501                     push @not_available_at, $item->holdingbranch;
502                 }
503             }
504         }
505
506         # Show serial enumeration when needed
507         if ($item_info->{enumchron}) {
508             $itemdata_enumchron = 1;
509         }
510         # Show collection when needed
511         if ($item_info->{ccode}) {
512             $itemdata_ccode = 1;
513         }
514
515         push @{$biblioLoopIter{itemLoop}}, $item_info;
516     }
517     $template->param(
518         itemdata_enumchron => $itemdata_enumchron,
519         itemdata_ccode     => $itemdata_ccode,
520     );
521
522     if ($numCopiesAvailable > 0) {
523         $numBibsAvailable++;
524         $biblioLoopIter{bib_available} = 1;
525         $biblioLoopIter{holdable} = 1;
526         $biblioLoopIter{itemholdable} = 1 if $numCopiesOPACAvailable;
527     }
528     if ($biblioLoopIter{already_reserved}) {
529         $biblioLoopIter{holdable} = undef;
530         $biblioLoopIter{itemholdable} = undef;
531     }
532     if ( $biblioLoopIter{holdable} ) {
533         @not_available_at = uniq @not_available_at;
534         $biblioLoopIter{not_available_at} = \@not_available_at ;
535     }
536
537     unless ( $can_place_hold_if_available_at_pickup ) {
538         @not_available_at = uniq @not_available_at;
539         $biblioLoopIter{not_available_at} = \@not_available_at ;
540         # The record is not holdable is not available at any of the libraries
541         if ( Koha::Libraries->search->count == @not_available_at ) {
542             $biblioLoopIter{holdable} = 0;
543         }
544     }
545
546     my $status = CanBookBeReserved( $borrowernumber, $biblioNum )->{status};
547     $biblioLoopIter{holdable} &&= $status eq 'OK';
548     $biblioLoopIter{$status} = 1;
549
550     if ( $biblioLoopIter{holdable} and C4::Context->preference('AllowHoldItemTypeSelection') ) {
551         # build the allowed item types loop
552         my $rs = $biblio->items->search_ordered(
553             undef,
554             {   select => [ { distinct => 'itype' } ],
555                 as     => 'item_type'
556             }
557         );
558
559         my @item_types =
560           grep { CanBookBeReserved( $borrowernumber, $biblioNum, $branch, { itemtype => $_ } )->{status} eq 'OK' }
561           $rs->get_column('item_type');
562
563         $biblioLoopIter{allowed_item_types} = \@item_types;
564     }
565
566     if ( $status eq 'recall' ) {
567         $biblioLoopIter{recall} = 1;
568     }
569
570     # For multiple holds per record, if a patron has previously placed a hold,
571     # the patron can only place more holds of the same type. That is, if the
572     # patron placed a record level hold, all the holds the patron places must
573     # be record level. If the patron placed an item level hold, all holds
574     # the patron places must be item level
575     my $forced_hold_level = Koha::Holds->search(
576         {
577             borrowernumber => $borrowernumber,
578             biblionumber   => $biblioNum,
579             found          => undef,
580         }
581     )->forced_hold_level();
582     if ($forced_hold_level) {
583         $biblioLoopIter{force_hold}   = 1 if $forced_hold_level eq 'item';
584         $biblioLoopIter{force_hold}   = 0 if $forced_hold_level eq 'item_group';
585         $biblioLoopIter{itemholdable} = 0 if $forced_hold_level eq 'record';
586         $biblioLoopIter{itemholdable} = 0 if $forced_hold_level eq 'item_group';
587         $biblioLoopIter{forced_hold_level} = $forced_hold_level;
588     }
589
590     # Pass through any reserve charge
591     $biblioLoopIter{reserve_charge} = GetReserveFee( $patron->id, $biblioNum );
592
593     push @$biblioLoop, \%biblioLoopIter;
594
595     $anyholdable = 1 if $biblioLoopIter{holdable};
596 }
597
598 unless ($pickup_locations->count) {
599     $numBibsAvailable = 0;
600     $anyholdable = 0;
601     $template->param(
602         message => 1,
603         no_pickup_locations => 1
604     );
605 }
606
607 if ( $numBibsAvailable == 0 || $anyholdable == 0) {
608     $template->param( none_available => 1 );
609 }
610
611 if (scalar @biblionumbers > 1) {
612     $template->param( multi_hold => 1);
613 }
614
615 my $show_notes=C4::Context->preference('OpacHoldNotes');
616 $template->param(OpacHoldNotes=>$show_notes);
617
618 # display infos
619 $template->param(bibitemloop => $biblioLoop);
620 # can set reserve date in future
621 if (
622     C4::Context->preference( 'AllowHoldDateInFuture' ) &&
623     C4::Context->preference( 'OPACAllowHoldDateInFuture' )
624     ) {
625     $template->param(
626             reserve_in_future         => 1,
627     );
628 }
629
630 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };