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>.
23 use autouse 'Data::Dumper' => qw(Dumper);
25 use C4::Auth qw(get_template_and_user);
26 use C4::Output qw(output_html_with_http_headers);
31 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33 template_name => "patroncards/print.tt",
36 flagsrequired => { tools => 'label_creator' },
40 my $op = $cgi->param('op') || 'none';
41 my @label_ids = $cgi->multi_param('label_id'); # this will handle individual card printing; we use label_id to maintain consistency with the column names in the creator_batches table
42 my @batch_ids = $cgi->multi_param('batch_id');
43 my $patronlist_id = $cgi->param('patronlist_id') || undef;
44 my $layout_id = $cgi->param('layout_id') || undef;
45 my $layout_back_id = $cgi->param('layout_back_id') || undef;
46 my $template_id = $cgi->param('template_id') || undef;
47 my $start_card = $cgi->param('start_card') || 1;
48 my @borrower_numbers = $cgi->multi_param('borrower_number');
49 my $output_format = $cgi->param('output_format') || 'pdf';
50 my $referer = $cgi->param('referer') || undef;
53 my $templates = undef;
54 my $output_formats = undef;
56 my $multi_batch_count = scalar(@batch_ids);
57 my $card_count = scalar(@label_ids);
58 my $borrower_count = scalar(@borrower_numbers);
60 if ($op eq 'export') {
62 my $label_id_param = '&label_id=';
63 $label_id_param .= join ('&label_id=',@label_ids);
64 push (@batches, {create_script => ($output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl'),
65 batch_id => $batch_ids[0],
66 template_id => $template_id,
67 layout_id => $layout_id,
68 layout_back_id => $layout_back_id,
69 start_card => $start_card,
70 label_ids => $label_id_param,
71 card_count => scalar(@label_ids),
78 elsif (@borrower_numbers) {
79 my $borrower_number_param = '&borrower_number=';
80 $borrower_number_param .= join ('&borrower_number=',@borrower_numbers);
81 push (@batches, {create_script => ($output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl'),
82 template_id => $template_id,
83 layout_id => $layout_id,
84 layout_back_id => $layout_back_id,
85 start_card => $start_card,
86 borrower_numbers => $borrower_number_param,
87 card_count => scalar(@borrower_numbers),
95 foreach my $batch_id (@batch_ids) {
96 push (@batches, {create_script => ($output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl'),
97 batch_id => $batch_id,
98 template_id => $template_id,
99 layout_id => $layout_id,
100 layout_back_id => $layout_back_id,
101 start_card => $start_card,
105 batches => \@batches,
109 elsif ($patronlist_id ) {
111 patronlist_id => $patronlist_id,
112 template_id => $template_id,
113 layout_id => $layout_id,
114 layout_back_id => $layout_back_id,
115 start_card => $start_card,
120 elsif ($op eq 'none') {
121 # setup select menus for selecting layout and template for this run...
122 $referer = $ENV{'HTTP_REFERER'};
123 $referer =~ s/^.*?:\/\/.*?(\/.*)$/$1/m;
124 @batch_ids = map { {batch_id => $_} } @batch_ids;
125 @label_ids = map { {label_id => $_} } @label_ids;
126 @borrower_numbers = map { {borrower_number => $_} } @borrower_numbers;
127 $templates = get_all_templates( { fields => [qw( template_id template_code ) ], filters => { creator => "Patroncards" } });
128 $layouts = get_all_layouts({ fields => [ qw( layout_id layout_name ) ], filters => { creator => "Patroncards" } });
129 $output_formats = get_output_formats();
131 batch_ids => \@batch_ids,
132 label_ids => \@label_ids,
133 borrower_numbers => \@borrower_numbers,
134 patronlist_id => $patronlist_id,
135 templates => $templates,
137 output_formats => $output_formats,
138 multi_batch_count => $multi_batch_count,
139 card_count => $card_count,
140 borrower_count => $borrower_count,
144 output_html_with_http_headers $cgi, $cookie, $template->output;