3 # Copyright Koha development team 2011
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
30 check_cookie_auth( $cgi->cookie('CGISESSID'), { catalogue => 1 } );
31 if ( $auth_status ne "ok" ) {
32 print $cgi->header( -type => 'text/plain', -status => '403 Forbidden' );
39 $batch_id = $cgi->param('batch_id') if $cgi->param('batch_id');
40 my $template_id = $cgi->param('template_id') || undef;
41 my $layout_id = $cgi->param('layout_id') || undef;
42 @label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id');
43 @item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
47 my $xml_file = (@label_ids || @item_numbers ? "label_single_" . scalar(@label_ids || @item_numbers) : "label_batch_$batch_id");
48 print $cgi->header(-type => 'text/xml',
50 -attachment => "$xml_file.xml",
53 my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
54 my $template = C4::Labels::Template->retrieve(template_id => $template_id, profile_id => 1);
55 my $layout = C4::Labels::Layout->retrieve(layout_id => $layout_id);
59 my $batch_items = $batch->get_attr('items');
62 push(@{$items}, grep{$_->{'label_id'} == $label_id;} @{$batch_items});
65 elsif (@item_numbers) {
67 push(@{$items}, {item_number => $_});
71 $items = $batch->get_attr('items');
74 my $xml = XML::Simple->new();
75 my $xml_data = {'label' => []};
79 foreach my $item (@$items) {
80 push(@{$xml_data->{'label'}}, {'item_number' => $item->{'item_number'}});
81 my $label = C4::Labels::Label->new(
82 batch_id => $batch_id,
83 item_number => $item->{'item_number'},
84 format_string => $layout->get_attr('format_string'),
86 my $format_string = $layout->get_attr('format_string');
87 my @data_fields = map { $_ eq 'callnumber' ? 'itemcallnumber' : $_ } # see bug 5653
88 split(/, /, $format_string);
89 my $csv_data = $label->csv_data();
90 for (my $i = 0; $i <= (scalar(@data_fields) - 1); $i++) {
91 push(@{$xml_data->{'label'}[$item_count]->{$data_fields[$i]}}, $$csv_data[$i]);
96 #die "XML DATA:\n" . Dumper($xml_data);
98 my $xml_out = $xml->XMLout($xml_data);
99 #die "XML OUT:\n" . Dumper($xml_out);
106 labels/label-create-xml.pl - A script for creating a xml export of labels and label batches in Koha
110 This script provides the means of producing a xml of labels for items either individually, in groups, or in batches from within Koha. This particular script is provided more as
111 a demonstration of the multitude of formats Koha labels could be exported in based on the current Label Creator API.
115 Chris Nighswonger <cnighswonger AT foundations DOT edu>
119 Copyright 2009 Foundations Bible College.
123 This file is part of Koha.
125 Koha is free software; you can redistribute it and/or modify it
126 under the terms of the GNU General Public License as published by
127 the Free Software Foundation; either version 3 of the License, or
128 (at your option) any later version.
130 Koha is distributed in the hope that it will be useful, but
131 WITHOUT ANY WARRANTY; without even the implied warranty of
132 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
133 GNU General Public License for more details.
135 You should have received a copy of the GNU General Public License
136 along with Koha; if not, see <http://www.gnu.org/licenses>.
138 =head1 DISCLAIMER OF WARRANTY
140 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
141 A PARTICULAR PURPOSE. See the GNU General Public License for more details.