Bug 19127: (follow-up) Fix Stored XSS in csv-profiles.pl
[koha.git] / patroncards / print.pl
blobc57be1d25c1a32730ac83df7a5bfe8c92d789e49
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 strict;
21 use warnings;
23 use CGI qw ( -utf8 );
24 use autouse 'Data::Dumper' => qw(Dumper);
26 use C4::Auth qw(get_template_and_user);
27 use C4::Output qw(output_html_with_http_headers);
28 use C4::Creators;
29 use C4::Patroncards;
31 my $cgi = new CGI;
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34 template_name => "patroncards/print.tt",
35 query => $cgi,
36 type => "intranet",
37 authnotrequired => 0,
38 flagsrequired => { catalogue => 1 },
39 debug => 1,
43 my $op = $cgi->param('op') || 'none';
44 my @label_ids = $cgi->multi_param('label_id') if $cgi->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
45 my @batch_ids = $cgi->multi_param('batch_id') if $cgi->param('batch_id');
46 my $patronlist_id = $cgi->param('patronlist_id') || undef;
47 my $layout_id = $cgi->param('layout_id') || undef;
48 my $layout_back_id = $cgi->param('layout_back_id') || undef;
49 my $template_id = $cgi->param('template_id') || undef;
50 my $start_card = $cgi->param('start_card') || 1;
51 my @borrower_numbers = $cgi->multi_param('borrower_number') if $cgi->param('borrower_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 $card_count = scalar(@label_ids);
61 my $borrower_count = scalar(@borrower_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' ? 'create-pdf.pl' : 'create-csv.pl'),
68 batch_id => $batch_ids[0],
69 template_id => $template_id,
70 layout_id => $layout_id,
71 layout_back_id => $layout_back_id,
72 start_card => $start_card,
73 label_ids => $label_id_param,
74 card_count => scalar(@label_ids),
75 });
76 $template->param(
77 batches => \@batches,
78 referer => $referer,
81 elsif (@borrower_numbers) {
82 my $borrower_number_param = '&amp;borrower_number=';
83 $borrower_number_param .= join ('&amp;borrower_number=',@borrower_numbers);
84 push (@batches, {create_script => ($output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl'),
85 template_id => $template_id,
86 layout_id => $layout_id,
87 layout_back_id => $layout_back_id,
88 start_card => $start_card,
89 borrower_numbers => $borrower_number_param,
90 card_count => scalar(@borrower_numbers),
91 });
92 $template->param(
93 batches => \@batches,
94 referer => $referer,
97 elsif (@batch_ids) {
98 foreach my $batch_id (@batch_ids) {
99 push (@batches, {create_script => ($output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl'),
100 batch_id => $batch_id,
101 template_id => $template_id,
102 layout_id => $layout_id,
103 layout_back_id => $layout_back_id,
104 start_card => $start_card,
107 $template->param(
108 batches => \@batches,
109 referer => $referer,
112 elsif ($patronlist_id ) {
113 $template->param(
114 patronlist_id => $patronlist_id,
115 template_id => $template_id,
116 layout_id => $layout_id,
117 layout_back_id => $layout_back_id,
118 start_card => $start_card,
119 referer => $referer,
123 elsif ($op eq 'none') {
124 # setup select menus for selecting layout and template for this run...
125 $referer = $ENV{'HTTP_REFERER'};
126 $referer =~ s/^.*?:\/\/.*?(\/.*)$/$1/m;
127 @batch_ids = grep{$_ = {batch_id => $_}} @batch_ids;
128 @label_ids = grep{$_ = {label_id => $_}} @label_ids;
129 @borrower_numbers = grep{$_ = {borrower_number => $_}} @borrower_numbers;
130 $templates = get_all_templates( { fields => [qw( template_id template_code ) ], filters => { creator => "Patroncards" } });
131 $layouts = get_all_layouts({ fields => [ qw( layout_id layout_name ) ], filters => { creator => "Patroncards" } });
132 $output_formats = get_output_formats();
133 $template->param(
134 batch_ids => \@batch_ids,
135 label_ids => \@label_ids,
136 borrower_numbers => \@borrower_numbers,
137 patronlist_id => $patronlist_id,
138 templates => $templates,
139 layouts => $layouts,
140 output_formats => $output_formats,
141 multi_batch_count => $multi_batch_count,
142 card_count => $card_count,
143 borrower_count => $borrower_count,
144 referer => $referer,
147 output_html_with_http_headers $cgi, $cookie, $template->output;