11 use C4
::Creators
1.000000;
12 use C4
::Labels
1.000000;
20 my $batch_id = $cgi->param('batch_id') if $cgi->param('batch_id');
21 my $template_id = $cgi->param('template_id') || undef;
22 my $layout_id = $cgi->param('layout_id') || undef;
23 my @label_ids = $cgi->param('label_id') if $cgi->param('label_id');
24 my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
28 my $csv_file = (@label_ids || @item_numbers ?
"label_single_" . scalar(@label_ids || @item_numbers) : "label_batch_$batch_id");
29 print $cgi->header(-type
=> 'application/vnd.sun.xml.calc',
31 -attachment
=> "$csv_file.csv",
35 my $batch = C4
::Labels
::Batch
->retrieve(batch_id
=> $batch_id);
36 my $template = C4
::Labels
::Template
->retrieve(template_id
=> $template_id, profile_id
=> 1);
37 my $layout = C4
::Labels
::Layout
->retrieve(layout_id
=> $layout_id);
41 my $batch_items = $batch->get_attr('items');
44 push(@
{$items}, grep{$_->{'label_id'} == $label_id;} @
{$batch_items});
47 elsif (@item_numbers) {
49 push(@
{$items}, {item_number
=> $_});
53 $items = $batch->get_attr('items');
56 my $csv = Text
::CSV_XS
->new();
59 foreach my $item (@
$items) {
60 my $label = C4
::Labels
::Label
->new(
61 batch_id
=> $batch_id,
62 item_number
=> $item->{'item_number'},
63 format_string
=> $layout->get_attr('format_string'),
65 my $csv_fields = $label->csv_data();
66 if ($csv->combine(@
$csv_fields)) {
67 print $csv->string() . "\n";
70 warn sprintf('Text::CSV_XS->combine() returned the following error: %s', $csv->error_input);
79 labels/label-create-csv.pl - A script for creating a csv export of labels and label batches in Koha
83 This script provides the means of producing a csv of labels for items either individually, in groups, or in batches from within Koha.
87 Chris Nighswonger <cnighswonger AT foundations DOT edu>
91 Copyright 2009 Foundations Bible College.
95 This file is part of Koha.
97 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
98 Foundation; either version 2 of the License, or (at your option) any later version.
100 You should have received a copy of the GNU General Public License along with Koha; if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
101 Fifth Floor, Boston, MA 02110-1301 USA.
103 =head1 DISCLAIMER OF WARRANTY
105 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
106 A PARTICULAR PURPOSE. See the GNU General Public License for more details.