Bug 25548: Remove Apache rewrite directives that trigger redirects
[koha.git] / cataloguing / value_builder / marc21_field_008_authorities.pl
blob1047faca475fd9131bd8cb5f307deb26b5d66c96
1 #!/usr/bin/perl
3 # Converted to new plugin style (Bug 13437)
5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use Modern::Perl;
23 use C4::Auth;
24 use CGI qw ( -utf8 );
25 use C4::Context;
27 use C4::Search;
28 use C4::Output;
29 use Koha::Util::FrameworkPlugin qw|date_entered|;
31 use constant FIXLEN_DATA_ELTS => '|| aca||aabn | a|a d';
32 use constant PREF_008 => 'MARCAuthorityControlField008';
34 my $builder = sub {
35 my ( $params ) = @_;
36 my $function_name = $params->{id};
37 my $dateentered = date_entered();
38 my $defaultval = substr( C4::Context->preference(PREF_008) || FIXLEN_DATA_ELTS, 0, 34 );
39 my $res="
40 <script>
42 function Focus$function_name(event) {
43 if (!document.getElementById(event.data.id).value) {
44 var authtype=document.forms['f'].elements['authtypecode'].value;
45 var fieldval='$dateentered$defaultval';
46 if(authtype && (authtype == 'TOPIC_TERM' || authtype == 'GENRE/FORM' || authtype == 'CHRON_TERM')) {
47 fieldval= fieldval.substr(0,14)+'b'+fieldval.substr(15);
49 document.getElementById(event.data.id).value=fieldval;
51 return 1;
54 function Click$function_name(event) {
55 var authtype=document.forms['f'].elements['authtypecode'].value;
56 defaultvalue=document.getElementById(event.data.id).value;
57 newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=marc21_field_008_authorities.pl&index=\"+ event.data.id +\"&result=\"+defaultvalue+\"&authtypecode=\"+authtype,\"tag_editor\",'width=1000,height=600,toolbar=false,scrollbars=yes');
60 </script>
63 return $res;
66 my $launcher = sub {
67 my ( $params ) = @_;
68 my $input = $params->{cgi};
69 my $index= $input->param('index');
70 my $result= $input->param('result');
71 my $authtype= $input->param('authtypecode')||'';
73 my $defaultval = substr( C4::Context->preference(PREF_008) || FIXLEN_DATA_ELTS, 0, 34 );
74 substr($defaultval,14-6,1)='b' if $authtype=~ /TOPIC_TERM|GENRE.FORM|CHRON_TERM/;
76 my $dbh = C4::Context->dbh;
78 my ($template, $loggedinuser, $cookie)
79 = get_template_and_user({template_name => "cataloguing/value_builder/marc21_field_008_authorities.tt",
80 query => $input,
81 type => "intranet",
82 flagsrequired => {editcatalogue => '*'},
83 debug => 1,
84 });
85 my $dateentered = date_entered();
86 $result = "$dateentered$defaultval" unless $result;
87 my @f;
88 for(0,6..17,28,29,31..33,38,39) {
89 $f[$_]=substr($result,$_,$_==0?6:1);
91 $template->param(index => $index);
93 $f[0]= $dateentered if !$f[0] || $f[0]=~/\s/;
94 $template->param(f1 => $f[0]);
96 for(6..17,28,29,31..33,38,39) {
97 $template->param(
98 "f$_" => $f[$_],
99 "f$_".($f[$_] eq '|'? 'pipe': $f[$_]) => $f[$_],
102 output_html_with_http_headers $input, $cookie, $template->output;
105 return { builder => $builder, launcher => $launcher };