Bug 17117: Patron personal details not displayed unless branch update request is...
[koha.git] / cataloguing / value_builder / marc21_field_008_authorities.pl
1 #!/usr/bin/perl
2
3 # Converted to new plugin style (Bug 13437)
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
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.
13 #
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.
18 #
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>.
21
22 use Modern::Perl;
23 use C4::Auth;
24 use CGI qw ( -utf8 );
25 use C4::Context;
26
27 use C4::Search;
28 use C4::Output;
29 use Koha::Util::FrameworkPlugin qw|date_entered|;
30
31 use constant FIXLEN_DATA_ELTS => '|| aca||aabn           | a|a     d';
32 use constant PREF_008 => 'MARCAuthorityControlField008';
33
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 type=\"text/javascript\">
41 //<![CDATA[
42
43 function Focus$function_name(event) {
44     if (!document.getElementById(event.data.id).value) {
45     var authtype=document.forms['f'].elements['authtypecode'].value;
46     var fieldval='$dateentered$defaultval';
47     if(authtype && (authtype == 'TOPIC_TERM' || authtype == 'GENRE/FORM' || authtype == 'CHRON_TERM')) {
48       fieldval= fieldval.substr(0,14)+'b'+fieldval.substr(15);
49     }
50         document.getElementById(event.data.id).value=fieldval;
51     }
52     return 1;
53 }
54
55 function Click$function_name(event) {
56     var authtype=document.forms['f'].elements['authtypecode'].value;
57     defaultvalue=document.getElementById(event.data.id).value;
58     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');
59
60 }
61 //]]>
62 </script>
63 ";
64
65     return $res;
66 };
67
68 my $launcher = sub {
69     my ( $params ) = @_;
70     my $input = $params->{cgi};
71     my $index= $input->param('index');
72     my $result= $input->param('result');
73     my $authtype= $input->param('authtypecode')||'';
74
75     my $defaultval = substr( C4::Context->preference(PREF_008) || FIXLEN_DATA_ELTS, 0, 34 );
76     substr($defaultval,14-6,1)='b' if $authtype=~ /TOPIC_TERM|GENRE.FORM|CHRON_TERM/;
77
78     my $dbh = C4::Context->dbh;
79
80     my ($template, $loggedinuser, $cookie)
81     = get_template_and_user({template_name => "cataloguing/value_builder/marc21_field_008_authorities.tt",
82                  query => $input,
83                  type => "intranet",
84                  authnotrequired => 0,
85                  flagsrequired => {editcatalogue => '*'},
86                  debug => 1,
87                  });
88     my $dateentered = date_entered();
89     $result = "$dateentered$defaultval" unless $result;
90     my @f;
91     for(0,6..17,28,29,31..33,38,39) {
92         $f[$_]=substr($result,$_,$_==0?6:1);
93     }
94     $template->param(index => $index);
95
96     $f[0]= $dateentered if !$f[0] || $f[0]=~/\s/;
97     $template->param(f1 => $f[0]);
98
99     for(6..17,28,29,31..33,38,39) {
100         $template->param(
101             "f$_" => $f[$_],
102             "f$_".($f[$_] eq '|'? 'pipe': $f[$_]) => $f[$_],
103         );
104     }
105     output_html_with_http_headers $input, $cookie, $template->output;
106 };
107
108 return { builder => $builder, launcher => $launcher };