+ $sth_update->execute($fine, $finedays,$firstremind, $chargeperiod, $maxissueqty, $renewalsallowed, $renewalperiod, $norenewalbefore, $reservesallowed, $issuelength,$lengthunit, $hardduedate,$hardduedatecompare,$rentaldiscount,$overduefinescap, $br,$bor,$cat);
+ } else {
+ $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed, $renewalperiod, $norenewalbefore, $reservesallowed,$issuelength,$lengthunit,$hardduedate,$hardduedatecompare,$fine,$finedays,$firstremind,$chargeperiod,$rentaldiscount,$overduefinescap);
+ }
+}
+elsif ($op eq "set-branch-defaults") {
+ my $categorycode = $input->param('categorycode');
+ my $maxissueqty = $input->param('maxissueqty');
+ my $holdallowed = $input->param('holdallowed');
+ my $returnbranch = $input->param('returnbranch');
+ $maxissueqty =~ s/\s//g;
+ $maxissueqty = undef if $maxissueqty !~ /^\d+/;
+ $holdallowed =~ s/\s//g;
+ $holdallowed = undef if $holdallowed !~ /^\d+/;
+
+ if ($branch eq "*") {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM default_circ_rules");
+ my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
+ (maxissueqty, holdallowed, returnbranch)
+ VALUES (?, ?, ?)");
+ my $sth_update = $dbh->prepare("UPDATE default_circ_rules
+ SET maxissueqty = ?, holdallowed = ?, returnbranch = ?");
+
+ $sth_search->execute();
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($maxissueqty, $holdallowed, $returnbranch);
+ } else {
+ $sth_insert->execute($maxissueqty, $holdallowed, $returnbranch);
+ }
+ } else {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM default_branch_circ_rules
+ WHERE branchcode = ?");
+ my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
+ (branchcode, maxissueqty, holdallowed, returnbranch)
+ VALUES (?, ?, ?, ?)");
+ my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
+ SET maxissueqty = ?, holdallowed = ?, returnbranch = ?
+ WHERE branchcode = ?");
+ $sth_search->execute($branch);
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($maxissueqty, $holdallowed, $returnbranch, $branch);
+ } else {
+ $sth_insert->execute($branch, $maxissueqty, $holdallowed, $returnbranch);
+ }
+ }
+}
+elsif ($op eq "add-branch-cat") {
+ my $categorycode = $input->param('categorycode');
+ my $maxissueqty = $input->param('maxissueqty');
+ $maxissueqty =~ s/\s//g;
+ $maxissueqty = undef if $maxissueqty !~ /^\d+/;
+
+ if ($branch eq "*") {
+ if ($categorycode eq "*") {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM default_circ_rules");
+ my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
+ (maxissueqty)
+ VALUES (?)");
+ my $sth_update = $dbh->prepare("UPDATE default_circ_rules
+ SET maxissueqty = ?");
+
+ $sth_search->execute();
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($maxissueqty);
+ } else {
+ $sth_insert->execute($maxissueqty);
+ }
+ } else {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM default_borrower_circ_rules
+ WHERE categorycode = ?");
+ my $sth_insert = $dbh->prepare("INSERT INTO default_borrower_circ_rules
+ (categorycode, maxissueqty)
+ VALUES (?, ?)");
+ my $sth_update = $dbh->prepare("UPDATE default_borrower_circ_rules
+ SET maxissueqty = ?
+ WHERE categorycode = ?");
+ $sth_search->execute($branch);
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($maxissueqty, $categorycode);
+ } else {
+ $sth_insert->execute($categorycode, $maxissueqty);
+ }
+ }
+ } elsif ($categorycode eq "*") {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM default_branch_circ_rules
+ WHERE branchcode = ?");
+ my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
+ (branchcode, maxissueqty)
+ VALUES (?, ?)");
+ my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
+ SET maxissueqty = ?
+ WHERE branchcode = ?");
+ $sth_search->execute($branch);
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($maxissueqty, $branch);
+ } else {
+ $sth_insert->execute($branch, $maxissueqty);
+ }
+ } else {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM branch_borrower_circ_rules
+ WHERE branchcode = ?
+ AND categorycode = ?");
+ my $sth_insert = $dbh->prepare("INSERT INTO branch_borrower_circ_rules
+ (branchcode, categorycode, maxissueqty)
+ VALUES (?, ?, ?)");
+ my $sth_update = $dbh->prepare("UPDATE branch_borrower_circ_rules
+ SET maxissueqty = ?
+ WHERE branchcode = ?
+ AND categorycode = ?");
+
+ $sth_search->execute($branch, $categorycode);
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($maxissueqty, $branch, $categorycode);
+ } else {
+ $sth_insert->execute($branch, $categorycode, $maxissueqty);
+ }
+ }
+}
+elsif ($op eq "add-branch-item") {
+ my $itemtype = $input->param('itemtype');
+ my $holdallowed = $input->param('holdallowed');
+ my $returnbranch = $input->param('returnbranch');
+ $holdallowed =~ s/\s//g;
+ $holdallowed = undef if $holdallowed !~ /^\d+/;
+
+ if ($branch eq "*") {
+ if ($itemtype eq "*") {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM default_circ_rules");
+ my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules
+ (holdallowed, returnbranch)
+ VALUES (?, ?)");
+ my $sth_update = $dbh->prepare("UPDATE default_circ_rules
+ SET holdallowed = ?, returnbranch = ?");
+
+ $sth_search->execute();
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($holdallowed, $returnbranch);
+ } else {
+ $sth_insert->execute($holdallowed, $returnbranch);
+ }
+ } else {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM default_branch_item_rules
+ WHERE itemtype = ?");
+ my $sth_insert = $dbh->prepare("INSERT INTO default_branch_item_rules
+ (itemtype, holdallowed, returnbranch)
+ VALUES (?, ?, ?)");
+ my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules
+ SET holdallowed = ?, returnbranch = ?
+ WHERE itemtype = ?");
+ $sth_search->execute($itemtype);
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($holdallowed, $returnbranch, $itemtype);
+ } else {
+ $sth_insert->execute($itemtype, $holdallowed, $returnbranch);
+ }
+ }
+ } elsif ($itemtype eq "*") {
+ my $sth_search = $dbh->prepare("SELECT count(*) AS total
+ FROM default_branch_circ_rules
+ WHERE branchcode = ?");
+ my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules
+ (branchcode, holdallowed, returnbranch)
+ VALUES (?, ?, ?)");
+ my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules
+ SET holdallowed = ?, returnbranch = ?
+ WHERE branchcode = ?");
+ $sth_search->execute($branch);
+ my $res = $sth_search->fetchrow_hashref();
+ if ($res->{total}) {
+ $sth_update->execute($holdallowed, $returnbranch, $branch);
+ } else {
+ $sth_insert->execute($branch, $holdallowed, $returnbranch);
+ }