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 $suspension_chargeperiod = $input->param('suspension_chargeperiod') || 1;
129 my $firstremind = $input->param('firstremind');
130 my $chargeperiod = $input->param('chargeperiod');
131 my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at');
132 my $maxissueqty = $input->param('maxissueqty');
133 my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
134 my $renewalsallowed = $input->param('renewalsallowed');
135 my $renewalperiod = $input->param('renewalperiod');
136 my $norenewalbefore = $input->param('norenewalbefore');
137 $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
138 my $auto_renew = $input->param('auto_renew') eq 'yes' ?
1 : 0;
139 my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
140 $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/;
141 my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || undef;
142 $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 );
143 $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 );
144 my $reservesallowed = $input->param('reservesallowed');
145 my $holds_per_record = $input->param('holds_per_record');
146 my $onshelfholds = $input->param('onshelfholds') || 0;
147 $maxissueqty =~ s/\s//g;
148 $maxissueqty = undef if $maxissueqty !~ /^\d+/;
149 $maxonsiteissueqty =~ s/\s//g;
150 $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
151 my $issuelength = $input->param('issuelength');
152 $issuelength = $issuelength eq q{} ?
undef : $issuelength;
153 my $lengthunit = $input->param('lengthunit');
154 my $hardduedate = $input->param('hardduedate') || undef;
155 $hardduedate = eval { dt_from_string
( $input->param('hardduedate') ) } if ( $hardduedate );
156 $hardduedate = output_pref
( { dt
=> $hardduedate, dateonly
=> 1, dateformat
=> 'iso' } ) if ( $hardduedate );
157 my $hardduedatecompare = $input->param('hardduedatecompare');
158 my $rentaldiscount = $input->param('rentaldiscount');
159 my $opacitemholds = $input->param('opacitemholds') || 0;
160 my $article_requests = $input->param('article_requests') || 'no';
161 my $overduefinescap = $input->param('overduefinescap') || undef;
162 my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
163 $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
167 categorycode
=> $bor,
168 itemtype
=> $itemtype,
170 finedays
=> $finedays,
171 maxsuspensiondays
=> $maxsuspensiondays,
172 suspension_chargeperiod
=> $suspension_chargeperiod,
173 firstremind
=> $firstremind,
174 chargeperiod
=> $chargeperiod,
175 chargeperiod_charge_at
=> $chargeperiod_charge_at,
176 maxissueqty
=> $maxissueqty,
177 maxonsiteissueqty
=> $maxonsiteissueqty,
178 renewalsallowed
=> $renewalsallowed,
179 renewalperiod
=> $renewalperiod,
180 norenewalbefore
=> $norenewalbefore,
181 auto_renew
=> $auto_renew,
182 no_auto_renewal_after
=> $no_auto_renewal_after,
183 no_auto_renewal_after_hard_limit
=> $no_auto_renewal_after_hard_limit,
184 reservesallowed
=> $reservesallowed,
185 holds_per_record
=> $holds_per_record,
186 issuelength
=> $issuelength,
187 lengthunit
=> $lengthunit,
188 hardduedate
=> $hardduedate,
189 hardduedatecompare
=> $hardduedatecompare,
190 rentaldiscount
=> $rentaldiscount,
191 onshelfholds
=> $onshelfholds,
192 opacitemholds
=> $opacitemholds,
193 overduefinescap
=> $overduefinescap,
194 cap_fine_to_replacement_price
=> $cap_fine_to_replacement_price,
195 article_requests
=> $article_requests,
198 my $issuingrule = Koha
::IssuingRules
->find({categorycode
=> $bor, itemtype
=> $itemtype, branchcode
=> $br});
200 $issuingrule->set($params)->store();
202 Koha
::IssuingRule
->new()->set($params)->store();
206 elsif ($op eq "set-branch-defaults") {
207 my $categorycode = $input->param('categorycode');
208 my $maxissueqty = $input->param('maxissueqty');
209 my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
210 my $holdallowed = $input->param('holdallowed');
211 my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
212 my $returnbranch = $input->param('returnbranch');
213 $maxissueqty =~ s/\s//g;
214 $maxissueqty = undef if $maxissueqty !~ /^\d+/;
215 $maxonsiteissueqty =~ s/\s//g;
216 $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
217 $holdallowed =~ s/\s//g;
218 $holdallowed = undef if $holdallowed !~ /^\d+/;
220 if ($branch eq "*") {
221 my $sth_search = $dbh->prepare("SELECT count(*) AS total
222 FROM default_circ_rules");
223 my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
224 (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
225 VALUES (?, ?, ?, ?, ?)");
226 my $sth_update = $dbh->prepare("UPDATE default_circ_rules
227 SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
229 $sth_search->execute();
230 my $res = $sth_search->fetchrow_hashref();
232 $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
234 $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
237 my $sth_search = $dbh->prepare("SELECT count(*) AS total
238 FROM default_branch_circ_rules
239 WHERE branchcode = ?");
240 my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
241 (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch)
242 VALUES (?, ?, ?, ?, ?, ?)");
243 my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
244 SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
245 WHERE branchcode = ?");
246 $sth_search->execute($branch);
247 my $res = $sth_search->fetchrow_hashref();
249 $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
251 $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch);
255 elsif ($op eq "add-branch-cat") {
256 my $categorycode = $input->param('categorycode');
257 my $maxissueqty = $input->param('maxissueqty');
258 my $maxonsiteissueqty = $input->param('maxonsiteissueqty');
259 $maxissueqty =~ s/\s//g;
260 $maxissueqty = undef if $maxissueqty !~ /^\d+/;
261 $maxonsiteissueqty =~ s/\s//g;
262 $maxonsiteissueqty = undef if $maxonsiteissueqty !~ /^\d+/;
264 if ($branch eq "*") {
265 if ($categorycode eq "*") {
266 my $sth_search = $dbh->prepare("SELECT count(*) AS total
267 FROM default_circ_rules");
268 my $sth_insert = $dbh->prepare(q
|
269 INSERT INTO default_circ_rules
270 (maxissueqty
, maxonsiteissueqty
)
273 my $sth_update = $dbh->prepare(q
|
274 UPDATE default_circ_rules
276 maxonsiteissueqty
= ?
279 $sth_search->execute();
280 my $res = $sth_search->fetchrow_hashref();
282 $sth_update->execute($maxissueqty, $maxonsiteissueqty);
284 $sth_insert->execute($maxissueqty, $maxonsiteissueqty);
287 my $sth_search = $dbh->prepare("SELECT count(*) AS total
288 FROM default_borrower_circ_rules
289 WHERE categorycode = ?");
290 my $sth_insert = $dbh->prepare(q
|
291 INSERT INTO default_borrower_circ_rules
292 (categorycode
, maxissueqty
, maxonsiteissueqty
)
295 my $sth_update = $dbh->prepare(q
|
296 UPDATE default_borrower_circ_rules
298 maxonsiteissueqty
= ?
299 WHERE categorycode
= ?
301 $sth_search->execute($categorycode);
302 my $res = $sth_search->fetchrow_hashref();
304 $sth_update->execute($maxissueqty, $maxonsiteissueqty, $categorycode);
306 $sth_insert->execute($categorycode, $maxissueqty, $maxonsiteissueqty);
309 } elsif ($categorycode eq "*") {
310 my $sth_search = $dbh->prepare("SELECT count(*) AS total
311 FROM default_branch_circ_rules
312 WHERE branchcode = ?");
313 my $sth_insert = $dbh->prepare(q
|
314 INSERT INTO default_branch_circ_rules
315 (branchcode
, maxissueqty
, maxonsiteissueqty
)
318 my $sth_update = $dbh->prepare(q
|
319 UPDATE default_branch_circ_rules
321 maxonsiteissueqty
= ?
324 $sth_search->execute($branch);
325 my $res = $sth_search->fetchrow_hashref();
327 $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch);
329 $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty);
332 my $sth_search = $dbh->prepare("SELECT count(*) AS total
333 FROM branch_borrower_circ_rules
335 AND categorycode = ?");
336 my $sth_insert = $dbh->prepare(q
|
337 INSERT INTO branch_borrower_circ_rules
338 (branchcode
, categorycode
, maxissueqty
, maxonsiteissueqty
)
341 my $sth_update = $dbh->prepare(q
|
342 UPDATE branch_borrower_circ_rules
344 maxonsiteissueqty
= ?
349 $sth_search->execute($branch, $categorycode);
350 my $res = $sth_search->fetchrow_hashref();
352 $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode);
354 $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty);
358 elsif ($op eq "add-branch-item") {
359 my $itemtype = $input->param('itemtype');
360 my $holdallowed = $input->param('holdallowed');
361 my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy');
362 my $returnbranch = $input->param('returnbranch');
364 $holdallowed =~ s/\s//g;
365 $holdallowed = undef if $holdallowed !~ /^\d+/;
367 if ($branch eq "*") {
368 if ($itemtype eq "*") {
369 my $sth_search = $dbh->prepare("SELECT count(*) AS total
370 FROM default_circ_rules");
371 my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
372 (holdallowed, hold_fulfillment_policy, returnbranch)
374 my $sth_update = $dbh->prepare("UPDATE default_circ_rules
375 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?");
377 $sth_search->execute();
378 my $res = $sth_search->fetchrow_hashref();
380 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
382 $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch);
385 my $sth_search = $dbh->prepare("SELECT count(*) AS total
386 FROM default_branch_item_rules
387 WHERE itemtype = ?");
388 my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
389 (itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
390 VALUES (?, ?, ?, ?)");
391 my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
392 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
393 WHERE itemtype = ?");
394 $sth_search->execute($itemtype);
395 my $res = $sth_search->fetchrow_hashref();
397 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $itemtype);
399 $sth_insert->execute($itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
402 } elsif ($itemtype eq "*") {
403 my $sth_search = $dbh->prepare("SELECT count(*) AS total
404 FROM default_branch_circ_rules
405 WHERE branchcode = ?");
406 my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
407 (branchcode, holdallowed, hold_fulfillment_policy, returnbranch)
408 VALUES (?, ?, ?, ?)");
409 my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
410 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
411 WHERE branchcode = ?");
412 $sth_search->execute($branch);
413 my $res = $sth_search->fetchrow_hashref();
415 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch);
417 $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch);
420 my $sth_search = $dbh->prepare("SELECT count(*) AS total
421 FROM branch_item_rules
424 my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules
425 (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch)
426 VALUES (?, ?, ?, ?, ?)");
427 my $sth_update = $dbh->prepare("UPDATE branch_item_rules
428 SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?
432 $sth_search->execute($branch, $itemtype);
433 my $res = $sth_search->fetchrow_hashref();
435 $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch, $itemtype);
437 $sth_insert->execute($branch, $itemtype, $holdallowed, $hold_fulfillment_policy, $returnbranch);
441 elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) {
443 my $refund = $input->param('refund');
445 if ( $refund eq '*' ) {
446 if ( $branch ne '*' ) {
447 # only do something for $refund eq '*' if branch-specific
449 # Delete it so it picks the default
450 Koha
::RefundLostItemFeeRules
->find({
451 branchcode
=> $branch
457 Koha
::RefundLostItemFeeRules
->find({
458 branchcode
=> $branch
459 }) // Koha
::RefundLostItemFeeRule
->new;
461 branchcode
=> $branch,
467 my $refundLostItemFeeRule = Koha
::RefundLostItemFeeRules
->find({ branchcode
=> $branch });
469 refundLostItemFeeRule
=> $refundLostItemFeeRule,
470 defaultRefundRule
=> Koha
::RefundLostItemFeeRules
->_default_rule
473 my $patron_categories = Koha
::Patron
::Categories
->search({}, { order_by
=> ['description'] });
476 my $itemtypes = Koha
::ItemTypes
->search_with_localization;
478 my $sth2 = $dbh->prepare("
479 SELECT issuingrules.*,
480 itemtypes.description AS humanitemtype,
481 categories.description AS humancategorycode,
482 COALESCE( localization.translation, itemtypes.description ) AS translated_description
485 ON (itemtypes.itemtype = issuingrules.itemtype)
487 ON (categories.categorycode = issuingrules.categorycode)
488 LEFT JOIN localization ON issuingrules.itemtype = localization.code
489 AND localization.entity = 'itemtypes'
490 AND localization.lang = ?
491 WHERE issuingrules.branchcode = ?
493 $sth2->execute($language, $branch);
495 while (my $row = $sth2->fetchrow_hashref) {
496 $row->{'current_branch'} ||= $row->{'branchcode'};
497 $row->{humanitemtype
} ||= $row->{itemtype
};
498 $row->{default_translated_description
} = 1 if $row->{humanitemtype
} eq '*';
499 $row->{'humancategorycode'} ||= $row->{'categorycode'};
500 $row->{'default_humancategorycode'} = 1 if $row->{'humancategorycode'} eq '*';
501 $row->{'fine'} = sprintf('%.2f', $row->{'fine'});
502 if ($row->{'hardduedate'} && $row->{'hardduedate'} ne '0000-00-00') {
503 my $harddue_dt = eval { dt_from_string
( $row->{'hardduedate'} ) };
504 $row->{'hardduedate'} = eval { output_pref
( { dt
=> $harddue_dt, dateonly
=> 1 } ) } if ( $harddue_dt );
505 $row->{'hardduedatebefore'} = 1 if ($row->{'hardduedatecompare'} == -1);
506 $row->{'hardduedateexact'} = 1 if ($row->{'hardduedatecompare'} == 0);
507 $row->{'hardduedateafter'} = 1 if ($row->{'hardduedatecompare'} == 1);
509 $row->{'hardduedate'} = 0;
511 if ($row->{no_auto_renewal_after_hard_limit
}) {
512 my $dt = eval { dt_from_string
( $row->{no_auto_renewal_after_hard_limit
} ) };
513 $row->{no_auto_renewal_after_hard_limit
} = eval { output_pref
( { dt
=> $dt, dateonly
=> 1 } ) } if $dt;
516 push @row_loop, $row;
519 my @sorted_row_loop = sort by_category_and_itemtype
@row_loop;
522 if ($branch eq "*") {
523 $sth_branch_cat = $dbh->prepare("
524 SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode
525 FROM default_borrower_circ_rules
526 JOIN categories USING (categorycode)
529 $sth_branch_cat->execute();
531 $sth_branch_cat = $dbh->prepare("
532 SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode
533 FROM branch_borrower_circ_rules
534 JOIN categories USING (categorycode)
535 WHERE branch_borrower_circ_rules.branchcode = ?
537 $sth_branch_cat->execute($branch);
540 my @branch_cat_rules = ();
541 while (my $row = $sth_branch_cat->fetchrow_hashref) {
542 push @branch_cat_rules, $row;
544 my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules;
546 # note undef maxissueqty so that template can deal with them
547 foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) {
548 $entry->{unlimited_maxissueqty
} = 1 unless defined($entry->{maxissueqty
});
549 $entry->{unlimited_maxonsiteissueqty
} = 1 unless defined($entry->{maxonsiteissueqty
});
552 @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);
594 $template->param(branch_cat_rule_loop
=> \
@sorted_branch_cat_rules);
597 if ($branch eq "*") {
598 $sth_defaults = $dbh->prepare("
600 FROM default_circ_rules
602 $sth_defaults->execute();
604 $sth_defaults = $dbh->prepare("
606 FROM default_branch_circ_rules
609 $sth_defaults->execute($branch);
612 my $defaults = $sth_defaults->fetchrow_hashref;
615 $template->param( default_holdallowed_none
=> 1 ) if ( $defaults->{holdallowed
} == 0 );
616 $template->param( default_holdallowed_same
=> 1 ) if ( $defaults->{holdallowed
} == 1 );
617 $template->param( default_holdallowed_any
=> 1 ) if ( $defaults->{holdallowed
} == 2 );
618 $template->param( default_hold_fulfillment_policy
=> $defaults->{hold_fulfillment_policy
} );
619 $template->param( default_maxissueqty
=> $defaults->{maxissueqty
} );
620 $template->param( default_maxonsiteissueqty
=> $defaults->{maxonsiteissueqty
} );
621 $template->param( default_returnbranch
=> $defaults->{returnbranch
} );
624 $template->param(default_rules
=> ($defaults ?
1 : 0));
627 patron_categories
=> $patron_categories,
628 itemtypeloop
=> $itemtypes,
629 rules
=> \
@sorted_row_loop,
630 humanbranch
=> ($branch ne '*' ?
$branch : ''),
631 current_branch
=> $branch,
632 definedbranch
=> scalar(@sorted_row_loop)>0
634 output_html_with_http_headers
$input, $cookie, $template->output;
638 # sort by patron category, then item type, putting
639 # default entries at the bottom
640 sub by_category_and_itemtype
{
641 unless (by_category
($a, $b)) {
642 return by_itemtype
($a, $b);
648 if ($a->{'default_humancategorycode'}) {
649 return ($b->{'default_humancategorycode'} ?
0 : 1);
650 } elsif ($b->{'default_humancategorycode'}) {
653 return $a->{'humancategorycode'} cmp $b->{'humancategorycode'};
659 if ($a->{default_translated_description
}) {
660 return ($b->{'default_translated_description'} ?
0 : 1);
661 } elsif ($b->{'default_translated_description'}) {
664 return lc $a->{'translated_description'} cmp lc $b->{'translated_description'};