Code39 section now has 'hide_asterisk', scans successfully
[koha.git] / barcodes / label-print.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Auth;
6 use C4::Output;
7 use C4::Interface::CGI::Output;
8 use C4::Context;
9 use HTML::Template;
10 use GD::Barcode::UPCE;
11
12 my $htdocs_path = C4::Context->config('intrahtdocs');
13 my $query       = new CGI;
14 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
15     {
16         template_name   => "barcodes/label-print.tmpl",
17         query           => $query,
18         type            => "intranet",
19         authnotrequired => 0,
20         flagsrequired   => { catalogue => 1 },
21         debug           => 1,
22     }
23 );
24
25 my $dbh    = C4::Context->dbh;
26 my $query2 = "SELECT * FROM labels_conf LIMIT 1";
27 my $sth    = $dbh->prepare($query2);
28 $sth->execute();
29 my $conf_data = $sth->fetchrow_hashref;
30
31 # get barcode type from $conf_data
32 my $barcodetype = $conf_data->{'barcodetype'};
33 $sth->finish;
34
35 my @data;
36 my $query3 = "Select * from labels";
37 my $sth    = $dbh->prepare($query3);
38 $sth->execute();
39 my @resultsloop;
40 my $cnt = $sth->rows;
41 my $i1  = 1;
42 while ( my $data = $sth->fetchrow_hashref ) {
43
44     # lets get some summary info from each item
45     my $query1 = "
46                         SELECT * FROM biblio,biblioitems,items WHERE itemnumber=? AND
47                                 items.biblioitemnumber=biblioitems.biblioitemnumber AND
48                                 biblioitems.biblionumber=biblio.biblionumber";
49
50     my $sth1 = $dbh->prepare($query1);
51     $sth1->execute( $data->{'itemnumber'} );
52     my $data1 = $sth1->fetchrow_hashref();
53     push( @resultsloop, $data1 );
54     $sth1->finish;
55
56     $i1++;
57 }
58 $sth->finish;
59
60 #lets write barcode files to tmp dir for every item in @resultsloop
61
62 binmode(FILE);
63 foreach my $item (@resultsloop) {
64     my $filename = "$htdocs_path/barcodes/$barcodetype-$item->{'barcode'}.png";
65     open( FILE, ">$filename" );
66     eval {
67         print FILE GD::Barcode->new( $barcodetype, $item->{'barcode'} )
68           ->plot->png;
69     };
70     if ($@) {
71         $item->{'barcodeerror'} = 1;
72     }
73     close(FILE);
74 }
75
76 $template->param(
77     resultsloop             => \@resultsloop,
78     itemtype_opt            => $conf_data->{'itemtype'},
79     papertype_opt           => $conf_data->{'papertype'},
80     author_opt              => $conf_data->{'author'},
81     id_opt                  => $conf_data->{'id'},
82     barcodetype_opt         => $conf_data->{'barcodetype'},
83     title_opt               => $conf_data->{'title'},
84     isbn_opt                => $conf_data->{'isbn'},
85     dewey_opt               => $conf_data->{'dewey'},
86     class_opt               => $conf_data->{'class'},
87     intranetcolorstylesheet =>
88       C4::Context->preference("intranetcolorstylesheet"),
89     intranetstylesheet => C4::Context->preference("intranetstylesheet"),
90     IntranetNav        => C4::Context->preference("IntranetNav"),
91 );
92 output_html_with_http_headers $query, $cookie, $template->output;