Bug 32875: Fix cataloguing/value_builder/unimarc_leader_authorities.pl
[koha.git] / cataloguing / value_builder / unimarc_leader_authorities.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright (C) 2013 Vitor Fernandes , adapted for UNIMARC by George Veranis
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use Koha::Util::FrameworkPlugin qw(wrapper);
23 use C4::Auth qw( get_template_and_user );
24 use CGI qw ( -utf8 );
25 use C4::Context;
26 use C4::Output qw( output_html_with_http_headers );
27
28
29 sub plugin_javascript {
30     my ( $dbh, $record, $tagslib, $field_number ) = @_;
31     my $res           = "
32         <script type='text/javascript'>
33             function Clic$field_number(event) {
34                 event.preventDefault();
35                 var defaultvalue;
36                 try {
37                     defaultvalue = document.getElementById(event.data.id).value;
38                 } catch(e) {
39                     alert('error when getting '+event.data.id);
40                     return;
41                 }
42                 window.open(\"/cgi-bin/koha/cataloguing/plugin_launcher.pl?plugin_name=unimarc_leader_authorities.pl&index=\" + event.data.id + \"&result=\"+defaultvalue,\"unimarc_field_000\",'width=1000,height=600,toolbar=false,scrollbars=yes');
43             }
44         </script>
45 ";
46
47     return ( $field_number, $res );
48 }
49
50
51 sub plugin {
52     my ($input) = @_;
53     my $index  = $input->param('index');
54     my $result = $input->param('result');
55
56     my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
57         {
58             template_name => "cataloguing/value_builder/unimarc_leader_authorities.tt",
59             query         => $input,
60             type          => "intranet",
61             flagsrequired   => { editcatalogue => '*' },
62         }
63     );
64     $result = "     nz  a22     3  4500" unless $result;
65
66     my $f5  = substr( $result, 5, 1 ); $f5   = wrapper( $f5 ) if $f5;
67     my $f6  = substr( $result, 6, 1 ); $f6   = wrapper( $f6 ) if $f6;
68     my $f9  = substr( $result, 9, 1 ); $f9   = wrapper( $f9 ) if $f9;
69     my $f17 = substr( $result, 17, 1 ); $f17 = wrapper( $f17 ) if $f17;
70
71     $template->param(
72         index     => $index,
73         "f5$f5"   => 1,
74         "f6$f6"   => 1,
75         "f9$f9"   => 1,
76         "f17$f17" => 1,
77 );
78     output_html_with_http_headers $input, $cookie, $template->output;
79 }