style sheet to hide styles from Netscape 4.7
[koha.git] / value_builder / unimarc_field_210c.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use C4::Auth;
24 use CGI;
25 use C4::Context;
26 use HTML::Template;
27 use C4::Search;
28 use C4::Output;
29
30 =head1
31
32 plugin_parameters : other parameters added when the plugin is called by the dopop function
33
34 =cut
35 sub plugin_parameters {
36 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
37 return "";
38 }
39
40 =head1
41
42 plugin_javascript : the javascript function called when the user enters the subfield.
43 contain 3 javascript functions :
44 * one called when the field is entered (OnFocus). Named FocusXXX
45 * one called when the field is leaved (onBlur). Named BlurXXX
46 * one called when the ... link is clicked (<a href="javascript:function">) named ClicXXX
47
48 returns :
49 * XXX
50 * a variable containing the 3 scripts.
51 the 3 scripts are inserted after the <input> in the html code
52
53 =cut
54 sub plugin_javascript {
55 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
56 my $function_name= "210c".(int(rand(100000))+1);
57 #---- build editors list.
58 #---- the editor list is built from the "EDITORS" thesaurus
59 #---- this thesaurus category must be filled as follow :
60 #---- isbn_identifier authorityseparator editor authorityseparator collection
61 #---- sample : 2224 -- Cerf -- Sources chrétiennes
62 my $sth = $dbh->prepare("select father,stdlib from bibliothesaurus where category='EDITORS' and level=2");
63 $sth->execute;
64 my @editors;
65 my $authoritysep = C4::Context->preference("authoritysep");
66 while (my ($father,$stdlib) = $sth->fetchrow) {
67         push(@editors,"$father $stdlib");
68 }
69 my $res  = "
70 <script>
71 function Focus$function_name(index) {
72 var isbn_array = [";
73 foreach my $editor (@editors) {
74         my @arr = split (/ $authoritysep /,$editor);
75         $res .='["'.$arr[0].'","'.$arr[1].'","'.$arr[2].'"],';
76 }
77 chop $res;
78 $res .= "
79 ];
80         // search isbn subfield. it's 010a
81         var isbn_found;
82         for (i=0 ; i<document.f.field_value.length ; i++) {
83                 if (document.f.tag[i].value == '010' && document.f.subfield[i].value == 'a') {
84                         isbn_found=document.f.field_value[i].value;
85                 }
86         }
87         for (i=0;i<=isbn_array.length;i++) {
88                 if (isbn_found.substr(0,isbn_array[i][0].length) == isbn_array[i][0]) {
89                         document.f.field_value[index].value =isbn_array[i][1];
90                 }
91         }
92 }
93
94 function Blur$function_name(subfield_managed) {
95         return 1;
96 }
97
98 function Clic$function_name(subfield_managed) {
99         defaultvalue=escape(document.forms[0].field_value[subfield_managed].value);
100         newin=window.open(\"../plugin_launcher.pl?plugin_name=unimarc_field_210c.pl&result=\"+defaultvalue+\"&index=$field_number\",\"value builder\",'width=500,height=400,toolbar=false,scrollbars=yes');
101
102 }
103 </script>
104 ";
105 return ($function_name,$res);
106 }
107
108 =head1
109
110 plugin : the true value_builded. The screen that is open in the popup window.
111
112 =cut
113
114 sub plugin {
115 my ($input) = @_;
116         my $index = $input->param("index");
117         my $result = $input->param("result");
118         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus_popup.pl?category=EDITORS&index=$index&result=$result\"></html>";
119         exit;
120 }
121
122 1;