Koha/labels/spinelabel-print.pl
Galen Charlton 57be4114d8 quell warning on NULL item fields
Signed-off-by: Galen Charlton <gmcharlt@gmail.com>
2009-08-02 11:08:16 -04:00

73 lines
1.8 KiB
Perl
Executable file

#!/usr/bin/perl
use warnings;
use strict;
use CGI;
use C4::Auth;
use C4::Output;
my $scheme = C4::Context->preference('SpineLabelFormat');
my $query = new CGI;
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
{
template_name => "labels/spinelabel-print.tmpl",
query => $query,
type => "intranet",
authnotrequired => 0,
flagsrequired => { catalogue => 1 },
debug => 1,
}
);
my $barcode = $query->param('barcode');
my $dbh = C4::Context->dbh;
my $sth;
my $item;
my $sql = "SELECT * FROM biblio, biblioitems, items
WHERE biblio.biblionumber = items.biblionumber
AND biblioitems.biblioitemnumber = items.biblioitemnumber
AND items.barcode = ?";
$sth = $dbh->prepare( $sql );
$sth->execute( $barcode );
$item = $sth->fetchrow_hashref;
my $body;
my $data;
while ( my ($key, $value ) = each(%$item) ) {
$data->{$key} .= "<span class='field' id='$key'>";
$value = '' unless defined $value;
my @characters = split(//, $value );
my $charnum = 1;
my $wordnum = 1;
my $i = 1;
foreach my $char ( @characters ) {
if ( $char ne ' ' ) {
$data->{$key} .= "<span class='character word$wordnum character$charnum' id='$key$i'>$char</span>";
} else {
$data->{$key} .= "<span class='space character$charnum' id='$key$i'>$char</span>";
$wordnum++;
$charnum = 1;
}
$charnum++;
$i++;
}
$data->{$key} .= "</span>";
}
while ( my ($key, $value ) = each(%$data) ) {
$scheme =~ s/<$key>/$value/g;
}
$body = $scheme;
$template->param( autoprint => C4::Context->preference("SpineLabelAutoPrint") );
$template->param( content => $body );
output_html_with_http_headers $query, $cookie, $template->output;