Bug 9259: Use is instead of is_deeply
[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 warnings;
19 use strict;
20 use CGI qw ( -utf8 );
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.tt",
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 my $body;
57
58 my $data;
59 while ( my ( $key, $value ) = each(%$item) ) {
60     $data->{$key} .= "<span class='field' id='$key'>";
61
62     $value = '' unless defined $value;
63     my @characters = split( //, $value );
64     my $charnum    = 1;
65     my $wordernumber    = 1;
66     my $i          = 1;
67     foreach my $char (@characters) {
68         if ( $char ne ' ' ) {
69             $data->{$key} .= "<span class='character word$wordernumber character$charnum' id='$key$i'>$char</span>";
70         } else {
71             $data->{$key} .= "<span class='space character$charnum' id='$key$i'>$char</span>";
72             $wordernumber++;
73             $charnum = 1;
74         }
75         $charnum++;
76         $i++;
77     }
78
79     $data->{$key} .= "</span>";
80 }
81
82 while ( my ( $key, $value ) = each(%$data) ) {
83     $scheme =~ s/<$key>/$value/g;
84 }
85
86 $body = $scheme;
87
88 $template->param( autoprint => C4::Context->preference("SpineLabelAutoPrint") );
89 $template->param( content   => $body );
90
91 output_html_with_http_headers $query, $cookie, $template->output;