4 #written 2/1/00 by chris@katipo.oc.nz
5 # Copyright 2000-2002 Katipo Communications
6 # Parts Copyright 2011 Catalyst IT
8 # This file is part of Koha.
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.
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.
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>.
25 script to place reserves/requests
32 use List::MoreUtils qw( uniq );
33 use Date::Calc qw( Date_to_Days );
34 use C4::Output qw( output_html_with_http_headers );
35 use C4::Auth qw( get_template_and_user );
36 use C4::Reserves qw( RevertWaitingStatus AlterPriority ToggleLowestPriority ToggleSuspend CanBookBeReserved GetMaxPatronHoldsForRecord ItemsAnyAvailableAndNotRestricted CanItemBeReserved IsAvailableForItemLevelRequest );
37 use C4::Items qw( get_hostitemnumbers_of );
38 use C4::Koha qw( getitemtypeimagelocation );
39 use C4::Serials qw( CountSubscriptionFromBiblionumber );
40 use C4::Circulation qw( _GetCircControlBranch GetBranchItemRule );
41 use Koha::DateUtils qw( dt_from_string );
42 use C4::Search qw( enabled_staff_search_views );
47 use Koha::CirculationRules;
52 use Koha::Patron::Attribute::Types;
54 use Koha::BackgroundJob::BatchCancelHold;
56 my $dbh = C4::Context->dbh;
58 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
60 template_name => "reserve/request.tt",
63 flagsrequired => { reserveforothers => 'place_holds' },
67 my $showallitems = $input->param('showallitems');
68 my $pickup = $input->param('pickup');
73 { %{ $_->unblessed }, image_location => $_->image_location('intranet'), notforloan => $_->notforloan }
74 } Koha::ItemTypes->search_with_localization->as_list
77 # Select borrowers infos
78 my $findborrower = $input->param('findborrower');
79 $findborrower = '' unless defined $findborrower;
80 $findborrower =~ s|,| |g;
81 my $findclub = $input->param('findclub');
82 $findclub = '' unless defined $findclub && !$findborrower;
83 my $borrowernumber_hold = $input->param('borrowernumber') || '';
84 my $club_hold = $input->param('club')||'';
89 my $exceeded_maxreserves;
90 my $exceeded_holds_per_record;
92 my $action = $input->param('action');
95 if ( $action eq 'move' ) {
96 my $where = $input->param('where');
97 my $reserve_id = $input->param('reserve_id');
98 my $prev_priority = $input->param('prev_priority');
99 my $next_priority = $input->param('next_priority');
100 my $first_priority = $input->param('first_priority');
101 my $last_priority = $input->param('last_priority');
102 my $hold_itemnumber = $input->param('itemnumber');
103 if ( $prev_priority == 0 && $next_priority == 1 ) {
104 C4::Reserves::RevertWaitingStatus( { itemnumber => $hold_itemnumber } );
108 $where, $reserve_id, $prev_priority,
109 $next_priority, $first_priority, $last_priority
113 elsif ( $action eq 'cancel' ) {
114 my $reserve_id = $input->param('reserve_id');
115 my $cancellation_reason = $input->param("cancellation-reason");
116 my $hold = Koha::Holds->find($reserve_id);
117 $hold->cancel( { cancellation_reason => $cancellation_reason } ) if $hold;
119 elsif ( $action eq 'setLowestPriority' ) {
120 my $reserve_id = $input->param('reserve_id');
121 ToggleLowestPriority($reserve_id);
123 elsif ( $action eq 'toggleSuspend' ) {
124 my $reserve_id = $input->param('reserve_id');
125 my $suspend_until = $input->param('suspend_until');
126 ToggleSuspend( $reserve_id, $suspend_until );
128 elsif ( $action eq 'cancelBulk' ) {
129 my $cancellation_reason = $input->param("cancellation-reason");
130 my @hold_ids = split( ',', scalar $input->param("ids"));
132 reason => $cancellation_reason,
133 hold_ids => \@hold_ids,
135 my $job_id = Koha::BackgroundJob::BatchCancelHold->new->enqueue($params);
144 my $patron = Koha::Patrons->find( { cardnumber => $findborrower } );
145 $borrowernumber_hold = $patron->borrowernumber if $patron;
149 my $club = Koha::Clubs->find( { name => $findclub } );
151 $club_hold = $club->id;
153 my @clubs = Koha::Clubs->search( [
154 { name => { like => '%'.$findclub.'%' } },
155 { description => { like => '%'.$findclub.'%' } }
157 if( scalar @clubs == 1 ) {
158 $club_hold = $clubs[0]->id;
160 $template->param( clubs => \@clubs );
162 $messageclub = "'$findclub'";
167 my @biblionumbers = $input->multi_param('biblionumber');
169 my $multi_hold = @biblionumbers > 1;
171 multi_hold => $multi_hold,
174 # If we have the borrowernumber because we've performed an action, then we
175 # don't want to try to place another reserve.
176 if ($borrowernumber_hold && !$action) {
177 my $patron = Koha::Patrons->find( $borrowernumber_hold );
180 # we check the reserves of the user, and if they can reserve a document
181 # FIXME At this time we have a simple count of reservs, but, later, we could improve the infos "title" ...
183 my $reserves_count = $patron->holds->count;
185 my $new_reserves_count = scalar( @biblionumbers );
187 my $maxreserves = C4::Context->preference('maxreserves');
188 $template->param( maxreserves => $maxreserves );
191 && ( $reserves_count + $new_reserves_count > $maxreserves ) )
193 my $new_reserves_allowed =
194 $maxreserves - $reserves_count > 0
195 ? $maxreserves - $reserves_count
198 $exceeded_maxreserves = 1;
200 new_reserves_allowed => $new_reserves_allowed,
201 new_reserves_count => $new_reserves_count,
202 reserves_count => $reserves_count,
203 maxreserves => $maxreserves,
207 # check if the borrower make the reserv in a different branch
208 if ( $patron->branchcode ne C4::Context->userenv->{'branch'} ) {
212 my $amount_outstanding = $patron->account->balance;
215 diffbranch => $diffbranch,
216 messages => $messages,
217 warnings => $warnings,
218 amount_outstanding => $amount_outstanding,
222 if ($club_hold && !$borrowernumber_hold && !$action) {
223 my $club = Koha::Clubs->find($club_hold);
225 my $enrollments = $club->club_enrollments;
227 my $maxreserves = C4::Context->preference('maxreserves');
228 my $new_reserves_count = scalar( @biblionumbers );
232 while(my $enrollment = $enrollments->next) {
233 next if $enrollment->is_canceled;
234 my $member = { patron => $enrollment->patron };
235 my $reserves_count = $enrollment->patron->holds->count;
237 && ( $reserves_count + $new_reserves_count > $maxreserves ) )
239 $member->{new_reserves_allowed} = $maxreserves - $reserves_count > 0
240 ? $maxreserves - $reserves_count
242 $member->{exceeded_maxreserves} = 1;
244 $member->{amount_outstanding} = $enrollment->patron->account->balance;
245 if ( $enrollment->patron->branchcode ne C4::Context->userenv->{'branch'} ) {
246 $member->{diffbranch} = 1;
249 push @members, $member;
254 members => \@members,
255 maxreserves => $maxreserves,
256 new_reserves_count => $new_reserves_count
260 unless ( $club_hold or $borrowernumber_hold ) {
261 $template->param( clubcount => Koha::Clubs->search->count );
265 messageborrower => $messageborrower,
266 messageclub => $messageclub
269 # Load the hold list if
270 # - we are searching for a patron or club and found one
271 # - we are not searching for anything
272 if ( ( $findborrower && $borrowernumber_hold || $findclub && $club_hold )
273 || ( !$findborrower && !$findclub ) )
275 # FIXME launch another time GetMember perhaps until (Joubu: Why?)
276 my $patron = Koha::Patrons->find( $borrowernumber_hold );
278 if ( $patron && $multi_hold ) {
279 my @multi_pickup_locations =
280 Koha::Biblios->search( { biblionumber => \@biblionumbers } )
281 ->pickup_locations( { patron => $patron } )->as_list;
282 $template->param( multi_pickup_locations => \@multi_pickup_locations );
285 my $logged_in_patron = Koha::Patrons->find( $borrowernumber );
289 $wants_check = $patron->wants_check_for_previous_checkout;
291 my $itemdata_enumchron = 0;
292 my $itemdata_ccode = 0;
294 my $no_reserves_allowed = 0;
295 my $num_bibs_available = 0;
296 foreach my $biblionumber (@biblionumbers) {
297 next unless $biblionumber =~ m|^\d+$|;
299 my %biblioloopiter = ();
301 my $biblio = Koha::Biblios->find( $biblionumber );
304 $biblioloopiter{noitems} = 1;
305 $template->param('nobiblio' => 1);
309 $biblioloopiter{object} = $biblio;
312 { # CanBookBeReserved
313 my $canReserve = CanBookBeReserved( $patron->borrowernumber, $biblionumber );
314 if ( $canReserve->{status} eq 'OK' ) {
316 #All is OK and we can continue
318 elsif ( $canReserve->{status} eq 'noReservesAllowed' || $canReserve->{status} eq 'notReservable' ) {
319 $no_reserves_allowed = 1;
321 elsif ( $canReserve->{status} eq 'tooManyReserves' ) {
322 $exceeded_maxreserves = 1;
323 $template->param( maxreserves => $canReserve->{limit} );
325 elsif ( $canReserve->{status} eq 'tooManyHoldsForThisRecord' ) {
326 $exceeded_holds_per_record = 1;
327 $biblioloopiter{ $canReserve->{status} } = 1;
329 elsif ( $canReserve->{status} eq 'ageRestricted' ) {
330 $template->param( $canReserve->{status} => 1 );
331 $biblioloopiter{ $canReserve->{status} } = 1;
333 elsif ( $canReserve->{status} eq 'alreadypossession' ) {
334 $template->param( $canReserve->{status} => 1);
335 $biblioloopiter{ $canReserve->{status} } = 1;
337 elsif ( $canReserve->{status} eq 'recall' ) {
338 $template->param( $canReserve->{status} => 1 );
339 $biblioloopiter{ $canReserve->{status} } = 1;
342 $biblioloopiter{ $canReserve->{status} } = 1;
346 # For multiple holds per record, if a patron has previously placed a hold,
347 # the patron can only place more holds of the same type. That is, if the
348 # patron placed a record level hold, all the holds the patron places must
349 # be record level. If the patron placed an item level hold, all holds
350 # the patron places must be item level
351 my $holds = Koha::Holds->search(
353 borrowernumber => $patron->borrowernumber,
354 biblionumber => $biblionumber,
358 $template->param( force_hold_level => $holds->forced_hold_level() );
360 # For a librarian to be able to place multiple record holds for a patron for a record,
361 # we must find out what the maximum number of holds they can place for the patron is
362 my $max_holds_for_record = GetMaxPatronHoldsForRecord( $patron->borrowernumber, $biblionumber );
363 my $remaining_holds_for_record = $max_holds_for_record - $holds->count();
364 $biblioloopiter{remaining_holds_for_record} = $max_holds_for_record;
365 $template->param( max_holds_for_record => $max_holds_for_record );
366 $template->param( remaining_holds_for_record => $remaining_holds_for_record );
369 # adding a fixed value for priority options
370 my $fixedRank = $biblio->holds->count + 1;
372 my @items = $biblio->items->as_list;
374 my @host_items = $biblio->host_items->as_list;
376 push @items, @host_items;
380 # FIXME Then why do we continue?
381 $template->param('noitems' => 1) unless ( $multi_hold );
382 $biblioloopiter{noitems} = 1;
385 if ( $club_hold or $borrowernumber_hold ) {
386 my @available_itemtypes;
387 my $num_items_available = 0;
388 my $num_override = 0;
390 my $num_alreadyheld = 0;
392 # iterating through all items first to check if any of them available
393 # to pass this value further inside down to IsAvailableForItemLevelRequest to
394 # it's complicated logic to analyse.
395 # (before this loop was inside that sub loop so it was O(n^2) )
396 my $items_any_available;
397 $items_any_available = ItemsAnyAvailableAndNotRestricted( { biblionumber => $biblio->biblionumber, patron => $patron })
400 for my $item_object ( @items ) {
402 my $item = $item_object->unblessed;
403 $item->{object} = $item_object;
405 $do_check = $patron->do_check_for_previous_checkout($item) if $wants_check;
406 if ( $do_check && $wants_check ) {
407 $item->{checked_previously} = $do_check;
409 $biblioloopiter{checked_previously} = $do_check;
411 $template->param( checked_previously => $do_check );
416 $item->{itemtype} = $itemtypes->{ $item_object->effective_itemtype };
418 if($item->{biblionumber} ne $biblio->biblionumber){
419 $item->{hosttitle} = Koha::Biblios->find( $item->{biblionumber} )->title;
422 # if the item is currently on loan, we display its return date and
423 # change the background color
424 my $issue = $item_object->checkout;
425 if ( $issue ) { # FIXME must be moved to the template
426 $item->{date_due} = $issue->date_due;
427 $item->{backgroundcolor} = 'onloan';
431 my $holds = $item_object->current_holds;
432 if ( my $first_hold = $holds->next ) {
433 my $p = Koha::Patrons->find( $first_hold->borrowernumber );
435 $item->{backgroundcolor} = 'reserved';
436 $item->{reservedate} = $first_hold->reservedate;
437 $item->{ReservedFor} = $p;
438 $item->{ExpectedAtLibrary} = $first_hold->branchcode;
439 $item->{waitingdate} = $first_hold->waitingdate;
442 # Management of the notforloan document
443 if ( $item->{notforloan} ) {
444 $item->{backgroundcolor} = 'other';
447 # Management of lost or long overdue items
448 if ( $item->{itemlost} ) {
449 $item->{backgroundcolor} = 'other';
450 if ($logged_in_patron->category->hidelostitems && !$showallitems) {
456 # Check the transit status
457 my $transfer = $item_object->get_transfer;
458 if ( $transfer && $transfer->in_transit ) {
459 $item->{transfertwhen} = $transfer->datesent;
460 $item->{transfertfrom} = $transfer->frombranch;
461 $item->{transfertto} = $transfer->tobranch;
462 $item->{nocancel} = 1;
465 # If there is no loan, return and transfer, we show a checkbox.
466 $item->{notforloanitype} = $item->{itemtype}->{notforloan};
467 $item->{notforloan} ||= 0;
469 # if independent branches is on we need to check if the person can reserve
470 # for branches they arent logged in to
471 if ( C4::Context->preference("IndependentBranches") ) {
472 if (! C4::Context->preference("canreservefromotherbranches")){
473 # can't reserve items so need to check if item homebranch and userenv branch match if not we can't reserve
474 my $userenv = C4::Context->userenv;
475 unless ( C4::Context->IsSuperLibrarian ) {
476 $item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
482 my $patron_unblessed = $patron->unblessed;
483 my $branch = C4::Circulation::_GetCircControlBranch($item, $patron_unblessed);
485 my $branchitemrule = GetBranchItemRule( $branch, $item->{'itype'} );
487 $item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
489 my $can_item_be_reserved = CanItemBeReserved( $patron, $item_object )->{status};
490 $item->{not_holdable} = $can_item_be_reserved unless ( $can_item_be_reserved eq 'OK' );
491 $item->{not_holdable} ||= 'notforloan' if ( $item->{notforloanitype} || $item->{notforloan} > 0 );
494 $item->{item_level_holds} = Koha::CirculationRules->get_opacitemholds_policy( { item => $item_object, patron => $patron } );
496 my $default_hold_pickup_location_pref = C4::Context->preference('DefaultHoldPickupLocation');
497 my $default_pickup_branch;
498 if( $default_hold_pickup_location_pref eq 'homebranch' ){
499 $default_pickup_branch = $item->{homebranch};
500 } elsif ( $default_hold_pickup_location_pref eq 'holdingbranch' ){
501 $default_pickup_branch = $item->{holdingbranch};
503 $default_pickup_branch = C4::Context->userenv->{branch};
507 !$item->{cantreserve}
508 && !$exceeded_maxreserves
509 && $can_item_be_reserved eq 'OK'
510 # items_any_available defined outside of the current loop,
511 # so we avoiding loop inside IsAvailableForItemLevelRequest:
512 && IsAvailableForItemLevelRequest($item_object, $patron, undef, $items_any_available)
515 # Send the pickup locations count to the UI, the pickup locations will be pulled using the API
516 my $pickup_locations = $item_object->pickup_locations({ patron => $patron });
517 $item->{pickup_locations_count} = $pickup_locations->count;
518 if ( $item->{pickup_locations_count} > 0 ) {
519 $num_items_available++;
520 $item->{available} = 1;
521 # pass the holding branch for use as default
522 my $default_pickup_location = $pickup_locations->search({ branchcode => $default_pickup_branch })->next;
523 $item->{default_pickup_location} = $default_pickup_location;
526 $item->{available} = 0;
527 $item->{not_holdable} = "no_valid_pickup_location";
530 push( @available_itemtypes, $item->{itype} );
532 elsif ( C4::Context->preference('AllowHoldPolicyOverride') ) {
533 # If AllowHoldPolicyOverride is set, it should override EVERY restriction, not just branch item rules
534 # with the exception of itemAlreadyOnHold because, you know, the item is already on hold
535 if ( $can_item_be_reserved ne 'itemAlreadyOnHold' ) {
536 # Send the pickup locations count to the UI, the pickup locations will be pulled using the API
537 my @pickup_locations = $item_object->pickup_locations({ patron => $patron })->as_list;
538 $item->{pickup_locations_count} = scalar @pickup_locations;
540 if ( @pickup_locations ) {
541 $num_items_available++;
542 $item->{override} = 1;
544 my $default_pickup_location;
546 ($default_pickup_location) = grep { $_->branchcode eq $default_pickup_branch } @pickup_locations;
548 $item->{default_pickup_location} = $default_pickup_location;
551 $item->{available} = 0;
552 $item->{not_holdable} = "no_valid_pickup_location";
554 } else { $num_alreadyheld++ }
556 push( @available_itemtypes, $item->{itype} );
558 # If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
559 $item->{available} = 0;
563 # Show serial enumeration when needed
564 if ($item->{enumchron}) {
565 $itemdata_enumchron = 1;
567 # Show collection when needed
568 if ($item->{ccode}) {
573 push @{ $biblioloopiter{itemloop} }, $item;
576 $biblioloopiter{biblioitem} = $biblio->biblioitem;
578 # While we can't override an alreay held item, we should be able to override the others
579 # Unless all items are already held
580 if ( $num_override > 0 && ($num_override + $num_alreadyheld) == scalar( @{ $biblioloopiter{itemloop} } ) ) {
581 # That is, if all items require an override
582 $template->param( override_required => 1 );
583 } elsif ( $num_items_available == 0 ) {
584 $template->param( none_available => 1 );
585 $biblioloopiter{warn} = 1;
586 $biblioloopiter{none_avail} = 1;
588 $template->param( hiddencount => $hiddencount);
590 @available_itemtypes = uniq( @available_itemtypes );
591 $template->param( available_itemtypes => \@available_itemtypes );
594 # existingreserves building
596 my $always_show_holds = $input->cookie('always_show_holds');
597 $template->param( always_show_holds => $always_show_holds );
598 my $show_holds_now = $input->param('show_holds_now');
599 unless( (defined $always_show_holds && $always_show_holds eq 'DONT') && !$show_holds_now ){
600 my @reserves = Koha::Holds->search( { biblionumber => $biblionumber }, { order_by => 'priority' } )->as_list;
603 my $a_found = $a->found() || '';
604 my $b_found = $a->found() || '';
605 $a_found cmp $b_found;
610 if ( $res->is_found() ) {
611 $reserve{'holdingbranch'} = $res->item()->holdingbranch();
612 $reserve{'biblionumber'} = $res->item()->biblionumber();
613 $reserve{'barcodenumber'} = $res->item()->barcode();
614 $reserve{'wbrcode'} = $res->branchcode();
615 $reserve{'itemnumber'} = $res->itemnumber();
616 $reserve{'wbrname'} = $res->branch()->branchname();
617 $reserve{'atdestination'} = $res->is_at_destination();
618 $reserve{'desk_name'} = ( $res->desk() ) ? $res->desk()->desk_name() : '' ;
619 $reserve{'found'} = $res->is_found();
620 $reserve{'inprocessing'} = $res->is_in_processing();
621 $reserve{'intransit'} = $res->is_in_transit();
623 elsif ( $res->priority() > 0 ) {
624 if ( my $item = $res->item() ) {
625 $reserve{'itemnumber'} = $item->id();
626 $reserve{'barcodenumber'} = $item->barcode();
627 $reserve{'item_level_hold'} = 1;
631 $reserve{'expirationdate'} = $res->expirationdate;
632 $reserve{'date'} = $res->reservedate;
633 $reserve{'borrowernumber'} = $res->borrowernumber();
634 $reserve{'biblionumber'} = $res->biblionumber();
635 $reserve{'patron'} = $res->borrower;
636 $reserve{'notes'} = $res->reservenotes();
637 $reserve{'waiting_date'} = $res->waitingdate();
638 $reserve{'ccode'} = $res->item() ? $res->item()->ccode() : undef;
639 $reserve{'barcode'} = $res->item() ? $res->item()->barcode() : undef;
640 $reserve{'priority'} = $res->priority();
641 $reserve{'lowestPriority'} = $res->lowestPriority();
642 $reserve{'suspend'} = $res->suspend();
643 $reserve{'suspend_until'} = $res->suspend_until();
644 $reserve{'reserve_id'} = $res->reserve_id();
645 $reserve{itemtype} = $res->itemtype();
646 $reserve{branchcode} = $res->branchcode();
647 $reserve{non_priority} = $res->non_priority();
648 $reserve{object} = $res;
650 push( @reserveloop, \%reserve );
654 # get the time for the form name...
659 fixedRank => $fixedRank,
664 itemdata_enumchron => $itemdata_enumchron,
665 itemdata_ccode => $itemdata_ccode,
666 date => dt_from_string,
667 biblionumber => $biblionumber,
668 findborrower => $findborrower,
671 C4::Search::enabled_staff_search_views,
674 $biblioloopiter{biblionumber} = $biblionumber;
675 $biblioloopiter{title} = $biblio->title;
676 $biblioloopiter{author} = $biblio->author;
677 $biblioloopiter{rank} = $fixedRank;
678 $biblioloopiter{reserveloop} = \@reserveloop;
681 $template->param( reserveloop => \@reserveloop );
684 if ( $patron && $multi_hold ) {
685 # Add the valid pickup locations
686 my @pickup_locations = $biblio->pickup_locations({ patron => $patron })->as_list;
687 $biblioloopiter{pickup_locations} = \@pickup_locations;
688 $biblioloopiter{pickup_locations_codes} = [ map { $_->branchcode } @pickup_locations ];
691 $num_bibs_available++ unless $biblioloopiter{none_avail};
692 push @biblioloop, \%biblioloopiter;
695 $template->param( no_bibs_available => 1 ) unless $num_bibs_available > 0;
697 $template->param( biblioloop => \@biblioloop );
698 $template->param( no_reserves_allowed => $no_reserves_allowed );
699 $template->param( exceeded_maxreserves => $exceeded_maxreserves );
700 $template->param( exceeded_holds_per_record => $exceeded_holds_per_record );
701 # FIXME: getting just the first bib's result doesn't seem right
702 $template->param( subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumbers[0]));
703 } elsif ( ! $multi_hold ) {
704 my $biblio = Koha::Biblios->find( $biblionumbers[0] );
705 $template->param( biblio => $biblio );
707 $template->param( biblionumbers => \@biblionumbers );
710 attribute_type_codes => ( C4::Context->preference('ExtendedPatronAttributes')
711 ? [ Koha::Patron::Attribute::Types->search( { staff_searchable => 1 } )->get_column('code') ]
717 # pass the userenv branch if no pickup location selected
718 $template->param( pickup => $pickup || C4::Context->userenv->{branch} );
720 $template->param(borrowernumber => $borrowernumber_hold);
723 output_html_with_http_headers $input, $cookie, $template->output;
725 sub sort_borrowerlist {
726 my $borrowerslist = shift;
729 uc( $a->{surname} . $a->{firstname} ) cmp
730 uc( $b->{surname} . $b->{firstname} )