followup - update SCO to recognize ITEMNOTSAMEBRANCH
[koha.git] / cataloguing / value_builder / marc21_field_008.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use strict;
21 #use warnings; FIXME - Bug 2505
22 use C4::Auth;
23 use CGI;
24 use C4::Context;
25
26 use C4::Search;
27 use C4::Output;
28
29 =head1
30
31 plugin_parameters : other parameters added when the plugin is called by the dopop function
32
33 =cut
34
35 # find today's date
36 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time);
37
38 $year += 1900;
39 $mon  += 1;
40 my $dateentered = substr($year, 2, 2) . sprintf("%0.2d", $mon) . sprintf("%0.2d", $mday);
41
42 sub plugin_parameters {
43     my ($dbh, $record, $tagslib, $i, $tabloop) = @_;
44     return "";
45 }
46
47 sub plugin_javascript {
48     my ($dbh, $record, $tagslib, $field_number, $tabloop) = @_;
49     my $function_name = $field_number;
50     my $res           = "
51 <script type=\"text/javascript\">
52 //<![CDATA[
53
54 function Focus$function_name(subfield_managed) {
55
56         if ( document.getElementById(\"$field_number\").value ) {
57         }
58         else {
59                 document.getElementById(\"$field_number\").value='$dateentered' + 't        xxu||||| |||| 00| 0 eng d';
60         }
61     return 1;
62 }
63
64 function Blur$function_name(subfield_managed) {
65         return 1;
66 }
67
68 function Clic$function_name(i) {
69         defaultvalue=document.getElementById(\"$field_number\").value;
70         newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=marc21_field_008.pl&index=$field_number&result=\"+defaultvalue,\"unimarc field 100\",'width=1000,height=600,toolbar=false,scrollbars=yes');
71
72 }
73 //]]>
74 </script>
75 ";
76
77     return ($function_name, $res);
78 }
79
80 sub plugin {
81     my ($input) = @_;
82     my $index   = $input->param('index');
83     my $result  = $input->param('result');
84
85     my $dbh = C4::Context->dbh;
86
87     my ($template, $loggedinuser, $cookie) = get_template_and_user(
88         {   template_name   => "cataloguing/value_builder/marc21_field_008.tmpl",
89             query           => $input,
90             type            => "intranet",
91             authnotrequired => 0,
92             flagsrequired   => { editcatalogue => '*' },
93             debug           => 1,
94         }
95     );
96
97     #   $result = "      t        xxu           00  0 eng d" unless $result;
98     $result = "$dateentered" . "t        xxu||||| |||| 00| 0 eng d" unless $result;
99     my $f1    = substr($result, 0,  6);
100     my $f6    = substr($result, 6,  1);
101     my $f710  = substr($result, 7,  4);
102     my $f1114 = substr($result, 11, 4);
103     my $f1517 = substr($result, 15, 3);
104     my $f1821 = substr($result, 18, 4);
105     my $f22   = substr($result, 22, 1);
106     my $f23   = substr($result, 23, 1);
107     my $f2427 = substr($result, 24, 4);
108     my $f28   = substr($result, 28, 1);
109     my $f29   = substr($result, 29, 1);
110     my $f30   = substr($result, 30, 1);
111     my $f31   = substr($result, 31, 1);
112     my $f33   = substr($result, 33, 1);
113     my $f34   = substr($result, 34, 1);
114     my $f3537 = substr($result, 35, 3);
115     my $f38   = substr($result, 38, 1);
116     my $f39   = substr($result, 39, 1);
117
118     # bug 2563
119     $f710  = "" if ($f710  =~ /^\s*$/);
120     $f1114 = "" if ($f1114 =~ /^\s*$/);
121
122     if ((!$f1) || ($f1 =~ m/ /)) {
123         $f1 = $dateentered;
124     }
125
126     $template->param(
127         index       => $index,
128         f1          => $f1,
129         f6          => $f6,
130         "f6$f6"     => $f6,
131         f710        => $f710,
132         f1114       => $f1114,
133         f1517       => $f1517,
134         f1821       => $f1821,
135         f22         => $f22,
136         "f22$f22"   => $f22,
137         f23         => $f23,
138         "f23$f23"   => $f23,
139         f2427       => $f2427,
140         "f24$f2427" => $f2427,
141         f28         => $f28,
142         "f28$f28"   => $f28,
143         f29         => $f29,
144         "f29$f29"   => $f29,
145         f30         => $f30,
146         "f30$f30"   => $f30,
147         f31         => $f31,
148         "f31$f31"   => $f31,
149         f33         => $f33,
150         "f33$f33"   => $f33,
151         f34         => $f34,
152         "f34$f34"   => $f34,
153         f3537       => $f3537,
154         f38         => $f38,
155         "f38$f38"   => $f38,
156         f39         => $f39,
157         "f39$f39"   => $f39,
158     );
159     output_html_with_http_headers $input, $cookie, $template->output;
160 }
161
162 1;