use C4::Debug;
use C4::Labels::Profile 1.000000;
use C4::Labels::PDF 1.000000;
+use C4::Labels::Lib 1.000000 qw(get_unit_values);
BEGIN {
use version; our $VERSION = qv('1.0.0_1');
}
-my $unit_values = {
- POINT => 1,
- INCH => 72,
- MM => 2.83464567,
- CM => 28.3464567,
-};
-
sub _check_params {
my $given_params = {};
my $exit_code = 0;
my @valid_template_params = (
- 'tmpl_code',
- 'tmpl_desc',
+ 'profile_id',
+ 'template_code',
+ 'template_desc',
'page_width',
'page_height',
'label_width',
'col_gap',
'row_gap',
'units',
- 'font_size',
- 'font',
);
if (scalar(@_) >1) {
$given_params = {@_};
sub _conv_points {
my $self = shift;
- $self->{page_width} = $self->{page_width} * $unit_values->{$self->{units}};
- $self->{page_height} = $self->{page_height} * $unit_values->{$self->{units}};
- $self->{label_width} = $self->{label_width} * $unit_values->{$self->{units}};
- $self->{label_height} = $self->{label_height} * $unit_values->{$self->{units}};
- $self->{top_text_margin} = $self->{top_text_margin} * $unit_values->{$self->{units}};
- $self->{left_text_margin} = $self->{left_text_margin} * $unit_values->{$self->{units}};
- $self->{top_margin} = $self->{top_margin} * $unit_values->{$self->{units}};
- $self->{left_margin} = $self->{left_margin} * $unit_values->{$self->{units}};
- $self->{col_gap} = $self->{col_gap} * $unit_values->{$self->{units}};
- $self->{row_gap} = $self->{row_gap} * $unit_values->{$self->{units}};
+ my @unit_value = grep {$_->{'type'} eq $self->{units}} get_unit_values();
+ $self->{page_width} = $self->{page_width} * $unit_value[0]->{'value'};
+ $self->{page_height} = $self->{page_height} * $unit_value[0]->{'value'};
+ $self->{label_width} = $self->{label_width} * $unit_value[0]->{'value'};
+ $self->{label_height} = $self->{label_height} * $unit_value[0]->{'value'};
+ $self->{top_text_margin} = $self->{top_text_margin} * $unit_value[0]->{'value'};
+ $self->{left_text_margin} = $self->{left_text_margin} * $unit_value[0]->{'value'};
+ $self->{top_margin} = $self->{top_margin} * $unit_value[0]->{'value'};
+ $self->{left_margin} = $self->{left_margin} * $unit_value[0]->{'value'};
+ $self->{col_gap} = $self->{col_gap} * $unit_value[0]->{'value'};
+ $self->{row_gap} = $self->{row_gap} * $unit_value[0]->{'value'};
return $self;
}
sub new {
my $invocant = shift;
if (_check_params(@_) eq 1) {
- return 1;
+ return -1;
}
my $type = ref($invocant) || $invocant;
my $self = {
- tmpl_code => '',
- tmpl_desc => '',
+ profile_id => '0',
+ template_code => 'DEFAULT TEMPLATE',
+ template_desc => 'Default description',
page_width => 0,
page_height => 0,
label_width => 0,
col_gap => 0,
row_gap => 0,
units => 'POINT',
- font_size => 3,
- font => 'TR',
tmpl_stat => 0, # false if any data has changed and the db has not been updated
@_,
};
my $invocant = shift;
my %opts = @_;
my $type = ref($invocant) || $invocant;
- my $query = "SELECT * FROM labels_templates WHERE tmpl_id = ?";
+ my $query = "SELECT * FROM labels_templates WHERE template_id = ?";
my $sth = C4::Context->dbh->prepare($query);
$sth->execute($opts{template_id});
if ($sth->err) {
syslog("LOG_ERR", "Database returned the following error: %s", $sth->errstr);
- return 1;
+ return -1;
}
my $self = $sth->fetchrow_hashref;
$self = _conv_points($self) if (($opts{convert} && $opts{convert} == 1) || $opts{profile_id});
return $self;
}
-=head2 C4::Labels::Template->delete(tmpl_id => template_id) | $template->delete()
+=head2 C4::Labels::Template::delete(template_id => template_id) | $template->delete()
Invoking the delete method attempts to delete the template from the database. The method returns 0 upon success
and 1 upon failure. Errors are logged to the syslog.
examples:
my $exitstat = $template->delete(); # to delete the record behind the $template object
- my $exitstat = C4::Labels::Template->delete(tmpl_id => 1); # to delete template record 1
+ my $exitstat = C4::Labels::Template::delete(template_id => 1); # to delete template record 1
=cut
sub delete {
- my $self = shift;
- if (!$self->{tmpl_id}) { # If there is no template tmpl_id then we cannot delete it
- syslog("LOG_ERR", "Cannot delete template as it has not been saved.");
- return 1;
+ my $self = {};
+ my %opts = ();
+ my $call_type = '';
+ my $query_param = '';
+ if (ref($_[0])) {
+ $self = shift; # check to see if this is a method call
+ $call_type = 'C4::Labels::Template->delete';
+ $query_param = $self->{'template_id'};
+ }
+ else {
+ %opts = @_;
+ $call_type = 'C4::Labels::Template::delete';
+ $query_param = $opts{'template_id'};
+ }
+ if ($query_param eq '') { # If there is no template id then we cannot delete it
+ syslog("LOG_ERR", "%s : Cannot delete layout as the template id is invalid or non-existant.", $call_type);
+ return -1;
}
- my $query = "DELETE FROM labels_templates WHERE tmpl_id = ?";
+ my $query = "DELETE FROM labels_templates WHERE template_id = ?";
my $sth = C4::Context->dbh->prepare($query);
- $sth->execute($self->{tmpl_id});
+ $sth->execute($query_param);
$self->{tmpl_stat} = 0;
return 0;
}
=head2 $template->save()
Invoking the I<save> method attempts to insert the template into the database if the template is new and
- update the existing template record if the template exists. The method returns the new record tmpl_id upon
- success and -1 upon failure (This avotmpl_ids conflicting with a record tmpl_id of 1). Errors are logged to the syslog.
+ update the existing template record if the template exists. The method returns the new record template_id upon
+ success and -1 upon failure (This avotemplate_ids conflicting with a record template_id of 1). Errors are logged to the syslog.
example:
my $exitstat = $template->save(); # to save the record behind the $template object
sub save {
my $self = shift;
- if ($self->{'tmpl_id'}) { # if we have an tmpl_id, the record exists and needs UPDATE
+ if ($self->{'template_id'}) { # if we have an template_id, the record exists and needs UPDATE
my @params;
my $query = "UPDATE labels_templates SET ";
foreach my $key (keys %{$self}) {
- next if ($key eq 'tmpl_id') || ($key eq 'tmpl_stat');
+ next if ($key eq 'template_id') || ($key eq 'tmpl_stat');
push (@params, $self->{$key});
$query .= "$key=?, ";
}
$query = substr($query, 0, (length($query)-2));
- push (@params, $self->{'tmpl_id'});
- $query .= " WHERE tmpl_id=?;";
+ push (@params, $self->{'template_id'});
+ $query .= " WHERE template_id=?;";
warn "DEBUG: Updating: $query\n" if $debug;
my $sth = C4::Context->dbh->prepare($query);
$sth->execute(@params);
return -1;
}
$self->{tmpl_stat} = 1;
- return $self->{'tmpl_id'};
+ return $self->{'template_id'};
}
else { # otherwise create a new record
my @params;
syslog("LOG_ERR", "Database returned the following error: %s", $sth->errstr);
return -1;
}
- my $sth1 = C4::Context->dbh->prepare("SELECT MAX(tmpl_id) FROM labels_templates;");
+ my $sth1 = C4::Context->dbh->prepare("SELECT MAX(template_id) FROM labels_templates;");
$sth1->execute();
- my $tmpl_id = $sth1->fetchrow_array;
- $self->{tmpl_id} = $tmpl_id;
+ my $template_id = $sth1->fetchrow_array;
+ $self->{template_id} = $template_id;
$self->{tmpl_stat} = 1;
- return $tmpl_id;
+ return $template_id;
}
}
sub get_attr {
my $self = shift;
if (_check_params(@_) eq 1) {
- return 1;
+ return -1;
}
my ($attr) = @_;
if (exists($self->{$attr})) {
return $self->{$attr};
}
else {
- return 1;
+ return -1;
}
}
sub set_attr {
my $self = shift;
if (_check_params(@_) eq 1) {
- return 1;
+ return -1;
}
- my ($attr, $value) = @_;
- $self->{$attr} = $value;
+ my %attrs = @_;
+ foreach my $attrib (keys(%attrs)) {
+ $self->{$attrib} = $attrs{$attrib};
+ };
}
=head2 $template->get_text_wrap_cols()
visibility:visible; /* you propably don't need to change this one */
display:block;
}
-#newbiblio a, #addchild a, #newentry a, #newshelf a, #newmenuc .first-child, #newsupplier .first-child, #newlabel a, #newtemplate a, #newlabelbatch a, #newpatroncardbatch a, #newprofile a, #newsubscription a, #newdictionary a, #neworder a {
+#newbiblio a, #addchild a, #newentry a, #newshelf a, #newmenuc .first-child, #newsupplier .first-child, #newlabel a, #newtemplate a, #newbatch a, #newprofile a, #newsubscription a, #newdictionary a, #neworder a {
padding-left : 34px;
background-image: url("../../img/toolbar-new.gif");
background-position : center left;
--- /dev/null
+<script type="text/javascript">
+ //<![CDATA[
+ // prepare DOM for YUI Toolbar
+ $(document).ready(function() {
+ yuiToolbar();
+ });
+ // YUI Toolbar Functions
+ function yuiToolbar() {
+ new YAHOO.widget.Button("newlabel");
+ new YAHOO.widget.Button("newtemplate");
+ new YAHOO.widget.Button("newprofile");
+ new YAHOO.widget.Button("newbatch");
+ }
+ //]]>
+</script>
+<div id="toolbar">
+ <ul class="toolbar">
+ <li><a id="newlabel" href="/cgi-bin/koha/labels/label-edit-layout.pl?op=new">New Layout</a></li>
+ <li><a id="newtemplate" href="/cgi-bin/koha/labels/label-edit-template.pl?op=new">New Template</a></li>
+ <li><a id="newprofile" href="/cgi-bin/koha/labels/label-edit-profile.pl?op=new">New Profile</a></li>
+ <li><a id="newbatch" href="/cgi-bin/koha/labels/label-edit-batch.pl?op=new">New Batch</a></li>
+ </ul>
+</div>
-<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><title>Koha › Tools › Labels</title>
-<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+ <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+ <title>Koha › Tools › Labels › Templates</title>
+ <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
</head>
<body>
-<!-- TMPL_INCLUDE NAME="header.inc" -->
-<!-- TMPL_INCLUDE NAME="cat-search.inc" -->
-
-<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a>› <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › <a href="/cgi-bin/koha/labels/label-home.pl">Labels</a> › <a href="/cgi-bin/koha/labels/label-templates.pl">Label Templates</a> › Edit Label Template</div>
-
-<div id="doc3" class="yui-t2">
-
- <div id="bd">
- <div id="yui-main">
- <div class="yui-b">
-<form name="input" action="/cgi-bin/koha/labels/label-save-template.pl" method="get">
-
-<div class="yui-g">
-<h3>Edit Label Template</h3>
-<div class="yui-u first">
-<fieldset class="rows"><legend>Template Settings</legend>
-
-<ol>
-<li><span class="label">Template ID: <!-- TMPL_VAR NAME="tmpl_id" --> </span></li>
- <li><label for="tmpl_code">Template Code:</label> <input type="text" size="40" name="tmpl_code" id="tmpl_code" value="<!-- TMPL_VAR NAME="tmpl_code" -->" /></li>
- <li><label for="tmpl_desc">Template Description:</label> <textarea cols="40" rows="3" id="tmpl_desc" name="tmpl_desc"><!-- TMPL_VAR NAME="tmpl_desc" --></textarea></li>
-
-<li>
- <label for="page_width">Page Width: </label><input type="text" size="4" name="page_width" id="page_width" value="<!-- TMPL_VAR NAME="page_width" -->" />
-</li>
-<li>
- <label for="page_height">Page Height: </label><input type="text" size="4" name="page_height" id="page_height" value="<!-- TMPL_VAR NAME="page_height" -->" />
-</li>
-<li>
- <label for="label_width">Label Width: </label><input type="text" size="4" name="label_width" id="label_width" value="<!-- TMPL_VAR NAME="label_width" -->" />
-</li>
-<li>
- <label for="label_height">Label Height: </label><input type="text" size="4" name="label_height" id="label_height" value="<!-- TMPL_VAR NAME="label_height" -->" />
-</li>
-<li>
- <label for="topmargin">Top Page Margin: </label><input type="text" size="4" name="topmargin" id="topmargin" value="<!-- TMPL_VAR NAME="topmargin" -->" />
-</li>
-<li>
- <label for="leftmargin">Left Page Margin: </label><input type="text" size="4" name="leftmargin" id="leftmargin" value="<!-- TMPL_VAR NAME="leftmargin" -->" />
-</li>
-</ol>
-</fieldset>
-</div>
-<div class="yui-u">
-<fieldset class="rows">
-<ol>
-
-<li>
- <label for="cols">Number of Columns: </label><input type="text" size="4" name="cols" id="cols" value="<!-- TMPL_VAR NAME="cols" -->" />
-</li>
-<li>
- <label for="rows">Number of Rows: </label><input type="text" size="4" name="rows" id="rows" value="<!-- TMPL_VAR NAME="rows" -->" />
-</li>
-<li>
- <label for="colgap">Gap between Columns: </label><input type="text" size="4" name="colgap" id="colgap" value="<!-- TMPL_VAR NAME="colgap" -->" />
-</li>
-<li>
- <label for="rowgap">Gap between Rows: </label><input type="text" size="4" name="rowgap" id="rowgap" value="<!-- TMPL_VAR NAME="rowgap" -->" />
-
-</li>
-
-<li><label for="units">Units: </label><select id="units" name="units">
- <!-- TMPL_LOOP NAME="units" -->
- <!-- TMPL_IF NAME="selected" -->
- <option value="<!-- TMPL_VAR NAME="unit" -->" selected="selected">
- <!-- TMPL_ELSE -->
- <option value="<!-- TMPL_VAR NAME="unit" -->">
- <!-- /TMPL_IF --><!-- TMPL_VAR NAME="desc" --></option>
- <!-- /TMPL_LOOP -->
-</select></li>
-
-<li><label for="prof_id">Profile: </label>
-<!-- TMPL_IF NAME="proflist" -->
- <select id="prof_id" name="prof_id">
- <!-- TMPL_LOOP NAME="proflist" -->
- <!-- TMPL_IF NAME="selected" -->
- <option value="<!-- TMPL_VAR NAME="prof_id" -->" selected="selected">
- <!-- TMPL_ELSE -->
- <option value="<!-- TMPL_VAR NAME="prof_id" -->">
- <!-- /TMPL_IF --><!-- TMPL_VAR NAME="printername" -->/<!-- TMPL_VAR NAME="paper_bin" --></option>
- <!-- /TMPL_LOOP -->
- </select>
-<!-- TMPL_ELSE -->
- None Defined
-<!-- /TMPL_IF -->
-</li>
-
-<li><label for="fonts">Font: </label><select id="fonts" name="fonts">
- <!-- TMPL_LOOP NAME="fonts" -->
- <!-- TMPL_IF NAME="selected" -->
- <option value="<!-- TMPL_VAR NAME="font" -->" selected="selected">
- <!-- TMPL_ELSE -->
- <option value="<!-- TMPL_VAR NAME="font" -->">
- <!-- /TMPL_IF --><!-- TMPL_VAR NAME="name" --></option>
- <!-- /TMPL_LOOP -->
-</select></li>
-
-<li><label for="fontsize">Font Size:</label> <input type="text" id="fontsize" name="fontsize" size="1" value="<!-- TMPL_VAR NAME="fontsize" -->" /></li>
-
-<li><label for="active">Active: </label>
-<!-- TMPL_IF NAME="active" -->
-<input type="checkbox" name="active" id="active" checked="checked" />
-<!-- TMPL_ELSE -->
-<input type="checkbox" name="active" id="active" />
-<!-- /TMPL_IF -->
- <input type="hidden" name="tmpl_id" value="<!-- TMPL_VAR NAME="tmpl_id" -->" /></li>
-
-</ol></fieldset>
-</div>
-</div><div class="yui-g">
-<fieldset class="action">
- <input type="submit" value="Save" /> <a class="cancel" href="/cgi-bin/koha/labels/label-save-template.pl">Cancel</a>
-</fieldset></div>
-</form>
-
-</div>
-</div>
-<div class="yui-b">
-<!-- TMPL_INCLUDE NAME="labels-menu.inc" -->
-</div>
-</div>
-<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
+ <!-- TMPL_INCLUDE NAME="header.inc" -->
+ <!-- TMPL_INCLUDE NAME="cat-search.inc" -->
+ <div id="breadcrumbs">
+ <a href="/cgi-bin/koha/mainpage.pl">Home</a>›
+ <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a>›
+ <a href="/cgi-bin/koha/labels/label-home.pl">Labels</a>›
+ <a href="/cgi-bin/koha/labels/label-manage.pl?label_element=template">Label Templates</a>›
+ Edit Label Template
+ </div>
+ <div id="doc3" class="yui-t2">
+ <div id="bd">
+ <div id="yui-main">
+ <div class="yui-b">
+ <form name="input" action="/cgi-bin/koha/labels/label-edit-template.pl" method="get">
+ <div class="yui-g">
+ <h3>Edit Label Template</h3>
+ <div class="yui-u first">
+ <fieldset class="rows">
+ <ol>
+ <li>
+ <span class="label">Template ID:</span><!-- TMPL_IF NAME="template_id" --><!-- TMPL_VAR NAME="template_id" --><!-- TMPL_ELSE -->N/A<!-- /TMPL_IF -->
+ </li>
+ <li>
+ <label for="template_code">Template Code:</label>
+ <input type="text" size="43" name="template_code" id="template_code" value="<!-- TMPL_VAR NAME="template_code" -->" />
+ </li>
+ <li>
+ <label for="template_desc">Template Description:</label>
+ <textarea cols="40" rows="3" id="template_desc" name="template_desc"><!-- TMPL_VAR NAME="template_desc" --></textarea>
+ </li>
+ <li>
+ <label for="page_height">Page Height:</label>
+ <input type="text" size="4" name="page_height" id="page_height" value="<!-- TMPL_VAR NAME="page_height" -->" />
+ </li>
+ <li>
+ <label for="page_width">Page Width:</label>
+ <input type="text" size="4" name="page_width" id="page_width" value="<!-- TMPL_VAR NAME="page_width" -->" />
+ </li>
+ <li>
+ <label for="label_width">Label Width:</label>
+ <input type="text" size="4" name="label_width" id="label_width" value="<!-- TMPL_VAR NAME="label_width" -->" />
+ </li>
+ <li>
+ <label for="label_height">Label Height:</label>
+ <input type="text" size="4" name="label_height" id="label_height" value="<!-- TMPL_VAR NAME="label_height" -->" />
+ </li>
+ <li>
+ <label for="top_margin">Top Page Margin:</label>
+ <input type="text" size="4" name="top_margin" id="top_margin" value="<!-- TMPL_VAR NAME="top_margin" -->" />
+ </li>
+ <li>
+ <label for="left_margin">Left Page Margin:</label>
+ <input type="text" size="4" name="left_margin" id="left_margin" value="<!-- TMPL_VAR NAME="left_margin" -->" />
+ </li>
+ </ol>
+ </fieldset>
+ </div>
+ <div class="yui-u">
+ <fieldset class="rows">
+ <ol>
+ <li>
+ <label for="top_text_margin">Top Text Margin:</label>
+ <input type="text" size="4" name="top_text_margin" id="top_text_margin" value="<!-- TMPL_VAR NAME="top_text_margin" -->" />
+ </li>
+ <li>
+ <label for="left_text_margin">Left Text Margin:</label>
+ <input type="text" size="4" name="left_text_margin" id="left_text_margin" value="<!-- TMPL_VAR NAME="left_text_margin" -->" />
+ </li>
+ <li>
+ <label for="cols">Number of Columns:</label>
+ <input type="text" size="4" name="cols" id="cols" value="<!-- TMPL_VAR NAME="cols" -->" />
+ </li>
+ <li>
+ <label for="rows">Number of Rows:</label>
+ <input type="text" size="4" name="rows" id="rows" value="<!-- TMPL_VAR NAME="rows" -->" />
+ </li>
+ <li>
+ <label for="col_gap">Gap between Columns:</label>
+ <input type="text" size="4" name="col_gap" id="col_gap" value="<!-- TMPL_VAR NAME="col_gap" -->" />
+ </li>
+ <li>
+ <label for="row_gap">Gap between Rows:</label>
+ <input type="text" size="4" name="row_gap" id="row_gap" value="<!-- TMPL_VAR NAME="row_gap" -->" />
+ </li>
+ <li>
+ <label for="units">Units:</label>
+ <select id="units" name="units">
+ <!-- TMPL_LOOP NAME="units" -->
+ <option value="<!-- TMPL_VAR NAME="type" -->"<!-- TMPL_IF NAME="selected" --> selected="selected"<!-- /TMPL_IF -->>
+ <!-- TMPL_VAR NAME="desc" -->
+ </option>
+ <!-- /TMPL_LOOP -->
+ </select>
+ </li>
+ <li>
+ <label for="profile_id">Profile:</label>
+ <!-- TMPL_IF NAME="profile_list" -->
+ <select id="profile_id" name="profile_id">
+ <!-- TMPL_LOOP NAME="profile_list" -->
+ <option value="<!-- TMPL_VAR NAME="profile_id" -->"<!-- TMPL_IF NAME="selected" --> selected="selected"<!-- /TMPL_IF -->>
+ <!-- TMPL_VAR NAME="printer_name" -->/<!-- TMPL_VAR NAME="paper_bin" -->
+ </option>
+ <!-- /TMPL_LOOP -->
+ </select>
+ <!-- TMPL_ELSE -->
+ <a href="/cgi-bin/koha/tools/tools-edit-profile.pl?op=new">Click here to define a printer profile.</a>
+ <!-- /TMPL_IF -->
+ </li>
+ </ol>
+ </fieldset>
+ </div>
+ </div>
+ <div class="yui-g">
+ <fieldset class="action">
+ <input type="submit" value="Submit" /><a class="cancel" href="/cgi-bin/koha/labels/label-manage.pl?label_element=template">Cancel</a>
+ <input type="hidden" name="op" value="save" />
+ <!-- TMPL_IF NAME="template_id" -->
+ <input type="hidden" name="template_id" value="<!-- TMPL_VAR NAME="template_id" -->" />
+ <!-- /TMPL_IF -->
+ </fieldset>
+ </div>
+ </form>
+ </div>
+ </div>
+ <div class="yui-b">
+ <!-- TMPL_INCLUDE NAME="labels-menu.inc" -->
+ </div>
+ </div>
+ <!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
#!/usr/bin/perl
+#
+# Copyright 2006 Katipo Communications.
+# 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
+# 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.
+#
+# 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
use strict;
+use warnings;
+use Sys::Syslog qw(syslog);
use CGI;
-use C4::Auth;
-use C4::Context;
-use C4::Output;
-use C4::Labels;
use HTML::Template::Pro;
-use POSIX;
-
-# use Data::Dumper;
-
-my $dbh = C4::Context->dbh;
-my $query = new CGI;
-
-my $tmpl_id = $query->param('tmpl_id');
+use Data::Dumper;
-my $width = $query->param('width');
-my $height = $query->param('height');
-my $topmargin = $query->param('topmargin');
-my $leftmargin = $query->param('leftmargin');
-my $columns = $query->param('columns');
-my $rows = $query->param('rows');
-my $colgap = $query->param('colgap');
-my $rowgap = $query->param('rowgap');
-my $prof_id = $query->param('prof_id');
+use C4::Auth;
+use C4::Output;
+use C4::Context;
+use C4::Debug;
+use C4::Labels::Lib 1.000000 qw(get_all_profiles get_unit_values);
+use C4::Labels::Template 1.000000;
+my $cgi = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "labels/label-edit-template.tmpl",
- query => $query,
+ query => $cgi,
type => "intranet",
- authnotrequired => 1,
+ authnotrequired => 0,
flagsrequired => { catalogue => 1 },
debug => 1,
}
);
-my $tmpl = GetSingleLabelTemplate($tmpl_id);
-my $curprof = GetAssociatedProfile($tmpl_id);
-my @prof = GetAllPrinterProfiles();
-my @proflist;
+my $op = $cgi->param('op') || $ARGV[0] || '';
+my $template_id = $cgi->param('template_id') || $cgi->param('element_id') || $ARGV[1] || '';
+my $label_template = '';
+my $profile_list = '';
+my $units = get_unit_values();
-# Generate an array of hashes containing possible profiles for given template and mark the currently associated one...
-
-foreach my $prof (@prof) {
- if ( $prof->{'tmpl_id'} eq $tmpl->{'tmpl_id'} && $prof->{'prof_id'} eq $curprof->{'prof_id'} ) {
- push ( @proflist, {prof_id => $prof->{'prof_id'},
- printername => $prof->{'printername'},
- paper_bin => $prof->{'paper_bin'},
- selected => 1} );
- }
-
- elsif ( $prof->{'tmpl_id'} eq $tmpl->{'tmpl_id'} ) {
- push ( @proflist, {prof_id => $prof->{'prof_id'},
- printername => $prof->{'printername'},
- paper_bin => $prof->{'paper_bin'}} );
+if ($op eq 'edit') {
+ $label_template = C4::Labels::Template->retrieve(template_id => $template_id);
+ $profile_list = get_all_profiles(field_list => 'profile_id,printer_name,paper_bin',filter => "template_id=$template_id OR template_id=''");
+}
+elsif ($op eq 'save') {
+ my @params = ( profile_id => $cgi->param('profile_id') || '',
+ template_code => $cgi->param('template_code'),
+ template_desc => $cgi->param('template_desc'),
+ page_width => $cgi->param('page_width'),
+ page_height => $cgi->param('page_height'),
+ label_width => $cgi->param('label_width'),
+ label_height => $cgi->param('label_height'),
+ top_text_margin => $cgi->param('top_text_margin'),
+ left_text_margin=> $cgi->param('left_text_margin'),
+ top_margin => $cgi->param('top_margin'),
+ left_margin => $cgi->param('left_margin'),
+ cols => $cgi->param('cols'),
+ rows => $cgi->param('rows'),
+ col_gap => $cgi->param('col_gap'),
+ row_gap => $cgi->param('row_gap'),
+ units => $cgi->param('units'),
+ );
+ if ($template_id) { # if a label_id was passed in, this is an update to an existing layout
+ $label_template = C4::Labels::Template->retrieve(template_id => $template_id);
+ my $profile = C4::Labels::Profile->retrieve(profile_id => $cgi->param('profile_id'));
+ $profile->set_attr(template_id => $label_template->get_attr('template_id')) if $label_template->get_attr('template_id') != $profile->get_attr('template_id');
+ $label_template->set_attr(@params);
+ $label_template->save();
}
-
- elsif ( !$prof ) {
- undef @proflist;
+ else { # if no label_id, this is a new layout so insert it
+ $label_template = C4::Labels::Template->new(@params);
+ my $template_id = $label_template->save();
+ my $profile = C4::Labels::Profile->retrieve(profile_id => $cgi->param('profile_id'));
+ $profile->set_attr(template_id => $template_id) if $template_id != $profile->get_attr('template_id');
}
+ print $cgi->redirect("label-manage.pl?label_element=template");
+ exit;
}
-
-my @units = (
- { unit => 'INCH', desc => 'Inches' },
- { unit => 'CM', desc => 'Centimeters' },
- { unit => 'MM', desc => 'Millimeters' },
- { unit => 'POINT', desc => 'Postscript Points' },
-);
-
-foreach my $unit (@units) {
- if ( $unit->{'unit'} eq $tmpl->{'units'} ) {
- $unit->{'selected'} = 1;
+else { # if we get here, this is a new layout
+ $label_template = C4::Labels::Template->new();
+}
+if ($template_id) {
+ foreach my $profile (@$profile_list) {
+ if ($profile->{'profile_id'} == $label_template->get_attr('profile_id')) {
+ $profile->{'selected'} = 1;
+ }
+ else {
+ $profile->{'selected'} = 0;
+ }
}
}
-my @fonts = ( #FIXME: There is probably a way to discover what additional fonts are installed on a user's system and generate this list dynamically...
- { font => 'TR', name => 'Times Roman' },
- { font => 'TB', name => 'Times Bold' },
- { font => 'TI', name => 'Times Italic' },
- { font => 'TBI', name => 'Times Bold Italic' },
- { font => 'C', name => 'Courier' },
- { font => 'CB', name => 'Courier Bold' },
- { font => 'CO', name => 'Courier Oblique' },
- { font => 'CBO', name => 'Courier Bold Oblique' },
- { font => 'H', name => 'Helvetica' },
- { font => 'HB', name => 'Helvetica Bold' },
- { font => 'HO', name => 'Helvetica Oblique' },
- { font => 'HBO', name => 'Helvetica Bold Oblique' },
-);
-
-foreach my $font (@fonts) {
- if ( $font->{'font'} eq $tmpl->{'font'} ) {
- $font->{'selected'} = 1;
+foreach my $unit (@$units) {
+ if ($unit->{'type'} eq $label_template->get_attr('units')) {
+ $unit->{'selected'} = 1;
}
}
$template->param(
-
- proflist => \@proflist,
- units => \@units,
- fonts => \@fonts,
-
- tmpl_id => $tmpl->{'tmpl_id'},
- tmpl_code => $tmpl->{'tmpl_code'},
- tmpl_desc => $tmpl->{'tmpl_desc'},
- page_width => $tmpl->{'page_width'},
- page_height => $tmpl->{'page_height'},
- label_width => $tmpl->{'label_width'},
- label_height => $tmpl->{'label_height'},
- topmargin => $tmpl->{'topmargin'},
- leftmargin => $tmpl->{'leftmargin'},
- cols => $tmpl->{'cols'},
- rows => $tmpl->{'rows'},
- colgap => $tmpl->{'colgap'},
- rowgap => $tmpl->{'rowgap'},
- fontsize => $tmpl->{'fontsize'},
- active => $tmpl->{'active'},
+ profile_list => $profile_list,
+ template_id => ($label_template->get_attr('template_id') > 0) ? $label_template->get_attr('template_id') : '',
+ template_code => $label_template->get_attr('template_code'),
+ template_desc => $label_template->get_attr('template_desc'),
+ page_width => $label_template->get_attr('page_width'),
+ page_height => $label_template->get_attr('page_height'),
+ label_width => $label_template->get_attr('label_width'),
+ label_height => $label_template->get_attr('label_height'),
+ top_text_margin => $label_template->get_attr('top_text_margin'),
+ left_text_margin => $label_template->get_attr('left_text_margin'),
+ top_margin => $label_template->get_attr('top_margin'),
+ left_margin => $label_template->get_attr('left_margin'),
+ cols => $label_template->get_attr('cols'),
+ rows => $label_template->get_attr('rows'),
+ col_gap => $label_template->get_attr('col_gap'),
+ row_gap => $label_template->get_attr('row_gap'),
+ units => $units,
);
-output_html_with_http_headers $query, $cookie, $template->output;
+output_html_with_http_headers $cgi, $cookie, $template->output;