leader length checking bugfix : 25 and not 24
[koha.git] / barcodes / label-print.pl
1 #!/usr/bin/perl
2
3 # This file is part of koha
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18 use strict;
19 use CGI;
20 use C4::Auth;
21 use C4::Serials;
22 use C4::Output;
23 use C4::Context;
24
25 use GD::Barcode::UPCE;
26 use Data::Random qw(:all);
27
28 my $htdocs_path = C4::Context->config('intrahtdocs');
29
30 my $query = new CGI;
31
32 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
33     {
34         template_name   => "barcodes/label-print.tmpl",
35         query           => $query,
36         type            => "intranet",
37         authnotrequired => 0,
38         flagsrequired   => { tools => 1 },
39         debug           => 1,
40     }
41 );
42
43 my $dbh    = C4::Context->dbh;
44 my $query2 = "SELECT * FROM labels_conf LIMIT 1";
45 my $sth    = $dbh->prepare($query2);
46 $sth->execute();
47
48 my $conf_data = $sth->fetchrow_hashref;
49
50 $sth->finish;
51
52 my @data;
53 my $query3 = "Select * from labels";
54 my $sth    = $dbh->prepare($query3);
55 $sth->execute();
56 my @resultsloop;
57 my $cnt = $sth->rows;
58 my $i1  = 1;
59 while ( my $data = $sth->fetchrow_hashref ) {
60
61     # lets get some summary info from each item
62
63     my $query1 = "
64                         select * from biblio,biblioitems,items where itemnumber=? and
65                                 items.biblioitemnumber=biblioitems.biblioitemnumber and
66                                 biblioitems.biblionumber=biblio.biblionumber";
67
68     my $sth1 = $dbh->prepare($query1);
69     $sth1->execute( $data->{'itemnumber'} );
70     my $data1 = $sth1->fetchrow_hashref();
71
72     push( @resultsloop, $data1 );
73     $sth1->finish;
74
75     $i1++;
76 }
77 $sth->finish;
78
79 #------------------------------------------------------
80
81 #lets write barcode files to tmp dir for every item in @resultsloop
82
83 binmode(FILE);
84 foreach my $item (@resultsloop) {
85
86     my $random = int( rand(100000000000) ) + 999999999999;
87
88     #warn  "$random\n";
89
90     $item->{'barcode'} = $random;
91
92     #   my $itembarcode = $item->{'barcode'};
93     #   warn $item->{'barcode'};
94
95     my $filename = "$htdocs_path/barcodes/$item->{'barcode'}.png";
96
97     #warn $filename;
98     open( FILE, ">$filename" );
99
100     print FILE GD::Barcode->new( 'EAN13', $item->{'barcode'} )->plot->png;
101
102     #   warn $GD::Barcode::errStr;
103
104     close(FILE);
105
106     #warn Dumper  $item->{'barcode'};
107
108 }
109
110 # lets pass the config setting
111
112 $template->param(
113
114     resultsloop => \@resultsloop,
115
116     itemtype_opt       => $conf_data->{'itemtype'},
117     papertype_opt      => $conf_data->{'papertype'},
118     author_opt         => $conf_data->{'author'},
119     barcode_opt        => $conf_data->{'barcode'},
120     id_opt             => $conf_data->{'id'},
121     type_opt           => $conf_data->{'type'},
122     title_opt          => $conf_data->{'title'},
123     isbn_opt           => $conf_data->{'isbn'},
124     dewey_opt          => $conf_data->{'dewey'},
125     class_opt          => $conf_data->{'class'},
126     subclass_opt       => $conf_data->{'subclass'},
127     itemcallnumber_opt => $conf_data->{'itemcallnumber'},
128
129     intranetcolorstylesheet =>
130       C4::Context->preference("intranetcolorstylesheet"),
131     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
132     IntranetNav        => C4::Context->preference("IntranetNav"),
133 );
134 output_html_with_http_headers $query, $cookie, $template->output;
135