X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=labels%2Flabel-edit-layout.pl;h=6a702122b254954494b99dc0146dfc625c20048a;hb=c8c019e07f224d5200668e746c5babea005ec7da;hp=62031b61af172eed4f773ec6332b8a604439bf6a;hpb=38817fb300e27882262c7a3ff071711342116fb1;p=koha.git diff --git a/labels/label-edit-layout.pl b/labels/label-edit-layout.pl index 62031b61af..6a702122b2 100755 --- a/labels/label-edit-layout.pl +++ b/labels/label-edit-layout.pl @@ -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,23 +14,21 @@ # 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; -use Sys::Syslog qw(syslog); use CGI; -use HTML::Template::Pro; use POSIX; 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( @@ -46,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 { @@ -75,7 +74,7 @@ sub _select_format_string { # generate field table based on format_string my $csv = Text::CSV_XS->new({ allow_whitespace => 1 }); my $status = $csv->parse($format_string); my @text_fields = $csv->fields(); - syslog("LOG_ERR", "labels/label-edit-layout.pl : Error parsing format_string. Parser returned: %s",$csv->error_input()) if $csv->error_input(); + warn sprintf('Error parsing format_string. Parser returned: %s', $csv->error_input()) if $csv->error_input(); my $field_count = $#text_fields + 1; POPULATE_TABLE: foreach my $text_field (@text_fields) { @@ -104,13 +103,13 @@ sub _select_format_string { # generate field table based on format_string } if ($op eq 'edit') { - syslog("LOG_ERR", "labels/label-edit-layout.pl : Error performing '%s': No 'layout_id' passed in.", $op) unless ($layout_id); + warn sprintf("Error performing '%s': No 'layout_id' passed in.", $op) unless ($layout_id); $layout = C4::Labels::Layout->retrieve(layout_id => $layout_id); } 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))) { @@ -123,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 @@ -167,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;