do not use REPLACE in SQL statements : it is not standard SQL, and don't work with...
[koha.git] / tools / 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 use CGI;
26 use PDF::API2;
27 use PDF::API2::Page;
28 use PDF::API2::PDF::Utils;
29
30 use C4::Context;
31 use C4::Output;
32 use C4::Auth;
33
34 # This function returns the path to deal with the correct files, considering
35 # templates set and language.
36 sub getPath {
37         my $type = shift @_;
38         my $templatesSet = C4::Context->preference('template');
39         my $lang = C4::Context->preference('opaclanguages');
40         if ($type eq "intranet") {
41                 return "$ENV{'DOCUMENT_ROOT'}/intranet-tmpl/$templatesSet/$lang";
42         } else {
43                 return "$ENV{'DOCUMENT_ROOT'}/opac-tmpl/$templatesSet/$lang";
44         }
45 }
46
47 # Load a configuration file.
48 sub loadConfFromFile {
49   my $fileName = shift @_;
50         my %keyValues;
51         open FILE, "<$fileName";
52         while (<FILE>) {
53                 chomp;
54                 if (/\s*([\w_]*)\s*=\s*([\[\]\<\>\w_\s:@,\.-]*)\s*/) {
55                         $keyValues{$1} = $2;
56                 }
57         }
58         close FILE;
59         return %keyValues;
60 }
61
62 # Save settings to a configuration file.
63 sub saveConfToFile {
64         my $fileName = shift @_;
65         my %keyValues = %{shift @_};
66         my $i;
67         open FILE, ">$fileName";                        
68         my $i;
69         foreach $i (keys(%keyValues)) {
70     print FILE $i." = ".$keyValues{$i}."\n";
71         }
72         close FILE;
73 }
74
75 # Creates a CGI object and take his parameters
76 my $input = new CGI;
77
78 if ($input->param('saveSettings')) {
79         my $labelConf = &getPath("intranet")."/includes/labelConfig/itemsLabelConfig.conf";
80         my %newConfiguration = (pageType => $input->param('pageType'),  
81                                                         columns => $input->param('columns'),            
82                                                         rows => $input->param('rows'),  
83                                                         systemDpi => $input->param('systemDpi'),        
84                                                         labelWidth => $input->param('labelWidth'),      
85                                                         labelHeigth => $input->param('labelHeigth'),    
86                                                         marginBottom => $input->param('marginBottom'),  
87                                                         marginLeft => $input->param('marginLeft'));     
88         saveConfToFile($labelConf, \%newConfiguration);
89         print $input->redirect('/cgi-bin/koha/barcodes/barcodes.pl')
90 }
91
92 # Get the template to use
93 my ($template, $loggedinuser, $cookie)
94     = get_template_and_user({template_name => "tools/printerConfig.tmpl",
95                                          type => "intranet",
96                                          query => $input,
97                                          authnotrequired => 0,
98                                          flagsrequired => {parameters => 1},
99                                                  debug => 1,
100                                        });
101
102 my $filenameConf = &getPath("intranet")."/includes/labelConfig/itemsLabelConfig.conf";
103 my %labelConfig = &loadConfFromFile($filenameConf);
104
105 $template->param(COLUMNS => $labelConfig{'columns'});
106 $template->param(ROWS => $labelConfig{'rows'});
107 $template->param(SYSTEM_DPI => $labelConfig{'systemDpi'});
108 $template->param(LABEL_WIDTH => $labelConfig{'labelWidth'});
109 $template->param(LABEL_HEIGTH => $labelConfig{'labelHeigth'});
110 $template->param(MARGIN_TOP => $labelConfig{'marginBottom'});
111 $template->param(MARGIN_LEFT => $labelConfig{'marginLeft'});
112 $template->param(SCRIPT_NAME => '/cgi-bin/koha/tools/printerConfig.pl');
113 $template->param("$labelConfig{'pageType'}" => 1);
114 output_html_with_http_headers $input, $cookie, $template->output;