Bug 10963: Simplified creation - CF framework
[koha.git] / labels / label-print.pl
blob55923239a7ae508a9274f2297fb0d8930cd77126
1 #!/usr/bin/perl
3 # Copyright 2009 Foundations Bible College.
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>.
20 use strict;
21 use warnings;
23 use CGI qw ( -utf8 );
24 use Data::Dumper;
26 use C4::Auth qw(get_template_and_user);
27 use C4::Output qw(output_html_with_http_headers);
28 use C4::Creators::Lib qw(get_all_templates get_all_layouts get_output_formats);
29 use C4::Labels::Batch;
31 my $cgi = new CGI;
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34 template_name => "labels/label-print.tt",
35 query => $cgi,
36 type => "intranet",
37 authnotrequired => 0,
38 flagsrequired => { catalogue => 1 },
39 debug => 1,
43 my $op = $cgi->param('op') || 'none';
44 my @label_ids;
45 @label_ids = $cgi->param('label_id') if $cgi->param('label_id'); # this will handle individual label printing
46 my @batch_ids;
47 @batch_ids = $cgi->param('batch_id') if $cgi->param('batch_id');
48 my $layout_id = $cgi->param('layout_id') || undef;
49 my $template_id = $cgi->param('template_id') || undef;
50 my $start_label = $cgi->param('start_label') || 1;
51 my @item_numbers;
52 @item_numbers = $cgi->param('item_number') if $cgi->param('item_number');
53 my $output_format = $cgi->param('output_format') || 'pdf';
54 my $referer = $cgi->param('referer') || undef;
56 my $layouts = undef;
57 my $templates = undef;
58 my $output_formats = undef;
59 my @batches = ();
60 my $multi_batch_count = scalar(@batch_ids);
61 my $label_count = scalar(@label_ids);
62 my $item_count = scalar(@item_numbers);
64 if ($op eq 'export') {
65 if (@label_ids) {
66 my $label_id_param = '&amp;label_id=';
67 $label_id_param .= join ('&amp;label_id=',@label_ids);
68 push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
69 batch_id => $batch_ids[0],
70 template_id => $template_id,
71 layout_id => $layout_id,
72 start_label => $start_label,
73 label_ids => $label_id_param,
74 label_count => scalar(@label_ids),
75 });
76 $template->param(
77 batches => \@batches,
78 referer => $referer,
81 elsif (@item_numbers) {
82 my $item_number_param = '&amp;item_number=';
83 $item_number_param .= join ('&amp;item_number=',@item_numbers);
84 push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
85 template_id => $template_id,
86 layout_id => $layout_id,
87 start_label => $start_label,
88 item_numbers => $item_number_param,
89 label_count => scalar(@item_numbers),
90 });
91 $template->param(
92 batches => \@batches,
93 referer => $referer,
96 elsif (@batch_ids) {
97 foreach my $batch_id (@batch_ids) {
98 push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
99 batch_id => $batch_id,
100 template_id => $template_id,
101 layout_id => $layout_id,
102 start_label => $start_label,
105 $template->param(
106 batches => \@batches,
107 referer => $referer,
111 elsif ($op eq 'none') {
112 # setup select menus for selecting layout and template for this run...
113 $referer = $ENV{'HTTP_REFERER'};
114 $referer =~ s/^.*?:\/\/.*?(\/.*)$/$1/m;
115 @batch_ids = map{{batch_id => $_}} @batch_ids;
116 @label_ids = map{{label_id => $_}} @label_ids;
117 @item_numbers = map{{item_number => $_}} @item_numbers;
118 $templates = get_all_templates(field_list => 'template_id, template_code', filter => 'creator = "Labels"', orderby => 'template_code' );
119 $layouts = get_all_layouts(field_list => 'layout_id, layout_name', filter => 'creator = "Labels"', orderby => 'layout_name' );
120 $output_formats = get_output_formats();
121 $template->param(
122 batch_ids => \@batch_ids,
123 label_ids => \@label_ids,
124 item_numbers => \@item_numbers,
125 templates => $templates,
126 layouts => $layouts,
127 output_formats => $output_formats,
128 multi_batch_count => $multi_batch_count,
129 label_count => $label_count,
130 item_count => $item_count,
131 referer => $referer,
134 output_html_with_http_headers $cgi, $cookie, $template->output;