fixed variable masking warnings found by perl -w
[koha.git] / cataloguing / value_builder / unimarc_field_210c.pl
blob64c243fa50e45888458e1baef928180b2f029dcf
1 #!/usr/bin/perl
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
21 require Exporter;
22 use C4::AuthoritiesMarc;
23 use C4::Auth;
24 use C4::Context;
25 use C4::Output;
26 use CGI;
27 use C4::Search;
28 use MARC::Record;
29 use C4::Koha;
31 ###TODO To rewrite in order to use SearchAuthorities
33 =head1
35 plugin_parameters : other parameters added when the plugin is called by the dopop function
37 =cut
38 sub plugin_parameters {
39 my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
40 return "";
43 =head1
45 plugin_javascript : the javascript function called when the user enters the subfield.
46 contain 3 javascript functions :
47 * one called when the field is entered (OnFocus). Named FocusXXX
48 * one called when the field is leaved (onBlur). Named BlurXXX
49 * one called when the ... link is clicked (<a href="javascript:function">) named ClicXXX
51 returns :
52 * XXX
53 * a variable containing the 3 scripts.
54 the 3 scripts are inserted after the <input> in the html code
56 =cut
57 sub plugin_javascript {
58 my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
59 my $function_name= $field_number;
60 #---- build editors list.
61 #---- the editor list is built from the "EDITORS" thesaurus
62 #---- this thesaurus category must be filled as follow :
63 #---- 200$a for isbn
64 #---- 200$b for editor
65 #---- 200$c (repeated) for collections
66 my $sth
67 = $dbh->prepare("select auth_subfield_table.authid,subfieldvalue from auth_subfield_table
68 left join auth_header on auth_subfield_table.authid=auth_header.authid
69 where authtypecode='EDITORS' and tag='200' and subfieldcode='a'");
70 my $sth2
71 = $dbh->prepare("select subfieldvalue from auth_subfield_table where tag='200' and subfieldcode='b' and authid=?");
72 $sth->execute;
73 my @editors;
74 my $authoritysep = C4::Context->preference("authoritysep");
75 while (my ($authid,$isbn) = $sth->fetchrow) {
76 $sth2->execute($authid);
77 my ($editor) = $sth2->fetchrow;
78 push(@editors,"$isbn $authoritysep $editor");
80 my $res = "
81 <script type=\"text/javascript\">
82 function Focus$function_name(index) {
83 var isbn_array = [ ";
84 foreach my $editor (@editors) {
85 my @arr = split (/ $authoritysep /,$editor);
86 $res .='["'.$arr[0].'","'.$arr[1].'","'.$arr[2].'"],';
88 chop $res;
89 $res .= "
91 // search isbn subfield. it''s 010a
92 var isbn_found;
93 var nb_fields = document.f.field_value.length;
94 for (i=0 ; i< nb_fields; i++) {
95 if (document.f.tag[i].value == '010' && document.f.subfield[i].value == 'a') {
96 isbn_found=document.f.field_value[i].value;
97 break;
100 try{
101 isbn_found.getAttribute('value'); // throw an exception if doesn't (if no 010a)
103 catch(e){
104 return;
106 for (i=0;i<=isbn_array.length;i++) {
107 if (isbn_found.substr(0,isbn_array[i][0].length) == isbn_array[i][0]) {
108 document.f.field_value[index].value =isbn_array[i][1];
113 function Blur$function_name(subfield_managed) {
114 return 1;
117 function Clic$function_name(subfield_managed) {
118 defaultvalue=escape(document.getElementById(\"$field_number\").value);
119 newin=window.open(\"../cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_210c.pl&index=\"+subfield_managed,\"unimarc 225a\",'width=500,height=600,toolbar=false,scrollbars=yes');
121 </script>
123 return ($function_name,$res);
126 =head1
128 plugin : the true value_builded. The screen that is open in the popup window.
130 =cut
132 sub plugin {
133 my ($input) = @_;
134 my $query=new CGI;
135 my $op = $query->param('op');
136 my $authtypecode = $query->param('authtypecode');
137 my $index = $query->param('index');
138 my $category = $query->param('category');
139 my $resultstring = $query->param('result');
140 my $dbh = C4::Context->dbh;
142 my $startfrom=$query->param('startfrom');
143 $startfrom=0 if(!defined $startfrom);
144 my ($template, $loggedinuser, $cookie);
145 my $resultsperpage;
147 my $authtypes = getauthtypes;
148 my @authtypesloop;
149 foreach my $thisauthtype (keys %$authtypes) {
150 my $selected = 1 if $thisauthtype eq $authtypecode;
151 my %row =(value => $thisauthtype,
152 selected => $selected,
153 authtypetext => $authtypes->{$thisauthtype}{'authtypetext'},
154 index => $index,
156 push @authtypesloop, \%row;
159 if ($op eq "do_search") {
160 my @marclist = $query->param('marclist');
161 my @and_or = $query->param('and_or');
162 my @excluding = $query->param('excluding');
163 my @operator = $query->param('operator');
164 my @value = $query->param('value');
166 $resultsperpage= $query->param('resultsperpage');
167 $resultsperpage = 19 if(!defined $resultsperpage);
169 # builds tag and subfield arrays
170 my @tags;
172 my ($results,$total) = SearchAuthorities( \@tags,\@and_or,
173 \@excluding, \@operator, \@value,
174 $startfrom*$resultsperpage, $resultsperpage,$authtypecode);# $orderby);
176 ($template, $loggedinuser, $cookie)
177 = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tmpl",
178 query => $query,
179 type => 'intranet',
180 authnotrequired => 0,
181 flagsrequired => {editcatalogue => 1},
182 debug => 1,
185 # multi page display gestion
186 my $displaynext=0;
187 my $displayprev=$startfrom;
188 if(($total - (($startfrom+1)*($resultsperpage))) > 0 ) {
189 $displaynext = 1;
192 my @numbers = ();
194 if ($total>$resultsperpage) {
195 for (my $i=1; $i<$total/$resultsperpage+1; $i++) {
196 if ($i<16) {
197 my $highlight=0;
198 ($startfrom==($i-1)) && ($highlight=1);
199 push @numbers, { number => $i,
200 highlight => $highlight ,
201 startfrom => ($i-1)};
206 my $from = $startfrom*$resultsperpage+1;
207 my $to;
209 if($total < (($startfrom+1)*$resultsperpage)) {
210 $to = $total;
211 } else {
212 $to = (($startfrom+1)*$resultsperpage);
214 my $link="../cataloguing/plugin_launcher.pl?plugin_name=unimarc_field_210c.pl&amp;authtypecode=EDITORS&and_or=and&operator=contains&".join("&",map {"value=".$_} @value)."&op=do_search&type=intranet&index=$index";
215 warn "$link ,".getnbpages($total, $resultsperpage);
216 $template->param(result => $results) if $results;
217 $template->param('index' => $query->param('index'));
218 $template->param(startfrom=> $startfrom,
219 displaynext=> $displaynext,
220 displayprev=> $displayprev,
221 resultsperpage => $resultsperpage,
222 startfromnext => $startfrom+1,
223 startfromprev => $startfrom-1,
224 total=>$total,
225 from=>$from,
226 to=>$to,
227 numbers=>\@numbers,
228 authtypecode =>$authtypecode,
229 resultstring =>$value[0],
230 pagination_bar => pagination_bar(
231 $link,
232 getnbpages($total, $resultsperpage),
233 $startfrom,
234 'startfrom'
237 } else {
238 ($template, $loggedinuser, $cookie)
239 = get_template_and_user({template_name => "cataloguing/value_builder/unimarc_field_210c.tmpl",
240 query => $query,
241 type => 'intranet',
242 authnotrequired => 0,
243 flagsrequired => {editcatalogue => 1},
244 debug => 1,
247 $template->param(index => $index,
248 resultstring => $resultstring
252 $template->param(authtypesloop => \@authtypesloop);
253 $template->param(category => $category);
255 # Print the page
256 output_html_with_http_headers $query, $cookie, $template->output;