bug: add items to label batch - need userenv loaded before call to SimpleSearch
[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     elsif ( !$prof ) {
62         undef @proflist;
63     }
64 }
65
66 my @units = (
67     { unit => 'INCH',  desc => 'Inches' },
68     { unit => 'CM',    desc => 'Centimeters' },
69     { unit => 'MM',    desc => 'Millimeters' },
70     { unit => 'POINT', desc => 'Postscript Points' },
71 );
72
73 foreach my $unit (@units) {
74     if ( $unit->{'unit'} eq $tmpl->{'units'} ) {
75         $unit->{'selected'} = 1;
76     }
77 }
78
79 my @fonts = (        #FIXME: There is probably a way to discover what additional fonts are installed on a user's system and generate this list dynamically...
80     { font => 'TR',     name => 'Times Roman' },
81     { font => 'TB',     name => 'Times Bold' },
82     { font => 'TI',     name => 'Times Italic' },
83     { font => 'TBI',    name => 'Times Bold Italic' },
84     { font => 'C',      name => 'Courier' },
85     { font => 'CB',     name => 'Courier Bold' },
86     { font => 'CO',     name => 'Courier Oblique' },
87     { font => 'CBO',    name => 'Courier Bold Oblique' },
88     { font => 'H',      name => 'Helvetica' },
89     { font => 'HB',     name => 'Helvetica Bold' },
90     { font => 'HO',     name => 'Helvetica Oblique' },
91     { font => 'HBO',    name => 'Helvetica Bold Oblique' },
92 );
93
94 foreach my $font (@fonts) {
95     if ( $font->{'font'} eq $tmpl->{'font'} ) {
96         $font->{'selected'} = 1;
97     }
98 }
99
100 $template->param(
101
102     proflist     => \@proflist,
103     units        => \@units,
104     fonts        => \@fonts,
105
106     tmpl_id      => $tmpl->{'tmpl_id'},
107     tmpl_code    => $tmpl->{'tmpl_code'},
108     tmpl_desc    => $tmpl->{'tmpl_desc'},
109     page_width   => $tmpl->{'page_width'},
110     page_height  => $tmpl->{'page_height'},
111     label_width  => $tmpl->{'label_width'},
112     label_height => $tmpl->{'label_height'},
113     topmargin    => $tmpl->{'topmargin'},
114     leftmargin   => $tmpl->{'leftmargin'},
115     cols         => $tmpl->{'cols'},
116     rows         => $tmpl->{'rows'},
117     colgap       => $tmpl->{'colgap'},
118     rowgap       => $tmpl->{'rowgap'},
119     fontsize     => $tmpl->{'fontsize'},
120     active       => $tmpl->{'active'},
121 );
122
123 output_html_with_http_headers $query, $cookie, $template->output;