Adding replacement price to issues loop and a totalprice variable which totals the...
[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 #---- 200$a for isbn
61 #---- 200$b for editor
62 #---- 200$c (repeated) for collections
63 my $sth = $dbh->prepare("select auth_subfield_table.authid,subfieldvalue from auth_subfield_table 
64                                                 left join auth_header on auth_subfield_table.authid=auth_header.authid 
65                                                 where authtypecode='EDITORS' and tag='200' and subfieldcode='a'");
66 my $sth2 = $dbh->prepare("select subfieldvalue from auth_subfield_table where tag='200' and subfieldcode='b' and authid=?");
67 $sth->execute;
68 my @editors;
69 my $authoritysep = C4::Context->preference("authoritysep");
70 while (my ($authid,$isbn) = $sth->fetchrow) {
71         $sth2->execute($authid);
72         my ($editor) = $sth2->fetchrow;
73         push(@editors,"$isbn $authoritysep $editor");
74 }
75 my $res  = "
76 <script>
77 function Focus$function_name(index) {
78 var isbn_array = [ ";
79 foreach my $editor (@editors) {
80         my @arr = split (/ $authoritysep /,$editor);
81         $res .='["'.$arr[0].'","'.$arr[1].'","'.$arr[2].'"],';
82 }
83 chop $res;
84 $res .= "
85 ];
86         // search isbn subfield. it''s 010a
87         var isbn_found;
88         for (i=0 ; i<document.f.field_value.length ; i++) {
89                 if (document.f.tag[i].value == '010' && document.f.subfield[i].value == 'a') {
90                         isbn_found=document.f.field_value[i].value;
91                 }
92         }
93         for (i=0;i<=isbn_array.length;i++) {
94                 if (isbn_found.substr(0,isbn_array[i][0].length) == isbn_array[i][0]) {
95                         document.f.field_value[index].value =isbn_array[i][1];
96                 }
97         }
98 }
99
100 function Blur$function_name(subfield_managed) {
101         return 1;
102 }
103
104 function Clic$function_name(subfield_managed) {
105         defaultvalue=escape(document.forms[0].field_value[subfield_managed].value);
106         newin=window.open(\"../authorities/authorities-home.pl\",\"value builder\",'width=500,height=400,toolbar=false,scrollbars=yes');
107
108 }
109 </script>
110 ";
111 return ($function_name,$res);
112 }
113
114 =head1
115
116 plugin : the true value_builded. The screen that is open in the popup window.
117
118 =cut
119
120 sub plugin {
121 my ($input) = @_;
122         my $index = $input->param("index");
123         my $result =  $input->param("result");
124         $result=~s/ /&nbsp;/g;
125         $result=~s/"/&quot;/g;
126         print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus_popup.pl?category=EDITORS&nohierarchy=1&index=$index&result=$result\"></html>";
127         exit;
128 }
129
130 1;