MARC21 plugins fixed
[koha.git] / cataloguing / value_builder / marc21_field_008.pl
1
2 #!/usr/bin/perl
3
4 # $Id$
5
6 # Copyright 2000-2002 Katipo Communications
7 #
8 # This file is part of Koha.
9 #
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
13 # version.
14 #
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA  02111-1307 USA
22
23 use strict;
24 use C4::Auth;
25 use CGI;
26 use C4::Context;
27
28 use C4::Search;
29 use C4::Output;
30
31 =head1
32
33 plugin_parameters : other parameters added when the plugin is called by the dopop function
34
35 =cut
36
37 # find today's date
38 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); 
39
40 $year +=1900; $mon +=1;
41 my $dateentered = substr($year,2,2).sprintf ("%0.2d", $mon).sprintf ("%0.2d",$mday);
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     document.getElementById(\"$field_number\").value='$dateentered' + 't        xxu||||| |||| 00| 0 eng d';
56     return 1;
57 }
58
59 function Blur$function_name(subfield_managed) {
60         return 1;
61 }
62
63 function Clic$function_name(i) {
64         defaultvalue=document.getElementById(\"$field_number\").value;
65         newin=window.open(\"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');
66
67 }
68 //]]>
69 </script>
70 ";
71
72         return ($function_name,$res);
73 }
74 sub plugin {
75         my ($input) = @_;
76         my $index= $input->param('index');
77         my $result= $input->param('result');
78
79
80         my $dbh = C4::Context->dbh;
81
82         my ($template, $loggedinuser, $cookie)
83     = get_template_and_user({template_name => "cataloguing/value_builder/marc21_field_008.tmpl",
84                              query => $input,
85                              type => "intranet",
86                              authnotrequired => 0,
87                              flagsrequired => {editcatalogue => 1},
88                              debug => 1,
89                              });
90 #       $result = "      t        xxu           00  0 eng d" unless $result;
91         $result = "$dateentered"."t        xxu||||| |||| 00| 0 eng d" unless $result;
92         my $f1 = substr($result,0,6);
93         my $f6 = substr($result,6,1);
94         my $f710 = substr($result,7,4);
95         my $f1114 = substr($result,11,4);
96         my $f1517 = substr($result,15,3);
97         my $f1821 = substr($result,18,4);
98         my $f22 = substr($result,22,1);
99         my $f23 = substr($result,23,1);
100         my $f2427 = substr($result,24,4);
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 $f33 = substr($result,33,1);
106         my $f34 = substr($result,34,1);
107         my $f3537 = substr($result,35,3);
108         my $f38 = substr($result,38,1);
109         my $f39 = substr($result,39,1);
110
111 if ((!$f1) ||($f1 =~ m/ /)){
112         $f1=$dateentered;
113 }
114
115         $template->param(                               index => $index,
116                                                         f1 => $f1,
117                                                         f6 => $f6,
118                                                         "f6$f6" => $f6,
119                                                         f710 => $f710,
120                                                         f1114 => $f1114,
121                                                         f1517 => $f1517,
122                                                         f1821 => $f1821,
123                                                         f22 => $f22,
124                                                         "f22$f22" => $f22,
125                                                         f23 => $f23,
126                                                         "f23$f23" => $f23,
127                                                         f2427 => $f2427,
128                                                         "f24$f2427" => $f2427,
129                                                         f28 => $f28,
130                                                         "f28$f28" => $f28,
131                                                         f29 => $f29,
132                                                         "f29$f29" => $f29,
133                                                         f30 => $f30,
134                                                         "f230$f30" => $f30,
135                                                         f31 => $f31,
136                                                         "f31$f31" => $f31,
137                                                         f33 => $f33,
138                                                         "f33$f33" => $f33,
139                                                         f34 => $f34,
140                                                         "f34$f34" => $f34,
141                                                         f3537 => $f3537,
142                                                         f38 => $f38,
143                                                         "f38$f38" => $f38,
144                                                         f39 => $f39,
145                                                         "f39$f39" => $f39,
146                                         );
147         output_html_with_http_headers $input, $cookie, $template->output;
148 }
149
150 1;