Bug 24083: (follow-up) Include SelfCheckInModule
[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
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             debug           => 1,
82         }
83     );
84
85     #   $result = "      t        xxu           00  0 eng d" unless $result;
86     $result = "$dateentered" . "t        no ||||| |||| 00| 0 $lang d" unless $result;
87     my $f1    = substr($result, 0,  6);
88     my $f6    = substr($result, 6,  1);
89     my $f710  = substr($result, 7,  4);
90     my $f1114 = substr($result, 11, 4);
91     my $f1517 = substr($result, 15, 3);
92     my $f18   = substr($result, 18, 1);
93     my $f19   = substr($result, 19, 1);
94     my $f20   = substr($result, 20, 1);
95     my $f21   = substr($result, 21, 1);
96     my $f22   = substr($result, 22, 1);
97     my $f23   = substr($result, 23, 1);
98     my $f24   = substr($result, 24, 1);
99     my $f25   = substr($result, 25, 1);
100     my $f26   = substr($result, 26, 1);
101     my $f27   = substr($result, 27, 1);
102     my $f28   = substr($result, 28, 1);
103     my $f29   = substr($result, 29, 1);
104     my $f30   = substr($result, 30, 1);
105     my $f31   = substr($result, 31, 1);
106     my $f32   = substr($result, 32, 1);
107     my $f33   = substr($result, 33, 1);
108     my $f34   = substr($result, 34, 1);
109     my $f3537 = substr($result, 35, 3);
110     my $f38   = substr($result, 38, 1);
111     my $f39   = substr($result, 39, 1);
112
113     # bug 2563
114     $f710  = "" if ($f710  =~ /^\s*$/);
115     $f1114 = "" if ($f1114 =~ /^\s*$/);
116
117     if ((!$f1) || ($f1 =~ m/ /)) {
118         $f1 = $dateentered;
119     }
120
121     $template->param(
122         index       => $index,
123         f1          => $f1,
124         f6          => $f6,
125         "f6$f6"     => $f6,
126         f710        => $f710,
127         f1114       => $f1114,
128         f1517       => $f1517,
129         f18         => $f18,
130         "f18$f18"   => $f18,
131         f19         => $f19,
132         "f19$f19"   => $f19,
133         f20         => $f20,
134         "f20$f20"   => $f20,
135         f21         => $f21,
136         "f21$f21"   => $f21,
137         f22         => $f22,
138         "f22$f22"   => $f22,
139         f23         => $f23,
140         "f23$f23"   => $f23,
141         f24         => $f24,
142         "f24$f24"   => $f24,
143         f25         => $f25,
144         "f25$f25"   => $f25,
145         f26         => $f26,
146         "f26$f26"   => $f26,
147         f27         => $f27,
148         "f27$f27"   => $f27,
149         f28         => $f28,
150         "f28$f28"   => $f28,
151         f29         => $f29,
152         "f29$f29"   => $f29,
153         f30         => $f30,
154         "f30$f30"   => $f30,
155         f31         => $f31,
156         "f31$f31"   => $f31,
157         f32         => $f32,
158         "f32$f32"   => $f32,
159         f33         => $f33,
160         "f33$f33"   => $f33,
161         f34         => $f34,
162         "f34$f34"   => $f34,
163         f3537       => $f3537,
164         f38         => $f38,
165         "f38$f38"   => $f38,
166         f39         => $f39,
167         "f39$f39"   => $f39,
168     );
169     output_html_with_http_headers $input, $cookie, $template->output;
170 }