Fix for Bug 6578, serial items have misaligned columns in holdings table
[koha.git] / labels / label-edit-layout.pl
index f47e8e6..6a70212 100755 (executable)
@@ -4,7 +4,7 @@
 # Parts Copyright 2009 Foundations Bible College.
 #
 # 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
@@ -14,9 +14,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;
@@ -27,8 +27,8 @@ use Text::CSV_XS;
 
 use C4::Auth qw(get_template_and_user);
 use C4::Output qw(output_html_with_http_headers);
-use C4::Labels::Lib 1.000000 qw(get_barcode_types get_label_types get_font_types get_text_justification_types);
-use C4::Labels::Layout 1.000000;
+use C4::Creators 1.000000;
+use C4::Labels 1.000000;
 
 my $cgi = new CGI;
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@@ -44,6 +44,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 
 my $op = $cgi->param('op') || $ARGV[0] || '';
 my $layout_id = $cgi->param('layout_id') || $cgi->param('element_id') || $ARGV[1] || '';
+my $layout_choice = $cgi->param('layout_choice') || '';
 my $layout = '';
 
 sub _set_selected {
@@ -108,7 +109,7 @@ if ($op eq 'edit') {
 }
 elsif  ($op eq 'save') {
     my $format_string = '';
-    if ($cgi->param('layout_choice') eq 'layout_table') {       # translate the field table into a format_string
+    if ($layout_choice eq 'layout_table') {       # translate the field table into a format_string
         my @layout_table = ();
         foreach my $cgi_param ($cgi->param()) {
             if (($cgi_param =~ m/^(.*)_tbl$/) && ($cgi->param($cgi_param))) {
@@ -121,26 +122,26 @@ elsif  ($op eq 'save') {
         $cgi->param('format_string', $format_string);
     }
     my @params = (
-                    barcode_type    => $cgi->param('barcode_type'),
-                    printing_type   => $cgi->param('printing_type'),
-                    layout_name     => $cgi->param('layout_name'),
+                    barcode_type    => $cgi->param('barcode_type') || 'CODE39',
+                    printing_type   => $cgi->param('printing_type') || 'BAR',
+                    layout_name     => $cgi->param('layout_name') || 'DEFAULT',
                     guidebox        => ($cgi->param('guidebox') ? 1 : 0),
-                    font            => $cgi->param('font'),
-                    font_size       => $cgi->param('font_size'),
+                    font            => $cgi->param('font') || 'TR',
+                    font_size       => $cgi->param('font_size') || 3,
                     callnum_split   => ($cgi->param('callnum_split') ? 1 : 0),
-                    text_justify    => $cgi->param('text_justify'),
-                    format_string   => $cgi->param('format_string'),
+                    text_justify    => $cgi->param('text_justify') || 'L',
+                    format_string   => $cgi->param('format_string') || 'title, author, isbn, issn, itemtype, barcode, itemcallnumber',
     );
     if ($layout_id) {   # if a label_id was passed in, this is an update to an existing layout
         $layout = C4::Labels::Layout->retrieve(layout_id => $layout_id);
         $layout->set_attr(@params);
-        $layout->save();
+        $layout_id = $layout->save();
     }
     else {      # if no label_id, this is a new layout so insert it
         $layout = C4::Labels::Layout->new(@params);
-        $layout->save();
+        $layout_id = $layout->save();
     }
-    print $cgi->redirect("label-manage.pl?label_element=layout");
+    print $cgi->redirect("label-manage.pl?label_element=layout" . ($layout_id == -1 ? "&element_id=$layout_id&op=$op&error=1" : ''));
     exit;
 }
 else {  # if we get here, this is a new layout
@@ -165,5 +166,6 @@ $template->param(
         font_size       => $layout->get_attr('font_size'),
         callnum_split   => $layout->get_attr('callnum_split'),
         format_string   => $layout->get_attr('format_string'),
+        layout_string   => 1,   # FIXME: This should not be hard-coded; It should perhaps be yet another syspref... CN
 );
 output_html_with_http_headers $cgi, $cookie, $template->output;