sql used to create 'labels_conf' and 'labels' table
[koha.git] / barcodes / label-print.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Bull;
7 use C4::Output;
8 use C4::Interface::CGI::Output;
9 use C4::Context;
10 use HTML::Template;
11 use GD::Barcode::UPCE;
12 use Data::Random qw(:all);
13
14 my $htdocs_path = C4::Context->config('intrahtdocs');
15
16 use Data::Dumper;
17
18 my $query = new CGI;
19
20 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
21     {
22         template_name   => "barcodes/label-print.tmpl",
23         query           => $query,
24         type            => "intranet",
25         authnotrequired => 0,
26         flagsrequired   => { catalogue => 1 },
27         debug           => 1,
28     }
29 );
30
31 my $dbh    = C4::Context->dbh;
32 my $query2 = "SELECT * FROM labels_conf LIMIT 1";
33 my $sth    = $dbh->prepare($query2);
34 $sth->execute();
35
36 my $conf_data = $sth->fetchrow_hashref;
37
38 #warn Dumper $conf_data;
39
40 $sth->finish;
41
42 my @data;
43 my $query3 = "Select * from labels";
44 my $sth    = $dbh->prepare($query3);
45 $sth->execute();
46 my @resultsloop;
47 my $cnt = $sth->rows;
48 my $i1  = 1;
49 while ( my $data = $sth->fetchrow_hashref ) {
50
51     # lets get some summary info from each item
52
53     my $query1 = "
54                         select * from biblio,biblioitems,items where itemnumber=? and
55                                 items.biblioitemnumber=biblioitems.biblioitemnumber and
56                                 biblioitems.biblionumber=biblio.biblionumber";
57
58     my $sth1 = $dbh->prepare($query1);
59     $sth1->execute( $data->{'itemnumber'} );
60     my $data1 = $sth1->fetchrow_hashref();
61
62     push( @resultsloop, $data1 );
63     $sth1->finish;
64
65     $i1++;
66 }
67 $sth->finish;
68
69 #warn Dumper @resultsloop;
70
71
72
73
74 #------------------------------------------------------
75
76 #lets write barcode files to tmp dir for every item in @resultsloop
77
78
79
80 binmode(FILE);
81 foreach my $item (@resultsloop){
82
83
84 my $random = int( rand(100000000000)) + 999999999999;
85 #warn  "$random\n";
86
87         $item->{'barcode'} = $random;
88
89 #       my $itembarcode = $item->{'barcode'};
90 #       warn $item->{'barcode'};
91
92
93         my $filename = "$htdocs_path/barcodes/$item->{'barcode'}.png";
94         #warn $filename;
95         open(FILE, ">$filename"); 
96
97         print FILE GD::Barcode->new('EAN13',  $item->{'barcode'})->plot->png;
98 #       warn $GD::Barcode::errStr;
99
100         close(FILE);
101
102 #warn Dumper  $item->{'barcode'};
103
104 }
105
106
107
108
109
110 # lets pass the config setting
111
112 $template->param(
113
114     resultsloop             => \@resultsloop,
115
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
128
129
130
131     intranetcolorstylesheet =>
132       C4::Context->preference("intranetcolorstylesheet"),
133     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
134     IntranetNav        => C4::Context->preference("IntranetNav"),
135 );
136 output_html_with_http_headers $query, $cookie, $template->output;
137
138