Browse Source

[8/40] Adding new layout management page

This moves the layouts off of the labels tool start page to bring it into
conformity with the other parts of this tool.
3.2.x
Chris Nighswonger 15 years ago
parent
commit
12663796ca
  1. 54
      C4/Labels/Layout.pm
  2. 4
      C4/Labels/Lib.pm
  3. 3
      koha-tmpl/intranet-tmpl/prog/en/includes/labels-menu.inc
  4. 433
      koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tmpl
  5. 100
      koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-layout.tmpl
  6. 208
      labels/label-edit-layout.pl
  7. 70
      labels/label-layout.pl

54
C4/Labels/Layout.pm

@ -21,6 +21,7 @@ use strict;
use warnings;
use Sys::Syslog qw(syslog);
use DBI qw(neat);
use C4::Context;
use C4::Debug;
@ -43,32 +44,30 @@ BEGIN {
# }
sub _check_params {
my $given_params = {};
my $exit_code = 0;
my @valtmpl_id_params = (
'barcode_type',
'start_label', #remove...pass in as a cgi->param
'printing_type',
'layout_name',
'guidebox',
'font_type',
'ccode', #remove...depricated...
'font',
'font_size',
'callnum_split',
'text_justify',
'format_string',
);
if (scalar(@_) >1) {
$given_params = {@_};
foreach my $key (keys %{$given_params}) {
my %given_params = @_;
foreach my $key (keys %given_params) {
if (!(grep m/$key/, @valtmpl_id_params)) {
syslog("LOG_ERR", "C4::Labels::Template : Unrecognized parameter type of \"%s\".", $key);
syslog("LOG_ERR", "C4::Labels::Layout : (Multiple parameters) Unrecognized parameter type of \"%s\".", $key);
$exit_code = 1;
}
}
}
else {
if (!(grep m/$_/, @valtmpl_id_params)) {
syslog("LOG_ERR", "C4::Labels::Template : Unrecognized parameter type of \"%s\".", $_);
syslog("LOG_ERR", "C4::Labels::Layout : (Single parameter) Unrecognized parameter type of \"%s\".", $_);
$exit_code = 1;
}
}
@ -101,16 +100,15 @@ sub new {
}
my $type = ref($invocant) || $invocant;
my $self = {
barcode_type => '',
start_label => 1,
printing_type => '',
layout_name => '',
barcode_type => 'CODE39',
printing_type => 'BAR',
layout_name => 'DEFAULT',
guidebox => 0,
font_type => '',
ccode => '',
font => 'TR',
font_size => 3,
callnum_split => 0,
text_justify => '',
format_string => '',
text_justify => 'L',
format_string => 'title, author, isbn, issn, itemtype, barcode, callnumber',
@_,
};
bless ($self, $type);
@ -169,17 +167,14 @@ sub delete {
$call_type = 'C4::Labels::Layout::delete';
$query_param = $opts{'layout_id'};
}
warn Dumper(\%opts);
if ($query_param eq '') { # If there is no layout id then we cannot delete it
syslog("LOG_ERR", "%s : Cannot delete layout as the layout id is invalid or non-existant.", $call_type);
return 1;
}
my $query = "DELETE FROM labels_layouts WHERE layout_id = ?";
my $sth = C4::Context->dbh->prepare($query);
warn "$query : ?= $query_param\n";
$sth->execute($query_param);
if ($sth->err) {
warn "DB error: $sth->errstr\n";
syslog("LOG_ERR", "%s : Database returned the following error: %s", $call_type, $sth->errstr);
return 1;
}
@ -203,18 +198,18 @@ sub save {
my @params;
my $query = "UPDATE labels_layouts SET ";
foreach my $key (keys %{$self}) {
next if $key eq 'id';
next if $key eq 'layout_id';
push (@params, $self->{$key});
$query .= "$key=?, ";
}
$query = substr($query, 0, (length($query)-2));
push (@params, $self->{'id'});
$query .= " WHERE layout_id=?;";
warn "DEBUG: Updating: $query\n" if $debug;
push (@params, $self->{'layout_id'});
my $sth = C4::Context->dbh->prepare($query);
#local $sth->{TraceLevel} = "3"; # enable DBI trace and set level; outputs to STDERR
$sth->execute(@params);
if ($sth->err) {
syslog("LOG_ERR", "Database returned the following error: %s", $sth->errstr);
syslog("LOG_ERR", "C4::Labels::Layout : Database returned the following error: %s", $sth->errstr);
return -1;
}
return $self->{'layout_id'};
@ -233,11 +228,10 @@ sub save {
}
$query = substr($query, 0, (length($query)-1));
$query .= ");";
warn "DEBUG: Saving: $query\n" if $debug;
my $sth = C4::Context->dbh->prepare($query);
$sth->execute(@params);
if ($sth->err) {
syslog("LOG_ERR", "Database returned the following error: %s", $sth->errstr);
syslog("LOG_ERR", "C4::Labels::Layout : Database returned the following error: %s", $sth->errstr);
return -1;
}
my $sth1 = C4::Context->dbh->prepare("SELECT MAX(layout_id) FROM labels_layouts;");
@ -259,14 +253,14 @@ sub save {
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;
}
return;
}
@ -285,8 +279,10 @@ sub set_attr {
if (_check_params(@_) eq 1) {
return 1;
}
my ($attr, $value) = @_;
$self->{$attr} = $value;
my %attrs = @_;
foreach my $attrib (keys(%attrs)) {
$self->{$attrib} = $attrs{$attrib};
};
return 0;
}
1;

4
C4/Labels/Lib.pm

@ -101,7 +101,7 @@ my $unit_values = [
examples:
my $templates = C4::Labels::Lib::get_all_templates();
my $templates = get_all_templates();
=cut
@ -127,7 +127,7 @@ sub get_all_templates {
examples:
my $layouts = C4::Labels::Lib::get_all_layouts();
my $layouts = get_all_layouts();
=cut

3
koha-tmpl/intranet-tmpl/prog/en/includes/labels-menu.inc

@ -1,5 +1,6 @@
<div id="navmenu"><ul id="navmenulist">
<li><a href="/cgi-bin/koha/labels/label-home.pl">Layouts</a></li>
<li><a href="/cgi-bin/koha/labels/label-home.pl">Labels Home</a></li>
<li><a href="/cgi-bin/koha/labels/label-layout.pl">Layouts</a></li>
<li><a href="/cgi-bin/koha/labels/label-templates.pl">Templates</a></li>
<li><a href="/cgi-bin/koha/labels/label-profiles.pl">Printer Profiles</a></li>
<li><a href="/cgi-bin/koha/labels/label-manager.pl?type=labels">Manage Label Batches</a></li>

433
koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-layout.tmpl

@ -1,264 +1,173 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><title>Koha &rsaquo; Tools &rsaquo; Labels</title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<script type="text/javascript">
$(document).ready(function() {
$("input[name=layoutchoice]").change( function() { layout_method() } );
layout_method();
});
function layout_method() {
if( $("input[name=layoutchoice]:checked").val() == 'layout_string' ) {
$('#layout_tx').hide();
$('#layout_string').show();
} else {
$('#layout_tx').show();
$('#layout_string').hide();
}
}
</script>
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
<title>Koha &rsaquo; Tools &rsaquo; Labels</title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<script type="text/JavaScript" language="JavaScript">
//<![CDATA[
$(document).ready(function() {
$("input[@name='layout_choice']").change( function() { layout_method() } );
layout_method();
});
function layout_method() {
if( $("input[@name='layout_choice']:checked").val() == 'layout_string' ) {
$('#layout_table').hide();
$('#layout_string').show();
} else {
$('#layout_table').show();
$('#layout_string').hide();
}
}
//]]>
</script>
</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> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; <a href="/cgi-bin/koha/labels/label-home.pl">Labels</a> &rsaquo; <!-- TMPL_IF NAME="layout_id" -->Edit<!-- TMPL_ELSE -->Create<!-- /TMPL_IF --> Label Layout</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="tools-labels-toolbar.inc" -->
<form name="input" action="/cgi-bin/koha/labels/label-manager.pl" method="get">
<fieldset class="rows">
<legend><!-- TMPL_IF NAME="layout_id" -->Edit<!-- TMPL_ELSE -->Create<!-- /TMPL_IF --> Label Layout</legend>
<ol>
<li><label for="layoutname">Layout Name</label>
<input type="text" name="layoutname" id="layoutname" size="20" value="<!-- TMPL_VAR NAME="layoutname" -->" /></li>
<li><label for="barcodetype">Choose Barcode Type (encoding)</label>
<select name="barcodetype" id="barcodetype">
<!-- TMPL_LOOP NAME="barcode_types" -->
<!-- TMPL_IF NAME="active" -->
<option value="<!-- TMPL_VAR NAME="code" -->" selected="selected"><!-- TMPL_VAR NAME="desc" --></option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR NAME="code" -->"><!-- TMPL_VAR NAME="desc" --></option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select></li>
<li><label for="printingtype">Choose Layout Type</label>
<select name="printingtype" id="printingtype">
<!-- TMPL_LOOP NAME="printingtypes" -->
<!-- TMPL_IF NAME="active" -->
<option value="<!-- TMPL_VAR NAME="code" -->" selected="selected"><!-- TMPL_VAR NAME="desc" --></option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR NAME="code" -->"><!-- TMPL_VAR NAME="desc" --></option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select></li>
<li>
<fieldset class="rows">
<legend>
Bibliographic Data to Print
</legend>
<!-- TMPL_IF NAME="layout_string" -->
<input type="radio" name="layoutchoice" value="layout_tx" />Choose Order Of Text Fields to Print
<!-- TMPL_ELSE -->
<input type="radio" name="layoutchoice" value="layout_tx" checked="checked" />Choose Order Of Text Fields to Print
<!-- /TMPL_IF -->
<br />
<fieldset id="layout_tx">
<table summary="fields to print">
<tr>
<td>
<select name="tx_title" id="tx_title">
<!-- TMPL_LOOP Name="tx_title" -->
<!-- TMPL_IF Name="selected" -->
<option value="<!-- TMPL_VAR Name="num" -->" selected="selected">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR Name="num" -->">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
<label for="tx_title">Title</label>
</td>
<td>
<select name="tx_author" id="tx_author">
<!-- TMPL_LOOP Name="tx_author" -->
<!-- TMPL_IF Name="selected" -->
<option value="<!-- TMPL_VAR Name="num" -->" selected="selected">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR Name="num" -->">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
<label for="tx_author">Author</label>
</td>
<td>
<select name="tx_isbn" id="tx_isbn">
<!-- TMPL_LOOP Name="tx_isbn" -->
<!-- TMPL_IF Name="selected" -->
<option value="<!-- TMPL_VAR Name="num" -->" selected="selected">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR Name="num" -->">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
<label for="tx_isbn">ISBN</label>
</td>
</tr>
<tr>
<td>
<select name="tx_issn" id="tx_issn">
<!-- TMPL_LOOP Name="tx_issn" -->
<!-- TMPL_IF Name="selected" -->
<option value="<!-- TMPL_VAR Name="num" -->" selected="selected">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR Name="num" -->">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
<label for="tx_issn">ISSN</label>
</td>
<td>
<select name="tx_itemtype" id="tx_itemtype">
<!-- TMPL_LOOP Name="tx_itemtype" -->
<!-- TMPL_IF Name="selected" -->
<option value="<!-- TMPL_VAR Name="num" -->" selected="selected">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR Name="num" -->">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
<label for="tx_itemtype">Itemtype</label>
</td>
<td>
<select id="tx_barcode" name="tx_barcode">
<!-- TMPL_LOOP Name="tx_barcode" -->
<!-- TMPL_IF Name="selected" -->
<option value="<!-- TMPL_VAR Name="num" -->" selected="selected">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR Name="num" -->">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
<label for="tx_barcode">Barcode (as text)</label>
</td>
</tr>
<tr>
<td>
<select name="tx_itemcallnumber" id="tx_itemcallnumber">
<!-- TMPL_LOOP Name="tx_itemcallnumber" -->
<!-- TMPL_IF Name="selected" -->
<option value="<!-- TMPL_VAR Name="num" -->" selected="selected">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR Name="num" -->">
<!-- TMPL_VAR Name="num" -->
</option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
<label for="tx_itemcallnumber">Call Number</label>
</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<br />
</fieldset>
<br />
<!-- TMPL_IF NAME="formatstring" -->
<input type="radio" name="layoutchoice" value="layout_string" checked="checked"/> List Fields
<!-- TMPL_ELSE -->
<input type="radio" name="layoutchoice" value="layout_string" /> List Fields
<!-- /TMPL_IF -->
<fieldset id="layout_string" class="brief">
<label for="layoutname">Data Fields</label>
<input type="text" name="formatstring" id="formatstring" size="80" value="<!-- TMPL_VAR ESCAPE='HTML' NAME="formatstring" -->" />
<div class="help">
<p>Enter a comma separated list of fields to print. You may include any <em>Koha field</em> or MARC subfield.</p>
<p>See online help for advanced options</p>
<p>ex: barcode, itemcallnumber, title, "050a 050b", 300a </p>
</div>
</fieldset>
</fieldset>
</li>
<li><label for="startlabel">Start printing from Label number: </label><input type="text" name="startlabel" id="startlabel" size="1" value="<!-- TMPL_IF NAME="startlabel" --><!-- TMPL_VAR NAME="startlabel" --><!-- TMPL_ELSE -->1<!-- /TMPL_IF -->" /></li>
<li><label for="guidebox">Draw Guide Boxes</label>
<!-- TMPL_IF NAME="guidebox"-->
<input type="checkbox" name="guidebox" id="guidebox" value="1" checked="checked" />
<!-- TMPL_ELSE -->
<input type="checkbox" name="guidebox" id="guidebox" value="1" />
<!-- /TMPL_IF --></li>
<li><label for="callnum_split">Split Call Numbers</label>
<!-- TMPL_IF NAME="callnum_split"-->
<input type="checkbox" name="callnum_split" id="callnum_split" value="1" checked="checked" />
<!-- TMPL_ELSE -->
<input type="checkbox" name="callnum_split" id="callnum_split" value="1" />
<!-- /TMPL_IF --></li>
<li><label for="text_justify">Text Justification</label>
<select id="text_justify" name="text_justify">
<!-- TMPL_IF NAME="justify_L" --><option value='L' selected="selected">Left</option>
<!-- TMPL_ELSE --><option value='L'>Left</option>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="justify_C" --><option value='C' selected="selected">Center</option>
<!-- TMPL_ELSE --><option value='C'>Center</option>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="justify_R" --><option value='R' selected="selected">Right</option>
<!-- TMPL_ELSE --><option value='R'>Right</option>
<!-- /TMPL_IF -->
</select>
</li>
</ol>
</fieldset>
<fieldset class="action">
<input type="submit" value="Submit" /> <a class="cancel" href="/cgi-bin/koha/labels/label-home.pl">Cancel</a>
<input type="hidden" name="op" value="<!-- TMPL_IF NAME="layout_id" -->save<!-- TMPL_ELSE -->add<!-- /TMPL_IF -->_layout" />
<input type="hidden" name="layout_id" value="<!-- TMPL_VAR NAME="layout_id" -->" />
</fieldset>
</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> &rsaquo;
<a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
<a href="/cgi-bin/koha/labels/label-home.pl">Labels</a> &rsaquo;
<!-- TMPL_IF NAME="layout_id" -->Edit<!-- TMPL_ELSE -->Create<!-- /TMPL_IF --> Label Layout
</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="tools-labels-toolbar.inc" -->
<form name="input" action="/cgi-bin/koha/labels/label-edit-layout.pl" method="get">
<fieldset class="rows">
<legend><!-- TMPL_IF NAME="layout_id" -->Edit<!-- TMPL_ELSE -->Create<!-- /TMPL_IF --> Label Layout</legend>
<ol>
<li>
<label for="layout_name">Layout Name</label>
<input type="text" name="layout_name" id="layout_name" size="20" value="<!-- TMPL_VAR NAME="layout_name" -->" />
</li>
<li>
<label for="barcode_type">Choose Barcode Type (encoding)</label>
<select name="barcode_type" id="barcode_type">
<!-- TMPL_LOOP NAME="barcode_types" -->
<!-- TMPL_IF NAME="selected" -->
<option value="<!-- TMPL_VAR NAME="type" -->" selected="selected"><!-- TMPL_VAR NAME="name" --></option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR NAME="type" -->"><!-- TMPL_VAR NAME="name" --></option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
</li>
<li>
<label for="printing_type">Choose Layout Type</label>
<select name="printing_type" id="printing_type">
<!-- TMPL_LOOP NAME="label_types" -->
<!-- TMPL_IF NAME="selected" -->
<option value="<!-- TMPL_VAR NAME="type" -->" selected="selected"><!-- TMPL_VAR NAME="name" --></option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR NAME="type" -->"><!-- TMPL_VAR NAME="name" --></option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
</li>
<li>
<fieldset class="rows">
<legend>Bibliographic Data to Print</legend>
<input type="radio" name="layout_choice" value="layout_table" <!-- TMPL_UNLESS NAME="layout_string" -->checked="checked"<!-- /TMPL_UNLESS -->" >Choose Order Of Text Fields to Print</input>
<br />
<fieldset id="layout_table">
<table summary="fields to print">
<!-- TMPL_LOOP NAME="field_table" -->
<tr>
<!-- TMPL_LOOP NAME="text_fields" -->
<!-- TMPL_IF NAME="field_empty" -->
<td>
&nbsp;
</td>
<!-- TMPL_ELSE -->
<td>
<select name="<!-- TMPL_VAR NAME="field_name" -->" id="<!-- TMPL_VAR NAME="field_name" -->">
<!-- TMPL_LOOP NAME="order" -->
<!-- TMPL_IF Name="selected" -->
<option value="<!-- TMPL_VAR Name="num" -->" selected="selected"><!-- TMPL_VAR Name="num" --></option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR Name="num" -->"><!-- TMPL_VAR Name="num" --></option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
<label for="<!-- TMPL_VAR NAME="field_name" -->"><!-- TMPL_VAR NAME="field_label" --></label>
</td>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</tr>
<!-- /TMPL_LOOP -->
</table>
<br />
</fieldset>
<br />
<input type="radio" name="layout_choice" value="layout_string" <!-- TMPL_IF NAME="layout_string" -->checked="checked"<!-- /TMPL_IF -->"> List Fields </input>
<fieldset id="layout_string" class="brief">
<label for="format_string">Data Fields</label>
<input type="text" name="format_string" id="format_string" size="80" value="<!-- TMPL_VAR ESCAPE='HTML' NAME="format_string" -->" />
<div class="help">
<p>Enter a comma separated list of fields to print. You may include any <em>Koha field</em> or MARC subfield.</p>
<p>See online help for advanced options</p>
<p>ex: barcode, itemcallnumber, title, "050a 050b", 300a </p>
</div>
</fieldset>
</fieldset>
</li>
<li>
<label for="guidebox">Draw Guide Boxes</label>
<!-- TMPL_IF NAME="guidebox"-->
<input type="checkbox" name="guidebox" id="guidebox" value="1" checked="checked" />
<!-- TMPL_ELSE -->
<input type="checkbox" name="guidebox" id="guidebox" value="1" />
<!-- /TMPL_IF -->
</li>
<li>
<label for="callnum_split">Split Call Numbers</label>
<!-- TMPL_IF NAME="callnum_split"-->
<input type="checkbox" name="callnum_split" id="callnum_split" value="1" checked="checked" />
<!-- TMPL_ELSE -->
<input type="checkbox" name="callnum_split" id="callnum_split" value="1" />
<!-- /TMPL_IF -->
</li>
<li>
<label for="text_justify">Text Justification</label>
<select name="text_justify" id="text_justify">
<!-- TMPL_LOOP Name="text_justification_types" -->
<!-- TMPL_IF Name="selected" -->
<option value="<!-- TMPL_VAR Name="type" -->" selected="selected"><!-- TMPL_VAR Name="name" --></option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR Name="type" -->"><!-- TMPL_VAR Name="name" --></option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
</li>
<li>
<label for="font">Font</label>
<select name="font" id="font">
<!-- TMPL_LOOP Name="font_types" -->
<!-- TMPL_IF Name="selected" -->
<option value="<!-- TMPL_VAR Name="type" -->" selected="selected"><!-- TMPL_VAR Name="name" --></option>
<!-- TMPL_ELSE -->
<option value="<!-- TMPL_VAR Name="type" -->"><!-- TMPL_VAR Name="name" --></option>
<!-- /TMPL_IF -->
<!-- /TMPL_LOOP -->
</select>
</li>
<li>
<label for="font_size">Font Size</label>
<input type="text" name="font_size" id="font_size" size="2" value="<!-- TMPL_VAR ESCAPE='HTML' NAME="font_size" -->" />
</li>
</ol>
</fieldset>
<fieldset class="action">
<input type="submit" value="Submit" /><a class="cancel" href="/cgi-bin/koha/labels/label-layout.pl">Cancel</a>
<input type="hidden" name="op" value="save" />
<input type="hidden" name="layout_id" value="<!-- TMPL_VAR NAME="layout_id" -->" />
</fieldset>
</form>
</div>
</div>
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="labels-menu.inc" -->
</div>
</div>
<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->

100
koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-layout.tmpl

@ -0,0 +1,100 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
<title>Koha &rsaquo; Tools &rsaquo; Labels</title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<script type="text/JavaScript" language="JavaScript">
//<![CDATA[
function DeleteConfirm() {
var layout_id = selected_layout();
if (layout_id>-1) {
var msg = "Are you sure you want to delete template " + layout_id + "?"
var answer = confirm(msg);
if (answer) {
window.location = "/cgi-bin/koha/labels/label-layout.pl?op=delete&amp;layout_id=" + layout_id;
}
else {
return; // abort delete
}
}
else {
return; // no layout selected
};
};
function Edit() {
var layout_id = selected_layout();
if (layout_id>-1) {
window.location = "/cgi-bin/koha/labels/label-edit-layout.pl?op=edit&amp;layout_id=" + layout_id;
}
else {
return; // no layout selected
};
};
function selected_layout() {
for (i=0;i<document.layouts.action.length;i++){
if (document.layouts.action[i].checked==true){
return(document.layouts.action[i].value);
};
};
alert("Please select a layout.");
return (-1);
};
//]]>
</script>
</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> &rsaquo;
<a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo;
Label Layouts
</div>
<div id="doc3" class="yui-t2">
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="tools-labels-toolbar.inc" -->
<div class="yui-gc">
<div class="yui-u first" id="manage-label-layouts">
<form name="layouts">
<h2>Currently Available Layouts</h2>
<table>
<tr>
<th>Layout ID</th>
<th>Layout</th>
<th>Barcode Type</th>
<th>Print Type</th>
<th>Fields to Print</th>
<th>Select</th>
</tr>
<!-- TMPL_LOOP NAME="layout_loop" -->
<tr>
<td><!-- TMPL_VAR NAME="layout_id" --></td>
<td><!-- TMPL_VAR NAME="layout_name" --></td>
<td><!-- TMPL_VAR NAME="barcode_type" --></td>
<td><!-- TMPL_VAR NAME="printing_type" --></td>
<td><!-- TMPL_VAR NAME="format_string" --></td>
<td align="center"><input type="radio" name="action" value="<!-- TMPL_VAR NAME="layout_id" -->"></td>
</tr>
<!-- /TMPL_LOOP -->
</table>
</form>
<div style="margin: 10px 10px 10px 0px;">
<span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="edit" onclick="Edit()" value="Edit"></span></span>
<span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="delete" onclick="DeleteConfirm()" value="Delete"></span></span>
</div>
</div>
<!-- TMPL_IF NAME="error" -->
<div class="yui-u">
<div class="dialog alert">
<strong>WARNING: An error was encountered and layout <!-- TMPL_VAR NAME="layout_id" --> was not deleted. Please have your system administrator check the syslog for details.</strong>
</div>
</div>
<!-- /TMPL_IF -->
</div>
</div>
</div>
<div class="yui-b">
<!-- TMPL_INCLUDE NAME="labels-menu.inc" -->
</div>
</div>
<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->

208
labels/label-edit-layout.pl

@ -1,80 +1,174 @@
#!/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 Data::Dumper;
use POSIX;
use Text::CSV_XS;
#use Data::Dumper;
#use Smart::Comments;
my $dbh = C4::Context->dbh;
my $query = new CGI;
my $layout_id = $query->param('layout_id');
### $query;
use C4::Auth;
use C4::Output;
use C4::Context;
use C4::Debug;
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;
my $cgi = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "labels/label-edit-layout.tmpl",
query => $query,
query => $cgi,
type => "intranet",
authnotrequired => 1,
authnotrequired => 0,
flagsrequired => { catalogue => 1 },
debug => 1,
}
);
my $layout = get_layout($layout_id);
my @barcode_types = get_barcode_types($layout_id);
my @printingtypes = get_printingtypes($layout_id);
### @printingtypes
### $layout
$layout_id = $layout->{'id'}; # has it changed since we set it above? --joe
my $layoutname = $layout->{'layoutname'};
my $guidebox = $layout->{'guidebox'};
my $startlabel = $layout->{'startlabel'};
my $op = $cgi->param('op') || $ARGV[0] || '';
my $layout_id = $cgi->param('layout_id') || $ARGV[1] || '';
my $layout = '';
my @title = build_text_dropbox( $layout->{'title'} );
my @subtitle = build_text_dropbox( $layout->{'subtitle'} );
my @author = build_text_dropbox( $layout->{'author'} );
my @barcode = build_text_dropbox( $layout->{'barcode'} );
my @isbn = build_text_dropbox( $layout->{'isbn'} );
my @issn = build_text_dropbox( $layout->{'issn'} );
my @itemtype = build_text_dropbox( $layout->{'itemtype'} );
my @dewey = build_text_dropbox( $layout->{'dewey'} );
my @class = build_text_dropbox( $layout->{'class'} );
my @subclass = build_text_dropbox( $layout->{'subclass'} );
my @itemcallnumber = build_text_dropbox( $layout->{'itemcallnumber'} );
sub _set_selected {
my ($type_list, $object, $data_type) = @_;
SET_SELECTED:
foreach my $type (@$type_list) {
if ($layout->get_attr($data_type)) {
if ($type->{'type'} eq $layout->get_attr($data_type)) {
$type->{'selected'} = 1;
}
}
else {
$type->{'selected'} = 1;
last SET_SELECTED;
}
};
return $type_list;
}
### @subclass
sub _select_format_string { # generate field table based on format_string
my $format_string = shift;
$format_string =~ s/(?<=,) (?![A-Z][a-z][0-9])//g; # remove spaces between fields
my $table = [];
my $fields = [];
my ($row_index, $col_index, $field_index) = (0,0,0);
my $cols = 5; # number of columns to wrap on
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();
my $field_count = $#text_fields + 1;
POPULATE_TABLE:
foreach my $text_field (@text_fields) {
$$fields[$col_index] = {field_empty => 0, field_name => ($text_field . "_tbl"), field_label => $text_field, order => [{num => '', selected => 0}]};
for (my $order_i = 1; $order_i <= $field_count; $order_i++) {
$$fields[$col_index]{'order'}[$order_i] = {num => $order_i, selected => ($field_index == $order_i-1 ? 1 : 0)};
}
$col_index++;
$field_index++;
if ((($col_index > 0) && !($col_index % $cols)) || ($field_index == $field_count)) { # wrap to new row
if ($field_index == $field_count) { # in this case fill out row with empty fields
while ($col_index < $cols) {
$$fields[$col_index] = {field_empty => 1, field_name => '', field_label => '', order => [{num => '', selected => 0}]};
$col_index++;
}
$$table[$row_index] = {text_fields => $fields};
last POPULATE_TABLE;
}
$$table[$row_index] = {text_fields => $fields};
$row_index++;
$fields = [];
$col_index = 0;
}
}
return $table;
}
if ($op eq 'edit') {
syslog("LOG_ERR", "labels/label-edit-layout.pl : Error performing '%s': No 'layout_id' passed in.", $op) unless ($layout);
$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
my @layout_table = ();
foreach my $cgi_param ($cgi->param()) {
if (($cgi_param =~ m/^(.*)_tbl$/) && ($cgi->param($cgi_param))) {
my $value = $cgi->param($cgi_param);
$layout_table[$value - 1] = $1;
}
}
@layout_table = grep {$_} @layout_table; # this removes numerically 'skipped' fields. ie. user omits a number in sequential order
$format_string = join ', ', @layout_table;
$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'),
guidebox => ($cgi->param('guidebox') ? 1 : 0),
font => $cgi->param('font'),
font_size => $cgi->param('font_size'),
callnum_split => ($cgi->param('callnum_split') ? 1 : 0),
text_justify => $cgi->param('text_justify'),
format_string => $cgi->param('format_string'),
);
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();
}
else { # if no label_id, this is a new layout so insert it
$layout = C4::Labels::Layout->new(@params);
$layout->save();
}
print $cgi->redirect("label-layout.pl");
exit;
}
else { # if we get here, this is a new layout
$layout = C4::Labels::Layout->new();
}
my $barcode_types = _set_selected(get_barcode_types(), $layout, 'barcode_type');
my $label_types = _set_selected(get_label_types(), $layout, 'printing_type');
my $font_types = _set_selected(get_font_types(), $layout, 'font');
my $text_justification_types = _set_selected(get_text_justification_types(), $layout, 'text_justify');
my $select_text_fields = _select_format_string($layout->get_attr('format_string'));
$template->param(
barcode_types => \@barcode_types,
printingtypes => \@printingtypes,
layoutname => $layoutname,
layout_id => $layout_id,
guidebox => $guidebox,
startlabel => $startlabel,
formatstring => $layout->{'formatstring'},
callnum_split => $layout->{'callnum_split'},
'justify_' . $layout->{'text_justify'} => 1,
tx_title => \@title,
tx_subtitle => \@subtitle,
tx_author => \@author,
tx_isbn => \@isbn,
tx_issn => \@issn,
tx_itemtype => \@itemtype,
tx_dewey => \@dewey,
tx_barcode => \@barcode,
tx_classif => \@class,
tx_subclass => \@subclass,
tx_itemcallnumber => \@itemcallnumber,
barcode_types => $barcode_types,
label_types => $label_types,
font_types => $font_types,
text_justification_types => $text_justification_types,
field_table => $select_text_fields,
layout_id => $layout->get_attr('layout_id') > -1 ? $layout->get_attr('layout_id') : '',
layout_name => $layout->get_attr('layout_name'),
guidebox => $layout->get_attr('guidebox'),
font_size => $layout->get_attr('font_size'),
callnum_split => $layout->get_attr('callnum_split'),
format_string => $layout->get_attr('format_string'),
);
output_html_with_http_headers $query, $cookie, $template->output;
output_html_with_http_headers $cgi, $cookie, $template->output;

70
labels/label-layout.pl

@ -0,0 +1,70 @@
#!/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 HTML::Template::Pro;
use Data::Dumper;
use C4::Auth;
use C4::Output;
use C4::Context;
use C4::Debug;
use C4::Labels::Lib 1.000000 qw(get_all_templates get_all_layouts get_barcode_types get_label_types);
use C4::Labels::Layout 1.000000;
my $cgi = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "labels/label-layout.tmpl",
query => $cgi,
type => "intranet",
authnotrequired => 0,
flagsrequired => { catalogue => 1 },
debug => 1,
}
);
my $error = 0;
my $op = $cgi->param('op') || $ARGV[0];
my $layout_id = $cgi->param('layout_id') || $ARGV[1];
if ($op eq 'delete') {
$error = C4::Labels::Layout::delete(layout_id => $layout_id);
}
my $layouts = get_all_layouts();
$template->param(
error => $error,
layout_id => $layout_id,
) if ($error ne 0);
$template->param(
op => $op,
barcode_types => get_barcode_types(),
printingtypes => get_label_types(),
layout_loop => $layouts,
);
output_html_with_http_headers $cgi, $cookie, $template->output;
Loading…
Cancel
Save