Adding labels generator.
[koha.git] / labels / label-templates.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;
10 use POSIX;
11
12 #use Data::Dumper;
13
14 my $dbh       = C4::Context->dbh;
15 my $query     = new CGI;
16 my $op        = $query->param('op');
17 my $tmpl_code = $query->param('tmpl_code');
18 my $tmpl_id = $query->param('tmpl_id');
19
20
21 my $width      = $query->param('width');
22 my $height     = $query->param('height');
23 my $topmargin  = $query->param('topmargin');
24 my $leftmargin = $query->param('leftmargin');
25 my $columns    = $query->param('columns');
26 my $rows       = $query->param('rows');
27 my $colgap     = $query->param('colgap');
28 my $rowgap     = $query->param('rowgap');
29
30 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
31     {
32         template_name   => "labels/label-templates.tmpl",
33         query           => $query,
34         type            => "intranet",
35         authnotrequired => 1,
36         flagsrequired   => { catalogue => 1 },
37         debug           => 1,
38     }
39 );
40
41
42 my @resultsloop;
43
44
45 if ( $op eq 'set_active_template' ) {
46     SetActiveTemplate($tmpl_id);
47 }
48
49 elsif ( $op eq 'delete' ) {
50     DeleteTemplate($tmpl_id);
51 }
52
53 elsif ( $op eq 'save' ) {
54     SaveTemplate($tmpl_code);
55 }
56
57     @resultsloop = GetAllLabelTemplates();
58
59 # little block for displaying active layout/template/batch in templates
60 # ----------
61 my $batch_id     = $query->param('batch_id');
62 my $active_layout = get_active_layout();
63 my $active_template = GetActiveLabelTemplate();
64 my $active_layout_name = $active_layout->{'layoutname'};
65 my $active_template_name = $active_template->{'tmpl_code'};
66 # ----------
67
68 $template->param(
69
70     batch_id => $batch_id,
71     active_layout_name => $active_layout_name,
72     active_template_name => $active_template_name,
73
74     resultsloop => \@resultsloop,
75
76     intranetcolorstylesheet =>
77       C4::Context->preference("intranetcolorstylesheet"),
78     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
79     IntranetNav        => C4::Context->preference("IntranetNav"),
80 );
81
82 output_html_with_http_headers $query, $cookie, $template->output;