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
::Patron
::Categories
;
38 my $dbh = C4
::Context
->dbh;
41 # $flagsrequired->{circulation}=1;
42 my ($template, $loggedinuser, $cookie)
43 = get_template_and_user
({template_name
=> "admin/smart-rules.tt",
47 flagsrequired
=> {parameters
=> 'manage_circ_rules'},
51 my $type=$input->param('type');
53 my $branch = $input->param('branch');
55 if ( C4
::Context
->preference('DefaultToLoggedInLibraryCircRules') ) {
56 $branch = Koha
::Libraries
->search->count() == 1 ?
undef : C4
::Context
::mybranch
();
59 $branch = C4
::Context
::only_my_library
() ?
( C4
::Context
::mybranch
() || '*' ) : '*';
62 $branch = '*' if $branch eq 'NO_LIBRARY_SET';
64 my $op = $input->param('op') || q{};
65 my $language = C4
::Languages
::getlanguage
();
67 if ($op eq 'delete') {
68 my $itemtype = $input->param('itemtype');
69 my $categorycode = $input->param('categorycode');
70 $debug and warn "deleting $1 $2 $branch";
72 my $sth_Idelete = $dbh->prepare("delete from issuingrules where branchcode=? and categorycode=? and itemtype=?");
73 $sth_Idelete->execute($branch, $categorycode, $itemtype);
75 elsif ($op eq 'delete-branch-cat') {
76 my $categorycode = $input->param('categorycode');
78 if ($categorycode eq "*") {
79 my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
80 $sth_delete->execute();
82 my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules
83 WHERE categorycode = ?");
84 $sth_delete->execute($categorycode);
86 } elsif ($categorycode eq "*") {
87 my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
88 WHERE branchcode = ?");
89 $sth_delete->execute($branch);
91 my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules
93 AND categorycode = ?");
94 $sth_delete->execute($branch, $categorycode);
97 elsif ($op eq 'delete-branch-item') {
98 my $itemtype = $input->param('itemtype');
100 if ($itemtype eq "*") {
101 my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules");
102 $sth_delete->execute();
104 my $sth_delete = $dbh->prepare("DELETE FROM default_branch_item_rules
105 WHERE itemtype = ?");
106 $sth_delete->execute($itemtype);
108 } elsif ($itemtype eq "*") {
109 my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules
110 WHERE branchcode = ?");
111 $sth_delete->execute($branch);
113 my $sth_delete = $dbh->prepare("DELETE FROM branch_item_rules
116 $sth_delete->execute($branch, $itemtype);
119 # save the values entered
120 elsif ($op eq 'add') {
121 my $br = $branch; # branch
122 my $bor = $input->param('categorycode'); # borrower category
123 my $itemtype = $input->param('itemtype'); # item type
124 my $fine = $input->param('fine');
125 my $finedays = $input->param('finedays');
126 my $maxsuspensiondays = $input->param('maxsuspensiondays');
127 $maxsuspensiondays = undef if $maxsuspensiondays eq q
||;
128 my $firstremind = $input->param('firstremind');
129 my $chargeperiod = $input->param('chargeperiod');
130 my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at');
131 my $maxissueqty = $input->param('maxissueqty');
132 my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
133 my $renewalsallowed = $input->param('renewalsallowed');
134 my $renewalperiod = $input->param('renewalperiod');
135 my $norenewalbefore = $input->param('norenewalbefore');
136 $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
137 my $auto_renew = $input->param('auto_renew') eq 'yes' ?
1 : 0;
138 my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
139 $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/;
140 my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || undef;
141 $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 );
142 $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 );
143 my $reservesallowed = $input->param('reservesallowed');
144 my $holds_per_record = $input->param('holds_per_record');
145 my $onshelfholds = $input->param('onshelfholds') || 0;
146 $maxissueqty =~ s/\s//g;
147 $maxissueqty = undef if $maxissueqty !~ /^\d+/;
148 $maxonsiteissueqty =~ s/\s//g;
149 $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
150 my $issuelength = $input->param('issuelength');
151 $issuelength = $issuelength eq q{} ?
undef : $issuelength;
152 my $lengthunit = $input->param('lengthunit');
153 my $hardduedate = $input->param('hardduedate') || undef;
154 $hardduedate = eval { dt_from_string
( $input->param('hardduedate') ) } if ( $hardduedate );
155 $hardduedate = output_pref
( { dt
=> $hardduedate, dateonly
=> 1, dateformat
=> 'iso' } ) if ( $hardduedate );
156 my $hardduedatecompare = $input->param('hardduedatecompare');
157 my $rentaldiscount = $input->param('rentaldiscount');
158 my $opacitemholds = $input->param('opacitemholds') || 0;
159 my $article_requests = $input->param('article_requests') || 'no';
160 my $overduefinescap = $input->param('overduefinescap') || undef;
161 my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
162 $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
166 categorycode
=> $bor,
167 itemtype
=> $itemtype,
169 finedays
=> $finedays,
170 maxsuspensiondays
=> $maxsuspensiondays,
171 firstremind
=> $firstremind,
172 chargeperiod
=> $chargeperiod,
173 chargeperiod_charge_at
=> $chargeperiod_charge_at,
174 maxissueqty
=> $maxissueqty,
175 maxonsiteissueqty
=> $maxonsiteissueqty,
176 renewalsallowed
=> $renewalsallowed,
177 renewalperiod
=> $renewalperiod,
178 norenewalbefore
=> $norenewalbefore,
179 auto_renew
=> $auto_renew,
180 no_auto_renewal_after
=> $no_auto_renewal_after,
181 no_auto_renewal_after_hard_limit
=> $no_auto_renewal_after_hard_limit,
182 reservesallowed
=> $reservesallowed,
183 holds_per_record
=> $holds_per_record,
184 issuelength
=> $issuelength,
185 lengthunit
=> $lengthunit,
186 hardduedate
=> $hardduedate,
187 hardduedatecompare
=> $hardduedatecompare,
188 rentaldiscount
=> $rentaldiscount,
189 onshelfholds
=> $onshelfholds,
190 opacitemholds
=> $opacitemholds,
191 overduefinescap
=> $overduefinescap,
192 cap_fine_to_replacement_price
=> $cap_fine_to_replacement_price,
193 article_requests
=> $article_requests,
196 my $issuingrule = Koha
::IssuingRules
->find({categorycode
=> $bor, itemtype
=> $itemtype, branchcode
=> $br});
198 $issuingrule->set($params)->store();
200 Koha
::IssuingRule
->new()->set($params)->store();
204 elsif ($op eq "set-branch-defaults") {
205 my $categorycode = $input->param('categorycode');
206 my $maxissueqty = $input->param('maxissueqty');
207 my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
208 my $holdallowed = $input->param('holdallowed');
209 my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
210 my $returnbranch = $input->param('returnbranch');
211 $maxissueqty =~ s/\s//g;
212 $maxissueqty = undef if $maxissueqty !~ /^\d+/;
213 $maxonsiteissueqty =~ s/\s//g;
214 $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
215 $holdallowed =~ s/\s//g;
216 $holdallowed = undef if $holdallowed !~ /^\d+/;
218 if ($branch eq "*") {
219 my $sth_search = $dbh->prepare("SELECT count(*) AS total
220 FROM default_circ_rules");
221 my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
222 (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
223 VALUES (?, ?, ?, ?, ?)");
224 my $sth_update = $dbh->prepare("UPDATE default_circ_rules
225 SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
227 $sth_search->execute();
228 my $res = $sth_search->fetchrow_hashref();
230 $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
232 $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
235 my $sth_search = $dbh->prepare("SELECT count(*) AS total
236 FROM default_branch_circ_rules
237 WHERE branchcode = ?");
238 my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
239 (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
240 VALUES (?, ?, ?, ?, ?, ?)");
241 my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
242 SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
243 WHERE branchcode = ?");
244 $sth_search->execute($branch);
245 my $res = $sth_search->fetchrow_hashref();
247 $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
249 $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
253 elsif ($op eq "add-branch-cat") {
254 my $categorycode = $input->param('categorycode');
255 my $maxissueqty = $input->param('maxissueqty');
256 my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
257 $maxissueqty =~ s/\s//g;
258 $maxissueqty = undef if $maxissueqty !~ /^\d+/;
259 $maxonsiteissueqty =~ s/\s//g;
260 $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
262 if ($branch eq "*") {
263 if ($categorycode eq "*") {
264 my $sth_search = $dbh->prepare("SELECT count(*) AS total
265 FROM default_circ_rules");
266 my $sth_insert = $dbh->prepare(q
|
267 INSERT INTO default_circ_rules
268 (maxissueqty
, maxonsiteissueqty
)
271 my $sth_update = $dbh->prepare(q
|
272 UPDATE default_circ_rules
274 maxonsiteissueqty
= ?
277 $sth_search->execute();
278 my $res = $sth_search->fetchrow_hashref();
280 $sth_update->execute($maxissueqty, $maxonsiteissueqty);
282 $sth_insert->execute($maxissueqty, $maxonsiteissueqty);
285 my $sth_search = $dbh->prepare("SELECT count(*) AS total
286 FROM default_borrower_circ_rules
287 WHERE categorycode = ?");
288 my $sth_insert = $dbh->prepare(q
|
289 INSERT INTO default_borrower_circ_rules
290 (categorycode
, maxissueqty
, maxonsiteissueqty
)
293 my $sth_update = $dbh->prepare(q
|
294 UPDATE default_borrower_circ_rules
296 maxonsiteissueqty
= ?
297 WHERE categorycode
= ?
299 $sth_search->execute($categorycode);
300 my $res = $sth_search->fetchrow_hashref();
302 $sth_update->execute($maxissueqty, $maxonsiteissueqty, $categorycode);
304 $sth_insert->execute($categorycode, $maxissueqty, $maxonsiteissueqty);
307 } elsif ($categorycode eq "*") {
308 my $sth_search = $dbh->prepare("SELECT count(*) AS total
309 FROM default_branch_circ_rules
310 WHERE branchcode = ?");
311 my $sth_insert = $dbh->prepare(q
|
312 INSERT INTO default_branch_circ_rules
313 (branchcode
, maxissueqty
, maxonsiteissueqty
)
316 my $sth_update = $dbh->prepare(q
|
317 UPDATE default_branch_circ_rules
319 maxonsiteissueqty
= ?
322 $sth_search->execute($branch);
323 my $res = $sth_search->fetchrow_hashref();
325 $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch);
327 $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty);
330 my $sth_search = $dbh->prepare("SELECT count(*) AS total
331 FROM branch_borrower_circ_rules
333 AND categorycode = ?");
334 my $sth_insert = $dbh->prepare(q
|
335 INSERT INTO branch_borrower_circ_rules
336 (branchcode
, categorycode
, maxissueqty
, maxonsiteissueqty
)
339 my $sth_update = $dbh->prepare(q
|
340 UPDATE branch_borrower_circ_rules
342 maxonsiteissueqty
= ?
347 $sth_search->execute($branch, $categorycode);
348 my $res = $sth_search->fetchrow_hashref();
350 $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode);
352 $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty);
356 elsif ($op eq "add-branch-item") {
357 my $itemtype = $input->param('itemtype');
358 my $holdallowed = $input->param('holdallowed');
359 my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
360 my $returnbranch = $input->param('returnbranch');
362 $holdallowed =~ s/\s//g;
363 $holdallowed = undef if $holdallowed !~ /^\d+/;
365 if ($branch eq "*") {
366 if ($itemtype eq "*") {
367 my $sth_search = $dbh->prepare("SELECT count(*) AS total
368 FROM default_circ_rules");
369 my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
370 (holdallowed, hold_fulfillment_policy, returnbranch)
372 my $sth_update = $dbh->prepare("UPDATE default_circ_rules
373 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
375 $sth_search->execute();
376 my $res = $sth_search->fetchrow_hashref();
378 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
380 $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
383 my $sth_search = $dbh->prepare("SELECT count(*) AS total
384 FROM default_branch_item_rules
385 WHERE itemtype = ?");
386 my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
387 (itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
388 VALUES (?, ?, ?, ?)");
389 my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
390 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
391 WHERE itemtype = ?");
392 $sth_search->execute($itemtype);
393 my $res = $sth_search->fetchrow_hashref();
395 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $itemtype);
397 $sth_insert->execute($itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
400 } elsif ($itemtype eq "*") {
401 my $sth_search = $dbh->prepare("SELECT count(*) AS total
402 FROM default_branch_circ_rules
403 WHERE branchcode = ?");
404 my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
405 (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
406 VALUES (?, ?, ?, ?)");
407 my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
408 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
409 WHERE branchcode = ?");
410 $sth_search->execute($branch);
411 my $res = $sth_search->fetchrow_hashref();
413 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
415 $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
418 my $sth_search = $dbh->prepare("SELECT count(*) AS total
419 FROM branch_item_rules
422 my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
423 (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
424 VALUES (?, ?, ?, ?, ?)");
425 my $sth_update = $dbh->prepare("UPDATE branch_item_rules
426 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
430 $sth_search->execute($branch, $itemtype);
431 my $res = $sth_search->fetchrow_hashref();
433 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch, $itemtype);
435 $sth_insert->execute($branch, $itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
439 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) {
441 my $refund = $input->param('refund');
443 if ( $refund eq '*' ) {
444 if ( $branch ne '*' ) {
445 # only do something for $refund eq '*' if branch-specific
447 # Delete it so it picks the default
448 Koha
::RefundLostItemFeeRules
->find({
449 branchcode
=> $branch
455 Koha
::RefundLostItemFeeRules
->find({
456 branchcode
=> $branch
457 }) // Koha
::RefundLostItemFeeRule
->new;
459 branchcode
=> $branch,
465 my $refundLostItemFeeRule = Koha
::RefundLostItemFeeRules
->find({ branchcode
=> $branch });
467 refundLostItemFeeRule
=> $refundLostItemFeeRule,
468 defaultRefundRule
=> Koha
::RefundLostItemFeeRules
->_default_rule
471 my $patron_categories = Koha
::Patron
::Categories
->search({}, { order_by
=> ['description'] });
474 my $itemtypes = Koha
::ItemTypes
->search_with_localization;
476 my $sth2 = $dbh->prepare("
477 SELECT issuingrules.*,
478 itemtypes.description AS humanitemtype,
479 categories.description AS humancategorycode,
480 COALESCE( localization.translation, itemtypes.description ) AS translated_description
483 ON (itemtypes.itemtype = issuingrules.itemtype)
485 ON (categories.categorycode = issuingrules.categorycode)
486 LEFT JOIN localization ON issuingrules.itemtype = localization.code
487 AND localization.entity = 'itemtypes'
488 AND localization.lang = ?
489 WHERE issuingrules.branchcode = ?
491 $sth2->execute($language, $branch);
493 while (my $row = $sth2->fetchrow_hashref) {
494 $row->{'current_branch'} ||= $row->{'branchcode'};
495 $row->{humanitemtype
} ||= $row->{itemtype
};
496 $row->{default_translated_description
} = 1 if $row->{humanitemtype
} eq '*';
497 $row->{'humancategorycode'} ||= $row->{'categorycode'};
498 $row->{'default_humancategorycode'} = 1 if $row->{'humancategorycode'} eq '*';
499 $row->{'fine'} = sprintf('%.2f', $row->{'fine'});
500 if ($row->{'hardduedate'} && $row->{'hardduedate'} ne '0000-00-00') {
501 my $harddue_dt = eval { dt_from_string
( $row->{'hardduedate'} ) };
502 $row->{'hardduedate'} = eval { output_pref
( { dt
=> $harddue_dt, dateonly
=> 1 } ) } if ( $harddue_dt );
503 $row->{'hardduedatebefore'} = 1 if ($row->{'hardduedatecompare'} == -1);
504 $row->{'hardduedateexact'} = 1 if ($row->{'hardduedatecompare'} == 0);
505 $row->{'hardduedateafter'} = 1 if ($row->{'hardduedatecompare'} == 1);
507 $row->{'hardduedate'} = 0;
509 if ($row->{no_auto_renewal_after_hard_limit
}) {
510 my $dt = eval { dt_from_string
( $row->{no_auto_renewal_after_hard_limit
} ) };
511 $row->{no_auto_renewal_after_hard_limit
} = eval { output_pref
( { dt
=> $dt, dateonly
=> 1 } ) } if $dt;
514 push @row_loop, $row;
517 my @sorted_row_loop = sort by_category_and_itemtype
@row_loop;
520 if ($branch eq "*") {
521 $sth_branch_cat = $dbh->prepare("
522 SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
523 FROM default_borrower_circ_rules
524 JOIN categories USING (categorycode)
527 $sth_branch_cat->execute();
529 $sth_branch_cat = $dbh->prepare("
530 SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
531 FROM branch_borrower_circ_rules
532 JOIN categories USING (categorycode)
533 WHERE branch_borrower_circ_rules.branchcode = ?
535 $sth_branch_cat->execute($branch);
538 my @branch_cat_rules = ();
539 while (my $row = $sth_branch_cat->fetchrow_hashref) {
540 push @branch_cat_rules, $row;
542 my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules;
544 # note undef maxissueqty so that template can deal with them
545 foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
546 $entry->{unlimited_maxissueqty
} = 1 unless defined($entry->{maxissueqty
});
547 $entry->{unlimited_maxonsiteissueqty
} = 1 unless defined($entry->{maxonsiteissueqty
});
550 @sorted_row_loop = sort by_category_and_itemtype
@row_loop;
553 if ($branch eq "*") {
554 $sth_branch_item = $dbh->prepare("
555 SELECT default_branch_item_rules.*,
556 COALESCE( localization.translation, itemtypes.description ) AS translated_description
557 FROM default_branch_item_rules
558 JOIN itemtypes USING (itemtype)
559 LEFT JOIN localization ON itemtypes.itemtype = localization.code
560 AND localization.entity = 'itemtypes'
561 AND localization.lang = ?
563 $sth_branch_item->execute($language);
565 $sth_branch_item = $dbh->prepare("
566 SELECT branch_item_rules.*,
567 COALESCE( localization.translation, itemtypes.description ) AS translated_description
568 FROM branch_item_rules
569 JOIN itemtypes USING (itemtype)
570 LEFT JOIN localization ON itemtypes.itemtype = localization.code
571 AND localization.entity = 'itemtypes'
572 AND localization.lang = ?
573 WHERE branch_item_rules.branchcode = ?
575 $sth_branch_item->execute($language, $branch);
578 my @branch_item_rules = ();
579 while (my $row = $sth_branch_item->fetchrow_hashref) {
580 push @branch_item_rules, $row;
582 my @sorted_branch_item_rules = sort { lc $a->{translated_description
} cmp lc $b->{translated_description
} } @branch_item_rules;
584 # note undef holdallowed so that template can deal with them
585 foreach my $entry (@sorted_branch_item_rules) {
586 $entry->{holdallowed_any
} = 1 if ( $entry->{holdallowed
} == 2 );
587 $entry->{holdallowed_same
} = 1 if ( $entry->{holdallowed
} == 1 );
590 $template->param(show_branch_cat_rule_form
=> 1);
591 $template->param(branch_item_rule_loop
=> \
@sorted_branch_item_rules);
592 $template->param(branch_cat_rule_loop
=> \
@sorted_branch_cat_rules);
595 if ($branch eq "*") {
596 $sth_defaults = $dbh->prepare("
598 FROM default_circ_rules
600 $sth_defaults->execute();
602 $sth_defaults = $dbh->prepare("
604 FROM default_branch_circ_rules
607 $sth_defaults->execute($branch);
610 my $defaults = $sth_defaults->fetchrow_hashref;
613 $template->param( default_holdallowed_none
=> 1 ) if ( $defaults->{holdallowed
} == 0 );
614 $template->param( default_holdallowed_same
=> 1 ) if ( $defaults->{holdallowed
} == 1 );
615 $template->param( default_holdallowed_any
=> 1 ) if ( $defaults->{holdallowed
} == 2 );
616 $template->param( default_hold_fulfillment_policy
=> $defaults->{hold_fulfillment_policy
} );
617 $template->param( default_maxissueqty
=> $defaults->{maxissueqty
} );
618 $template->param( default_maxonsiteissueqty
=> $defaults->{maxonsiteissueqty
} );
619 $template->param( default_returnbranch
=> $defaults->{returnbranch
} );
622 $template->param(default_rules
=> ($defaults ?
1 : 0));
625 patron_categories
=> $patron_categories,
626 itemtypeloop
=> $itemtypes,
627 rules
=> \
@sorted_row_loop,
628 humanbranch
=> ($branch ne '*' ?
$branch : ''),
629 current_branch
=> $branch,
630 definedbranch
=> scalar(@sorted_row_loop)>0
632 output_html_with_http_headers
$input, $cookie, $template->output;
636 # sort by patron category, then item type, putting
637 # default entries at the bottom
638 sub by_category_and_itemtype
{
639 unless (by_category
($a, $b)) {
640 return by_itemtype
($a, $b);
646 if ($a->{'default_humancategorycode'}) {
647 return ($b->{'default_humancategorycode'} ?
0 : 1);
648 } elsif ($b->{'default_humancategorycode'}) {
651 return $a->{'humancategorycode'} cmp $b->{'humancategorycode'};
657 if ($a->{default_translated_description
}) {
658 return ($b->{'default_translated_description'} ?
0 : 1);
659 } elsif ($b->{'default_translated_description'}) {
662 return lc $a->{'translated_description'} cmp lc $b->{'translated_description'};