rel_3_0 moved to HEAD
[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::Interface::CGI::Output;
24 use C4::Context;
25
26 use GD::Barcode::UPCE;
27 use Data::Random qw(:all);
28
29 my $htdocs_path = C4::Context->config('intrahtdocs');
30
31 my $query = new CGI;
32
33 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
34     {
35         template_name   => "barcodes/label-print.tmpl",
36         query           => $query,
37         type            => "intranet",
38         authnotrequired => 0,
39         flagsrequired   => { tools => 1 },
40         debug           => 1,
41     }
42 );
43
44 my $dbh    = C4::Context->dbh;
45 my $query2 = "SELECT * FROM labels_conf LIMIT 1";
46 my $sth    = $dbh->prepare($query2);
47 $sth->execute();
48
49 my $conf_data = $sth->fetchrow_hashref;
50
51 $sth->finish;
52
53 my @data;
54 my $query3 = "Select * from labels";
55 my $sth    = $dbh->prepare($query3);
56 $sth->execute();
57 my @resultsloop;
58 my $cnt = $sth->rows;
59 my $i1  = 1;
60 while ( my $data = $sth->fetchrow_hashref ) {
61
62     # lets get some summary info from each item
63
64     my $query1 = "
65                         select * from biblio,biblioitems,items where itemnumber=? and
66                                 items.biblioitemnumber=biblioitems.biblioitemnumber and
67                                 biblioitems.biblionumber=biblio.biblionumber";
68
69     my $sth1 = $dbh->prepare($query1);
70     $sth1->execute( $data->{'itemnumber'} );
71     my $data1 = $sth1->fetchrow_hashref();
72
73     push( @resultsloop, $data1 );
74     $sth1->finish;
75
76     $i1++;
77 }
78 $sth->finish;
79
80 #------------------------------------------------------
81
82 #lets write barcode files to tmp dir for every item in @resultsloop
83
84 binmode(FILE);
85 foreach my $item (@resultsloop) {
86
87     my $random = int( rand(100000000000) ) + 999999999999;
88
89     #warn  "$random\n";
90
91     $item->{'barcode'} = $random;
92
93     #   my $itembarcode = $item->{'barcode'};
94     #   warn $item->{'barcode'};
95
96     my $filename = "$htdocs_path/barcodes/$item->{'barcode'}.png";
97
98     #warn $filename;
99     open( FILE, ">$filename" );
100
101     print FILE GD::Barcode->new( 'EAN13', $item->{'barcode'} )->plot->png;
102
103     #   warn $GD::Barcode::errStr;
104
105     close(FILE);
106
107     #warn Dumper  $item->{'barcode'};
108
109 }
110
111 # lets pass the config setting
112
113 $template->param(
114
115     resultsloop => \@resultsloop,
116
117     itemtype_opt       => $conf_data->{'itemtype'},
118     papertype_opt      => $conf_data->{'papertype'},
119     author_opt         => $conf_data->{'author'},
120     barcode_opt        => $conf_data->{'barcode'},
121     id_opt             => $conf_data->{'id'},
122     type_opt           => $conf_data->{'type'},
123     title_opt          => $conf_data->{'title'},
124     isbn_opt           => $conf_data->{'isbn'},
125     dewey_opt          => $conf_data->{'dewey'},
126     class_opt          => $conf_data->{'class'},
127     subclass_opt       => $conf_data->{'subclass'},
128     itemcallnumber_opt => $conf_data->{'itemcallnumber'},
129
130     intranetcolorstylesheet =>
131       C4::Context->preference("intranetcolorstylesheet"),
132     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
133     IntranetNav        => C4::Context->preference("IntranetNav"),
134 );
135 output_html_with_http_headers $query, $cookie, $template->output;
136