Bug 19794: DBRev 17.12.00.032
[koha.git] / labels / spinelabel-print.pl
blobd1e81ea14bba9a061248acf1dcb06f0dc1dc0164
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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>.
18 use Modern::Perl;
19 use CGI qw ( -utf8 );
20 use C4::Auth;
21 use C4::Output;
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,
35 my $barcode = $query->param('barcode');
37 my $dbh = C4::Context->dbh;
38 my $sth;
40 my $item;
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;
50 unless (defined $item) {
51 $template->param( 'Barcode' => $barcode );
52 $template->param( 'BarcodeNotFound' => 1 );
55 my $body;
57 my $data;
58 while ( my ( $key, $value ) = each(%$item) ) {
59 $data->{$key} .= "<span class='field' id='$key'>";
61 $value = '' unless defined $value;
62 my @characters = split( //, $value );
63 my $charnum = 1;
64 my $wordernumber = 1;
65 my $i = 1;
66 foreach my $char (@characters) {
67 if ( $char ne ' ' ) {
68 $data->{$key} .= "<span class='character word$wordernumber character$charnum' id='$key$i'>$char</span>";
69 } else {
70 $data->{$key} .= "<span class='space character$charnum' id='$key$i'>$char</span>";
71 $wordernumber++;
72 $charnum = 1;
74 $charnum++;
75 $i++;
78 $data->{$key} .= "</span>";
81 while ( my ( $key, $value ) = each(%$data) ) {
82 $scheme =~ s/<$key>/$value/g;
85 $body = $scheme;
87 $template->param( autoprint => C4::Context->preference("SpineLabelAutoPrint") );
88 $template->param( content => $body );
90 output_html_with_http_headers $query, $cookie, $template->output;