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>.
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
;
31 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
33 template_name
=> "labels/label-print.tt",
37 flagsrequired
=> { catalogue
=> 1 },
42 my $op = $cgi->param('op') || 'none';
44 @label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id'); # this will handle individual label printing
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;
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;
56 my $templates = undef;
57 my $output_formats = undef;
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') {
65 my $label_id_param = '&label_id=';
66 $label_id_param .= join ('&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),
80 elsif (@item_numbers) {
81 my $item_number_param = '&item_number=';
82 $item_number_param .= join ('&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),
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,
105 batches
=> \
@batches,
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
();
121 batch_ids
=> \
@batch_ids,
122 label_ids
=> \
@label_ids,
123 item_numbers
=> \
@item_numbers,
124 templates
=> $templates,
126 output_formats
=> $output_formats,
127 multi_batch_count
=> $multi_batch_count,
128 label_count
=> $label_count,
129 item_count
=> $item_count,
133 output_html_with_http_headers
$cgi, $cookie, $template->output;