Adding a warning On subscription deletion for item
[koha.git] / labels / label-create-xml.pl
blob7e90b1f4566cef0f1912577f7b0256debe24eaee
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
6 use CGI;
7 use XML::Simple;
8 use Data::Dumper;
10 use C4::Debug;
11 use C4::Labels::Batch 1.000000;
12 use C4::Labels::Template 1.000000;
13 use C4::Labels::Layout 1.000000;
14 use C4::Labels::PDF 1.000000;
15 use C4::Labels::Label 1.000000;
17 =head
19 =cut
21 my $cgi = new CGI;
23 my $batch_id = $cgi->param('batch_id') if $cgi->param('batch_id');
24 my $template_id = $cgi->param('template_id') || undef;
25 my $layout_id = $cgi->param('layout_id') || undef;
26 my @label_ids = $cgi->param('label_id') if $cgi->param('label_id');
27 my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
29 my $items = undef;
31 my $xml_file = (@label_ids || @item_numbers ? "label_single_" . scalar(@label_ids || @item_numbers) : "label_batch_$batch_id");
32 print $cgi->header(-type => 'text/xml',
33 -encoding => 'utf-8',
34 -attachment => "$xml_file.xml",
37 my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
38 my $template = C4::Labels::Template->retrieve(template_id => $template_id, profile_id => 1);
39 my $layout = C4::Labels::Layout->retrieve(layout_id => $layout_id);
42 if (@label_ids) {
43 my $batch_items = $batch->get_attr('items');
44 grep {
45 my $label_id = $_;
46 push(@{$items}, grep{$_->{'label_id'} == $label_id;} @{$batch_items});
47 } @label_ids;
49 elsif (@item_numbers) {
50 grep {
51 push(@{$items}, {item_number => $_});
52 } @item_numbers;
54 else {
55 $items = $batch->get_attr('items');
58 my $xml = XML::Simple->new();
59 my $xml_data = {'label' => []};
61 my $item_count = 0;
63 XML_ITEMS:
64 foreach my $item (@$items) {
65 push(@{$xml_data->{'label'}}, {'item_number' => $item->{'item_number'}});
66 my $label = C4::Labels::Label->new(
67 batch_id => $batch_id,
68 item_number => $item->{'item_number'},
69 format_string => $layout->get_attr('format_string'),
71 my $format_string = $layout->get_attr('format_string');
72 my @data_fields = split(/, /, $format_string);
73 my $csv_data = $label->csv_data();
74 for (my $i = 0; $i < (scalar(@data_fields) - 1); $i++) {
75 push(@{$xml_data->{'label'}[$item_count]->{$data_fields[$i]}}, $$csv_data[$i]);
77 $item_count++;
80 #die "XML DATA:\n" . Dumper($xml_data);
82 my $xml_out = $xml->XMLout($xml_data);
83 #die "XML OUT:\n" . Dumper($xml_out);
84 print $xml_out;
86 exit(1);
88 =head1 NAME
90 labels/label-create-xml.pl - A script for creating a xml export of labels and label batches in Koha
92 =head1 ABSTRACT
94 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
95 a demonstration of the multitude of formats Koha labels could be exported in based on the current Label Creator API.
97 =head1 AUTHOR
99 Chris Nighswonger <cnighswonger AT foundations DOT edu>
101 =head1 COPYRIGHT
103 Copyright 2009 Foundations Bible College.
105 =head1 LICENSE
107 This file is part of Koha.
109 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
110 Foundation; either version 2 of the License, or (at your option) any later version.
112 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,
113 Suite 330, Boston, MA 02111-1307 USA
115 =head1 DISCLAIMER OF WARRANTY
117 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
118 A PARTICULAR PURPOSE. See the GNU General Public License for more details.