Bug 26265: (QA follow-up) Remove g option from regex, add few dirs
[koha-equinox.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  = 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,
32     }
33 );
34
35 my $barcode = $query->param('barcode');
36
37 my $dbh = C4::Context->dbh;
38 my $sth;
39
40 my $item;
41
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;
49
50 unless (defined $item) {
51   $template->param( 'Barcode' => $barcode );
52   $template->param( 'BarcodeNotFound' => 1 );
53 }
54
55 my $body;
56
57 my $data;
58 while ( my ( $key, $value ) = each(%$item) ) {
59     $data->{$key} .= "<span class='field' id='$key'>";
60
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;
73         }
74         $charnum++;
75         $i++;
76     }
77
78     $data->{$key} .= "</span>";
79 }
80
81 while ( my ( $key, $value ) = each(%$data) ) {
82     $scheme =~ s/<$key>/$value/g;
83 }
84
85 $body = $scheme;
86
87 $template->param( autoprint => C4::Context->preference("SpineLabelAutoPrint") );
88 $template->param( content   => $body );
89
90 output_html_with_http_headers $query, $cookie, $template->output;