de487bd7432f883160c7cf5977aa80052f446d93
[srvgit] / 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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21 use C4::Auth;
22 use CGI qw ( -utf8 );
23 use C4::Context;
24
25 use C4::Search;
26 use C4::Output;
27
28 # find today's date
29 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
30
31 $year += 1900;
32 $mon  += 1;
33 my $dateentered = substr($year, 2, 2) . sprintf("%0.2d", $mon) . sprintf("%0.2d", $mday);
34
35 sub plugin_javascript {
36     my $lang = C4::Context->preference('DefaultLanguageField008' );
37     $lang = "eng" unless $lang;
38     $lang = pack("A3", $lang);
39     my ($dbh, $record, $tagslib, $field_number, $tabloop) = @_;
40     my $function_name = $field_number;
41     my $res           = "
42 <script>
43
44 function Focus$function_name(subfield_managed) {
45
46         if ( document.getElementById(\"$field_number\").value ) {
47         }
48         else {
49         document.getElementById(\"$field_number\").value='$dateentered' + 't        no ||||| |||| 00| 0 $lang d';
50         }
51     return 1;
52 }
53
54 function Clic$function_name(i) {
55         defaultvalue=document.getElementById(\"$field_number\").value;
56         defaultvalue=defaultvalue.replace(/ /g, \"+\");
57         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');
58
59 }
60 </script>
61 ";
62
63     return ($function_name, $res);
64 }
65
66 sub plugin {
67     my $lang = C4::Context->preference('DefaultLanguageField008' );
68     $lang = "eng" unless $lang;
69     $lang = pack("A3", $lang);
70     my ($input) = @_;
71     my $index   = $input->param('index');
72     my $result  = $input->param('result');
73
74     my $dbh = C4::Context->dbh;
75
76     my ($template, $loggedinuser, $cookie) = get_template_and_user(
77         {   template_name   => "cataloguing/value_builder/normarc_field_008.tt",
78             query           => $input,
79             type            => "intranet",
80             flagsrequired   => { editcatalogue => 1 },
81         }
82     );
83
84     #   $result = "      t        xxu           00  0 eng d" unless $result;
85     $result = "$dateentered" . "t        no ||||| |||| 00| 0 $lang d" unless $result;
86     my $f1    = substr($result, 0,  6);
87     my $f6    = substr($result, 6,  1);
88     my $f710  = substr($result, 7,  4);
89     my $f1114 = substr($result, 11, 4);
90     my $f1517 = substr($result, 15, 3);
91     my $f18   = substr($result, 18, 1);
92     my $f19   = substr($result, 19, 1);
93     my $f20   = substr($result, 20, 1);
94     my $f21   = substr($result, 21, 1);
95     my $f22   = substr($result, 22, 1);
96     my $f23   = substr($result, 23, 1);
97     my $f24   = substr($result, 24, 1);
98     my $f25   = substr($result, 25, 1);
99     my $f26   = substr($result, 26, 1);
100     my $f27   = substr($result, 27, 1);
101     my $f28   = substr($result, 28, 1);
102     my $f29   = substr($result, 29, 1);
103     my $f30   = substr($result, 30, 1);
104     my $f31   = substr($result, 31, 1);
105     my $f32   = substr($result, 32, 1);
106     my $f33   = substr($result, 33, 1);
107     my $f34   = substr($result, 34, 1);
108     my $f3537 = substr($result, 35, 3);
109     my $f38   = substr($result, 38, 1);
110     my $f39   = substr($result, 39, 1);
111
112     # bug 2563
113     $f710  = "" if ($f710  =~ /^\s*$/);
114     $f1114 = "" if ($f1114 =~ /^\s*$/);
115
116     if ((!$f1) || ($f1 =~ m/ /)) {
117         $f1 = $dateentered;
118     }
119
120     $template->param(
121         index       => $index,
122         f1          => $f1,
123         f6          => $f6,
124         "f6$f6"     => $f6,
125         f710        => $f710,
126         f1114       => $f1114,
127         f1517       => $f1517,
128         f18         => $f18,
129         "f18$f18"   => $f18,
130         f19         => $f19,
131         "f19$f19"   => $f19,
132         f20         => $f20,
133         "f20$f20"   => $f20,
134         f21         => $f21,
135         "f21$f21"   => $f21,
136         f22         => $f22,
137         "f22$f22"   => $f22,
138         f23         => $f23,
139         "f23$f23"   => $f23,
140         f24         => $f24,
141         "f24$f24"   => $f24,
142         f25         => $f25,
143         "f25$f25"   => $f25,
144         f26         => $f26,
145         "f26$f26"   => $f26,
146         f27         => $f27,
147         "f27$f27"   => $f27,
148         f28         => $f28,
149         "f28$f28"   => $f28,
150         f29         => $f29,
151         "f29$f29"   => $f29,
152         f30         => $f30,
153         "f30$f30"   => $f30,
154         f31         => $f31,
155         "f31$f31"   => $f31,
156         f32         => $f32,
157         "f32$f32"   => $f32,
158         f33         => $f33,
159         "f33$f33"   => $f33,
160         f34         => $f34,
161         "f34$f34"   => $f34,
162         f3537       => $f3537,
163         f38         => $f38,
164         "f38$f38"   => $f38,
165         f39         => $f39,
166         "f39$f39"   => $f39,
167     );
168     output_html_with_http_headers $input, $cookie, $template->output;
169 }