2 # Copyright 2000-2002 Katipo Communications
3 # copyright 2010 BibLibre
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
29 use Koha
::IssuingRule
;
30 use Koha
::IssuingRules
;
32 use Koha
::RefundLostItemFeeRule
;
33 use Koha
::RefundLostItemFeeRules
;
35 use Koha
::CirculationRules
;
36 use Koha
::Patron
::Categories
;
41 my $dbh = C4
::Context
->dbh;
44 # $flagsrequired->{circulation}=1;
45 my ($template, $loggedinuser, $cookie)
46 = get_template_and_user
({template_name
=> "admin/smart-rules.tt",
50 flagsrequired
=> {parameters
=> 'manage_circ_rules'},
54 my $type=$input->param('type');
56 my $branch = $input->param('branch');
58 if ( C4
::Context
->preference('DefaultToLoggedInLibraryCircRules') ) {
59 $branch = Koha
::Libraries
->search->count() == 1 ?
undef : C4
::Context
::mybranch
();
62 $branch = C4
::Context
::only_my_library
() ?
( C4
::Context
::mybranch
() || '*' ) : '*';
66 my $logged_in_patron = Koha
::Patrons
->find( $loggedinuser );
68 my $can_edit_from_any_library = $logged_in_patron->has_permission( {parameters
=> 'manage_circ_rules_from_any_libraries' } );
69 $template->param( restricted_to_own_library
=> not $can_edit_from_any_library );
70 $branch = C4
::Context
::mybranch
() unless $can_edit_from_any_library;
72 $branch = '*' if $branch eq 'NO_LIBRARY_SET';
74 my $op = $input->param('op') || q{};
75 my $language = C4
::Languages
::getlanguage
();
77 my $cache = Koha
::Caches
->get_instance;
78 $cache->clear_from_cache( Koha
::IssuingRules
::GUESSED_ITEMTYPES_KEY
);
80 if ($op eq 'delete') {
81 my $itemtype = $input->param('itemtype');
82 my $categorycode = $input->param('categorycode');
83 $debug and warn "deleting $1 $2 $branch";
85 my $sth_Idelete = $dbh->prepare("delete from issuingrules where branchcode=? and categorycode=? and itemtype=?");
86 $sth_Idelete->execute($branch, $categorycode, $itemtype);
88 elsif ($op eq 'delete-branch-cat') {
89 my $categorycode = $input->param('categorycode');
91 if ($categorycode eq "*") {
92 my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
93 $sth_delete->execute();
95 } elsif ($categorycode eq "*") {
96 my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
97 WHERE branchcode = ?");
98 $sth_delete->execute($branch);
100 Koha
::CirculationRules
->set_rules(
102 categorycode
=> $categorycode eq '*' ?
undef : $categorycode,
103 branchcode
=> $branch eq '*' ?
undef : $branch,
107 maxissueqty
=> undef,
108 maxonsiteissueqty
=> undef,
113 elsif ($op eq 'delete-branch-item') {
114 my $itemtype = $input->param('itemtype');
115 if ($branch eq "*") {
116 if ($itemtype eq "*") {
117 my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
118 $sth_delete->execute();
120 my $sth_delete = $dbh->prepare("DELETE FROM default_branch_item_rules
121 WHERE itemtype = ?");
122 $sth_delete->execute($itemtype);
124 } elsif ($itemtype eq "*") {
125 my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
126 WHERE branchcode = ?");
127 $sth_delete->execute($branch);
129 my $sth_delete = $dbh->prepare("DELETE FROM branch_item_rules
132 $sth_delete->execute($branch, $itemtype);
135 # save the values entered
136 elsif ($op eq 'add') {
137 my $br = $branch; # branch
138 my $bor = $input->param('categorycode'); # borrower category
139 my $itemtype = $input->param('itemtype'); # item type
140 my $fine = $input->param('fine');
141 my $finedays = $input->param('finedays');
142 my $maxsuspensiondays = $input->param('maxsuspensiondays');
143 $maxsuspensiondays = undef if $maxsuspensiondays eq q
||;
144 my $suspension_chargeperiod = $input->param('suspension_chargeperiod') || 1;
145 my $firstremind = $input->param('firstremind');
146 my $chargeperiod = $input->param('chargeperiod');
147 my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at');
148 my $maxissueqty = $input->param('maxissueqty');
149 my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
150 my $renewalsallowed = $input->param('renewalsallowed');
151 my $renewalperiod = $input->param('renewalperiod');
152 my $norenewalbefore = $input->param('norenewalbefore');
153 $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
154 my $auto_renew = $input->param('auto_renew') eq 'yes' ?
1 : 0;
155 my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
156 $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/;
157 my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || undef;
158 $no_auto_renewal_after_hard_limit = eval { dt_from_string
( $input->param('no_auto_renewal_after_hard_limit') ) } if ( $no_auto_renewal_after_hard_limit );
159 $no_auto_renewal_after_hard_limit = output_pref
( { dt
=> $no_auto_renewal_after_hard_limit, dateonly
=> 1, dateformat
=> 'iso' } ) if ( $no_auto_renewal_after_hard_limit );
160 my $reservesallowed = $input->param('reservesallowed');
161 my $holds_per_record = $input->param('holds_per_record');
162 my $holds_per_day = $input->param('holds_per_day');
163 $holds_per_day =~ s/\s//g;
164 $holds_per_day = undef if $holds_per_day !~ /^\d+/;
165 my $onshelfholds = $input->param('onshelfholds') || 0;
166 $maxissueqty =~ s/\s//g;
167 $maxissueqty = undef if $maxissueqty !~ /^\d+/;
168 $maxonsiteissueqty =~ s/\s//g;
169 $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
170 my $issuelength = $input->param('issuelength');
171 $issuelength = $issuelength eq q{} ?
undef : $issuelength;
172 my $lengthunit = $input->param('lengthunit');
173 my $hardduedate = $input->param('hardduedate') || undef;
174 $hardduedate = eval { dt_from_string
( $input->param('hardduedate') ) } if ( $hardduedate );
175 $hardduedate = output_pref
( { dt
=> $hardduedate, dateonly
=> 1, dateformat
=> 'iso' } ) if ( $hardduedate );
176 my $hardduedatecompare = $input->param('hardduedatecompare');
177 my $rentaldiscount = $input->param('rentaldiscount');
178 my $opacitemholds = $input->param('opacitemholds') || 0;
179 my $article_requests = $input->param('article_requests') || 'no';
180 my $overduefinescap = $input->param('overduefinescap') || undef;
181 my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
182 my $note = $input->param('note');
183 $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
187 categorycode
=> $bor,
188 itemtype
=> $itemtype,
190 finedays
=> $finedays,
191 maxsuspensiondays
=> $maxsuspensiondays,
192 suspension_chargeperiod
=> $suspension_chargeperiod,
193 firstremind
=> $firstremind,
194 chargeperiod
=> $chargeperiod,
195 chargeperiod_charge_at
=> $chargeperiod_charge_at,
196 renewalsallowed
=> $renewalsallowed,
197 renewalperiod
=> $renewalperiod,
198 norenewalbefore
=> $norenewalbefore,
199 auto_renew
=> $auto_renew,
200 no_auto_renewal_after
=> $no_auto_renewal_after,
201 no_auto_renewal_after_hard_limit
=> $no_auto_renewal_after_hard_limit,
202 reservesallowed
=> $reservesallowed,
203 holds_per_record
=> $holds_per_record,
204 holds_per_day
=> $holds_per_day,
205 issuelength
=> $issuelength,
206 lengthunit
=> $lengthunit,
207 hardduedate
=> $hardduedate,
208 hardduedatecompare
=> $hardduedatecompare,
209 rentaldiscount
=> $rentaldiscount,
210 onshelfholds
=> $onshelfholds,
211 opacitemholds
=> $opacitemholds,
212 overduefinescap
=> $overduefinescap,
213 cap_fine_to_replacement_price
=> $cap_fine_to_replacement_price,
214 article_requests
=> $article_requests,
218 my $issuingrule = Koha
::IssuingRules
->find({categorycode
=> $bor, itemtype
=> $itemtype, branchcode
=> $br});
220 $issuingrule->set($params)->store();
222 Koha
::IssuingRule
->new()->set($params)->store();
225 Koha
::CirculationRules
->set_rules(
227 categorycode
=> $bor,
228 itemtype
=> $itemtype,
231 maxissueqty
=> $maxissueqty,
232 maxonsiteissueqty
=> $maxonsiteissueqty,
238 elsif ($op eq "set-branch-defaults") {
239 my $categorycode = $input->param('categorycode');
240 my $maxissueqty = $input->param('maxissueqty');
241 my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
242 my $holdallowed = $input->param('holdallowed');
243 my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
244 my $returnbranch = $input->param('returnbranch');
245 my $max_holds = $input->param('max_holds');
246 $maxissueqty =~ s/\s//g;
247 $maxissueqty = undef if $maxissueqty !~ /^\d+/;
248 $maxonsiteissueqty =~ s/\s//g;
249 $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
250 $holdallowed =~ s/\s//g;
251 $holdallowed = undef if $holdallowed !~ /^\d+/;
252 $max_holds =~ s/\s//g;
253 $max_holds = '' if $max_holds !~ /^\d+/;
255 if ($branch eq "*") {
256 my $sth_search = $dbh->prepare("SELECT count(*) AS total
257 FROM default_circ_rules");
258 my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
259 (holdallowed, hold_fulfillment_policy, returnbranch)
261 my $sth_update = $dbh->prepare("UPDATE default_circ_rules
262 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
264 $sth_search->execute();
265 my $res = $sth_search->fetchrow_hashref();
267 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
269 $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
272 Koha
::CirculationRules
->set_rules(
274 categorycode
=> undef,
278 maxissueqty
=> $maxissueqty,
279 maxonsiteissueqty
=> $maxonsiteissueqty,
284 my $sth_search = $dbh->prepare("SELECT count(*) AS total
285 FROM default_branch_circ_rules
286 WHERE branchcode = ?");
287 my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
288 (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
289 VALUES (?, ?, ?, ?)");
290 my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
291 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
292 WHERE branchcode = ?");
293 $sth_search->execute($branch);
294 my $res = $sth_search->fetchrow_hashref();
296 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
298 $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
301 Koha
::CirculationRules
->set_rules(
303 categorycode
=> undef,
305 branchcode
=> $branch,
307 maxissueqty
=> $maxissueqty,
308 maxonsiteissueqty
=> $maxonsiteissueqty,
313 Koha
::CirculationRules
->set_rule(
315 branchcode
=> $branch,
316 categorycode
=> undef,
318 rule_name
=> 'max_holds',
319 rule_value
=> $max_holds,
323 elsif ($op eq "add-branch-cat") {
324 my $categorycode = $input->param('categorycode');
325 my $maxissueqty = $input->param('maxissueqty');
326 my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
327 my $max_holds = $input->param('max_holds');
328 $maxissueqty =~ s/\s//g;
329 $maxissueqty = undef if $maxissueqty !~ /^\d+/;
330 $maxonsiteissueqty =~ s/\s//g;
331 $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
332 $max_holds =~ s/\s//g;
333 $max_holds = undef if $max_holds !~ /^\d+/;
335 if ($branch eq "*") {
336 if ($categorycode eq "*") {
337 Koha
::CirculationRules
->set_rules(
339 categorycode
=> undef,
343 max_holds
=> $max_holds,
344 maxissueqty
=> $maxissueqty,
345 maxonsiteissueqty
=> $maxonsiteissueqty,
350 Koha
::CirculationRules
->set_rules(
353 categorycode
=> $categorycode,
356 max_holds
=> $max_holds,
357 maxissueqty
=> $maxissueqty,
358 maxonsiteissueqty
=> $maxonsiteissueqty,
363 } elsif ($categorycode eq "*") {
364 Koha
::CirculationRules
->set_rules(
366 categorycode
=> undef,
368 branchcode
=> $branch,
370 max_holds
=> $max_holds,
371 maxissueqty
=> $maxissueqty,
372 maxonsiteissueqty
=> $maxonsiteissueqty,
377 Koha
::CirculationRules
->set_rules(
379 categorycode
=> $categorycode,
381 branchcode
=> $branch,
383 max_holds
=> $max_holds,
384 maxissueqty
=> $maxissueqty,
385 maxonsiteissueqty
=> $maxonsiteissueqty,
391 elsif ($op eq "add-branch-item") {
392 my $itemtype = $input->param('itemtype');
393 my $holdallowed = $input->param('holdallowed');
394 my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
395 my $returnbranch = $input->param('returnbranch');
397 $holdallowed =~ s/\s//g;
398 $holdallowed = undef if $holdallowed !~ /^\d+/;
400 if ($branch eq "*") {
401 if ($itemtype eq "*") {
402 my $sth_search = $dbh->prepare("SELECT count(*) AS total
403 FROM default_circ_rules");
404 my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
405 (holdallowed, hold_fulfillment_policy, returnbranch)
407 my $sth_update = $dbh->prepare("UPDATE default_circ_rules
408 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
410 $sth_search->execute();
411 my $res = $sth_search->fetchrow_hashref();
413 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
415 $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
418 my $sth_search = $dbh->prepare("SELECT count(*) AS total
419 FROM default_branch_item_rules
420 WHERE itemtype = ?");
421 my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
422 (itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
423 VALUES (?, ?, ?, ?)");
424 my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
425 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
426 WHERE itemtype = ?");
427 $sth_search->execute($itemtype);
428 my $res = $sth_search->fetchrow_hashref();
430 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $itemtype);
432 $sth_insert->execute($itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
435 } elsif ($itemtype eq "*") {
436 my $sth_search = $dbh->prepare("SELECT count(*) AS total
437 FROM default_branch_circ_rules
438 WHERE branchcode = ?");
439 my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
440 (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
441 VALUES (?, ?, ?, ?)");
442 my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
443 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
444 WHERE branchcode = ?");
445 $sth_search->execute($branch);
446 my $res = $sth_search->fetchrow_hashref();
448 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
450 $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
453 my $sth_search = $dbh->prepare("SELECT count(*) AS total
454 FROM branch_item_rules
457 my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
458 (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
459 VALUES (?, ?, ?, ?, ?)");
460 my $sth_update = $dbh->prepare("UPDATE branch_item_rules
461 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
465 $sth_search->execute($branch, $itemtype);
466 my $res = $sth_search->fetchrow_hashref();
468 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch, $itemtype);
470 $sth_insert->execute($branch, $itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
474 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) {
476 my $refund = $input->param('refund');
478 if ( $refund eq '*' ) {
479 if ( $branch ne '*' ) {
480 # only do something for $refund eq '*' if branch-specific
482 # Delete it so it picks the default
483 Koha
::RefundLostItemFeeRules
->find({
484 branchcode
=> $branch
490 Koha
::RefundLostItemFeeRules
->find({
491 branchcode
=> $branch
492 }) // Koha
::RefundLostItemFeeRule
->new;
494 branchcode
=> $branch,
500 my $refundLostItemFeeRule = Koha
::RefundLostItemFeeRules
->find({ branchcode
=> $branch });
502 refundLostItemFeeRule
=> $refundLostItemFeeRule,
503 defaultRefundRule
=> Koha
::RefundLostItemFeeRules
->_default_rule
506 my $patron_categories = Koha
::Patron
::Categories
->search({}, { order_by
=> ['description'] });
509 my $itemtypes = Koha
::ItemTypes
->search_with_localization;
511 my $sth2 = $dbh->prepare("
512 SELECT issuingrules.*,
513 itemtypes.description AS humanitemtype,
514 categories.description AS humancategorycode,
515 COALESCE( localization.translation, itemtypes.description ) AS translated_description
518 ON (itemtypes.itemtype = issuingrules.itemtype)
520 ON (categories.categorycode = issuingrules.categorycode)
521 LEFT JOIN localization ON issuingrules.itemtype = localization.code
522 AND localization.entity = 'itemtypes'
523 AND localization.lang = ?
524 WHERE issuingrules.branchcode = ?
526 $sth2->execute($language, $branch);
528 while (my $row = $sth2->fetchrow_hashref) {
529 $row->{'current_branch'} ||= $row->{'branchcode'};
530 $row->{humanitemtype
} ||= $row->{itemtype
};
531 $row->{default_translated_description
} = 1 if $row->{humanitemtype
} eq '*';
532 $row->{'humancategorycode'} ||= $row->{'categorycode'};
533 $row->{'default_humancategorycode'} = 1 if $row->{'humancategorycode'} eq '*';
534 $row->{'fine'} = sprintf('%.2f', $row->{'fine'});
535 if ($row->{'hardduedate'} && $row->{'hardduedate'} ne '0000-00-00') {
536 my $harddue_dt = eval { dt_from_string
( $row->{'hardduedate'} ) };
537 $row->{'hardduedate'} = eval { output_pref
( { dt
=> $harddue_dt, dateonly
=> 1 } ) } if ( $harddue_dt );
538 $row->{'hardduedatebefore'} = 1 if ($row->{'hardduedatecompare'} == -1);
539 $row->{'hardduedateexact'} = 1 if ($row->{'hardduedatecompare'} == 0);
540 $row->{'hardduedateafter'} = 1 if ($row->{'hardduedatecompare'} == 1);
542 $row->{'hardduedate'} = 0;
544 if ($row->{no_auto_renewal_after_hard_limit
}) {
545 my $dt = eval { dt_from_string
( $row->{no_auto_renewal_after_hard_limit
} ) };
546 $row->{no_auto_renewal_after_hard_limit
} = eval { output_pref
( { dt
=> $dt, dateonly
=> 1 } ) } if $dt;
549 push @row_loop, $row;
552 my @sorted_row_loop = sort by_category_and_itemtype
@row_loop;
555 if ($branch eq "*") {
556 $sth_branch_item = $dbh->prepare("
557 SELECT default_branch_item_rules.*,
558 COALESCE( localization.translation, itemtypes.description ) AS translated_description
559 FROM default_branch_item_rules
560 JOIN itemtypes USING (itemtype)
561 LEFT JOIN localization ON itemtypes.itemtype = localization.code
562 AND localization.entity = 'itemtypes'
563 AND localization.lang = ?
565 $sth_branch_item->execute($language);
567 $sth_branch_item = $dbh->prepare("
568 SELECT branch_item_rules.*,
569 COALESCE( localization.translation, itemtypes.description ) AS translated_description
570 FROM branch_item_rules
571 JOIN itemtypes USING (itemtype)
572 LEFT JOIN localization ON itemtypes.itemtype = localization.code
573 AND localization.entity = 'itemtypes'
574 AND localization.lang = ?
575 WHERE branch_item_rules.branchcode = ?
577 $sth_branch_item->execute($language, $branch);
580 my @branch_item_rules = ();
581 while (my $row = $sth_branch_item->fetchrow_hashref) {
582 push @branch_item_rules, $row;
584 my @sorted_branch_item_rules = sort { lc $a->{translated_description
} cmp lc $b->{translated_description
} } @branch_item_rules;
586 # note undef holdallowed so that template can deal with them
587 foreach my $entry (@sorted_branch_item_rules) {
588 $entry->{holdallowed_any
} = 1 if ( $entry->{holdallowed
} == 2 );
589 $entry->{holdallowed_same
} = 1 if ( $entry->{holdallowed
} == 1 );
592 $template->param(show_branch_cat_rule_form
=> 1);
593 $template->param(branch_item_rule_loop
=> \
@sorted_branch_item_rules);
596 if ($branch eq "*") {
597 $sth_defaults = $dbh->prepare("
599 FROM default_circ_rules
601 $sth_defaults->execute();
603 $sth_defaults = $dbh->prepare("
605 FROM default_branch_circ_rules
608 $sth_defaults->execute($branch);
611 my $defaults = $sth_defaults->fetchrow_hashref;
614 $template->param( default_holdallowed_none
=> 1 ) if ( $defaults->{holdallowed
} == 0 );
615 $template->param( default_holdallowed_same
=> 1 ) if ( $defaults->{holdallowed
} == 1 );
616 $template->param( default_holdallowed_any
=> 1 ) if ( $defaults->{holdallowed
} == 2 );
617 $template->param( default_hold_fulfillment_policy
=> $defaults->{hold_fulfillment_policy
} );
618 $template->param( default_maxissueqty
=> $defaults->{maxissueqty
} );
619 $template->param( default_maxonsiteissueqty
=> $defaults->{maxonsiteissueqty
} );
620 $template->param( default_returnbranch
=> $defaults->{returnbranch
} );
623 $template->param(default_rules
=> ($defaults ?
1 : 0));
626 patron_categories
=> $patron_categories,
627 itemtypeloop
=> $itemtypes,
628 rules
=> \
@sorted_row_loop,
629 humanbranch
=> ($branch ne '*' ?
$branch : ''),
630 current_branch
=> $branch,
631 definedbranch
=> scalar(@sorted_row_loop)>0
633 output_html_with_http_headers
$input, $cookie, $template->output;
637 # sort by patron category, then item type, putting
638 # default entries at the bottom
639 sub by_category_and_itemtype
{
640 unless (by_category
($a, $b)) {
641 return by_itemtype
($a, $b);
647 if ($a->{'default_humancategorycode'}) {
648 return ($b->{'default_humancategorycode'} ?
0 : 1);
649 } elsif ($b->{'default_humancategorycode'}) {
652 return $a->{'humancategorycode'} cmp $b->{'humancategorycode'};
658 if ($a->{default_translated_description
}) {
659 return ($b->{'default_translated_description'} ?
0 : 1);
660 } elsif ($b->{'default_translated_description'}) {
663 return lc $a->{'translated_description'} cmp lc $b->{'translated_description'};