Click on the following link(s) to download the exported batch(es).
@@ -19,27 +25,48 @@
|
+
+ ?batch_id=&template_id=&layout_id=&start_label=">label_single_.pdf
+
+ ?template_id=&layout_id=&start_label=">label_single_.pdf
+
?batch_id=&template_id=&layout_id=&start_label=">label_batch_.pdf
+
|
+
+
Exporting label(s).
+
+ Exporting label(s).
+
batch(es) to export.
+
diff --git a/labels/label-create-csv.pl b/labels/label-create-csv.pl
index be29afa5a5..7b1cc8ff9a 100755
--- a/labels/label-create-csv.pl
+++ b/labels/label-create-csv.pl
@@ -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 ?
-
-
-
diff --git a/labels/label-create-pdf.pl b/labels/label-create-pdf.pl
index 9c2812822e..ae0ba86f44 100755
--- a/labels/label-create-pdf.pl
+++ b/labels/label-create-pdf.pl
@@ -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);
diff --git a/labels/label-create-xml.pl b/labels/label-create-xml.pl
new file mode 100755
index 0000000000..a71c9afc39
--- /dev/null
+++ b/labels/label-create-xml.pl
@@ -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);
diff --git a/labels/label-edit-batch.pl b/labels/label-edit-batch.pl
index 1278df90c0..197ec7b02c 100755
--- a/labels/label-edit-batch.pl
+++ b/labels/label-edit-batch.pl
@@ -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;
diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl
index 433ed14699..8f950eca82 100755
--- a/labels/label-item-search.pl
+++ b/labels/label-item-search.pl
@@ -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);
diff --git a/labels/label-print.pl b/labels/label-print.pl
index 32eeb076f3..289caa1ad6 100755
--- a/labels/label-print.pl
+++ b/labels/label-print.pl
@@ -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 = '&label_id=';
+ $label_id_param .= join ('&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 = '&item_number=';
+ $item_number_param .= join ('&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;