[23/40] Initial work on label export interface.
[koha.git] / labels / label-print.pl
1 #!/usr/bin/perl
2 #
3 # Copyright 2009 Foundations Bible College.
4 #
5 # This file is part of Koha.
6 #       
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
10 # version.
11 #
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.
15 #
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
19
20 use strict;
21 use warnings;
22
23 use CGI;
24 use HTML::Template::Pro;
25 use Data::Dumper;
26
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
31 my $cgi = new CGI;
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33     {
34         template_name   => "labels/label-print.tmpl",
35         query           => $cgi,
36         type            => "intranet",
37         authnotrequired => 0,
38         flagsrequired   => { catalogue => 1 },
39         debug           => 1,
40     }
41 );
42
43 my $op = $cgi->param('op') || 'none';
44 my @select_labels = $cgi->param('label_id') if $cgi->param('label_id');   # this will handle individual label printing
45 my @batch_ids = $cgi->param('batch_id') if $cgi->param('batch_id');
46 my $layout_id = $cgi->param('layout_id') || undef; 
47 my $template_id = $cgi->param('template_id') || undef; 
48 my $start_label = $cgi->param('start_label') || 1; 
49 my $output_format = $cgi->param('output_format') || 'pdf';
50 my $layouts = undef;
51 my $templates = undef;
52 my $label_output_formats = undef;
53 my @batches = ();
54 my $multi_batch_count = scalar(@batch_ids);
55
56 if ($op eq 'export') {
57     foreach my $batch_id (@batch_ids) {
58        push (@batches, {create_script   => ($output_format eq 'pdf' ? 'label-create-pdf.pl' : 'label-create-csv.pl'),
59                         batch_id        => $batch_id,
60                         template_id     => $template_id,
61                         layout_id       => $layout_id,
62                         start_label     => $start_label,
63                         });
64     }
65     $template->param(
66                     batches     => \@batches,
67                     );
68 }
69 elsif ($op eq 'none') {
70     # setup select menus for selecting layout and template for this run...
71     @batch_ids = grep{$_ = {batch_id => $_}} @batch_ids;
72     $templates = get_all_templates(field_list => 'template_id, template_code');
73     $layouts = get_all_layouts(field_list => 'layout_id, layout_name');
74     $label_output_formats = get_label_output_formats();
75     $template->param(
76                     batch_ids                   => \@batch_ids,
77                     templates                   => $templates,
78                     layouts                     => $layouts,
79                     label_output_formats        => $label_output_formats,
80                     multi_batch_count           => $multi_batch_count,
81                     );
82 }
83 output_html_with_http_headers $cgi, $cookie, $template->output;