[24/40] Adding single/multiple label printing to label export code and interface.

This adds single/multiple label printing by item number along with new CSV and XML export code.
This commit is contained in:
Chris Nighswonger 2009-09-01 14:13:39 -04:00
parent 51db13b8da
commit 39d227d712
14 changed files with 389 additions and 111 deletions

View File

@ -96,7 +96,7 @@ sub new {
my $sth = C4::Context->dbh->prepare("SELECT MAX(batch_id) FROM labels_batches;");
$sth->execute();
my $batch_id = $sth->fetchrow_array;
$self->{'batch_id'} = ++$batch_id;
$self->{'batch_id'} = ++$batch_id unless $self->{'batch_id'} != 0; # this allows batch_id to be passed in for individual label printing
bless ($self, $type);
return $self;
}

View File

@ -509,6 +509,15 @@ sub barcode {
}
}
sub csv_data {
my $self = shift;
my $label_fields = _get_text_fields($self->{'format_string'});
my $item = _get_label_item($self->{'item_number'});
my $bib_record = GetMarcBiblio($item->{biblionumber});
my @csv_data = (map { _get_barcode_data($_->{'code'},$item,$bib_record) } @$label_fields);
return \@csv_data;
}
1;
__END__

View File

@ -19,6 +19,7 @@ package C4::Labels::Lib;
use strict;
use warnings;
use Sys::Syslog qw(syslog);
use Data::Dumper;

View File

@ -22,6 +22,7 @@ use warnings;
use Sys::Syslog qw(syslog);
use Data::Dumper;
use PDF::Reuse;
use POSIX qw(ceil);
use C4::Context;
use C4::Debug;

View File

