Bug 23720: Add div wrapper to search results to make moving cover images easier
[koha.git] / labels / label-print.pl
blobe8a42fa20628542011b8cb354cbae6538be70ae8
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 Modern::Perl;
22 use CGI qw ( -utf8 );
23 use Data::Dumper;
25 use C4::Auth qw(get_template_and_user);
26 use C4::Output qw(output_html_with_http_headers);
27 use C4::Creators::Lib qw(get_all_templates get_all_layouts get_output_formats);
28 use C4::Labels::Batch;
30 my $cgi = new CGI;
31 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33 template_name => "labels/label-print.tt",
34 query => $cgi,
35 type => "intranet",
36 authnotrequired => 0,
37 flagsrequired => { catalogue => 1 },
38 debug => 1,
42 my $op = $cgi->param('op') || 'none';
43 my @label_ids;
44 @label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id'); # this will handle individual label printing
45 my @batch_ids;
46 @batch_ids = $cgi->multi_param('batch_id') if $cgi->param('batch_id');
47 my $layout_id = $cgi->param('layout_id') || undef;
48 my $template_id = $cgi->param('template_id') || undef;
49 my $start_label = $cgi->param('start_label') || 1;
50 my @item_numbers;
51 @item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number');
52 my $output_format = $cgi->param('output_format') || 'pdf';
53 my $referer = $cgi->param('referer') || undef;
55 my $layouts = undef;
56 my $templates = undef;
57 my $output_formats = undef;
58 my @batches = ();
59 my $multi_batch_count = scalar(@batch_ids);
60 my $label_count = scalar(@label_ids);
61 my $item_count = scalar(@item_numbers);
63 if ($op eq 'export') {
64 if (@label_ids) {
65 my $label_id_param = '&amp;label_id=';
66 $label_id_param .= join ('&amp;label_id=',@label_ids);
67 push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
68 batch_id => $batch_ids[0],
69 template_id => $template_id,
70 layout_id => $layout_id,
71 start_label => $start_label,
72 label_ids => $label_id_param,
73 label_count => scalar(@label_ids),
74 });
75 $template->param(
76 batches => \@batches,
77 referer => $referer,
80 elsif (@item_numbers) {
81 my $item_number_param = '&amp;item_number=';
82 $item_number_param .= join ('&amp;item_number=',@item_numbers);
83 push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
84 template_id => $template_id,
85 layout_id => $layout_id,
86 start_label => $start_label,
87 item_numbers => $item_number_param,
88 label_count => scalar(@item_numbers),
89 });
90 $template->param(
91 batches => \@batches,
92 referer => $referer,
95 elsif (@batch_ids) {
96 foreach my $batch_id (@batch_ids) {
97 push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
98 batch_id => $batch_id,
99 template_id => $template_id,
100 layout_id => $layout_id,
101 start_label => $start_label,
104 $template->param(
105 batches => \@batches,
106 referer => $referer,
110 elsif ($op eq 'none') {
111 # setup select menus for selecting layout and template for this run...
112 $referer = $ENV{'HTTP_REFERER'};
113 $referer =~ s/^.*?:\/\/.*?(\/.*)$/$1/m;
114 @batch_ids = map{{batch_id => $_}} @batch_ids;
115 @label_ids = map{{label_id => $_}} @label_ids;
116 @item_numbers = map{{item_number => $_}} @item_numbers;
117 $templates = get_all_templates( { fields => [ qw( template_id template_code ) ], filters => { creator => "Labels" }, orderby => 'template_code' } );
118 $layouts = get_all_layouts( { fields => [ qw( layout_id layout_name ) ], filters => { creator => "Labels" }, orderby => 'layout_name' } );
119 $output_formats = get_output_formats();
120 $template->param(
121 batch_ids => \@batch_ids,
122 label_ids => \@label_ids,
123 item_numbers => \@item_numbers,
124 templates => $templates,
125 layouts => $layouts,
126 output_formats => $output_formats,
127 multi_batch_count => $multi_batch_count,
128 label_count => $label_count,
129 item_count => $item_count,
130 referer => $referer,
133 output_html_with_http_headers $cgi, $cookie, $template->output;