3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #use warnings; FIXME - Bug 2505
29 my ($searchstring,$authtypecode)=@_;
30 my $dbh = C4
::Context
->dbh;
31 $searchstring=~ s/\'/\\\'/g;
32 my @data=split(' ',$searchstring);
33 my $sth=$dbh->prepare("Select * from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield");
34 $sth->execute("$searchstring%",$authtypecode);
35 my $results = $sth->fetchall_arrayref({});
36 return (scalar(@
$results), $results);
39 sub auth_subfield_structure_exists
{
40 my ($authtypecode, $tagfield, $tagsubfield) = @_;
41 my $dbh = C4
::Context
->dbh;
42 my $sql = "select tagfield from auth_subfield_structure where authtypecode = ? and tagfield = ? and tagsubfield = ?";
43 my $rows = $dbh->selectall_arrayref($sql, {}, $authtypecode, $tagfield, $tagsubfield);
48 my $tagfield = $input->param('tagfield');
49 my $tagsubfield = $input->param('tagsubfield');
50 my $authtypecode = $input->param('authtypecode');
51 my $offset = $input->param('offset');
52 my $op = $input->param('op') || '';
53 my $script_name = "/cgi-bin/koha/admin/auth_subfields_structure.pl";
55 my ($template, $borrowernumber, $cookie) = get_template_and_user
(
56 { template_name
=> "admin/auth_subfields_structure.tmpl",
60 flagsrequired
=> { parameters
=> 'parameters_remaining_permissions' },
68 $template->param(script_name
=> $script_name,
70 authtypecode
=> $authtypecode,
71 $op => 1); # we show only the TMPL_VAR names $op
73 $template->param(script_name
=> $script_name,
75 authtypecode
=> $authtypecode,
76 else => 1); # we show only the TMPL_VAR names $op
79 my $dbh = C4
::Context
->dbh;
80 ################## ADD_FORM ##################################
81 # called by default. Used to create form to add or modify a record
82 if ($op eq 'add_form') {
84 my $more_subfields = $input->param("more_subfields")+1;
85 # builds kohafield tables
88 my $sth2=$dbh->prepare("SHOW COLUMNS from auth_header");
90 while ((my $field) = $sth2->fetchrow_array) {
91 push @kohafields, "auth_header.".$field;
94 # build authorised value list
95 $sth2 = $dbh->prepare("select distinct category from authorised_values");
97 my @authorised_values;
98 push @authorised_values,"";
99 while ((my $category) = $sth2->fetchrow_array) {
100 push @authorised_values, $category;
102 push (@authorised_values,"branches");
103 push (@authorised_values,"itemtypes");
105 # build thesaurus categories list
106 $sth2 = $dbh->prepare("select authtypecode from auth_types");
110 while ( ( my $authtypecode ) = $sth2->fetchrow_array ) {
111 push @authtypes, $authtypecode;
114 # build value_builder list
115 my @value_builder=('');
117 # read value_builder directory.
118 # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
119 # on a standard install, /cgi-bin need to be added.
120 # test one, then the other
121 my $cgidir = C4
::Context
->intranetdir ."/cgi-bin";
122 unless (opendir(DIR
, "$cgidir/cataloguing/value_builder")) {
123 $cgidir = C4
::Context
->intranetdir;
124 opendir(DIR
, "$cgidir/cataloguing/value_builder") || die "can't opendir $cgidir/value_builder: $!";
126 while (my $line = readdir(DIR
)) {
127 if ($line =~ /\.pl$/) {
128 push (@value_builder,$line);
131 @value_builder= sort {$a cmp $b} @value_builder;
135 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
136 $sth->execute($tagfield,$authtypecode);
139 while ($data =$sth->fetchrow_hashref) {
141 my %row_data; # get a fresh hash for the row data
142 $row_data{defaultvalue
} = $data->{defaultvalue
};
143 $row_data{tab
} = CGI
::scrolling_list
(-name
=>'tab',
146 [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
160 -default=>$data->{'tab'},
165 $row_data{ohidden
} = CGI
::scrolling_list
(-name
=>'ohidden',
167 #-values=>['0','1','2'],
168 #-labels => {'0'=>'Show','1'=>'Show Collapsed',
172 -labels
=> {'0'=>'Show All','-5'=>'Hide All',},
173 -default=>$data->{'hidden'},
178 #$row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
180 # -values=>['0','1','2'],
181 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
184 # -default=>substr($data->{'hidden'},1,1),
188 #$row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
190 # -values=>['0','1','2'],
191 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
194 # -default=>substr($data->{'hidden'}." ",2,1),
198 $row_data{tagsubfieldinput
} = "<input type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" id=\"tagsubfield\" />";
199 $row_data{tagsubfield
} = $data->{'tagsubfield'};
200 $row_data{liblibrarian
} = CGI
::escapeHTML
($data->{'liblibrarian'});
201 $row_data{libopac
} = CGI
::escapeHTML
($data->{'libopac'});
202 $row_data{seealso
} = CGI
::escapeHTML
($data->{'seealso'});
203 $row_data{kohafield
}= CGI
::scrolling_list
( -name
=>"kohafield",
205 -values=> \
@kohafields,
206 -default=> "$data->{'kohafield'}",
210 $row_data{authorised_value
} = CGI
::scrolling_list
(-name
=>'authorised_value',
211 -id
=>"authorised_value$i",
212 -values=> \
@authorised_values,
213 -default=>$data->{'authorised_value'},
218 $row_data{frameworkcode
} = CGI
::scrolling_list
(-name
=>'frameworkcode',
219 -id
=>"frameworkcode$i",
220 -values=> \
@authtypes,
221 -default=>$data->{'frameworkcode'},
226 $row_data{value_builder
} = CGI
::scrolling_list
(-name
=>'value_builder',
227 -id
=>"value_builder$i",
228 -values=> \
@value_builder,
229 -default=>$data->{'value_builder'},
235 $row_data{repeatable
} = CGI
::checkbox
(-name
=>"repeatable$i",
236 -checked
=> $data->{'repeatable'}?
'checked':'',
239 -id
=> "repeatable$i");
240 $row_data{mandatory
} = CGI
::checkbox
(-name
=> "mandatory$i",
241 -checked
=> $data->{'mandatory'}?
'checked':'',
244 -id
=> "mandatory$i");
245 $row_data{hidden
} = CGI
::escapeHTML
($data->{hidden
}) ;
246 $row_data{isurl
} = CGI
::checkbox
( -name
=> "isurl$i",
248 -checked
=> $data->{'isurl'}?
'checked':'',
252 push(@loop_data, \
%row_data);
255 # add more_subfields empty lines for add if needed
256 for (my $i=1;$i<=$more_subfields;$i++) {
257 my %row_data; # get a fresh hash for the row data
258 $row_data{'new_subfield'} = 1;
259 $row_data{tab
} = CGI
::scrolling_list
(-name
=>'tab',
262 [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
281 $row_data{ohidden
} = CGI
::scrolling_list
(-name
=>'ohidden',
283 #-values=>['0','1','2'],
284 #-labels => {'0'=>'Show','1'=>'Show Collapsed',
288 -labels
=> {'0'=>'Show All','-5'=>'Hide All',},
290 -default=>$data->{'hidden'},
296 #$row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
298 # -values=>['0','1','2'],
299 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
306 #$row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
308 # -values=>['0','1','2'],
309 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
316 $row_data{tagsubfieldinput
} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" />";
317 $row_data{tagsubfieldinput
} =
318 "<label><input type=\"text\" name=\"tagsubfield\" value=\""
319 . $data->{'tagsubfield'}
320 . "\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" /></label>";
321 $row_data{tagsubfield
} = $data->{'tagsubfield'};
322 $row_data{liblibrarian
} = "";
323 $row_data{libopac
} = "";
324 $row_data{seealso
} = "";
325 $row_data{hidden
} = "000";
326 $row_data{repeatable
} = CGI
::checkbox
( -name
=> 'repeatable',
327 -id
=> "repeatable$i",
331 $row_data{mandatory
} = CGI
::checkbox
( -name
=> 'mandatory',
332 -id
=> "mandatory$i",
336 $row_data{isurl
} = CGI
::checkbox
(-name
=> 'isurl',
341 $row_data{kohafield
}= CGI
::scrolling_list
( -name
=>'kohafield',
342 -id
=> "kohafield$i",
343 -values=> \
@kohafields,
348 $row_data{frameworkcode
} = CGI
::scrolling_list
(-name
=>'frameworkcode',
349 -id
=>'frameworkcode',
350 -values=> \
@authtypes,
351 -default=>$data->{'frameworkcode'},
356 $row_data{authorised_value
} = CGI
::scrolling_list
(-name
=>'authorised_value',
357 -id
=> 'authorised_value',
358 -values=> \
@authorised_values,
363 $row_data{value_builder
} = CGI
::scrolling_list
(-name
=>'value_builder',
364 -id
=>'value_builder',
365 -values=> \
@value_builder,
366 -default=>$data->{'value_builder'},
372 push(@loop_data, \
%row_data);
374 $template->param('use_heading_flags_p' => 1);
375 $template->param('heading_edit_subfields_p' => 1);
376 $template->param(action
=> "Edit subfields",
377 tagfield
=> $tagfield,
378 tagfieldinput
=> "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
380 more_subfields
=> $more_subfields,
381 more_tag
=> $tagfield);
383 # END $OP eq ADD_FORM
384 ################## ADD_VALIDATE ##################################
385 # called by add_form, used to insert/modify data in DB
386 } elsif ($op eq 'add_validate') {
387 $template->param(tagfield
=> "$input->param('tagfield')");
388 # my $sth=$dbh->prepare("replace auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl)
389 # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
390 my $sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,seealso,authorised_value,frameworkcode,value_builder,hidden,isurl,defaultvalue)
391 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
392 my $sth_update = $dbh->prepare("update auth_subfield_structure set authtypecode=?, tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, frameworkcode=?, value_builder=?, hidden=?, isurl=?, defaultvalue=?
393 where authtypecode=? and tagfield=? and tagsubfield=?");
394 my @tagsubfield = $input->param('tagsubfield');
395 my @liblibrarian = $input->param('liblibrarian');
396 my @libopac = $input->param('libopac');
397 my @kohafield = ''.$input->param('kohafield');
398 my @tab = $input->param('tab');
399 my @seealso = $input->param('seealso');
401 my @ohidden = $input->param('ohidden');
402 #my @ihidden = $input->param('ihidden');
403 #my @ehidden = $input->param('ehidden');
404 my @authorised_values = $input->param('authorised_value');
405 my $authtypecode = $input->param('authtypecode');
406 my @frameworkcodes = $input->param('frameworkcode');
407 my @value_builder =$input->param('value_builder');
408 my @defaultvalue = $input->param('defaultvalue');
409 for (my $i=0; $i<= $#tagsubfield ; $i++) {
410 my $tagfield =$input->param('tagfield');
411 my $tagsubfield =$tagsubfield[$i];
412 $tagsubfield="@" unless $tagsubfield ne '';
413 my $liblibrarian =$liblibrarian[$i];
414 my $libopac =$libopac[$i];
415 my $repeatable =$input->param("repeatable$i")?
1:0;
416 my $mandatory =$input->param("mandatory$i")?
1:0;
417 my $kohafield =$kohafield[$i];
419 my $seealso =$seealso[$i];
420 my $authorised_value =$authorised_values[$i];
421 my $frameworkcode =$frameworkcodes[$i];
422 my $value_builder=$value_builder[$i];
423 my $defaultvalue = $defaultvalue[$i];
424 #my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens;
425 my $hidden = $ohidden[$i]; #collate from 3 hiddens;
426 my $isurl = $input->param("isurl$i")?
1:0;
428 unless (C4
::Context
->config('demo') eq 1) {
429 if (auth_subfield_structure_exists
($authtypecode, $tagfield, $tagsubfield)) {
430 $sth_update->execute(
454 $sth_insert->execute(
476 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
479 # END $OP eq ADD_VALIDATE
480 ################## DELETE_CONFIRM ##################################
481 # called by default form, used to confirm deletion of data in DB
482 } elsif ($op eq 'delete_confirm') {
483 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
484 $sth->execute($tagfield,$tagsubfield,$authtypecode);
485 my $data=$sth->fetchrow_hashref;
486 $template->param(liblibrarian
=> $data->{'liblibrarian'},
487 tagsubfield
=> $data->{'tagsubfield'},
488 delete_link
=> $script_name,
489 tagfield
=>$tagfield,
490 tagsubfield
=> $tagsubfield,
491 authtypecode
=> $authtypecode,
493 # END $OP eq DELETE_CONFIRM
494 ################## DELETE_CONFIRMED ##################################
495 # called by delete_confirm, used to effectively confirm deletion of data in DB
496 } elsif ($op eq 'delete_confirmed') {
497 unless (C4
::Context
->config('demo') eq 1) {
498 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
499 $sth->execute($tagfield,$tagsubfield,$authtypecode);
501 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
503 $template->param(tagfield
=> $tagfield);
504 # END $OP eq DELETE_CONFIRMED
505 ################## DEFAULT ##################################
507 my ($count,$results)=string_search
($tagfield,$authtypecode);
509 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
510 my %row_data; # get a fresh hash for the row data
511 $row_data{tagfield
} = $results->[$i]{'tagfield'};
512 $row_data{tagsubfield
} = $results->[$i]{'tagsubfield'};
513 $row_data{liblibrarian
} = $results->[$i]{'liblibrarian'};
514 $row_data{kohafield
} = $results->[$i]{'kohafield'};
515 $row_data{repeatable
} = $results->[$i]{'repeatable'};
516 $row_data{mandatory
} = $results->[$i]{'mandatory'};
517 $row_data{tab
} = $results->[$i]{'tab'};
518 $row_data{seealso
} = $results->[$i]{'seealso'};
519 $row_data{authorised_value
} = $results->[$i]{'authorised_value'};
520 $row_data{authtypecode
} = $results->[$i]{'authtypecode'};
521 $row_data{value_builder
} = $results->[$i]{'value_builder'};
522 $row_data{hidden
} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
523 $row_data{isurl
} = $results->[$i]{'isurl'};
524 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
525 if ($row_data{tab
} eq -1) {
526 $row_data{subfield_ignored
} = 1;
529 push(@loop_data, \
%row_data);
531 $template->param(loop => \
@loop_data);
532 $template->param(edit_tagfield
=> $tagfield,
533 edit_authtypecode
=> $authtypecode);
536 my $prevpage = $offset-$pagesize;
537 $template->param(prev
=>"<a href=\"$script_name?offset=$prevpage\">");
539 if ($offset+$pagesize<$count) {
540 my $nextpage =$offset+$pagesize;
541 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
543 } #---- END $OP eq DEFAULT
544 output_html_with_http_headers
$input, $cookie, $template->output;