Adding Printer Profiles feature to the Label Creator.
[koha.git] / labels / label-edit-template.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Context;
7 use C4::Output;
8 use C4::Labels;
9 use HTML::Template::Pro;
10 use POSIX;
11
12 # use Data::Dumper;
13
14 my $dbh       = C4::Context->dbh;
15 my $query     = new CGI;
16
17 my $tmpl_id = $query->param('tmpl_id');
18
19 my $width      = $query->param('width');
20 my $height     = $query->param('height');
21 my $topmargin  = $query->param('topmargin');
22 my $leftmargin = $query->param('leftmargin');
23 my $columns    = $query->param('columns');
24 my $rows       = $query->param('rows');
25 my $colgap     = $query->param('colgap');
26 my $rowgap     = $query->param('rowgap');
27 my $prof_id    = $query->param('prof_id');
28
29 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
30     {
31         template_name   => "labels/label-edit-template.tmpl",
32         query           => $query,
33         type            => "intranet",
34         authnotrequired => 1,
35         flagsrequired   => { catalogue => 1 },
36         debug           => 1,
37     }
38 );
39
40 my $tmpl = GetSingleLabelTemplate($tmpl_id);
41 my $curprof = GetAssociatedProfile($tmpl_id);
42 my @prof = GetAllPrinterProfiles();
43 my @proflist;
44
45 # Generate an array of hashes containing possible profiles for given template and mark the currently associated one...
46
47 foreach my $prof (@prof) {
48     if ( $prof->{'tmpl_id'} eq $tmpl->{'tmpl_id'} && $prof->{'prof_id'} eq $curprof->{'prof_id'} ) {
49         push ( @proflist,  {prof_id         => $prof->{'prof_id'},
50                             printername     => $prof->{'printername'},
51                             paper_bin       => $prof->{'paper_bin'},
52                             selected        => 1} );
53     }
54     
55     elsif ( $prof->{'tmpl_id'} eq $tmpl->{'tmpl_id'} ) {
56         push ( @proflist,  {prof_id         => $prof->{'prof_id'},
57                             printername     => $prof->{'printername'},
58                             paper_bin       => $prof->{'paper_bin'}} );
59     }
60 }
61
62 my @units = (
63     { unit => 'INCH',  desc => 'Inches' },
64     { unit => 'CM',    desc => 'Centimeters' },
65     { unit => 'MM',    desc => 'Millimeters' },
66     { unit => 'POINT', desc => 'Postscript Points' },
67 );
68
69 foreach my $unit (@units) {
70     if ( $unit->{'unit'} eq $tmpl->{'units'} ) {
71         $unit->{'selected'} = 1;
72     }
73 }
74
75 $template->param(
76
77     proflist     => \@proflist,
78     units        => \@units,
79
80     tmpl_id      => $tmpl->{'tmpl_id'},
81     tmpl_code    => $tmpl->{'tmpl_code'},
82     tmpl_desc    => $tmpl->{'tmpl_desc'},
83     page_width   => $tmpl->{'page_width'},
84     page_height  => $tmpl->{'page_height'},
85     label_width  => $tmpl->{'label_width'},
86     label_height => $tmpl->{'label_height'},
87     topmargin    => $tmpl->{'topmargin'},
88     leftmargin   => $tmpl->{'leftmargin'},
89     cols         => $tmpl->{'cols'},
90     rows         => $tmpl->{'rows'},
91     colgap       => $tmpl->{'colgap'},
92     rowgap       => $tmpl->{'rowgap'},
93     fontsize     => $tmpl->{'fontsize'},
94     active       => $tmpl->{'active'},
95 );
96
97 output_html_with_http_headers $query, $cookie, $template->output;