585b06a367fdb27f7c1b9c2adcd30d62f1ce460a
[koha.git] / labels / spinelabel-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 warnings;
19 use strict;
20 use CGI;
21 use C4::Auth;
22 use C4::Output;
23
24 my $scheme = C4::Context->preference('SpineLabelFormat');
25 my $query  = new CGI;
26 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
27     {   template_name   => "labels/spinelabel-print.tmpl",
28         query           => $query,
29         type            => "intranet",
30         authnotrequired => 0,
31         flagsrequired   => { catalogue => 1 },
32         debug           => 1,
33     }
34 );
35
36 my $barcode = $query->param('barcode');
37
38 my $dbh = C4::Context->dbh;
39 my $sth;
40
41 my $item;
42
43 my $sql = "SELECT * FROM biblio, biblioitems, items 
44           WHERE biblio.biblionumber = items.biblionumber 
45           AND biblioitems.biblioitemnumber = items.biblioitemnumber 
46           AND items.barcode = ?";
47 $sth = $dbh->prepare($sql);
48 $sth->execute($barcode);
49 $item = $sth->fetchrow_hashref;
50
51 unless (defined $item) {
52   $template->param( 'Barcode' => $barcode );
53   $template->param( 'BarcodeNotFound' => 1 );
54 }
55
56 # XXX FFZG #1059 -- dpavlin 2012-02-07 print spine labels
57
58 use URI::Escape;
59
60 my $ip = $query->remote_addr;
61
62 if ( my $station = $query->param('station') ) {
63
64         warn "PRINTED $barcode on $station\n";
65
66         my $insert = $dbh->prepare(qq{
67                 insert into items_print_log (barcode,itemnumber,station) values (?,?,?)
68         });
69         $insert->execute( $item->{barcode}, $item->{biblioitemnumber}, $station );
70
71 } else {
72
73         my $print_data = join(' ',
74                 $item->{barcode},
75                 $item->{itemcallnumber},
76         );
77
78         print $query->redirect( 'http://printer-zebra.vbz.ffzg.hr/print.cgi?print=' . uri_escape_utf8($print_data) . '&return=' . uri_escape($query->self_url) );
79         exit 0;
80
81 }
82
83 # XXX /FFZG
84
85 my $body;
86
87 my $data;
88 while ( my ( $key, $value ) = each(%$item) ) {
89     $data->{$key} .= "<span class='field' id='$key'>";
90
91     $value = '' unless defined $value;
92     my @characters = split( //, $value );
93     my $charnum    = 1;
94     my $wordernumber    = 1;
95     my $i          = 1;
96     foreach my $char (@characters) {
97         if ( $char ne ' ' ) {
98             $data->{$key} .= "<span class='character word$wordernumber character$charnum' id='$key$i'>$char</span>";
99         } else {
100             $data->{$key} .= "<span class='space character$charnum' id='$key$i'>$char</span>";
101             $wordernumber++;
102             $charnum = 1;
103         }
104         $charnum++;
105         $i++;
106     }
107
108     $data->{$key} .= "</span>";
109 }
110
111 while ( my ( $key, $value ) = each(%$data) ) {
112     $scheme =~ s/<$key>/$value/g;
113 }
114
115 $body = $scheme;
116
117 # XXX FFZG
118
119 $body .= qq|
120 <style type="text/css">
121 #printed_label {
122         display: block;
123         border: 1px solid #ccc;
124         position: absolute;
125         top: 0;
126         left: 0;
127 }
128 #print_button {
129         display: none;
130 }
131 </style>
132 <img id="printed_label" src="http://printer-zebra.vbz.ffzg.hr/$barcode.png">
133 |;
134
135 # XXX /FFZG
136
137 $template->param( autoprint => C4::Context->preference("SpineLabelAutoPrint") );
138 $template->param( content   => $body );
139
140 output_html_with_http_headers $query, $cookie, $template->output;