quell warning on NULL item fields
[koha.git] / labels / spinelabel-print.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5 use CGI;
6 use C4::Auth;
7 use C4::Output;
8
9 my $scheme = C4::Context->preference('SpineLabelFormat');
10 my $query = new CGI;
11 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
12     {
13         template_name   => "labels/spinelabel-print.tmpl",
14         query           => $query,
15         type            => "intranet",
16         authnotrequired => 0,
17         flagsrequired   => { catalogue => 1 },
18         debug           => 1,
19     }
20 );
21
22
23 my $barcode = $query->param('barcode');
24
25 my $dbh = C4::Context->dbh;
26 my $sth;
27
28 my $item;
29
30 my $sql = "SELECT * FROM biblio, biblioitems, items 
31           WHERE biblio.biblionumber = items.biblionumber 
32           AND biblioitems.biblioitemnumber = items.biblioitemnumber 
33           AND items.barcode = ?";
34 $sth = $dbh->prepare( $sql );
35 $sth->execute( $barcode );
36 $item = $sth->fetchrow_hashref;
37
38 my $body;
39
40 my $data;
41 while ( my ($key, $value ) = each(%$item) ) {
42   $data->{$key} .= "<span class='field' id='$key'>";
43
44   $value = '' unless defined $value;
45   my @characters = split(//, $value );
46   my $charnum = 1;
47   my $wordnum = 1;
48   my $i = 1;
49   foreach my $char ( @characters ) {
50     if ( $char ne ' ' ) {
51       $data->{$key} .= "<span class='character word$wordnum character$charnum' id='$key$i'>$char</span>";
52     } else {
53       $data->{$key} .= "<span class='space character$charnum' id='$key$i'>$char</span>";
54       $wordnum++;
55       $charnum = 1;
56     }
57     $charnum++;
58     $i++;
59   }
60   
61   $data->{$key} .= "</span>";
62 }
63
64 while ( my ($key, $value ) = each(%$data) ) {
65   $scheme =~ s/<$key>/$value/g;
66 }
67
68 $body = $scheme;
69
70 $template->param( autoprint => C4::Context->preference("SpineLabelAutoPrint") );
71 $template->param( content => $body );
72
73 output_html_with_http_headers $query, $cookie, $template->output;