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
28 use C4::Barcodes::PrinterConfig;
30 # This function returns the path to deal with the correct files, considering
31 # templates set and language.
34 my $templatesSet = C4::Context->preference('template');
35 my $lang = C4::Context->preference('opaclanguages');
36 if ( $type eq "intranet" ) {
37 return "$ENV{'DOCUMENT_ROOT'}/intranet-tmpl/$templatesSet/$lang";
40 return "$ENV{'DOCUMENT_ROOT'}/opac-tmpl/$templatesSet/$lang";
44 # Load a configuration file. Before use this function, check if that file exists.
45 sub loadConfFromFile {
46 my $fileName = shift @_;
48 open FILE, "<$fileName";
51 if (/\s*([\w_]*)\s*=\s*([\[\]\<\>\w_\s:@,\.-]*)\s*/) {
59 # Save settings to a configuration file. It delete previous configuration settings.
61 my $fileName = shift @_;
62 my %keyValues = %{ shift @_ };
64 open FILE, ">$fileName";
65 foreach $i ( keys(%keyValues) ) {
66 print FILE $i . " = " . $keyValues{$i} . "\n";
71 # Load the config file.
73 &getPath("intranet") . "/includes/labelConfig/itemsLabelConfig.conf";
74 my %labelConfig = &loadConfFromFile($filenameConf);
78 # Defines type of page to use in the printer process
80 C4::Barcodes::PrinterConfig::labelsPage( $labelConfig{'rows'},
81 $labelConfig{'columns'} );
83 # It creates a list of posible intervals to choose codes to generate
85 'continuous' => 'Continuous Range of items',
86 'individuals' => 'Individual Codes'
88 my @listValues = keys(%list);
89 my $rangeType = CGI::scrolling_list(
91 -values => \@listValues,
94 -default => ['continuous'],
97 -onChange => "changeRange(this)"
100 # It creates a list of posible standard codifications. First checks if the user has just added a new code.
101 if ( $input->param('addCode') ) {
102 my $newCountryName = $input->param('countryName');
103 my $newCountryCode = $input->param('countryCode');
105 my $countryCodesFilename =
106 &getPath("intranet") . "/includes/countryCodes/countryCodes.dat";
107 open COUNTRY_CODES, ">>$countryCodesFilename";
108 print COUNTRY_CODES $newCountryCode . " = " . $newCountryName . "\n";
112 # Takes the country codes from a file and use them to set the country list.
114 &getPath("intranet") . "/includes/countryCodes/countryCodes.dat";
115 %list = &loadConfFromFile($countryCodes);
116 @listValues = keys(%list);
117 my $number_system = CGI::scrolling_list(
118 -name => 'numbersystem',
119 -values => \@listValues,
125 # Set the script name
126 my $script_name = "/cgi-bin/koha/barcodes/barcodesGenerator.pl";
128 # Get the template to use
129 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
131 template_name => "barcodes/barcodes.tmpl",
134 authnotrequired => 0,
135 flagsrequired => { tools => 1 },
140 # Replace the template values with the real ones
141 $template->param( SCRIPT_NAME => $script_name );
142 $template->param( NUMBER_SYSTEM => $number_system );
143 $template->param( PAGES => $labelConfig{'pageType'} );
144 $template->param( RANGE_TYPE => $rangeType );
145 $template->param( LABEL_TABLE => \@labelTable );
146 $template->param( COL_SPAN => $labelConfig{'columns'} );
147 if ( $input->param('error') ) {
148 $template->param( ERROR => 1 );
151 $template->param( ERROR => 0 );
154 intranetcolorstylesheet =>
155 C4::Context->preference("intranetcolorstylesheet"),
156 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
157 IntranetNav => C4::Context->preference("IntranetNav"),
160 # Shows the template with the real values replaced
161 output_html_with_http_headers $input, $cookie, $template->output;