fix for #2884: Add error management to branches
authorPaul Poulain <paul.poulain@biblibre.com>
Thu, 28 May 2009 16:32:16 +0000 (18:32 +0200)
committerGalen Charlton <galen.charlton@liblime.com>
Fri, 29 May 2009 00:55:09 +0000 (19:55 -0500)
While trying to add a new Branch with an existing Branch code, the UI says "Library saved" instead of something such as "Please select a unique branch code".

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
C4/Branch.pm
admin/branches.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tmpl

index 73cd5fd..29b1a93 100644 (file)
@@ -177,9 +177,9 @@ sub GetBranchName {
 
 =head2 ModBranch
 
-&ModBranch($newvalue);
+$error = &ModBranch($newvalue);
 
-This function modify an existing branches.
+This function modify an existing branch
 
 C<$newvalue> is a ref to an array wich is containt all the column from branches table.
 
@@ -205,6 +205,7 @@ sub ModBranch {
             $data->{'branchfax'},        $data->{'branchemail'},
             $data->{'branchip'},         $data->{'branchprinter'},
         );
+        return 1 if $dbh->err;
     } else {
         my $query  = "
             UPDATE branches
index c2f37f7..9c6b2e9 100755 (executable)
@@ -114,9 +114,15 @@ elsif ( $op eq 'add_validate' ) {
         default("MESSAGE1",$template);
     }
     else {
-        ModBranch($params);
-        $template->param( else => 1 );
-        default("MESSAGE2",$template);
+        my $error = ModBranch($params);
+        # if error saving, stay on edit and rise error
+        if ($error) {
+            editbranchform($branchcode,$template);
+            $template->param( 'heading-branches-add-branch-p' => 1, 'add' => 1, "ERROR$error" => 1 );
+        } else {
+            $template->param( else => 1);
+            default("MESSAGE2",$template);
+        }
     }
 }
 elsif ( $op eq 'delete' ) {
index 5068691..5fbc653 100644 (file)
@@ -59,6 +59,7 @@
 <!-- /TMPL_IF -->
 
 <!-- TMPL_IF name="add" -->
+    <!-- TMPL_IF name="ERROR1" --><div class="dialog message">Code already exist &mdash; Please enter a unique code</div><!-- /TMPL_IF -->
   <h3><!-- TMPL_IF name="heading-branches-add-branch-p" -->New library<!-- TMPL_ELSE -->Modify library<!-- /TMPL_IF --></h3>
     <form action="<!-- TMPL_VAR name="action" -->" name="Aform" method="post">
        <fieldset class="rows">
@@ -69,7 +70,7 @@
             <input type="hidden" name="add" value="0" />
         <!-- /TMPL_IF -->
         <ol><li>
-            <!-- TMPL_IF name="branchcode" -->
+            <!-- TMPL_IF name="heading-branches-add-p" -->
                        <span class="label">Library code</span>
                 <input type="hidden" name="branchcode" value="<!-- TMPL_VAR name="branchcode" escape="HTML" -->" />
                 <!-- TMPL_VAR name="branchcode" -->