Bug 19436: Add SRU support for authorities
[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;
20 use CGI qw ( -utf8 );
21 use C4::Context;
22
23 use C4::Search;
24 use C4::Output;
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 type=\"text/javascript\">
36 //<![CDATA[
37
38 function Focus$function_name(event) {
39     if (!document.getElementById(event.data.id).value) {
40     var authtype=document.forms['f'].elements['authtypecode'].value;
41     var fieldval='$dateentered$defaultval';
42         document.getElementById(event.data.id).value=fieldval;
43     }
44     return 1;
45 }
46
47 function Click$function_name(event) {
48     var authtype=document.forms['f'].elements['authtypecode'].value;
49     defaultvalue=document.getElementById(event.data.id).value;
50     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');
51 }
52
53 //]]>
54 </script>
55 ";
56
57     return $res;
58 };
59
60 my $launcher = sub {
61     my ( $params ) = @_;
62     my $input = $params->{cgi};
63     my $index = $input->param('index');
64     my $result = $input->param('result');
65     my $authtype = $input->param('authtypecode') || '';
66
67     my $defaultval = FIXLEN_DATA_ELTS;
68
69     my ($template, $loggedinuser, $cookie) = get_template_and_user({
70         template_name => "cataloguing/value_builder/marc21_field_008_classifications.tt",
71         query => $input,
72         type => "intranet",
73         authnotrequired => 0,
74         flagsrequired => { editcatalogue => '*' },
75         debug => 1,
76     });
77     my $dateentered = date_entered();
78     $result = "$dateentered$defaultval" unless $result;
79     my @f;
80     for (0,6..13) {
81         $f[$_]=substr($result,$_,$_==0?6:1);
82     }
83     $template->param(index => $index);
84
85     $f[0] = $dateentered if !$f[0] || $f[0]=~/\s/;
86     $template->param(f1 => $f[0]);
87
88     for (6..13) {
89         $template->param(
90             "f$_" => $f[$_],
91             "f$_".($f[$_] eq '|'? 'pipe': $f[$_]) => $f[$_],
92         );
93     }
94     output_html_with_http_headers $input, $cookie, $template->output;
95 };
96
97 return { builder => $builder, launcher => $launcher };