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 under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
24 use HTML::Template::Pro;
27 use C4::Auth qw(get_template_and_user);
28 use C4::Output qw(output_html_with_http_headers);
29 use C4::Labels::Lib 1.000000 qw(get_all_templates get_all_layouts get_label_output_formats);
30 use C4::Labels::Batch 1.000000;
33 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
35 template_name => "labels/label-print.tmpl",
39 flagsrequired => { catalogue => 1 },
44 my $op = $cgi->param('op') || 'none';
45 my @label_ids = $cgi->param('label_id') if $cgi->param('label_id'); # this will handle individual label printing
46 my @batch_ids = $cgi->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 = $cgi->param('item_number') if $cgi->param('item_number');
51 my $output_format = $cgi->param('output_format') || 'pdf';
52 my $referer = $cgi->param('referer') || undef;
55 my $templates = undef;
56 my $label_output_formats = undef;
58 my $multi_batch_count = scalar(@batch_ids);
59 my $label_count = scalar(@label_ids);
60 my $item_count = scalar(@item_numbers);
62 if ($op eq 'export') {
64 my $label_id_param = '&label_id=';
65 $label_id_param .= join ('&label_id=',@label_ids);
66 push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
67 batch_id => $batch_ids[0],
68 template_id => $template_id,
69 layout_id => $layout_id,
70 start_label => $start_label,
71 label_ids => $label_id_param,
72 label_count => scalar(@label_ids),
79 elsif (@item_numbers) {
80 my $item_number_param = '&item_number=';
81 $item_number_param .= join ('&item_number=',@item_numbers);
82 push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
83 template_id => $template_id,
84 layout_id => $layout_id,
85 start_label => $start_label,
86 item_numbers => $item_number_param,
87 label_count => scalar(@item_numbers),
95 foreach my $batch_id (@batch_ids) {
96 push (@batches, {create_script => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
97 batch_id => $batch_id,
98 template_id => $template_id,
99 layout_id => $layout_id,
100 start_label => $start_label,
104 batches => \@batches,
109 elsif ($op eq 'none') {
110 # setup select menus for selecting layout and template for this run...
111 $referer = $ENV{'HTTP_REFERER'};
112 $referer =~ s/^.*?:\/\/.*?(\/.*)$/$1/m;
113 @batch_ids = grep{$_ = {batch_id => $_}} @batch_ids;
114 @label_ids = grep{$_ = {label_id => $_}} @label_ids;
115 @item_numbers = grep{$_ = {item_number => $_}} @item_numbers;
116 $templates = get_all_templates(field_list => 'template_id, template_code');
117 $layouts = get_all_layouts(field_list => 'layout_id, layout_name');
118 $label_output_formats = get_label_output_formats();
120 batch_ids => \@batch_ids,
121 label_ids => \@label_ids,
122 item_numbers => \@item_numbers,
123 templates => $templates,
125 label_output_formats => $label_output_formats,
126 multi_batch_count => $multi_batch_count,
127 label_count => $label_count,
128 item_count => $item_count,
132 output_html_with_http_headers $cgi, $cookie, $template->output;