Bug 20581: Unit tests for status_alias
[koha.git] / patroncards / print.pl
blob8992038fecdd38a0d16cdcd994b84909ec5ed516
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 Modern::Perl;
22 use CGI qw ( -utf8 );
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);
27 use C4::Creators;
28 use C4::Patroncards;
30 my $cgi = new CGI;
31 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33 template_name => "patroncards/print.tt",
34 query => $cgi,
35 type => "intranet",
36 authnotrequired => 0,
37 flagsrequired => { catalogue => 1 },
38 debug => 1,
42 my $op = $cgi->param('op') || 'none';
43 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
44 my @batch_ids = $cgi->multi_param('batch_id') if $cgi->param('batch_id');
45 my $patronlist_id = $cgi->param('patronlist_id') || undef;
46 my $layout_id = $cgi->param('layout_id') || undef;
47 my $layout_back_id = $cgi->param('layout_back_id') || undef;
48 my $template_id = $cgi->param('template_id') || undef;
49 my $start_card = $cgi->param('start_card') || 1;
50 my @borrower_numbers = $cgi->multi_param('borrower_number') if $cgi->param('borrower_number');
51 my $output_format = $cgi->param('output_format') || 'pdf';
52 my $referer = $cgi->param('referer') || undef;
54 my $layouts = undef;
55 my $templates = undef;
56 my $output_formats = undef;
57 my @batches = ();
58 my $multi_batch_count = scalar(@batch_ids);
59 my $card_count = scalar(@label_ids);
60 my $borrower_count = scalar(@borrower_numbers);
62 if ($op eq 'export') {
63 if (@label_ids) {
64 my $label_id_param = '&amp;label_id=';
65 $label_id_param .= join ('&amp;label_id=',@label_ids);
66 push (@batches, {create_script => ($output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl'),
67 batch_id => $batch_ids[0],
68 template_id => $template_id,
69 layout_id => $layout_id,
70 layout_back_id => $layout_back_id,
71 start_card => $start_card,
72 label_ids => $label_id_param,
73 card_count => scalar(@label_ids),
74 });
75 $template->param(
76 batches => \@batches,
77 referer => $referer,
80 elsif (@borrower_numbers) {
81 my $borrower_number_param = '&amp;borrower_number=';
82 $borrower_number_param .= join ('&amp;borrower_number=',@borrower_numbers);
83 push (@batches, {create_script => ($output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl'),
84 template_id => $template_id,
85 layout_id => $layout_id,
86 layout_back_id => $layout_back_id,
87 start_card => $start_card,
88 borrower_numbers => $borrower_number_param,
89 card_count => scalar(@borrower_numbers),
90 });
91 $template->param(
92 batches => \@batches,
93 referer => $referer,
96 elsif (@batch_ids) {
97 foreach my $batch_id (@batch_ids) {
98 push (@batches, {create_script => ($output_format eq 'pdf' ? 'create-pdf.pl' : 'create-csv.pl'),
99 batch_id => $batch_id,
100 template_id => $template_id,
101 layout_id => $layout_id,
102 layout_back_id => $layout_back_id,
103 start_card => $start_card,
106 $template->param(
107 batches => \@batches,
108 referer => $referer,
111 elsif ($patronlist_id ) {
112 $template->param(
113 patronlist_id => $patronlist_id,
114 template_id => $template_id,
115 layout_id => $layout_id,
116 layout_back_id => $layout_back_id,
117 start_card => $start_card,
118 referer => $referer,
122 elsif ($op eq 'none') {
123 # setup select menus for selecting layout and template for this run...
124 $referer = $ENV{'HTTP_REFERER'};
125 $referer =~ s/^.*?:\/\/.*?(\/.*)$/$1/m;
126 @batch_ids = grep{$_ = {batch_id => $_}} @batch_ids;
127 @label_ids = grep{$_ = {label_id => $_}} @label_ids;
128 @borrower_numbers = grep{$_ = {borrower_number => $_}} @borrower_numbers;
129 $templates = get_all_templates( { fields => [qw( template_id template_code ) ], filters => { creator => "Patroncards" } });
130 $layouts = get_all_layouts({ fields => [ qw( layout_id layout_name ) ], filters => { creator => "Patroncards" } });
131 $output_formats = get_output_formats();
132 $template->param(
133 batch_ids => \@batch_ids,
134 label_ids => \@label_ids,
135 borrower_numbers => \@borrower_numbers,
136 patronlist_id => $patronlist_id,
137 templates => $templates,
138 layouts => $layouts,
139 output_formats => $output_formats,
140 multi_batch_count => $multi_batch_count,
141 card_count => $card_count,
142 borrower_count => $borrower_count,
143 referer => $referer,
146 output_html_with_http_headers $cgi, $cookie, $template->output;