Bug 25030: (QA follow-up) Add POD
[koha.git] / cataloguing / value_builder / marc21_field_008_classifications.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 C4::Auth qw( get_template_and_user );
20 use CGI qw ( -utf8 );
21 use C4::Context;
22
23 use C4::Search;
24 use C4::Output qw( output_html_with_http_headers );
25 use Koha::Util::FrameworkPlugin qw|date_entered|;
26
27 use constant FIXLEN_DATA_ELTS => 'baaaaaaa';
28
29 my $builder = sub {
30     my ( $params ) = @_;
31     my $function_name = $params->{id};
32     my $dateentered = date_entered();
33     my $defaultval = FIXLEN_DATA_ELTS;
34     my $res="
35 <script>
36
37 function Focus$function_name(event) {
38     if (!document.getElementById(event.data.id).value) {
39     var authtype=document.forms['f'].elements['authtypecode'].value;
40     var fieldval='$dateentered$defaultval';
41         document.getElementById(event.data.id).value=fieldval;
42     }
43     return 1;
44 }
45
46 function Click$function_name(event) {
47     var authtype=document.forms['f'].elements['authtypecode'].value;
48     defaultvalue=document.getElementById(event.data.id).value;
49     newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=marc21_field_008_classifications.pl&index=\"+ event.data.id +\"&result=\"+defaultvalue+\"&authtypecode=\"+authtype,\"tag_editor\",'width=1000,height=600,toolbar=false,scrollbars=yes');
50 }
51
52 </script>
53 ";
54
55     return $res;
56 };
57
58 my $launcher = sub {
59     my ( $params ) = @_;
60     my $input = $params->{cgi};
61     my $index = $input->param('index');
62     my $result = $input->param('result');
63     my $authtype = $input->param('authtypecode') || '';
64
65     my $defaultval = FIXLEN_DATA_ELTS;
66
67     my ($template, $loggedinuser, $cookie) = get_template_and_user({
68         template_name => "cataloguing/value_builder/marc21_field_008_classifications.tt",
69         query => $input,
70         type => "intranet",
71         flagsrequired => { editcatalogue => '*' },
72     });
73     my $dateentered = date_entered();
74     $result = "$dateentered$defaultval" unless $result;
75     my @f;
76     for (0,6..13) {
77         $f[$_]=substr($result,$_,$_==0?6:1);
78     }
79     $template->param(index => $index);
80
81     $f[0] = $dateentered if !$f[0] || $f[0]=~/\s/;
82     $template->param(f1 => $f[0]);
83
84     for (6..13) {
85         $template->param(
86             "f$_" => $f[$_],
87             "f$_".($f[$_] eq '|'? 'pipe': $f[$_]) => $f[$_],
88         );
89     }
90     output_html_with_http_headers $input, $cookie, $template->output;
91 };
92
93 return { builder => $builder, launcher => $launcher };