X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=admin%2Fsmart-rules.pl;h=b3c0727cac6f06224a326df5c1d0a2c9f89bb096;hb=5d6c092921919526ade501facb1220f8a108a08f;hp=f29093411b89f17ec4ea648daf59e3cdc4e377f3;hpb=16f1fffdd1f5d1c97db0bf664f83496864b7e24d;p=koha_fer diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index f29093411b..b3c0727cac 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -18,7 +18,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use strict; -#use warnings; FIXME - Bug 2505 +use warnings; use CGI; use C4::Context; use C4::Output; @@ -28,7 +28,7 @@ use C4::Debug; use C4::Branch; # GetBranches use C4::Dates qw/format_date format_date_in_iso/; -my $input = new CGI; +my $input = CGI->new; my $dbh = C4::Context->dbh; # my $flagsrequired; @@ -38,13 +38,13 @@ my ($template, $loggedinuser, $cookie) query => $input, type => "intranet", authnotrequired => 0, - flagsrequired => {parameters => 1}, + flagsrequired => {parameters => 'manage_circ_rules'}, debug => 1, }); my $type=$input->param('type'); my $branch = $input->param('branch') || ( C4::Branch::onlymine() ? ( C4::Branch::mybranch() || '*' ) : '*' ); -my $op = $input->param('op'); +my $op = $input->param('op') || q{}; if ($op eq 'delete') { my $itemtype = $input->param('itemtype'); @@ -100,41 +100,49 @@ elsif ($op eq 'delete-branch-item') { } # save the values entered elsif ($op eq 'add') { - my $sth_search = $dbh->prepare("SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?"); - my $sth_insert = $dbh->prepare("INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, renewalsallowed, reservesallowed, issuelength, hardduedate, hardduedatecompare, fine, finedays, firstremind, chargeperiod,rentaldiscount) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); - my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, reservesallowed=?, issuelength=?, hardduedate=?, hardduedatecompare=?, rentaldiscount=? WHERE branchcode=? AND categorycode=? AND itemtype=?"); + my $sth_search = $dbh->prepare('SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?'); + my $sth_insert = $dbh->prepare('INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, renewalsallowed, renewalperiod, norenewalbefore, reservesallowed, issuelength, lengthunit, hardduedate, hardduedatecompare, fine, finedays, maxsuspensiondays, firstremind, chargeperiod,rentaldiscount, overduefinescap) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'); + my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, maxsuspensiondays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, renewalperiod=?, norenewalbefore=?, reservesallowed=?, issuelength=?, lengthunit = ?, hardduedate=?, hardduedatecompare=?, rentaldiscount=?, overduefinescap=? WHERE branchcode=? AND categorycode=? AND itemtype=?"); my $br = $branch; # branch my $bor = $input->param('categorycode'); # borrower category my $cat = $input->param('itemtype'); # item type my $fine = $input->param('fine'); my $finedays = $input->param('finedays'); + my $maxsuspensiondays = $input->param('maxsuspensiondays'); + $maxsuspensiondays = undef if $maxsuspensiondays eq q||; my $firstremind = $input->param('firstremind'); my $chargeperiod = $input->param('chargeperiod'); my $maxissueqty = $input->param('maxissueqty'); my $renewalsallowed = $input->param('renewalsallowed'); + my $renewalperiod = $input->param('renewalperiod'); + my $norenewalbefore = $input->param('norenewalbefore'); + $norenewalbefore = undef if $norenewalbefore eq '0' or $norenewalbefore =~ /^\s*$/; my $reservesallowed = $input->param('reservesallowed'); $maxissueqty =~ s/\s//g; $maxissueqty = undef if $maxissueqty !~ /^\d+/; my $issuelength = $input->param('issuelength'); + my $lengthunit = $input->param('lengthunit'); my $hardduedate = $input->param('hardduedate'); $hardduedate = format_date_in_iso($hardduedate); my $hardduedatecompare = $input->param('hardduedatecompare'); my $rentaldiscount = $input->param('rentaldiscount'); + my $overduefinescap = $input->param('overduefinescap') || undef; $debug and warn "Adding $br, $bor, $cat, $fine, $maxissueqty"; $sth_search->execute($br,$bor,$cat); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($fine, $finedays,$firstremind, $chargeperiod, $maxissueqty, $renewalsallowed,$reservesallowed, $issuelength,$hardduedate,$hardduedatecompare,$rentaldiscount, $br,$bor,$cat); + $sth_update->execute($fine, $finedays, $maxsuspensiondays, $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,$reservesallowed,$issuelength,$hardduedate,$hardduedatecompare,$fine,$finedays,$firstremind,$chargeperiod,$rentaldiscount); + $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed, $renewalperiod, $norenewalbefore, $reservesallowed,$issuelength,$lengthunit,$hardduedate,$hardduedatecompare,$fine,$finedays, $maxsuspensiondays, $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; @@ -144,34 +152,34 @@ elsif ($op eq "set-branch-defaults") { 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) - VALUES (?, ?)"); + (maxissueqty, holdallowed, returnbranch) + VALUES (?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_circ_rules - SET maxissueqty = ?, holdallowed = ?"); + SET maxissueqty = ?, holdallowed = ?, returnbranch = ?"); $sth_search->execute(); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($maxissueqty, $holdallowed); + $sth_update->execute($maxissueqty, $holdallowed, $returnbranch); } else { - $sth_insert->execute($maxissueqty, $holdallowed); + $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) - VALUES (?, ?, ?)"); + (branchcode, maxissueqty, holdallowed, returnbranch) + VALUES (?, ?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules - SET maxissueqty = ?, holdallowed = ? + SET maxissueqty = ?, holdallowed = ?, returnbranch = ? WHERE branchcode = ?"); $sth_search->execute($branch); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($maxissueqty, $holdallowed, $branch); + $sth_update->execute($maxissueqty, $holdallowed, $returnbranch, $branch); } else { - $sth_insert->execute($branch, $maxissueqty, $holdallowed); + $sth_insert->execute($branch, $maxissueqty, $holdallowed, $returnbranch); } } } @@ -258,6 +266,7 @@ elsif ($op eq "add-branch-cat") { 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+/; @@ -266,34 +275,34 @@ elsif ($op eq "add-branch-item") { my $sth_search = $dbh->prepare("SELECT count(*) AS total FROM default_circ_rules"); my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules - (holdallowed) - VALUES (?)"); + (holdallowed, returnbranch) + VALUES (?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_circ_rules - SET holdallowed = ?"); + SET holdallowed = ?, returnbranch = ?"); $sth_search->execute(); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($holdallowed); + $sth_update->execute($holdallowed, $returnbranch); } else { - $sth_insert->execute($holdallowed); + $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) - VALUES (?, ?)"); + (itemtype, holdallowed, returnbranch) + VALUES (?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_branch_item_rules - SET holdallowed = ? + SET holdallowed = ?, returnbranch = ? WHERE itemtype = ?"); $sth_search->execute($itemtype); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($holdallowed, $itemtype); + $sth_update->execute($holdallowed, $returnbranch, $itemtype); } else { - $sth_insert->execute($itemtype, $holdallowed); + $sth_insert->execute($itemtype, $holdallowed, $returnbranch); } } } elsif ($itemtype eq "*") { @@ -301,17 +310,17 @@ elsif ($op eq "add-branch-item") { FROM default_branch_circ_rules WHERE branchcode = ?"); my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules - (branchcode, holdallowed) - VALUES (?, ?)"); + (branchcode, holdallowed, returnbranch) + VALUES (?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules - SET holdallowed = ? + SET holdallowed = ?, returnbranch = ? WHERE branchcode = ?"); $sth_search->execute($branch); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($holdallowed, $branch); + $sth_update->execute($holdallowed, $returnbranch, $branch); } else { - $sth_insert->execute($branch, $holdallowed); + $sth_insert->execute($branch, $holdallowed, $returnbranch); } } else { my $sth_search = $dbh->prepare("SELECT count(*) AS total @@ -319,19 +328,19 @@ elsif ($op eq "add-branch-item") { WHERE branchcode = ? AND itemtype = ?"); my $sth_insert = $dbh->prepare("INSERT INTO branch_item_rules - (branchcode, itemtype, holdallowed) - VALUES (?, ?, ?)"); + (branchcode, itemtype, holdallowed, returnbranch) + VALUES (?, ?, ?, ?)"); my $sth_update = $dbh->prepare("UPDATE branch_item_rules - SET holdallowed = ? + SET holdallowed = ?, returnbranch = ? WHERE branchcode = ? AND itemtype = ?"); $sth_search->execute($branch, $itemtype); my $res = $sth_search->fetchrow_hashref(); if ($res->{total}) { - $sth_update->execute($holdallowed, $branch, $itemtype); + $sth_update->execute($holdallowed, $returnbranch, $branch, $itemtype); } else { - $sth_insert->execute($branch, $itemtype, $holdallowed); + $sth_insert->execute($branch, $itemtype, $holdallowed, $returnbranch); } } } @@ -484,6 +493,7 @@ if ($defaults) { $template->param(default_holdallowed_same => 1) if($defaults->{holdallowed} == 1); $template->param(default_holdallowed_any => 1) if($defaults->{holdallowed} == 2); $template->param(default_maxissueqty => $defaults->{maxissueqty}); + $template->param(default_returnbranch => $defaults->{returnbranch}); } $template->param(default_rules => ($defaults ? 1 : 0));