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