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
27 use C4::Interface::CGI::Output;
31 use C4::Barcodes::PrinterConfig;
35 # This function returns the path to deal with the correct files, considering
36 # templates set and language.
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";
44 return "$ENV{'DOCUMENT_ROOT'}/opac-tmpl/$templatesSet/$lang";
48 # Load a configuration file. Before use this function, check if that file exists.
49 sub loadConfFromFile {
50 my $fileName = shift @_;
52 open FILE, "<$fileName";
55 if (/\s*([\w_]*)\s*=\s*([\[\]\<\>\w_\s:@,\.-]*)\s*/) {
63 # Save settings to a configuration file. It delete previous configuration settings.
65 my $fileName = shift @_;
66 my %keyValues = %{shift @_};
68 open FILE, ">$fileName";
70 foreach $i (keys(%keyValues)) {
71 print FILE $i." = ".$keyValues{$i}."\n";
76 # Load the config file.
77 my $filenameConf = &getPath("intranet")."/includes/labelConfig/itemsLabelConfig.conf";
78 my %labelConfig = &loadConfFromFile($filenameConf);
81 # Defines type of page to use in the printer process
82 my @labelTable = C4::Barcodes::PrinterConfig::labelsPage($labelConfig{'rows'}, $labelConfig{'columns'});
84 # It creates a list of posible intervals to choose codes to generate
85 my %list = ('continuous' => 'Continuous Range of items', 'individuals' => 'Individual Codes');
86 my @listValues = keys(%list);
87 my $rangeType = CGI::scrolling_list(-name => 'rangeType',
88 -values => \@listValues,
91 -default => ['continuous'],
94 -onChange => "changeRange(this)");
95 # It creates a list of posible standard codifications. First checks if the user has just added a new code.
96 if ($input->param('addCode')) {
97 my $newCountryName = $input->param('countryName');
98 my $newCountryCode = $input->param('countryCode');
100 my $countryCodesFilename = &getPath("intranet")."/includes/countryCodes/countryCodes.dat";
101 open COUNTRY_CODES, ">>$countryCodesFilename";
102 print COUNTRY_CODES $newCountryCode." = ".$newCountryName."\n";
106 # Takes the country codes from a file and use them to set the country list.
107 my $countryCodes = &getPath("intranet")."/includes/countryCodes/countryCodes.dat";
108 my %list = &loadConfFromFile($countryCodes);
109 @listValues = keys(%list);
110 my $number_system = CGI::scrolling_list(-name => 'numbersystem',
111 -values => \@listValues,
116 # Set the script name
117 my $script_name = "/cgi-bin/koha/barcodes/barcodesGenerator.pl";
120 # Get the template to use
121 my ($template, $loggedinuser, $cookie)
122 = get_template_and_user({template_name => "barcodes/barcodes.tmpl",
125 authnotrequired => 0,
126 flagsrequired => {parameters => 1},
130 # Replace the template values with the real ones
131 $template->param(SCRIPT_NAME => $script_name);
132 $template->param(NUMBER_SYSTEM => $number_system);
133 $template->param(PAGES => $labelConfig{'pageType'});
134 $template->param(RANGE_TYPE => $rangeType);
135 $template->param(LABEL_TABLE => \@labelTable);
136 $template->param(COL_SPAN => $labelConfig{'columns'});
137 if ($input->param('error')) {
138 $template->param(ERROR => 1);
140 $template->param(ERROR => 0);
142 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
143 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
144 IntranetNav => C4::Context->preference("IntranetNav"),
146 # Shows the template with the real values replaced
147 output_html_with_http_headers $input, $cookie, $template->output;