@ -156,3 +156,15 @@
.GB_Window .on { border-bottom: 1px solid #333; }
.GB_Window .click { border-bottom: 1px solid red; }
table {
border-collapse: separate;
border-spacing: 0;
border: hidden none;
}
.header {
cursor: auto;
background-position: center center;
background-repeat: repeat;
}

View File

@ -1,6 +1,7 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
<title>Koha &rsaquo; Tools &rsaquo; Labels &rsaquo; Manage Label Batches</title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<!-- TMPL_INCLUDE NAME="greybox.inc" -->
<script type="text/JavaScript" language="JavaScript">
//<![CDATA[
function Remove() {
@ -36,21 +37,41 @@
function Add() {
window.location = "/cgi-bin/koha/labels/label-edit-batch.pl?op=add&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->";
};
function Print(mode) {
if (mode == 'batch') {
alert("Print batch <!-- TMPL_VAR NAME="batch_id" -->.");
// window.location = "/cgi-bin/koha/labels/label-edit-batch.pl?op=print&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->";
function Xport(mode) {
if (mode == 'label') {
labels= new Array;
if(document.items.action.length > 0) {
for (var i=0; i < document.items.action.length; i++) {
if (document.items.action[i].checked) {
labels.push("label_id=" + document.items.action[i].value);
}
}
if (labels.length < 1) {
alert("Please select at least one label to export.");
return; // no batch selected
}
getstr = labels.join("&");
}
else if (document.items.action.checked) {
getstr = document.items.action.value;
}
else {
alert("Please select at least one label to export.");
return; // no batch selected
}
//<td><a href="/cgi-bin/koha/catalogue/showmarc.pl?importid=<!-- TMPL_VAR NAME="breedingid" -->" title="MARC" rel="gb_page_center[600,500]">MARC</a></td>
//window.location = "/cgi-bin/koha/labels/label-print.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&" + getstr;
//return GB_show('Google', this.href)
return GB_showCenter('Export Labels', "/cgi-bin/koha/labels/label-print.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&" + getstr, 700, 800);
}
else if (mode == 'batch') {
//window.location = "/cgi-bin/koha/labels/label-print.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->";
//$(".checkboxed").uncheckCheckboxes();
return GB_showCenter('Export Labels', "/cgi-bin/koha/labels/label-print.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->", 700, 800);
}
else {
var label_id = selected_layout();
alert("Print item " + label_id + ".");
// if (label_id>-1) {
// window.location = "/cgi-bin/koha/labels/label-edit-batch.pl?op=print&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;label_id=" + label_id;
// }
// else {
// return; // no layout selected
// };
};
// some pass-thru error trapping just in case...
}
};
function selected_layout() {
if (document.items.action.length) {
@ -93,7 +114,7 @@
<div class="yui-gc">
<div class="yui-u first" id="manage-label-batches">
<div class="hint">Current Branch: <!-- TMPL_VAR NAME="LoginBranchname" --></div>
<form name="items">
<form name="items" class="checkboxed">
<h2>Items in batch number <!-- TMPL_VAR NAME="batch_id" --></h2>
<table>
<!-- TMPL_LOOP NAME="table_loop" -->
@ -120,8 +141,8 @@
<div style="margin: 10px 10px 10px 0px;">
<span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="add" onclick="Add()" value="Add Item(s)"></span></span>
<span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="remove" onclick="Remove()" value="Remove Item(s)"></span></span>
<span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="print_item" onclick="Print(item)" value="Print Item(s)"></span></span>
<span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="print_batch" onclick="Print(batch)" value="Print Batch"></span></span>
<span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="print_item" onclick="Xport('label')" value="Print Item(s)"></span></span>
<span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="print_batch" onclick="Xport('batch')" value="Print Batch"></span></span>
</div>
</div>
<!-- TMPL_IF NAME="err" -->

View File

@ -1,6 +1,7 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
<title>Koha &rsaquo; Tools &rsaquo; Labels &rsaquo; Manage Label Elements</title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<!-- TMPL_INCLUDE NAME="greybox.inc" -->
<script type="text/JavaScript" language="JavaScript">
//<![CDATA[
function DeleteConfirm() {
@ -28,18 +29,7 @@
return; // no layout selected
};
};
function Print() {
var element_id = selected_layout("print");
if (element_id>-1) {
window.location = "/cgi-bin/koha/labels/label-print.pl?batch_id=" + element_id;
}
else {
return; // no layout selected
};
};
function Xport() {
function Xport() {
batches= new Array;
if(document.layouts.action.length > 0) {
for (var i=0; i < document.layouts.action.length; i++) {
@ -63,13 +53,13 @@
var msg = "Are you sure you want to export the selected batch(s)?"
var answer = confirm(msg);
if (answer) {
window.location = "/cgi-bin/koha/labels/label-print.pl?" + getstr;
return GB_showCenter('Export Labels', "/cgi-bin/koha/labels/label-print.pl?" + getstr, 700, 800);
// window.location = "/cgi-bin/koha/labels/label-print.pl?" + getstr;
}
else {
return; // abort export
}
};
function selected_layout(op) {
var selected = new Array;
if (document.layouts.action.length) {

View File

@ -1,14 +1,20 @@
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
<title>Koha &rsaquo; Tools &rsaquo; Labels &rsaquo; Label Printing/Exporting</title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<script type="text/JavaScript" language="JavaScript">
//<![CDATA[
function Done() {
window.location = "<!-- TMPL_VAR NAME="referer" -->";
};
//]]>
</script>
<style type="text/css">#custom-doc {width:47.23em; *width:46.04em; min-width:610px; margin:auto; margin-top:0.4em;}</style>
</head>
<body>
<div id="custom-doc" class="yui-t2">
<div id="bd">
<!-- TMPL_IF NAME="batches" -->
<form name="exporting" method="post" action="/cgi-bin/koha/labels/label-manage.pl">
<input type="hidden" name="label_element" value="batch" />
<form>
<div align="center">
<div class="message">
<h2>Click on the following link(s) to download the exported batch(es).</h2>
@ -19,27 +25,48 @@
<!-- TMPL_LOOP NAME="batches" -->
<tr>
<td class="borderless">
<!-- TMPL_IF NAME="label_ids" -->
<a href="/cgi-bin/koha/labels/<!-- TMPL_VAR NAME="create_script" -->?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;template_id=<!-- TMPL_VAR NAME="template_id" -->&amp;layout_id=<!-- TMPL_VAR NAME="layout_id" -->&amp;start_label=<!-- TMPL_VAR NAME="start_label" --><!-- TMPL_VAR NAME="label_ids" -->">label_single_<!-- TMPL_VAR NAME="label_count" -->.pdf</a>
<!-- TMPL_ELSIF NAME="item_numbers" -->
<a href="/cgi-bin/koha/labels/<!-- TMPL_VAR NAME="create_script" -->?template_id=<!-- TMPL_VAR NAME="template_id" -->&amp;layout_id=<!-- TMPL_VAR NAME="layout_id" -->&amp;start_label=<!-- TMPL_VAR NAME="start_label" --><!-- TMPL_VAR NAME="item_numbers" -->">label_single_<!-- TMPL_VAR NAME="label_count" -->.pdf</a>
<!-- TMPL_ELSE -->
<a href="/cgi-bin/koha/labels/<!-- TMPL_VAR NAME="create_script" -->?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;template_id=<!-- TMPL_VAR NAME="template_id" -->&amp;layout_id=<!-- TMPL_VAR NAME="layout_id" -->&amp;start_label=<!-- TMPL_VAR NAME="start_label" -->">label_batch_<!-- TMPL_VAR NAME="batch_id" -->.pdf</a>
<!-- /TMPL_IF -->
</td>
</tr>
<!-- /TMPL_LOOP -->
</table>
</fieldset>
<fieldset class="action">
<input type="submit" value="Done" class="submit" />
<div style="margin: 10px 10px 10px 0px;">
<span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="done" onclick="parent.parent.GB_hide();" value="Done"></span></span>
</div>
</fieldset>
</form>
<!-- TMPL_ELSE -->
<div align="center">
<div class="message">
<!-- TMPL_IF NAME="label_ids" -->
<h2>Exporting <!-- TMPL_VAR NAME="label_count" --> label(s).</h2>
<!-- TMPL_ELSIF NAME="item_numbers"-->
<h2>Exporting <!-- TMPL_VAR NAME="item_count" --> label(s).</h2>
<!-- TMPL_ELSE -->
<h2><!-- TMPL_VAR NAME="multi_batch_count" --> batch(es) to export.</h2>
<!-- /TMPL_IF -->
</div>
</div>
<form name="exporting" method="post" action="/cgi-bin/koha/labels/label-print.pl">
<input type="hidden" name="op" value="export" />
<input type="hidden" name="referer" value="<!-- TMPL_VAR NAME="referer" -->" />
<!-- TMPL_LOOP NAME="batch_ids" -->
<input type="hidden" name="batch_id" value="<!-- TMPL_VAR NAME="batch_id" -->" />
<!-- /TMPL_LOOP -->
<!-- TMPL_LOOP NAME="label_ids" -->
<input type="hidden" name="label_id" value="<!-- TMPL_VAR NAME="label_id" -->" />
<!-- /TMPL_LOOP -->
<!-- TMPL_LOOP NAME="item_numbers" -->
<input type="hidden" name="item_number" value="<!-- TMPL_VAR NAME="item_number" -->" />
<!-- /TMPL_LOOP -->
<fieldset class="rows">
<table class="borderless">
<tr>
@ -89,8 +116,10 @@
</table>
</fieldset>
<fieldset class="action">
<input type="submit" value="Export" class="submit" />
<a class="cancel close" href="#">Cancel</a>
<div style="margin: 10px 10px 10px 0px;">
<span class="yui-button yui-link-button"><span class="first-child"><input type="submit" value="Export" /></span></span>
<span class="yui-button yui-link-button"><span class="first-child"><input type="button" id="done" onclick="parent.parent.GB_hide();" value="Cancel"></span></span>
</div>
</fieldset>
</form>
<!-- /TMPL_IF -->

View File

@ -1,55 +1,95 @@
#!/usr/bin/perl
# 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 CGI;
use C4::Labels;
use C4::Auth;
use C4::Output;
use C4::Context;
use C4::Biblio;
use Sys::Syslog qw(syslog);
use Text::CSV_XS;
use Data::Dumper;
my $DEBUG = 0;
my $DEBUG_LPT = 0;
use C4::Debug;
use C4::Labels::Batch 1.000000;
use C4::Labels::Template 1.000000;
use C4::Labels::Layout 1.000000;
use C4::Labels::PDF 1.000000;
use C4::Labels::Label 1.000000;
my $htdocs_path = C4::Context->config('intrahtdocs');
my $cgi = new CGI;
=head
=cut
my $cgi = new CGI;
my $batch_id = $cgi->param('batch_id') if $cgi->param('batch_id');
my $template_id = $cgi->param('template_id') || undef;
my $layout_id = $cgi->param('layout_id') || undef;
my @label_ids = $cgi->param('label_id') if $cgi->param('label_id');
my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
my $items = undef;
my $csv_file = (@label_ids || @item_numbers ? "label_single_" . scalar(@label_ids || @item_numbers) : "label_batch_$batch_id");
print $cgi->header(-type => 'application/vnd.sun.xml.calc',
-encoding => 'utf-8',
-attachment => "$csv_file.csv",
);
# get the printing settings
my $template = GetActiveLabelTemplate();
my $conf_data = get_label_options();
my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
my $template = C4::Labels::Template->retrieve(template_id => $template_id, profile_id => 1);
my $layout = C4::Labels::Layout->retrieve(layout_id => $layout_id);
my $batch_id = $cgi->param('batch_id');
my $exportname = 'koha_label_' . $batch_id . '.csv';
print $cgi->header(-type => 'application/vnd.sun.xml.calc',
-encoding => 'utf-8',
-attachment => $exportname,
-filename => $exportname );
if (@label_ids) {
my $batch_items = $batch->get_attr('items');
grep {
my $label_id = $_;
push(@{$items}, grep{$_->{'label_id'} == $label_id;} @{$batch_items});
} @label_ids;
}
elsif (@item_numbers) {
grep {
push(@{$items}, {item_number => $_});
} @item_numbers;
}
else {
$items = $batch->get_attr('items');
}
my $batch_type = $conf_data->{'type'};
my $barcodetype = $conf_data->{'barcodetype'};
my $printingtype = $conf_data->{'printingtype'};
my @resultsloop = GetLabelItems($batch_id);
my $csv = Text::CSV_XS->new();
my @str_fields = get_text_fields($conf_data->{'id'}, 'codes' );
for my $item (@resultsloop) {
my $record = GetMarcBiblio($item->{biblionumber});
my @datafields = map { C4::Labels::GetBarcodeData($_->{'code'},$item,$record) } @str_fields ;
my $csvout ;
if($csv->combine(@datafields)) {
$csvout = $csv->string();
print "$csvout\n";
} else {
warn "CSV ERROR: " . $csv->error_input;
}
} # end for item loop
CSV_ITEMS:
foreach my $item (@$items) {
my $label = C4::Labels::Label->new(
batch_id => $batch_id,
item_number => $item->{'item_number'},
format_string => $layout->get_attr('format_string'),
);
my $csv_fields = $label->csv_data();
if ($csv->combine(@$csv_fields)) {
print $csv->string() . "\n";
}
else {
syslog("LOG_ERR", "labels/label-create-csv.pl : Text::CSV_XS->combine() returned the following error: %s", $csv->error_input);
next CSV_ITEMS;
}
}
exit(1);
# is that the right way to do this ?

View File

@ -22,17 +22,9 @@ use strict;
use warnings;
use CGI;
use HTML::Template::Pro;
use POSIX qw(ceil);
use Data::Dumper;
use Sys::Syslog qw(syslog);
use Data::Dumper;
use C4::Labels;
use C4::Auth;
use C4::Output;
use C4::Context;
use C4::Members;
use C4::Branch;
use C4::Debug;
use C4::Labels::Batch 1.000000;
use C4::Labels::Template 1.000000;
@ -40,15 +32,26 @@ use C4::Labels::Layout 1.000000;
use C4::Labels::PDF 1.000000;
use C4::Labels::Label 1.000000;
=head
=cut
my $cgi = new CGI;
my $htdocs_path = C4::Context->config('intrahtdocs');
my $batch_id = $cgi->param('batch_id') || $ARGV[0];
my $template_id = $cgi->param('template_id') || $ARGV[1];
my $layout_id = $cgi->param('layout_id') || $ARGV[2];
my $start_label = $cgi->param('start_label') || $ARGV[3];
my $batch_id = $cgi->param('batch_id') if $cgi->param('batch_id');
my $template_id = $cgi->param('template_id') || undef;
my $layout_id = $cgi->param('layout_id') || undef;
my $start_label = $cgi->param('start_label') || 1;
my @label_ids = $cgi->param('label_id') if $cgi->param('label_id');
my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
print $cgi->header( -type => 'application/pdf', -attachment => "label_batch_$batch_id.pdf" );
my $items = undef;
my $pdf_file = (@label_ids || @item_numbers ? "label_single_" . scalar(@label_ids || @item_numbers) : "label_batch_$batch_id");
print $cgi->header( -type => 'application/pdf',
-encoding => 'utf-8',
-attachment => "$pdf_file.pdf",
);
my $pdf = C4::Labels::PDF->new(InitVars => 0);
my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
@ -98,8 +101,25 @@ $pdf->Compress(1);
$pdf->Mbox($lowerLeftX, $lowerLeftY, $upperRightX, $upperRightY);
my ($row_count, $col_count, $llx, $lly) = $template->get_label_position($start_label);
if (@label_ids) {
my $batch_items = $batch->get_attr('items');
grep {
my $label_id = $_;
push(@{$items}, grep{$_->{'label_id'} == $label_id;} @{$batch_items});
} @label_ids;
}
elsif (@item_numbers) {
grep {
push(@{$items}, {item_number => $_});
} @item_numbers;
}
else {
$items = $batch->get_attr('items');
}
LABEL_ITEMS:
foreach my $item (@{$batch->get_attr('items')}) {
foreach my $item (@{$items}) {
my ($barcode_llx, $barcode_lly, $barcode_width, $barcode_y_scale_factor) = 0,0,0,0;
my $label = C4::Labels::Label->new(
batch_id => $batch_id,
@ -174,3 +194,5 @@ foreach my $item (@{$batch->get_attr('items')}) {
}
$pdf->End();
exit(1);

107
labels/label-create-xml.pl Executable file
View File

@ -0,0 +1,107 @@
#!/usr/bin/perl
# 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 CGI;
use Sys::Syslog qw(syslog);
use XML::Simple;
use Data::Dumper;
use C4::Debug;
use C4::Labels::Batch 1.000000;
use C4::Labels::Template 1.000000;
use C4::Labels::Layout 1.000000;
use C4::Labels::PDF 1.000000;
use C4::Labels::Label 1.000000;
=head
=cut
my $cgi = new CGI;
my $batch_id = $cgi->param('batch_id') if $cgi->param('batch_id');
my $template_id = $cgi->param('template_id') || undef;
my $layout_id = $cgi->param('layout_id') || undef;
my @label_ids = $cgi->param('label_id') if $cgi->param('label_id');
my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
my $items = undef;
my $xml_file = (@label_ids || @item_numbers ? "label_single_" . scalar(@label_ids || @item_numbers) : "label_batch_$batch_id");
print $cgi->header(-type => 'text/xml',
-encoding => 'utf-8',
-attachment => "$xml_file.xml",
);
my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
my $template = C4::Labels::Template->retrieve(template_id => $template_id, profile_id => 1);
my $layout = C4::Labels::Layout->retrieve(layout_id => $layout_id);
if (@label_ids) {
my $batch_items = $batch->get_attr('items');
grep {
my $label_id = $_;
push(@{$items}, grep{$_->{'label_id'} == $label_id;} @{$batch_items});
} @label_ids;
}
elsif (@item_numbers) {
grep {
push(@{$items}, {item_number => $_});
} @item_numbers;
}
else {
$items = $batch->get_attr('items');
}
my $xml = XML::Simple->new();
my $xml_data = {'label' => []};
my $item_count = 0;
XML_ITEMS:
foreach my $item (@$items) {
push(@{$xml_data->{'label'}}, {'item_number' => $item->{'item_number'}});
my $label = C4::Labels::Label->new(
batch_id => $batch_id,
item_number => $item->{'item_number'},
format_string => $layout->get_attr('format_string'),
);
my $format_string = $layout->get_attr('format_string');
my @data_fields = split(/, /, $format_string);
my $csv_data = $label->csv_data();
for (my $i = 0; $i < (scalar(@data_fields) - 1); $i++) {
push(@{$xml_data->{'label'}[$item_count]->{$data_fields[$i]}}, $$csv_data[$i]);
}
$item_count++;
# else {
# syslog("LOG_ERR", "labels/label-create-csv.pl : Text::CSV_XS->combine() returned the following error: %s", $csv->error_input);
# next CSV_ITEMS;
# }
}
#die "XML DATA:\n" . Dumper($xml_data);
my $xml_out = $xml->XMLout($xml_data);
#die "XML OUT:\n" . Dumper($xml_out);
print $xml_out;
exit(1);

View File

@ -104,20 +104,17 @@ $db_rows = get_label_summary(items => $items, batch_id => $batch_id);
my $table = html_table($display_columns, $db_rows);
$template->param(
duplicate_message => $duplicate_message,
duplicate_count => $duplicate_count,
);
$template->param(
err => $err,
errstr => $errstr,
) if ($err ne 0);
$template->param(
op => $op,
batch_id => $batch_id,
table_loop => $table,
op => $op,
batch_id => $batch_id,
table_loop => $table,
duplicate_message => $duplicate_message,
duplicate_count => $duplicate_count,
);
output_html_with_http_headers $cgi, $cookie, $template->output;

View File

@ -24,7 +24,7 @@ use vars qw($debug $cgi_debug);
use CGI;
use HTML::Template::Pro;
use List::Util qw( max min );
use POSIX;
use POSIX qw(ceil);
use C4::Auth qw(get_template_and_user);
use C4::Output qw(output_html_with_http_headers);

View File

@ -27,6 +27,7 @@ use Data::Dumper;
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_all_templates get_all_layouts get_label_output_formats);
use C4::Labels::Batch 1.000000;
my $cgi = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@ -41,43 +42,91 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
);
my $op = $cgi->param('op') || 'none';
my @select_labels = $cgi->param('label_id') if $cgi->param('label_id'); # this will handle individual label printing
my @label_ids = $cgi->param('label_id') if $cgi->param('label_id'); # this will handle individual label printing
my @batch_ids = $cgi->param('batch_id') if $cgi->param('batch_id');
my $layout_id = $cgi->param('layout_id') || undef;
my $template_id = $cgi->param('template_id') || undef;
my $start_label = $cgi->param('start_label') || 1;
my $start_label = $cgi->param('start_label') || 1;
my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
my $output_format = $cgi->param('output_format') || 'pdf';
my $referer = $cgi->param('referer') || undef;
my $layouts = undef;
my $templates = undef;
my $label_output_formats = undef;
my @batches = ();
my $multi_batch_count = scalar(@batch_ids);
my $label_count = scalar(@label_ids);
my $item_count = scalar(@item_numbers);
if ($op eq 'export') {
foreach my $batch_id (@batch_ids) {
push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
batch_id => $batch_id,
template_id => $template_id,
layout_id => $layout_id,
start_label => $start_label,
if (@label_ids) {
my $label_id_param = '&amp;label_id=';
$label_id_param .= join ('&amp;label_id=',@label_ids);
push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
batch_id => $batch_ids[0],
template_id => $template_id,
layout_id => $layout_id,
start_label => $start_label,
label_ids => $label_id_param,
label_count => scalar(@label_ids),
});
$template->param(
batches => \@batches,
referer => $referer,
);
}
elsif (@item_numbers) {
my $item_number_param = '&amp;item_number=';
$item_number_param .= join ('&amp;item_number=',@item_numbers);
push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
template_id => $template_id,
layout_id => $layout_id,
start_label => $start_label,
item_numbers => $item_number_param,
label_count => scalar(@item_numbers),
});
$template->param(
batches => \@batches,
referer => $referer,
);
}
elsif (@batch_ids) {
foreach my $batch_id (@batch_ids) {
push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
batch_id => $batch_id,
template_id => $template_id,
layout_id => $layout_id,
start_label => $start_label,
});
}
$template->param(
batches => \@batches,
referer => $referer,
);
}
$template->param(
batches => \@batches,
);
}
elsif ($op eq 'none') {
# setup select menus for selecting layout and template for this run...
$referer = $ENV{'HTTP_REFERER'};
$referer =~ s/^.*?:\/\/.*?(\/.*)$/$1/m;
@batch_ids = grep{$_ = {batch_id => $_}} @batch_ids;
@label_ids = grep{$_ = {label_id => $_}} @label_ids;
@item_numbers = grep{$_ = {item_number => $_}} @item_numbers;
$templates = get_all_templates(field_list => 'template_id, template_code');
$layouts = get_all_layouts(field_list => 'layout_id, layout_name');
$label_output_formats = get_label_output_formats();
$template->param(
batch_ids => \@batch_ids,
label_ids => \@label_ids,
item_numbers => \@item_numbers,
templates => $templates,
layouts => $layouts,
label_output_formats => $label_output_formats,
multi_batch_count => $multi_batch_count,
label_count => $label_count,
item_count => $item_count,
referer => $referer,
);
}
output_html_with_http_headers $cgi, $cookie, $template->output;