Bug 8015: (follow-up) trap exceptions thrown by SetUTF8Flag()
[koha.git] / tools / overduerules.pl
index e14d1d8..cc90d0b 100755 (executable)
@@ -13,9 +13,9 @@
 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
 use warnings;
@@ -28,7 +28,7 @@ use C4::Branch;
 use C4::Letters;
 use C4::Members;
 
-my $input = new CGI;
+our $input = new CGI;
 my $dbh = C4::Context->dbh;
 
 my @categories = @{$dbh->selectall_arrayref(
@@ -36,7 +36,7 @@ my @categories = @{$dbh->selectall_arrayref(
     { Slice => {} }
 )};
 my @category_codes  = map { $_->{categorycode} } @categories;
-my @rule_params     = qw(delay letter debarred);
+our @rule_params     = qw(delay letter debarred);
 
 # blank_row($category_code) - return true if the entire row is blank.
 sub blank_row {
@@ -86,11 +86,17 @@ if ($op eq 'save') {
     my $sth_delete=$dbh->prepare("DELETE FROM overduerules WHERE branchcode=? AND categorycode=?");
     foreach my $key (@names){
             # ISSUES
-            if ($key =~ /(.*)([1-3])-(.*)/) {
+            if ($key =~ /(delay|letter|debarred)([1-3])-(.*)/) {
                     my $type = $1; # data type
                     my $num = $2; # From 1 to 3
                     my $bor = $3; # borrower category
-                    $temphash{$bor}->{"$type$num"}=$input->param("$key") if (($input->param("$key") ne "") or ($input->param("$key")>0));
+                    my $value = $input->param($key);
+                    if ($type eq 'delay') {
+                        $temphash{$bor}->{"$type$num"} = ($value =~ /^\d+$/ && int($value) > 0) ? int($value) : '';
+                    } else {
+                        # type is letter
+                        $temphash{$bor}->{"$type$num"} = $value if $value ne '';
+                    }
             }
     }
 
@@ -136,13 +142,13 @@ if ($op eq 'save') {
                     my $res = $sth_search->fetchrow_hashref();
                     if ($res->{'total'}>0) {
                         $sth_update->execute(
-                            ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:0),
+                            ($temphash{$bor}->{"delay1"}?$temphash{$bor}->{"delay1"}:undef),
                             ($temphash{$bor}->{"letter1"}?$temphash{$bor}->{"letter1"}:""),
                             ($temphash{$bor}->{"debarred1"}?$temphash{$bor}->{"debarred1"}:0),
-                            ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:0),
+                            ($temphash{$bor}->{"delay2"}?$temphash{$bor}->{"delay2"}:undef),
                             ($temphash{$bor}->{"letter2"}?$temphash{$bor}->{"letter2"}:""),
                             ($temphash{$bor}->{"debarred2"}?$temphash{$bor}->{"debarred2"}:0),
-                            ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:0),
+                            ($temphash{$bor}->{"delay3"}?$temphash{$bor}->{"delay3"}:undef),
                             ($temphash{$bor}->{"letter3"}?$temphash{$bor}->{"letter3"}:""),
                             ($temphash{$bor}->{"debarred3"}?$temphash{$bor}->{"debarred3"}:0),
                             $branch ,$bor