Bug 18336: (follow-up) Shift TINYTEXT columns
[koha.git] / reserve / request.pl
1 #!/usr/bin/perl
2
3
4 #written 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
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # Koha is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22
23 =head1 request.pl
24
25 script to place reserves/requests
26
27 =cut
28
29 use Modern::Perl;
30
31 use CGI qw ( -utf8 );
32 use List::MoreUtils qw/uniq/;
33 use Date::Calc qw/Date_to_Days/;
34 use C4::Output;
35 use C4::Auth;
36 use C4::Reserves;
37 use C4::Biblio;
38 use C4::Items;
39 use C4::Koha;
40 use C4::Circulation;
41 use Koha::DateUtils;
42 use C4::Utils::DataTables::Members;
43 use C4::Members;
44 use C4::Search;         # enabled_staff_search_views
45
46 use Koha::Biblios;
47 use Koha::DateUtils;
48 use Koha::Checkouts;
49 use Koha::Holds;
50 use Koha::IssuingRules;
51 use Koha::Items;
52 use Koha::ItemTypes;
53 use Koha::Libraries;
54 use Koha::Patrons;
55
56 my $dbh = C4::Context->dbh;
57 my $input = new CGI;
58 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
59     {
60         template_name   => "reserve/request.tt",
61         query           => $input,
62         type            => "intranet",
63         authnotrequired => 0,
64         flagsrequired   => { reserveforothers => 'place_holds' },
65     }
66 );
67
68 my $multihold = $input->param('multi_hold');
69 $template->param(multi_hold => $multihold);
70 my $showallitems = $input->param('showallitems');
71
72 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
73
74 # Select borrowers infos
75 my $findborrower = $input->param('findborrower');
76 $findborrower = '' unless defined $findborrower;
77 $findborrower =~ s|,| |g;
78 my $borrowernumber_hold = $input->param('borrowernumber') || '';
79 my $messageborrower;
80 my $warnings;
81 my $messages;
82 my $exceeded_maxreserves;
83 my $exceeded_holds_per_record;
84
85 my $date = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 });
86 my $action = $input->param('action');
87 $action ||= q{};
88
89 if ( $action eq 'move' ) {
90   my $where = $input->param('where');
91   my $reserve_id = $input->param('reserve_id');
92   AlterPriority( $where, $reserve_id );
93 } elsif ( $action eq 'cancel' ) {
94   my $reserve_id = $input->param('reserve_id');
95   my $hold = Koha::Holds->find( $reserve_id );
96   $hold->cancel if $hold;
97 } elsif ( $action eq 'setLowestPriority' ) {
98   my $reserve_id = $input->param('reserve_id');
99   ToggleLowestPriority( $reserve_id );
100 } elsif ( $action eq 'toggleSuspend' ) {
101   my $reserve_id = $input->param('reserve_id');
102   my $suspend_until  = $input->param('suspend_until');
103   ToggleSuspend( $reserve_id, $suspend_until );
104 }
105
106 if ($findborrower) {
107     my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
108     if ( $patron ) {
109         $borrowernumber_hold = $patron->borrowernumber;
110     } else {
111         my $dt_params = { iDisplayLength => -1 };
112         my $results = C4::Utils::DataTables::Members::search(
113             {
114                 searchmember => $findborrower,
115                 dt_params => $dt_params,
116             }
117         );
118         my $borrowers = $results->{patrons};
119         if ( scalar @$borrowers == 1 ) {
120             $borrowernumber_hold = $borrowers->[0]->{borrowernumber};
121         } elsif ( @$borrowers ) {
122             $template->param( borrowers => $borrowers );
123         } else {
124             $messageborrower = "'$findborrower'";
125         }
126     }
127 }
128
129 my @biblionumbers = ();
130 my $biblionumbers = $input->param('biblionumbers');
131 if ($multihold) {
132     @biblionumbers = split '/', $biblionumbers;
133 } else {
134     push @biblionumbers, $input->multi_param('biblionumber');
135 }
136
137
138 # If we have the borrowernumber because we've performed an action, then we
139 # don't want to try to place another reserve.
140 if ($borrowernumber_hold && !$action) {
141     my $patron = Koha::Patrons->find( $borrowernumber_hold );
142     my $diffbranch;
143
144     # we check the reserves of the user, and if they can reserve a document
145     # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
146
147     my $reserves_count = $patron->holds->count;
148
149     my $new_reserves_count = scalar( @biblionumbers );
150
151     my $maxreserves = C4::Context->preference('maxreserves');
152     if ( $maxreserves
153         && ( $reserves_count + $new_reserves_count > $maxreserves ) )
154     {
155         my $new_reserves_allowed =
156             $maxreserves - $reserves_count > 0
157           ? $maxreserves - $reserves_count
158           : 0;
159         $warnings             = 1;
160         $exceeded_maxreserves = 1;
161         $template->param(
162             new_reserves_allowed => $new_reserves_allowed,
163             new_reserves_count   => $new_reserves_count,
164             reserves_count       => $reserves_count,
165             maxreserves          => $maxreserves,
166         );
167     }
168
169     # we check the date expiry of the borrower (only if there is an expiry date, otherwise, set to 1 (warn)
170     my $expiry_date = $patron->dateexpiry;
171     my $expiry = 0; # flag set if patron account has expired
172     if ($expiry_date and $expiry_date ne '0000-00-00' and
173         Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
174         $expiry = 1;
175     }
176
177     # check if the borrower make the reserv in a different branch
178     if ( $patron->branchcode ne C4::Context->userenv->{'branch'} ) {
179         $diffbranch = 1;
180     }
181
182     $template->param(
183                 expiry              => $expiry,
184                 diffbranch          => $diffbranch,
185                 messages            => $messages,
186                 warnings            => $warnings,
187                 amount_outstanding  => GetMemberAccountRecords($patron->borrowernumber),
188     );
189 }
190
191 $template->param( messageborrower => $messageborrower );
192
193 # FIXME launch another time GetMember perhaps until (Joubu: Why?)
194 my $patron = Koha::Patrons->find( $borrowernumber_hold );
195
196 my $logged_in_patron = Koha::Patrons->find( $borrowernumber );
197
198 my $itemdata_enumchron = 0;
199 my @biblioloop = ();
200 foreach my $biblionumber (@biblionumbers) {
201     next unless $biblionumber =~ m|^\d+$|;
202
203     my %biblioloopiter = ();
204
205     my $biblio = Koha::Biblios->find( $biblionumber );
206
207     my $force_hold_level;
208     if ( $patron ) {
209         { # CanBookBeReserved
210             my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber );
211             $canReserve //= '';
212             if ( $canReserve eq 'OK' ) {
213
214                 #All is OK and we can continue
215             }
216             elsif ( $canReserve eq 'tooManyReserves' ) {
217                 $exceeded_maxreserves = 1;
218             }
219             elsif ( $canReserve eq 'tooManyHoldsForThisRecord' ) {
220                 $exceeded_holds_per_record = 1;
221                 $biblioloopiter{$canReserve} = 1;
222             }
223             elsif ( $canReserve eq 'ageRestricted' ) {
224                 $template->param( $canReserve => 1 );
225                 $biblioloopiter{$canReserve} = 1;
226             }
227             else {
228                 $biblioloopiter{$canReserve} = 1;
229             }
230         }
231
232         # For multiple holds per record, if a patron has previously placed a hold,
233         # the patron can only place more holds of the same type. That is, if the
234         # patron placed a record level hold, all the holds the patron places must
235         # be record level. If the patron placed an item level hold, all holds
236         # the patron places must be item level
237         my $holds = Koha::Holds->search(
238             {
239                 borrowernumber => $patron->borrowernumber,
240                 biblionumber   => $biblionumber,
241                 found          => undef,
242             }
243         );
244         $force_hold_level = $holds->forced_hold_level();
245         $biblioloopiter{force_hold_level} = $force_hold_level;
246         $template->param( force_hold_level => $force_hold_level );
247
248         # For a librarian to be able to place multiple record holds for a patron for a record,
249         # we must find out what the maximum number of holds they can place for the patron is
250         my $max_holds_for_record = GetMaxPatronHoldsForRecord( $patron->borrowernumber, $biblionumber );
251         my $remaining_holds_for_record = $max_holds_for_record - $holds->count();
252         $biblioloopiter{remaining_holds_for_record} = $max_holds_for_record;
253         $template->param( max_holds_for_record => $max_holds_for_record );
254         $template->param( remaining_holds_for_record => $remaining_holds_for_record );
255
256         { # alreadypossession
257             # Check to see if patron is allowed to place holds on records where the
258             # patron already has an item from that record checked out
259             if ( !C4::Context->preference('AllowHoldsOnPatronsPossessions')
260                 && CheckIfIssuedToPatron( $patron->borrowernumber, $biblionumber ) )
261             {
262                 $template->param( alreadypossession => 1, );
263             }
264         }
265     }
266
267
268     my $count = Koha::Holds->search( { biblionumber => $biblionumber } )->count();
269     my $totalcount = $count;
270
271     # FIXME think @optionloop, is maybe obsolete, or  must be switchable by a systeme preference fixed rank or not
272     # make priorities options
273
274     my @optionloop;
275     for ( 1 .. $count + 1 ) {
276         push(
277              @optionloop,
278              {
279               num      => $_,
280               selected => ( $_ == $count + 1 ),
281              }
282             );
283     }
284     # adding a fixed value for priority options
285     my $fixedRank = $count+1;
286
287     my %itemnumbers_of_biblioitem;
288
289     my @hostitems = get_hostitemnumbers_of($biblionumber);
290     my @itemnumbers;
291     if (@hostitems){
292         $template->param('hostitemsflag' => 1);
293         push(@itemnumbers, @hostitems);
294     }
295
296     my $items = Koha::Items->search({ -or => { biblionumber => $biblionumber, itemnumber => { in => \@itemnumbers } } });
297
298     unless ( $items->count ) {
299         # FIXME Then why do we continue?
300         $template->param('noitems' => 1);
301         $biblioloopiter{noitems} = 1;
302     }
303
304     ## Here we go backwards again to create hash of biblioitemnumber to itemnumbers,
305     ## when by definition all of the itemnumber have the same biblioitemnumber
306     my ( $iteminfos_of );
307     while ( my $item = $items->next ) {
308         $item = $item->unblessed;
309         my $biblioitemnumber = $item->{biblioitemnumber};
310         my $itemnumber = $item->{itemnumber};
311         push( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} }, $itemnumber );
312         $iteminfos_of->{$itemnumber} = $item;
313     }
314
315     ## Should be same as biblionumber
316     my @biblioitemnumbers = keys %itemnumbers_of_biblioitem;
317
318     ## Hash of biblioitemnumber to 'biblioitem' table records
319     my $biblioiteminfos_of  = GetBiblioItemInfosOf(@biblioitemnumbers);
320
321     my $frameworkcode = GetFrameworkCode( $biblionumber );
322     my @notforloan_avs = Koha::AuthorisedValues->search_by_koha_field({ kohafield => 'items.notforloan', frameworkcode => $frameworkcode });
323     my $notforloan_label_of = { map { $_->authorised_value => $_->lib } @notforloan_avs };
324
325     my @bibitemloop;
326
327     my @available_itemtypes;
328     foreach my $biblioitemnumber (@biblioitemnumbers) {
329         my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
330         my $num_available = 0;
331         my $num_override  = 0;
332         my $hiddencount   = 0;
333
334         $biblioitem->{force_hold_level} = $force_hold_level;
335
336         if ( $biblioitem->{biblioitemnumber} ne $biblionumber ) {
337             $biblioitem->{hostitemsflag} = 1;
338         }
339
340         $biblioloopiter{description} = $biblioitem->{description};
341         $biblioloopiter{itypename}   = $biblioitem->{description};
342         if ( $biblioitem->{itemtype} ) {
343
344             $biblioitem->{description} =
345               $itemtypes->{ $biblioitem->{itemtype} }{description};
346
347             $biblioloopiter{imageurl} =
348               getitemtypeimagelocation( 'intranet',
349                 $itemtypes->{ $biblioitem->{itemtype} }{imageurl} );
350         }
351
352         foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )    {
353             my $item = $iteminfos_of->{$itemnumber};
354
355             $item->{force_hold_level} = $force_hold_level;
356
357             unless (C4::Context->preference('item-level_itypes')) {
358                 $item->{itype} = $biblioitem->{itemtype};
359             }
360
361             $item->{itypename} = $itemtypes->{ $item->{itype} }{description};
362             $item->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $item->{itype} }{imageurl} );
363             $item->{homebranch} = $item->{homebranch};
364
365             # if the holdingbranch is different than the homebranch, we show the
366             # holdingbranch of the document too
367             if ( $item->{homebranch} ne $item->{holdingbranch} ) {
368                 $item->{holdingbranch} = $item->{holdingbranch};
369             }
370
371             if($item->{biblionumber} ne $biblionumber){
372                 $item->{hostitemsflag} = 1;
373                 $item->{hosttitle} = Koha::Biblios->find( $item->{biblionumber} )->title;
374             }
375
376             # if the item is currently on loan, we display its return date and
377             # change the background color
378             my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } );
379             if ( $issue ) {
380                 $item->{date_due} = $issue->date_due;
381                 $item->{backgroundcolor} = 'onloan';
382             }
383
384             # checking reserve
385             my $item_object = Koha::Items->find( $itemnumber );
386             my $holds = $item_object->current_holds;
387             if ( my $first_hold = $holds->next ) {
388                 my $p = Koha::Patrons->find( $first_hold->borrowernumber );
389
390                 $item->{backgroundcolor} = 'reserved';
391                 $item->{reservedate}     = output_pref({ dt => dt_from_string( $first_hold->reservedate ), dateonly => 1 }); # FIXME Should be formatted in the template
392                 $item->{ReservedFor}     = $p;
393                 $item->{ExpectedAtLibrary}     = $first_hold->branchcode;
394                 $item->{waitingdate} = $first_hold->waitingdate;
395             }
396
397             # Management of the notforloan document
398             if ( $item->{notforloan} ) {
399                 $item->{backgroundcolor} = 'other';
400                 $item->{notforloanvalue} =
401                   $notforloan_label_of->{ $item->{notforloan} };
402             }
403
404             # Management of lost or long overdue items
405             if ( $item->{itemlost} ) {
406
407                 # FIXME localized strings should never be in Perl code
408                 $item->{message} =
409                   $item->{itemlost} == 1 ? "(lost)"
410                     : $item->{itemlost} == 2 ? "(long overdue)"
411                       : "";
412                 $item->{backgroundcolor} = 'other';
413                 if ($logged_in_patron->category->hidelostitems && !$showallitems) {
414                     $item->{hide} = 1;
415                     $hiddencount++;
416                 }
417             }
418
419             # Check the transit status
420             my ( $transfertwhen, $transfertfrom, $transfertto ) =
421               GetTransfers($itemnumber);
422
423             if ( defined $transfertwhen && $transfertwhen ne '' ) {
424                 $item->{transfertwhen} = output_pref({ dt => dt_from_string( $transfertwhen ), dateonly => 1 });
425                 $item->{transfertfrom} = $transfertfrom;
426                 $item->{transfertto} = $transfertto;
427                 $item->{nocancel} = 1;
428             }
429
430             # If there is no loan, return and transfer, we show a checkbox.
431             $item->{notforloan} ||= 0;
432
433             # if independent branches is on we need to check if the person can reserve
434             # for branches they arent logged in to
435             if ( C4::Context->preference("IndependentBranches") ) {
436                 if (! C4::Context->preference("canreservefromotherbranches")){
437                     # cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
438                     my $userenv = C4::Context->userenv;
439                     unless ( C4::Context->IsSuperLibrarian ) {
440                         $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
441                     }
442                 }
443             }
444
445             if ( $patron ) {
446                 my $patron_unblessed = $patron->unblessed;
447                 my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed);
448
449                 my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
450
451                 $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
452
453                 my $can_item_be_reserved = CanItemBeReserved( $patron->borrowernumber, $itemnumber );
454                 $item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' );
455
456                 $item->{item_level_holds} = Koha::IssuingRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
457
458                 if (
459                        !$item->{cantreserve}
460                     && !$exceeded_maxreserves
461                     && IsAvailableForItemLevelRequest($item, $patron_unblessed)
462                     && $can_item_be_reserved eq 'OK'
463                   )
464                 {
465                     $item->{available} = 1;
466                     $num_available++;
467
468                     push( @available_itemtypes, $item->{itype} );
469                 }
470                 elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
471                     # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
472                     $item->{override} = 1;
473                     $num_override++;
474
475                     push( @available_itemtypes, $item->{itype} );
476                 }
477
478                 # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
479
480                 # Show serial enumeration when needed
481                 if ($item->{enumchron}) {
482                     $itemdata_enumchron = 1;
483                 }
484             }
485
486             push @{ $biblioitem->{itemloop} }, $item;
487         }
488
489         if ( $num_override == scalar( @{ $biblioitem->{itemloop} } ) ) { # That is, if all items require an override
490             $template->param( override_required => 1 );
491         } elsif ( $num_available == 0 ) {
492             $template->param( none_available => 1 );
493             $biblioloopiter{warn} = 1;
494             $biblioloopiter{none_avail} = 1;
495         }
496         $template->param( hiddencount => $hiddencount);
497
498         push @bibitemloop, $biblioitem;
499     }
500
501     @available_itemtypes = uniq( @available_itemtypes );
502     $template->param( available_itemtypes => \@available_itemtypes );
503
504     # existingreserves building
505     my @reserveloop;
506     my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } );
507     foreach my $res (
508         sort {
509             my $a_found = $a->found() || '';
510             my $b_found = $a->found() || '';
511             $a_found cmp $b_found;
512         } @reserves
513       )
514     {
515         my $priority = $res->priority();
516         my %reserve;
517         my @optionloop;
518         for ( my $i = 1 ; $i <= $totalcount ; $i++ ) {
519             push(
520                 @optionloop,
521                 {
522                     num      => $i,
523                     selected => ( $i == $priority ),
524                 }
525             );
526         }
527
528         if ( $res->is_found() ) {
529             $reserve{'holdingbranch'} = $res->item()->holdingbranch();
530             $reserve{'biblionumber'}  = $res->item()->biblionumber();
531             $reserve{'barcodenumber'} = $res->item()->barcode();
532             $reserve{'wbrcode'}       = $res->branchcode();
533             $reserve{'itemnumber'}    = $res->itemnumber();
534             $reserve{'wbrname'}       = $res->branch()->branchname();
535
536             if ( $reserve{'holdingbranch'} eq $reserve{'wbrcode'} ) {
537
538                 # Just because the holdingbranch matches the reserve branch doesn't mean the item
539                 # has arrived at the destination, check for an open transfer for the item as well
540                 my ( $transfertwhen, $transfertfrom, $transferto ) =
541                   C4::Circulation::GetTransfers( $res->itemnumber() );
542                 if ( not $transferto or $transferto ne $res->branchcode() ) {
543                     $reserve{'atdestination'} = 1;
544                 }
545             }
546
547             # set found to 1 if reserve is waiting for patron pickup
548             $reserve{'found'}     = $res->is_found();
549             $reserve{'intransit'} = $res->is_in_transit();
550         }
551         elsif ( $res->priority() > 0 ) {
552             if ( my $item = $res->item() )  {
553                 $reserve{'itemnumber'}      = $item->id();
554                 $reserve{'barcodenumber'}   = $item->barcode();
555                 $reserve{'item_level_hold'} = 1;
556             }
557         }
558
559         $reserve{'expirationdate'} = output_pref( { dt => dt_from_string( $res->expirationdate ), dateonly => 1 } )
560           unless ( !defined( $res->expirationdate ) || $res->expirationdate eq '0000-00-00' );
561         $reserve{'date'}           = output_pref( { dt => dt_from_string( $res->reservedate ), dateonly => 1 } );
562         $reserve{'borrowernumber'} = $res->borrowernumber();
563         $reserve{'biblionumber'}   = $res->biblionumber();
564         $reserve{'patron'}         = $res->borrower;
565         $reserve{'notes'}          = $res->reservenotes();
566         $reserve{'waiting_date'}   = $res->waitingdate();
567         $reserve{'ccode'}          = $res->item() ? $res->item()->ccode() : undef;
568         $reserve{'barcode'}        = $res->item() ? $res->item()->barcode() : undef;
569         $reserve{'priority'}       = $res->priority();
570         $reserve{'lowestPriority'} = $res->lowestPriority();
571         $reserve{'optionloop'}     = \@optionloop;
572         $reserve{'suspend'}        = $res->suspend();
573         $reserve{'suspend_until'}  = $res->suspend_until();
574         $reserve{'reserve_id'}     = $res->reserve_id();
575         $reserve{itemtype}         = $res->itemtype();
576         $reserve{branchcode}       = $res->branchcode();
577
578         push( @reserveloop, \%reserve );
579     }
580
581     # get the time for the form name...
582     my $time = time();
583
584     $template->param(
585                      time        => $time,
586                      fixedRank   => $fixedRank,
587                     );
588
589     # display infos
590     $template->param(
591                      optionloop        => \@optionloop,
592                      bibitemloop       => \@bibitemloop,
593                      itemdata_enumchron => $itemdata_enumchron,
594                      date              => $date,
595                      biblionumber      => $biblionumber,
596                      findborrower      => $findborrower,
597                      title             => $biblio->title,
598                      author            => $biblio->author,
599                      holdsview => 1,
600                      C4::Search::enabled_staff_search_views,
601                     );
602
603     $biblioloopiter{biblionumber} = $biblionumber;
604     $biblioloopiter{title} = $biblio->title;
605     $biblioloopiter{rank} = $fixedRank;
606     $biblioloopiter{reserveloop} = \@reserveloop;
607
608     if (@reserveloop) {
609         $template->param( reserveloop => \@reserveloop );
610     }
611
612     push @biblioloop, \%biblioloopiter;
613 }
614
615 $template->param( biblioloop => \@biblioloop );
616 $template->param( biblionumbers => $biblionumbers );
617 $template->param( exceeded_maxreserves => $exceeded_maxreserves );
618 $template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
619
620 if ($multihold) {
621     $template->param( multi_hold => 1 );
622 }
623
624 if ( C4::Context->preference( 'AllowHoldDateInFuture' ) ) {
625     $template->param( reserve_in_future => 1 );
626 }
627
628 $template->param(
629     patron => $patron,
630     SuspendHoldsIntranet => C4::Context->preference('SuspendHoldsIntranet'),
631     AutoResumeSuspendedHolds => C4::Context->preference('AutoResumeSuspendedHolds'),
632 );
633
634 # printout the page
635 output_html_with_http_headers $input, $cookie, $template->output;
636
637 sub sort_borrowerlist {
638     my $borrowerslist = shift;
639     my $ref           = [];
640     push @{$ref}, sort {
641         uc( $a->{surname} . $a->{firstname} ) cmp
642           uc( $b->{surname} . $b->{firstname} )
643     } @{$borrowerslist};
644     return $ref;
645 }