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