f34c1f811d4edb5d0afd458a2c59ef28f17dfc9d
[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  = CGI->new;
25 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
26     {   template_name   => "labels/spinelabel-print.tt",
27         query           => $query,
28         type            => "intranet",
29         flagsrequired   => { catalogue => 1 },
30         debug           => 1,
31     }
32 );
33
34 my $barcode = $query->param('barcode');
35
36 my $dbh = C4::Context->dbh;
37 my $sth;
38
39 my $item;
40
41 my $sql = "SELECT * FROM biblio, biblioitems, items 
42           WHERE biblio.biblionumber = items.biblionumber 
43           AND biblioitems.biblioitemnumber = items.biblioitemnumber 
44           AND items.barcode = ?";
45 $sth = $dbh->prepare($sql);
46 $sth->execute($barcode);
47 $item = $sth->fetchrow_hashref;
48
49 unless (defined $item) {
50   $template->param( 'Barcode' => $barcode );
51   $template->param( 'BarcodeNotFound' => 1 );
52 }
53
54 my $body;
55
56 my $data;
57 while ( my ( $key, $value ) = each(%$item) ) {
58     $data->{$key} .= "<span class='field' id='$key'>";
59
60     $value = '' unless defined $value;
61     my @characters = split( //, $value );
62     my $charnum    = 1;
63     my $wordernumber    = 1;
64     my $i          = 1;
65     foreach my $char (@characters) {
66         if ( $char ne ' ' ) {
67             $data->{$key} .= "<span class='character word$wordernumber character$charnum' id='$key$i'>$char</span>";
68         } else {
69             $data->{$key} .= "<span class='space character$charnum' id='$key$i'>$char</span>";
70             $wordernumber++;
71             $charnum = 1;
72         }
73         $charnum++;
74         $i++;
75     }
76
77     $data->{$key} .= "</span>";
78 }
79
80 while ( my ( $key, $value ) = each(%$data) ) {
81     $scheme =~ s/<$key>/$value/g;
82 }
83
84 $body = $scheme;
85
86 $template->param( autoprint => C4::Context->preference("SpineLabelAutoPrint") );
87 $template->param( content   => $body );
88
89 output_html_with_http_headers $query, $cookie, $template->output;