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;
29 use C4::Barcodes::PrinterConfig;
31 # This function returns the path to deal with the correct files, considering
32 # templates set and language.
35 my $templatesSet = C4::Context->preference('template');
36 my $lang = C4::Context->preference('opaclanguages');
37 if ( $type eq "intranet" ) {
38 return "$ENV{'DOCUMENT_ROOT'}/intranet-tmpl/$templatesSet/$lang";
41 return "$ENV{'DOCUMENT_ROOT'}/opac-tmpl/$templatesSet/$lang";
45 # Load a configuration file. Before use this function, check if that file exists.
46 sub loadConfFromFile {
47 my $fileName = shift @_;
49 open FILE, "<$fileName";
52 if (/\s*([\w_]*)\s*=\s*([\[\]\<\>\w_\s:@,\.-]*)\s*/) {
60 # Save settings to a configuration file. It delete previous configuration settings.
62 my $fileName = shift @_;
63 my %keyValues = %{ shift @_ };
65 open FILE, ">$fileName";
66 foreach $i ( keys(%keyValues) ) {
67 print FILE $i . " = " . $keyValues{$i} . "\n";
72 # Load the config file.
74 &getPath("intranet") . "/includes/labelConfig/itemsLabelConfig.conf";
75 my %labelConfig = &loadConfFromFile($filenameConf);
79 # Defines type of page to use in the printer process
81 C4::Barcodes::PrinterConfig::labelsPage( $labelConfig{'rows'},
82 $labelConfig{'columns'} );
84 # It creates a list of posible intervals to choose codes to generate
86 'continuous' => 'Continuous Range of items',
87 'individuals' => 'Individual Codes'
89 my @listValues = keys(%list);
90 my $rangeType = CGI::scrolling_list(
92 -values => \@listValues,
95 -default => ['continuous'],
98 -onChange => "changeRange(this)"
101 # It creates a list of posible standard codifications. First checks if the user has just added a new code.
102 if ( $input->param('addCode') ) {
103 my $newCountryName = $input->param('countryName');
104 my $newCountryCode = $input->param('countryCode');
106 my $countryCodesFilename =
107 &getPath("intranet") . "/includes/countryCodes/countryCodes.dat";
108 open COUNTRY_CODES, ">>$countryCodesFilename";
109 print COUNTRY_CODES $newCountryCode . " = " . $newCountryName . "\n";
113 # Takes the country codes from a file and use them to set the country list.
115 &getPath("intranet") . "/includes/countryCodes/countryCodes.dat";
116 %list = &loadConfFromFile($countryCodes);
117 @listValues = keys(%list);
118 my $number_system = CGI::scrolling_list(
119 -name => 'numbersystem',
120 -values => \@listValues,
126 # Set the script name
127 my $script_name = "/cgi-bin/koha/barcodes/barcodesGenerator.pl";
129 # Get the template to use
130 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
132 template_name => "barcodes/barcodes.tmpl",
135 authnotrequired => 0,
136 flagsrequired => { tools => 1 },
141 # Replace the template values with the real ones
142 $template->param( SCRIPT_NAME => $script_name );
143 $template->param( NUMBER_SYSTEM => $number_system );
144 $template->param( PAGES => $labelConfig{'pageType'} );
145 $template->param( RANGE_TYPE => $rangeType );
146 $template->param( LABEL_TABLE => \@labelTable );
147 $template->param( COL_SPAN => $labelConfig{'columns'} );
148 if ( $input->param('error') ) {
149 $template->param( ERROR => 1 );
152 $template->param( ERROR => 0 );
155 intranetcolorstylesheet =>
156 C4::Context->preference("intranetcolorstylesheet"),
157 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
158 IntranetNav => C4::Context->preference("IntranetNav"),
161 # Shows the template with the real values replaced
162 output_html_with_http_headers $input, $cookie, $template->output;