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>.
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
;
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
34 template_name
=> "labels/label-print.tt",
38 flagsrequired
=> { catalogue
=> 1 },
43 my $op = $cgi->param('op') || 'none';
45 @label_ids = $cgi->param('label_id') if $cgi->param('label_id'); # this will handle individual label printing
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;
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;
57 my $templates = undef;
58 my $output_formats = undef;
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') {
66 my $label_id_param = '&label_id=';
67 $label_id_param .= join ('&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),
81 elsif (@item_numbers) {
82 my $item_number_param = '&item_number=';
83 $item_number_param .= join ('&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),
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,
106 batches
=> \
@batches,
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
();
122 batch_ids
=> \
@batch_ids,
123 label_ids
=> \
@label_ids,
124 item_numbers
=> \
@item_numbers,
125 templates
=> $templates,
127 output_formats
=> $output_formats,
128 multi_batch_count
=> $multi_batch_count,
129 label_count
=> $label_count,
130 item_count
=> $item_count,
134 output_html_with_http_headers
$cgi, $cookie, $template->output;