Reverting to previous version, kohastructure.sql file didn't work for me, I got an...
[koha.git] / barcodes / printerConfig.pl
1 #!/usr/bin/perl
2
3 # script to set the labels configuration for the printer process.
4 # written 07/04
5 # by Veleda Matias - matias_veleda@hotmail.com - Physics Library UNLP Argentina and
6
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 require Exporter;
23
24 use strict;
25
26 use CGI;
27 use C4::Context;
28 use C4::Output;
29 use C4::Auth;
30
31 use PDF::API2;
32 use PDF::API2::Page;
33 use PDF::API2::Util;
34
35 # This function returns the path to deal with the correct files, considering
36 # templates set and language.
37 sub getPath {
38     my $type         = shift @_;
39     my $templatesSet = C4::Context->preference('template');
40     my $lang         = C4::Context->preference('opaclanguages');
41     if ( $type eq "intranet" ) {
42         return "$ENV{'DOCUMENT_ROOT'}/intranet-tmpl/$templatesSet/$lang";
43     }
44     else {
45         return "$ENV{'DOCUMENT_ROOT'}/opac-tmpl/$templatesSet/$lang";
46     }
47 }
48
49 # Load a configuration file.
50 sub loadConfFromFile {
51     my $fileName = shift @_;
52     my %keyValues;
53     open FILE, "<$fileName";
54     while (<FILE>) {
55         chomp;
56         if (/\s*([\w_]*)\s*=\s*([\[\]\<\>\w_\s:@,\.-]*)\s*/) {
57             $keyValues{$1} = $2;
58         }
59     }
60     close FILE;
61     return %keyValues;
62 }
63
64 # Save settings to a configuration file.
65 sub saveConfToFile {
66     my $fileName  = shift @_;
67     my %keyValues = %{ shift @_ };
68     my $i;
69     open FILE, ">$fileName";
70     my $i;
71     foreach $i ( keys(%keyValues) ) {
72         print FILE $i . " = " . $keyValues{$i} . "\n";
73     }
74     close FILE;
75 }
76
77 # Creates a CGI object and take his parameters
78 my $input = new CGI;
79
80 if ( $input->param('saveSettings') ) {
81     my $labelConf =
82       &getPath("intranet") . "/includes/labelConfig/itemsLabelConfig.conf";
83     my %newConfiguration = (
84         pageType     => $input->param('pageType'),
85         columns      => $input->param('columns'),
86         rows         => $input->param('rows'),
87         systemDpi    => $input->param('systemDpi'),
88         labelWidth   => $input->param('labelWidth'),
89         labelHeigth  => $input->param('labelHeigth'),
90         marginBottom => $input->param('marginBottom'),
91         marginLeft   => $input->param('marginLeft')
92     );
93     saveConfToFile( $labelConf, \%newConfiguration );
94     print $input->redirect('/cgi-bin/koha/barcodes/barcodes.pl');
95 }
96
97 # Get the template to use
98 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
99     {
100         template_name   => "barcodes/printerConfig.tmpl",
101         type            => "intranet",
102         query           => $input,
103         authnotrequired => 0,
104         flagsrequired   => { tools => 1 },
105         debug           => 1,
106     }
107 );
108
109 my $filenameConf =
110   &getPath("intranet") . "/includes/labelConfig/itemsLabelConfig.conf";
111 my %labelConfig = &loadConfFromFile($filenameConf);
112
113 $template->param( COLUMNS      => $labelConfig{'columns'} );
114 $template->param( ROWS         => $labelConfig{'rows'} );
115 $template->param( SYSTEM_DPI   => $labelConfig{'systemDpi'} );
116 $template->param( LABEL_WIDTH  => $labelConfig{'labelWidth'} );
117 $template->param( LABEL_HEIGTH => $labelConfig{'labelHeigth'} );
118 $template->param( MARGIN_TOP   => $labelConfig{'marginBottom'} );
119 $template->param( MARGIN_LEFT  => $labelConfig{'marginLeft'} );
120 $template->param( SCRIPT_NAME  => '/cgi-bin/koha/barcodes/printerConfig.pl' );
121 $template->param( "$labelConfig{'pageType'}" => 1 );
122 $template->param(
123     intranetcolorstylesheet =>
124       C4::Context->preference("intranetcolorstylesheet"),
125     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
126     IntranetNav        => C4::Context->preference("IntranetNav"),
127 );
128 output_html_with_http_headers $input, $cookie, $template->output;