Bug 9573: Lost items report - Add a new itemlost_on column
[koha.git] / admin / classsources.pl
index 6ca29d0..ff6d86e 100755 (executable)
@@ -4,22 +4,21 @@
 #
 # This file is part of Koha.
 #
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
 #
-# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
-# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
-# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY 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.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
 #
 
-use strict;
-#use warnings; FIXME - Bug 2505
+use Modern::Perl;
 use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Context;
@@ -34,7 +33,7 @@ my $input = new CGI;
 my $op          = $input->param('op') || '';
 my $source_code = $input->param('class_source');
 my $rule_code   = $input->param('sort_rule');
-
+my $sort_routine = $input->param('sort_routine');
 my ($template, $loggedinuser, $cookie)
     = get_template_and_user({template_name => "admin/classsources.tt",
                  query => $input,
@@ -46,19 +45,20 @@ my ($template, $loggedinuser, $cookie)
 
 $template->param(script_name => $script_name);
 $template->param($op => 1) if $op;
-
+my $description = $input->param('description');
+my $used = $input->param('used');
 my $display_lists = 0;
 if ($op eq "add_source") {
     add_class_source_form($template);
 } elsif ($op eq "add_source_confirmed") {
     add_class_source($template,
                      $source_code,
-                     $input->param('description'),
-                     $input->param('used') eq "used" ? 1 : 0,
+                     $description,
+                     $used eq "used" ? 1 : 0,
                      $rule_code);
     $display_lists = 1;
 } elsif ($op eq "delete_source") {
-    delete_class_source_form($template);
+    delete_class_source_form($template, $source_code);
 } elsif ($op eq "delete_source_confirmed") {
     delete_class_source($template, $source_code);
     $display_lists = 1;
@@ -67,8 +67,8 @@ if ($op eq "add_source") {
 } elsif ($op eq "edit_source_confirmed") {
     edit_class_source($template,
                      $source_code,
-                     $input->param('description'),
-                     $input->param('used') eq "used" ? 1 : 0,
+                     $description,
+                     $used eq "used" ? 1 : 0,
                      $rule_code);
     $display_lists = 1;
 } elsif ($op eq "add_sort_rule") {
@@ -76,8 +76,8 @@ if ($op eq "add_source") {
 } elsif ($op eq "add_sort_rule_confirmed") {
     add_class_sort_rule($template,
                         $rule_code,
-                        $input->param('description'),
-                        $input->param('sort_routine'));
+                        $description,
+                        $sort_routine);
     $display_lists = 1;
 } elsif ($op eq "delete_sort_rule") {
     delete_sort_rule_form($template, $rule_code);
@@ -89,8 +89,8 @@ if ($op eq "add_source") {
 } elsif ($op eq "edit_sort_rule_confirmed") {
     edit_class_sort_rule($template,
                          $rule_code,
-                         $input->param('description'),
-                         $input->param('sort_routine'));
+                         $description,
+                         $sort_routine);
     $display_lists = 1;
 } else {
     $display_lists = 1;
@@ -118,8 +118,12 @@ sub add_class_source_form {
 
 sub add_class_source {
     my ($template, $source_code, $description, $used, $sort_rule) = @_;
-    AddClassSource($source_code, $description, $used, $sort_rule);
-    $template->param(added_source => $source_code);
+    my $success = AddClassSource($source_code, $description, $used, $sort_rule);
+    if ($success > 0) {
+        $template->param(added_source => $source_code);
+    } else {
+        $template->param(failed_add_source => $source_code);
+    }
 }
 
 sub edit_class_source_form {
@@ -146,7 +150,7 @@ sub edit_class_source {
 
 
 sub delete_class_source_form {
-    my ($template) = @_;
+    my ($template, $source_code) = @_;
     $template->param(
         delete_class_source_form => 1,
         confirm_op   => "delete_source_confirmed",
@@ -189,8 +193,12 @@ sub add_class_sort_rule_form {
 
 sub add_class_sort_rule {
     my ($template, $rule_code, $description, $sort_routine) = @_;
-    AddClassSortRule($rule_code, $description, $sort_routine);
-    $template->param(added_rule => $rule_code);
+    my $success = AddClassSortRule($rule_code, $description, $sort_routine);
+    if ($success > 0) {
+        $template->param(added_rule => $rule_code);
+    } else {
+        $template->param(failed_add_rule => $rule_code);
+    }
 }
 
 sub delete_sort_rule_form {