Bug 11944: use CGI( -utf8 ) everywhere
[koha.git] / cataloguing / value_builder / normarc_field_008.pl
1 #!/usr/bin/perl
2
3 # Copyright 2009 Magnus Enger Libriotech
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 use C4::Auth;
22 use CGI qw ( -utf8 );
23 use C4::Context;
24
25 use C4::Search;
26 use C4::Output;
27
28 =head1 FUNCTIONS
29
30 =head2 plugin_parameters
31
32 Other parameters added when the plugin is called by the dopop function
33
34 =cut
35
36 # find today's date
37 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
38
39 $year += 1900;
40 $mon  += 1;
41 my $dateentered = substr($year, 2, 2) . sprintf("%0.2d", $mon) . sprintf("%0.2d", $mday);
42
43 sub plugin_parameters {
44     my ($dbh, $record, $tagslib, $i, $tabloop) = @_;
45     return "";
46 }
47
48 sub plugin_javascript {
49     my $lang = C4::Context->preference('DefaultLanguageField008' );
50     $lang = "eng" unless $lang;
51     $lang = pack("A3", $lang);
52     my ($dbh, $record, $tagslib, $field_number, $tabloop) = @_;
53     my $function_name = $field_number;
54     my $res           = "
55 <script type=\"text/javascript\">
56 //<![CDATA[
57
58 function Focus$function_name(subfield_managed) {
59
60         if ( document.getElementById(\"$field_number\").value ) {
61         }
62         else {
63         document.getElementById(\"$field_number\").value='$dateentered' + 't        no ||||| |||| 00| 0 $lang d';
64         }
65     return 1;
66 }
67
68 function Blur$function_name(subfield_managed) {
69         return 1;
70 }
71
72 function Clic$function_name(i) {
73         defaultvalue=document.getElementById(\"$field_number\").value;
74         defaultvalue=defaultvalue.replace(/ /g, \"+\");
75         newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=normarc_field_008.pl&index=$field_number&result=\"+defaultvalue,\"unimarc field 100\",'width=1000,height=600,toolbar=false,scrollbars=yes');
76
77 }
78 //]]>
79 </script>
80 ";
81
82     return ($function_name, $res);
83 }
84
85 sub plugin {
86     my $lang = C4::Context->preference('DefaultLanguageField008' );
87     $lang = "eng" unless $lang;
88     $lang = pack("A3", $lang);
89     my ($input) = @_;
90     my $index   = $input->param('index');
91     my $result  = $input->param('result');
92
93     my $dbh = C4::Context->dbh;
94
95     my ($template, $loggedinuser, $cookie) = get_template_and_user(
96         {   template_name   => "cataloguing/value_builder/normarc_field_008.tt",
97             query           => $input,
98             type            => "intranet",
99             authnotrequired => 0,
100             flagsrequired   => { editcatalogue => 1 },
101             debug           => 1,
102         }
103     );
104
105     #   $result = "      t        xxu           00  0 eng d" unless $result;
106     $result = "$dateentered" . "t        no ||||| |||| 00| 0 $lang d" unless $result;
107     my $f1    = substr($result, 0,  6);
108     my $f6    = substr($result, 6,  1);
109     my $f710  = substr($result, 7,  4);
110     my $f1114 = substr($result, 11, 4);
111     my $f1517 = substr($result, 15, 3);
112     my $f18   = substr($result, 18, 1);
113     my $f19   = substr($result, 19, 1);
114     my $f20   = substr($result, 20, 1);
115     my $f21   = substr($result, 21, 1);
116     my $f22   = substr($result, 22, 1);
117     my $f23   = substr($result, 23, 1);
118     my $f24   = substr($result, 24, 1);
119     my $f25   = substr($result, 25, 1);
120     my $f26   = substr($result, 26, 1);
121     my $f27   = substr($result, 27, 1);
122     my $f28   = substr($result, 28, 1);
123     my $f29   = substr($result, 29, 1);
124     my $f30   = substr($result, 30, 1);
125     my $f31   = substr($result, 31, 1);
126     my $f32   = substr($result, 32, 1);
127     my $f33   = substr($result, 33, 1);
128     my $f34   = substr($result, 34, 1);
129     my $f3537 = substr($result, 35, 3);
130     my $f38   = substr($result, 38, 1);
131     my $f39   = substr($result, 39, 1);
132
133     # bug 2563
134     $f710  = "" if ($f710  =~ /^\s*$/);
135     $f1114 = "" if ($f1114 =~ /^\s*$/);
136
137     if ((!$f1) || ($f1 =~ m/ /)) {
138         $f1 = $dateentered;
139     }
140
141     $template->param(
142         index       => $index,
143         f1          => $f1,
144         f6          => $f6,
145         "f6$f6"     => $f6,
146         f710        => $f710,
147         f1114       => $f1114,
148         f1517       => $f1517,
149         f18         => $f18,
150         "f18$f18"   => $f18,
151         f19         => $f19,
152         "f19$f19"   => $f19,
153         f20         => $f20,
154         "f20$f20"   => $f20,
155         f21         => $f21,
156         "f21$f21"   => $f21,
157         f22         => $f22,
158         "f22$f22"   => $f22,
159         f23         => $f23,
160         "f23$f23"   => $f23,
161         f24         => $f24,
162         "f24$f24"   => $f24,
163         f25         => $f25,
164         "f25$f25"   => $f25,
165         f26         => $f26,
166         "f26$f26"   => $f26,
167         f27         => $f27,
168         "f27$f27"   => $f27,
169         f28         => $f28,
170         "f28$f28"   => $f28,
171         f29         => $f29,
172         "f29$f29"   => $f29,
173         f30         => $f30,
174         "f30$f30"   => $f30,
175         f31         => $f31,
176         "f31$f31"   => $f31,
177         f32         => $f32,
178         "f32$f32"   => $f32,
179         f33         => $f33,
180         "f33$f33"   => $f33,
181         f34         => $f34,
182         "f34$f34"   => $f34,
183         f3537       => $f3537,
184         f38         => $f38,
185         "f38$f38"   => $f38,
186         f39         => $f39,
187         "f39$f39"   => $f39,
188     );
189     output_html_with_http_headers $input, $cookie, $template->output;
190 }
191
192 1;