Spanish and Turkish updates
[koha.git] / admin / branches.pl
index 0b7532c..f2bc827 100755 (executable)
@@ -44,6 +44,7 @@ FIXME: looped html (e.g., list of checkboxes) need to be properly
 =cut
 
 use strict;
+use warnings;
 use CGI;
 use C4::Auth;
 use C4::Context;
@@ -63,6 +64,10 @@ my $branchname   = $input->param('branchname');
 my $categorycode = $input->param('categorycode');
 my $op           = $input->param('op');
 
+if(!defined($op)){
+  $op = '';
+}
+
 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
     {
         template_name   => "admin/branches.tmpl",
@@ -109,9 +114,18 @@ 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) {
+            # copy input parameters back to form
+            # FIXME - doing this doesn't preserve any branch group selections, but good enough for now
+            $template->param(%$params);
+            $template->param(branch_name => $params->{branchname});
+            $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' ) {
@@ -226,8 +240,10 @@ sub editbranchform {
 
         #      printer loop
         foreach my $thisprinter ( keys %$printers ) {
+
             my $selected = 1
-              if $oldprinter eq $printers->{$thisprinter}->{'printqueue'};
+              if $oldprinter and ( $oldprinter eq $printers->{$thisprinter} );
+
             my %row = (
                 value         => $thisprinter,
                 selected      => $selected,
@@ -282,6 +298,7 @@ sub editbranchform {
           {
             categoryname    => $cat->{'categoryname'},
             categorycode    => $cat->{'categorycode'},
+            categorytype    => $cat->{'categorytype'},
             codedescription => $cat->{'codedescription'},
             checked         => $checked,
           };
@@ -303,13 +320,19 @@ sub editcatform {
     my ($categorycode,$innertemplate) = @_;
     warn "cat : $categorycode";
     my $data;
-    if ($categorycode) {
+       my @cats;
+    $innertemplate->param( categorytype => \@cats);
+       if ($categorycode) {
         $data = GetBranchCategory($categorycode);
         $data = $data->[0];
-        $innertemplate->param( categorycode    => $data->{'categorycode'} );
-        $innertemplate->param( categoryname    => $data->{'categoryname'} );
-        $innertemplate->param( codedescription => $data->{'codedescription'} );
+        $innertemplate->param( categorycode    => $data->{'categorycode'} ,
+                                       categoryname    => $data->{'categoryname'},
+                                       codedescription => $data->{'codedescription'} ,
+                                               );
     }
+       for my $ctype (GetCategoryTypes()) {
+               push @cats , { type => $ctype , selected => ($data->{'categorytype'} eq $ctype) };
+       }
 }
 
 sub deleteconfirm {
@@ -331,7 +354,7 @@ sub branchinfotable {
         $branchinfo = GetBranchInfo();
     }
     my $toggle;
-    my $i;
+    my $i = 0;
     my @loop_data = ();
     foreach my $branch (@$branchinfo) {
         ( $i % 2 ) ? ( $toggle = 1 ) : ( $toggle = 0 );
@@ -408,20 +431,20 @@ sub branchinfotable {
         $i++;
     }
     my @branchcategories = ();
-    my $catinfo          = GetBranchCategory();
-    $i = 0;
-    foreach my $cat (@$catinfo) {
-        ( $i % 2 ) ? ( $toggle = 1 ) : ( $toggle = 0 );
-        push @branchcategories,
-          {
-            toggle          => $toggle,
-            categoryname    => $cat->{'categoryname'},
-            categorycode    => $cat->{'categorycode'},
-            codedescription => $cat->{'codedescription'},
-          };
-        $i++;
-    }
-
+       for my $ctype ( GetCategoryTypes() ) {
+       my $catinfo = GetBranchCategories(undef,$ctype);
+       my @categories;
+               foreach my $cat (@$catinfo) {
+               push @categories,
+                 {
+                   categoryname    => $cat->{'categoryname'},
+                   categorycode    => $cat->{'categorycode'},
+                   codedescription => $cat->{'codedescription'},
+                   categorytype => $cat->{'categorytype'},
+                 };
+       }
+       push @branchcategories, { categorytype => $ctype , $ctype => 1 , catloop => \@categories};
+       }
     $innertemplate->param(
         branches         => \@loop_data,
         branchcategories => \@branchcategories
@@ -429,7 +452,7 @@ sub branchinfotable {
 
 }
 
-# FIXME logic seems wrong
+# FIXME logic seems wrong   ##  sub is not used.
 sub branchcategoriestable {
     my $innertemplate = shift;
     #Needs to be implemented...
@@ -443,12 +466,6 @@ sub branchcategoriestable {
     }
 }
 
-$template->param(
-    intranetcolorstylesheet =>
-      C4::Context->preference("intranetcolorstylesheet"),
-    intranetstylesheet => C4::Context->preference("intranetstylesheet"),
-    IntranetNav        => C4::Context->preference("IntranetNav"),
-);
 output_html_with_http_headers $input, $cookie, $template->output;
 
 # Local Variables: