Bug 19996: (QA follow-up) Remove commented use warnings;
[koha.git] / cataloguing / value_builder / unimarc_field_100.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use Modern::Perl;
22
23 use Date::Calc qw( Today );
24
25 use Koha::Util::FrameworkPlugin qw(wrapper);
26 use C4::Auth;
27 use CGI qw ( -utf8 );
28 use C4::Context;
29 use C4::Output;
30
31
32 sub plugin_javascript {
33     my ( $dbh, $record, $tagslib, $field_number, $tabloop ) = @_;
34     my $res           = "
35         <script type='text/javascript'>
36             function Clic$field_number(i) {
37                 var defaultvalue;
38                 try {
39                     defaultvalue = document.getElementById(i).value;
40                 } catch(e) {
41                     alert('error when getting '+i);
42                     return;
43                 }
44                 window.open(\"/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_100.pl&index=\"+i+\"&result=\"+defaultvalue,\"unimarc_field_100\",'width=1000,height=600,toolbar=false,scrollbars=yes');
45             }
46         </script>
47 ";
48
49     return ( $field_number, $res );
50 }
51
52
53 sub plugin {
54     my ($input) = @_;
55     my $index  = $input->param('index');
56     my $result = $input->param('result');
57
58     my $dbh = C4::Context->dbh;
59
60     my $defaultlanguage = C4::Context->preference("UNIMARCField100Language");
61     $defaultlanguage = "fre" if (!$defaultlanguage || length($defaultlanguage) != 3);
62
63     my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64         {
65             template_name => "cataloguing/value_builder/unimarc_field_100.tt",
66             query         => $input,
67             type          => "intranet",
68             authnotrequired => 0,
69             flagsrequired   => { editcatalogue => '*' },
70             debug           => 1,
71         }
72     );
73     $result = "        d        u  y0".$defaultlanguage."y50      ba" unless $result;
74     my $f1 = substr( $result, 0, 8 );
75     if ( $f1 eq '        ' ) {
76         my @today = Date::Calc::Today();
77         $f1 = $today[0] . sprintf('%02s',$today[1]) . sprintf('%02s',$today[2]);
78     }
79     my $f2  = substr( $result, 8,  1 ); $f2  = wrapper( $f2 ) if $f2;
80     my $f3  = substr( $result, 9,  4 );
81     $f3='' if $f3 eq '    '; # empty publication year if only spaces, otherwise it's hard to fill the field
82     my $f4  = substr( $result, 13, 4 );
83     $f4='' if $f4 eq '    ';
84     my $f5  = substr( $result, 17, 1 ); $f5  = wrapper( $f5 ) if $f5;
85     my $f6  = substr( $result, 18, 1 ); $f6  = wrapper( $f6 ) if $f6;
86     my $f7  = substr( $result, 19, 1 ); $f7  = wrapper( $f7 ) if $f7;
87     my $f8  = substr( $result, 20, 1 );
88     my $f9  = substr( $result, 21, 1 );
89     my $f10 = substr( $result, 22, 3 );
90     my $f11 = substr( $result, 25, 1 );
91     my $f12 = substr( $result, 26, 2 );
92     my $f13 = substr( $result, 28, 2 );
93     my $f14 = substr( $result, 30, 4 );
94     my $f15 = substr( $result, 34, 2 ); $f15 = wrapper( $f15 ) if $f15;
95
96     $template->param(
97         index     => $index,
98         f1        => $f1,
99         f3        => $f3,
100         "f2$f2"   => 1,
101         f4        => $f4,
102         "f5$f5"   => 1,
103         "f6$f6"   => 1,
104         "f7$f7"   => 1,
105         "f8$f8"   => 1,
106         "f9$f9"   => 1,
107         "f10"     => $f10,
108         "f11$f11" => 1,
109         "f12$f12" => 1,
110         "f13$f13" => 1,
111         "f14"     => $f14,
112         "f15$f15" => 1
113     );
114     output_html_with_http_headers $input, $cookie, $template->output;
115 }