ffzg/recall_notices.pl: added --interval and --dedup
[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
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19 use CGI qw ( -utf8 );
20 use C4::Auth;
21 use C4::Output;
22
23 my $scheme = C4::Context->preference('SpineLabelFormat');
24 my $query  = new CGI;
25 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
26     {   template_name   => "labels/spinelabel-print.tt",
27         query           => $query,
28         type            => "intranet",
29         authnotrequired => 0,
30         flagsrequired   => { catalogue => 1 },
31         debug           => 1,
32     }
33 );
34
35 my $barcode = $query->param('barcode');
36
37 my $dbh = C4::Context->dbh;
38 my $sth;
39
40 my $item;
41
42 my $sql = "SELECT * FROM biblio, biblioitems, items 
43           WHERE biblio.biblionumber = items.biblionumber 
44           AND biblioitems.biblioitemnumber = items.biblioitemnumber 
45           AND items.barcode = ?";
46 $sth = $dbh->prepare($sql);
47 $sth->execute($barcode);
48 $item = $sth->fetchrow_hashref;
49
50 unless (defined $item) {
51   $template->param( 'Barcode' => $barcode );
52   $template->param( 'BarcodeNotFound' => 1 );
53 }
54
55 # XXX FFZG #1059 -- dpavlin 2012-02-07 print spine labels
56
57 use URI::Escape;
58
59 my $ip = $query->remote_addr;
60
61 if ( my $station = $query->param('station') ) {
62
63         warn "PRINTED $barcode on $station\n";
64
65         my $insert = $dbh->prepare(qq{
66                 insert into items_print_log (barcode,itemnumber,station) values (?,?,?)
67         });
68         $insert->execute( $item->{barcode}, $item->{biblioitemnumber}, $station );
69
70 } elsif ( $item ) {
71
72         my $print_data = join(' ',
73                 $item->{barcode},
74                 $item->{itemcallnumber},
75         );
76
77         print $query->redirect( 'http://printer-zebra.vbz.ffzg.hr/print.cgi?print=' . uri_escape_utf8($print_data) . '&return=' . uri_escape($query->self_url) );
78         exit 0;
79
80 }
81
82 # XXX /FFZG
83
84 my $body;
85
86 my $data;
87 while ( my ( $key, $value ) = each(%$item) ) {
88     $data->{$key} .= "<span class='field' id='$key'>";
89
90     $value = '' unless defined $value;
91     my @characters = split( //, $value );
92     my $charnum    = 1;
93     my $wordernumber    = 1;
94     my $i          = 1;
95     foreach my $char (@characters) {
96         if ( $char ne ' ' ) {
97             $data->{$key} .= "<span class='character word$wordernumber character$charnum' id='$key$i'>$char</span>";
98         } else {
99             $data->{$key} .= "<span class='space character$charnum' id='$key$i'>$char</span>";
100             $wordernumber++;
101             $charnum = 1;
102         }
103         $charnum++;
104         $i++;
105     }
106
107     $data->{$key} .= "</span>";
108 }
109
110 while ( my ( $key, $value ) = each(%$data) ) {
111     $scheme =~ s/<$key>/$value/g;
112 }
113
114 $body = $scheme;
115
116 # XXX FFZG
117
118 my $url = $query->url;
119 my $station = $query->param('station');
120
121 $body = qq|
122 <style type="text/css">
123 #print_button {
124         display: none;
125 }
126 #printed_label {
127         border: 1px solid #aaa;
128 }
129 body {
130         margin: 1em;
131 }
132 </style>
133
134 <form action="$url" method="get" autocomplete="off">
135 Enter another barcode:
136 <input id=focus_barcode type=text name=barcode autofocus autocomplete="off">
137 <input type=submit value="Print">
138 </form>
139
140 <h1>Last printed call number for $barcode on $station</h1>
141
142 <img id="printed_label" src="http://printer-zebra.vbz.ffzg.hr/$barcode.png">
143
144 <script type="text/javascript">
145 function formfocus() {
146         document.getElementById('focus_barcode').focus();
147 }
148 window.onload = formfocus;
149 </script>
150
151 |;
152
153 # XXX /FFZG
154
155 $template->param( autoprint => C4::Context->preference("SpineLabelAutoPrint") );
156 $template->param( content   => $body );
157
158 output_html_with_http_headers $query, $cookie, $template->output;