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
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
23 use C4::Interface::CGI::Output;
31 my ($env,$searchstring,$authtypecode)=@_;
32 my $dbh = C4::Context->dbh;
33 $searchstring=~ s/\'/\\\'/g;
34 my @data=split(' ',$searchstring);
36 my $sth=$dbh->prepare("Select * from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield");
37 $sth->execute("$searchstring%",$authtypecode);
41 while (my $data=$sth->fetchrow_hashref){
48 return ($cnt,\@results);
52 my $tagfield=$input->param('tagfield');
53 my $tagsubfield=$input->param('tagsubfield');
54 my $authtypecode=$input->param('authtypecode');
55 my $pkfield="tagfield";
56 my $offset=$input->param('offset');
57 my $script_name="/cgi-bin/koha/admin/auth_subfields_structure.pl";
59 my ($template, $borrowernumber, $cookie)
60 = get_template_and_user({template_name => "admin/auth_subfields_structure.tmpl",
64 flagsrequired => {parameters => 1},
68 my $op = $input->param('op');
72 $template->param(script_name => $script_name,
74 authtypecode => $authtypecode,
75 $op => 1); # we show only the TMPL_VAR names $op
77 $template->param(script_name => $script_name,
79 authtypecode => $authtypecode,
80 else => 1); # we show only the TMPL_VAR names $op
83 ################## ADD_FORM ##################################
84 # called by default. Used to create form to add or modify a record
85 if ($op eq 'add_form') {
87 my $dbh = C4::Context->dbh;
88 my $more_subfields = $input->param("more_subfields")+1;
89 # builds kohafield tables
92 my $sth2=$dbh->prepare("SHOW COLUMNS from auth_header");
94 while ((my $field) = $sth2->fetchrow_array) {
95 push @kohafields, "auth_header.".$field;
98 # build authorised value list
100 $sth2 = $dbh->prepare("select distinct category from authorised_values");
102 my @authorised_values;
103 push @authorised_values,"";
104 while ((my $category) = $sth2->fetchrow_array) {
105 push @authorised_values, $category;
107 push (@authorised_values,"branches");
108 push (@authorised_values,"itemtypes");
110 # build value_builder list
111 my @value_builder=('');
113 # read value_builder directory.
114 # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
115 # on a standard install, /cgi-bin need to be added.
116 # test one, then the other
117 my $cgidir = C4::Context->intranetdir ."/cgi-bin";
118 unless (opendir(DIR, "$cgidir/value_builder")) {
119 $cgidir = C4::Context->intranetdir;
120 opendir(DIR, "$cgidir/value_builder") || die "can't opendir $cgidir/value_builder: $!";
122 while (my $line = readdir(DIR)) {
123 if ($line =~ /\.pl$/) {
124 push (@value_builder,$line);
130 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
131 $sth->execute($tagfield,$authtypecode);
135 while ($data =$sth->fetchrow_hashref) {
137 my %row_data; # get a fresh hash for the row data
143 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
146 -labels => {'-1' =>'ignore','0'=>'0',
148 -default=>$data->{'tab'},
152 $row_data{ohidden} = CGI::scrolling_list(-name=>'ohidden',
154 -values=>['0','1','2'],
155 -labels => {'0'=>'Show','1'=>'Show Collapsed',
158 -default=>substr($data->{'hidden'},0,1),
162 $row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
164 -values=>['0','1','2'],
165 -labels => {'0'=>'Show','1'=>'Show Collapsed',
168 -default=>substr($data->{'hidden'},1,1),
172 $row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
174 -values=>['0','1','2'],
175 -labels => {'0'=>'Show','1'=>'Show Collapsed',
178 -default=>substr($data->{'hidden'},2,1),
182 $row_data{tagsubfield} =$data->{'tagsubfield'}."<input type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" id=\"tagsubfield\">";
183 $row_data{liblibrarian} = CGI::escapeHTML($data->{'liblibrarian'});
184 $row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
185 $row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
186 $row_data{kohafield}= CGI::scrolling_list( -name=>"kohafield",
188 -values=> \@kohafields,
189 -default=> "$data->{'kohafield'}",
193 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
194 -id=>'authorised_value',
195 -values=> \@authorised_values,
196 -default=>$data->{'authorised_value'},
200 $row_data{value_builder} = CGI::scrolling_list(-name=>'value_builder',
201 -id=>'value_builder',
202 -values=> \@value_builder,
203 -default=>$data->{'value_builder'},
208 $row_data{repeatable} = CGI::checkbox(-name=>"repeatable$i",
209 -checked => $data->{'repeatable'}?'checked':'',
212 -id => "repeatable$i");
213 $row_data{mandatory} = CGI::checkbox(-name => "mandatory$i",
214 -checked => $data->{'mandatory'}?'checked':'',
217 -id => "mandatory$i");
218 $row_data{hidden} = CGI::escapeHTML($data->{hidden}) ;
219 $row_data{isurl} = CGI::checkbox( -name => "isurl$i",
221 -checked => $data->{'isurl'}?'checked':'',
224 $row_data{link} = CGI::checkbox( -name => "link$i",
226 -checked => $data->{'link'}?'checked':'',
230 $row_data{toggle} = $toggle;
231 # $row_data{link} = CGI::escapeHTML($data->{'link'});
232 push(@loop_data, \%row_data);
235 # add more_subfields empty lines for add if needed
236 for (my $i=1;$i<=$more_subfields;$i++) {
237 my %row_data; # get a fresh hash for the row data
238 $row_data{tab} = CGI::scrolling_list(-name=>'tab',
241 -labels => {'-1' =>'ignore','0'=>'0',
247 $row_data{ohidden} = CGI::scrolling_list(-name=>'ohidden',
249 -values=>['0','1','2'],
250 -labels => {'0'=>'Show','1'=>'Show Collapsed',
258 $row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
260 -values=>['0','1','2'],
261 -labels => {'0'=>'Show','1'=>'Show Collapsed',
268 $row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
270 -values=>['0','1','2'],
271 -labels => {'0'=>'Show','1'=>'Show Collapsed',
278 $row_data{tagsubfield} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\">";
279 $row_data{liblibrarian} = "";
280 $row_data{libopac} = "";
281 $row_data{seealso} = "";
282 $row_data{hidden} = "000";
283 $row_data{repeatable} = CGI::checkbox( -name=> 'repeatable',
284 -id => "repeatable$i",
288 $row_data{mandatory} = CGI::checkbox( -name=> 'mandatory',
289 -id => "mandatory$i",
293 $row_data{isurl} = CGI::checkbox(-name => 'isurl',
298 $row_data{kohafield}= CGI::scrolling_list( -name=>'kohafield',
299 -id => "kohafield$i",
300 -values=> \@kohafields,
305 $row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
306 -id => 'authorised_value',
307 -values=> \@authorised_values,
311 $row_data{link} = CGI::checkbox( -name => "link",
316 # $row_data{link} = CGI::escapeHTML($data->{'link'});
317 $row_data{toggle} = $toggle;
319 push(@loop_data, \%row_data);
321 $template->param('use-heading-flags-p' => 1);
322 $template->param('heading-edit-subfields-p' => 1);
323 $template->param(action => "Edit subfields",
324 tagfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
326 more_subfields => $more_subfields,
327 more_tag => $tagfield);
329 # END $OP eq ADD_FORM
330 ################## ADD_VALIDATE ##################################
331 # called by add_form, used to insert/modify data in DB
332 } elsif ($op eq 'add_validate') {
333 my $dbh = C4::Context->dbh;
334 $template->param(tagfield => "$input->param('tagfield')");
335 my $sth=$dbh->prepare("replace auth_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,authtypecode,value_builder,hidden,isurl, link)
336 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
337 my @tagsubfield = $input->param('tagsubfield');
338 my @liblibrarian = $input->param('liblibrarian');
339 my @libopac = $input->param('libopac');
340 my @kohafield = $input->param('kohafield');
341 my @tab = $input->param('tab');
342 my @seealso = $input->param('seealso');
343 #my @hidden = $input->param('hidden');
345 my @ohidden = $input->param('ohidden');
346 my @ihidden = $input->param('ihidden');
347 my @ehidden = $input->param('ehidden');
348 my @authorised_values = $input->param('authorised_value');
349 # my $authtypecodes = $input->param('authtypecode');
350 my @value_builder =$input->param('value_builder');
351 my @link =$input->param('link');
352 for (my $i=0; $i<= $#tagsubfield ; $i++) {
353 my $tagfield =$input->param('tagfield');
354 my $tagsubfield =$tagsubfield[$i];
355 $tagsubfield="@" unless $tagsubfield ne '';
356 my $liblibrarian =$liblibrarian[$i];
357 my $libopac =$libopac[$i];
358 my $repeatable =$input->param("repeatable$i")?1:0;
359 my $mandatory =$input->param("mandatory$i")?1:0;
360 my $kohafield =$kohafield[$i];
362 my $seealso =$seealso[$i];
363 my $authorised_value =$authorised_values[$i];
364 # my $authtypecode =$authtypecodes;
365 my $value_builder=$value_builder[$i];
366 my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens;
367 my $isurl = $input->param("isurl$i")?1:0;
368 my $link = $input->param("link$i")?1:0;
370 unless (C4::Context->config('demo') eq 1) {
371 $sth->execute ($tagfield,
393 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
396 # END $OP eq ADD_VALIDATE
397 ################## DELETE_CONFIRM ##################################
398 # called by default form, used to confirm deletion of data in DB
399 } elsif ($op eq 'delete_confirm') {
400 my $dbh = C4::Context->dbh;
401 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
402 #FIXME : called with 2 bind variables when 3 are needed
403 $sth->execute($tagfield,$tagsubfield);
404 my $data=$sth->fetchrow_hashref;
406 $template->param(liblibrarian => $data->{'liblibrarian'},
407 tagsubfield => $data->{'tagsubfield'},
408 delete_link => $script_name,
409 tagfield =>$tagfield,
410 tagsubfield => $tagsubfield,
411 authtypecode => $authtypecode,
413 # END $OP eq DELETE_CONFIRM
414 ################## DELETE_CONFIRMED ##################################
415 # called by delete_confirm, used to effectively confirm deletion of data in DB
416 } elsif ($op eq 'delete_confirmed') {
417 my $dbh = C4::Context->dbh;
418 unless (C4::Context->config('demo') eq 1) {
419 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
420 $sth->execute($tagfield,$tagsubfield,$authtypecode);
423 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
425 $template->param(tagfield => $tagfield);
426 # END $OP eq DELETE_CONFIRMED
427 ################## DEFAULT ##################################
430 my ($count,$results)=StringSearch($env,$tagfield,$authtypecode);
433 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
439 my %row_data; # get a fresh hash for the row data
440 $row_data{tagfield} = $results->[$i]{'tagfield'};
441 $row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
442 $row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
443 $row_data{kohafield} = $results->[$i]{'kohafield'};
444 $row_data{repeatable} = $results->[$i]{'repeatable'};
445 $row_data{mandatory} = $results->[$i]{'mandatory'};
446 $row_data{tab} = $results->[$i]{'tab'};
447 $row_data{seealso} = $results->[$i]{'seealso'};
448 $row_data{authorised_value} = $results->[$i]{'authorised_value'};
449 $row_data{authtypecode} = $results->[$i]{'authtypecode'};
450 $row_data{value_builder} = $results->[$i]{'value_builder'};
451 $row_data{hidden} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
452 $row_data{isurl} = $results->[$i]{'isurl'};
453 $row_data{link} = $results->[$i]{'link'};
454 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
455 $row_data{toggle} = $toggle;
456 if ($row_data{tab} eq -1) {
457 $row_data{subfield_ignored} = 1;
460 push(@loop_data, \%row_data);
462 $template->param(loop => \@loop_data);
463 $template->param(edit_tagfield => $tagfield,
464 edit_authtypecode => $authtypecode);
467 my $prevpage = $offset-$pagesize;
468 $template->param(prev =>"<a href=\"$script_name?offset=$prevpage\">");
470 if ($offset+$pagesize<$count) {
471 my $nextpage =$offset+$pagesize;
472 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
474 } #---- END $OP eq DEFAULT
475 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
476 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
477 IntranetNav => C4::Context->preference("IntranetNav"),
479 output_html_with_http_headers $input, $cookie, $template->output;