3 # script to generate items barcodes
5 # by Veleda Matias - matias_veleda@hotmail.com - Physics Library UNLP Argentina and
6 # Casta�eda Sebastian - seba3c@yahoo.com.ar - Physics Library UNLP Argentina and
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
30 use C4::Barcodes::PrinterConfig;
34 # This function returns the path to deal with the correct files, considering
35 # templates set and language.
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";
43 return "$ENV{'DOCUMENT_ROOT'}/opac-tmpl/$templatesSet/$lang";
47 # Load a configuration file. Before use this function, check if that file exists.
48 sub loadConfFromFile {
49 my $fileName = shift @_;
51 open FILE, "<$fileName";
54 if (/\s*([\w_]*)\s*=\s*([\[\]\<\>\w_\s:@,\.-]*)\s*/) {
62 # Save settings to a configuration file. It delete previous configuration settings.
64 my $fileName = shift @_;
65 my %keyValues = %{shift @_};
67 open FILE, ">$fileName";
69 foreach $i (keys(%keyValues)) {
70 print FILE $i." = ".$keyValues{$i}."\n";
75 # Load the config file.
76 my $filenameConf = &getPath("intranet")."/includes/labelConfig/itemsLabelConfig.conf";
77 my %labelConfig = &loadConfFromFile($filenameConf);
80 # Defines type of page to use in the printer process
81 my @labelTable = C4::Barcodes::PrinterConfig::labelsPage($labelConfig{'rows'}, $labelConfig{'columns'});
83 # It creates a list of posible intervals to choose codes to generate
84 my %list = ('continuous' => 'Continuous Range of items', 'individuals' => 'Individual Codes');
85 my @listValues = keys(%list);
86 my $rangeType = CGI::scrolling_list(-name => 'rangeType',
87 -values => \@listValues,
90 -default => ['continuous'],
93 -onChange => "changeRange(this)");
94 # It creates a list of posible standard codifications. First checks if the user has just added a new code.
95 if ($input->param('addCode')) {
96 my $newCountryName = $input->param('countryName');
97 my $newCountryCode = $input->param('countryCode');
99 my $countryCodesFilename = &getPath("intranet")."/includes/countryCodes/countryCodes.dat";
100 open COUNTRY_CODES, ">>$countryCodesFilename";
101 print COUNTRY_CODES $newCountryCode." = ".$newCountryName."\n";
105 # Takes the country codes from a file and use them to set the country list.
106 my $countryCodes = &getPath("intranet")."/includes/countryCodes/countryCodes.dat";
107 my %list = &loadConfFromFile($countryCodes);
108 @listValues = keys(%list);
109 my $number_system = CGI::scrolling_list(-name => 'numbersystem',
110 -values => \@listValues,
115 # Set the script name
116 my $script_name = "/cgi-bin/koha/tools/barcodesGenerator.pl";
119 # Get the template to use
120 my ($template, $loggedinuser, $cookie)
121 = get_template_and_user({template_name => "barcodes/barcodes.tmpl",
124 authnotrequired => 0,
125 flagsrequired => {tools => 1},
129 # Replace the template values with the real ones
130 $template->param(SCRIPT_NAME => $script_name);
131 $template->param(NUMBER_SYSTEM => $number_system);
132 $template->param(PAGES => $labelConfig{'pageType'});
133 $template->param(RANGE_TYPE => $rangeType);
134 $template->param(LABEL_TABLE => \@labelTable);
135 $template->param(COL_SPAN => $labelConfig{'columns'});
136 if ($input->param('error')) {
137 $template->param(ERROR => 1);
139 $template->param(ERROR => 0);
141 # Shows the template with the real values replaced
142 output_html_with_http_headers $input, $cookie, $template->output;