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
=> 1 },
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{tab
} = CGI
::scrolling_list
(-name
=>'tab',
145 [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
159 -default=>$data->{'tab'},
164 $row_data{ohidden
} = CGI
::scrolling_list
(-name
=>'ohidden',
166 #-values=>['0','1','2'],
167 #-labels => {'0'=>'Show','1'=>'Show Collapsed',
171 -labels
=> {'0'=>'Show All','-5'=>'Hide All',},
172 -default=>$data->{'hidden'},
177 #$row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
179 # -values=>['0','1','2'],
180 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
183 # -default=>substr($data->{'hidden'},1,1),
187 #$row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
189 # -values=>['0','1','2'],
190 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
193 # -default=>substr($data->{'hidden'}." ",2,1),
197 $row_data{tagsubfieldinput
} = "<input type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" id=\"tagsubfield\" />";
198 $row_data{tagsubfield
} = $data->{'tagsubfield'};
199 $row_data{liblibrarian
} = CGI
::escapeHTML
($data->{'liblibrarian'});
200 $row_data{libopac
} = CGI
::escapeHTML
($data->{'libopac'});
201 $row_data{seealso
} = CGI
::escapeHTML
($data->{'seealso'});
202 $row_data{kohafield
}= CGI
::scrolling_list
( -name
=>"kohafield",
204 -values=> \
@kohafields,
205 -default=> "$data->{'kohafield'}",
209 $row_data{authorised_value
} = CGI
::scrolling_list
(-name
=>'authorised_value',
210 -id
=>"authorised_value$i",
211 -values=> \
@authorised_values,
212 -default=>$data->{'authorised_value'},
217 $row_data{frameworkcode
} = CGI
::scrolling_list
(-name
=>'frameworkcode',
218 -id
=>"frameworkcode$i",
219 -values=> \
@authtypes,
220 -default=>$data->{'frameworkcode'},
225 $row_data{value_builder
} = CGI
::scrolling_list
(-name
=>'value_builder',
226 -id
=>"value_builder$i",
227 -values=> \
@value_builder,
228 -default=>$data->{'value_builder'},
234 $row_data{repeatable
} = CGI
::checkbox
(-name
=>"repeatable$i",
235 -checked
=> $data->{'repeatable'}?
'checked':'',
238 -id
=> "repeatable$i");
239 $row_data{mandatory
} = CGI
::checkbox
(-name
=> "mandatory$i",
240 -checked
=> $data->{'mandatory'}?
'checked':'',
243 -id
=> "mandatory$i");
244 $row_data{hidden
} = CGI
::escapeHTML
($data->{hidden
}) ;
245 $row_data{isurl
} = CGI
::checkbox
( -name
=> "isurl$i",
247 -checked
=> $data->{'isurl'}?
'checked':'',
251 push(@loop_data, \
%row_data);
254 # add more_subfields empty lines for add if needed
255 for (my $i=1;$i<=$more_subfields;$i++) {
256 my %row_data; # get a fresh hash for the row data
257 $row_data{'new_subfield'} = 1;
258 $row_data{tab
} = CGI
::scrolling_list
(-name
=>'tab',
261 [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
280 $row_data{ohidden
} = CGI
::scrolling_list
(-name
=>'ohidden',
282 #-values=>['0','1','2'],
283 #-labels => {'0'=>'Show','1'=>'Show Collapsed',
287 -labels
=> {'0'=>'Show All','-5'=>'Hide All',},
289 -default=>$data->{'hidden'},
295 #$row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
297 # -values=>['0','1','2'],
298 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
305 #$row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
307 # -values=>['0','1','2'],
308 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
315 $row_data{tagsubfieldinput
} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" />";
316 $row_data{tagsubfieldinput
} =
317 "<label><input type=\"text\" name=\"tagsubfield\" value=\""
318 . $data->{'tagsubfield'}
319 . "\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" /></label>";
320 $row_data{tagsubfield
} = $data->{'tagsubfield'};
321 $row_data{liblibrarian
} = "";
322 $row_data{libopac
} = "";
323 $row_data{seealso
} = "";
324 $row_data{hidden
} = "000";
325 $row_data{repeatable
} = CGI
::checkbox
( -name
=> 'repeatable',
326 -id
=> "repeatable$i",
330 $row_data{mandatory
} = CGI
::checkbox
( -name
=> 'mandatory',
331 -id
=> "mandatory$i",
335 $row_data{isurl
} = CGI
::checkbox
(-name
=> 'isurl',
340 $row_data{kohafield
}= CGI
::scrolling_list
( -name
=>'kohafield',
341 -id
=> "kohafield$i",
342 -values=> \
@kohafields,
347 $row_data{frameworkcode
} = CGI
::scrolling_list
(-name
=>'frameworkcode',
348 -id
=>'frameworkcode',
349 -values=> \
@authtypes,
350 -default=>$data->{'frameworkcode'},
355 $row_data{authorised_value
} = CGI
::scrolling_list
(-name
=>'authorised_value',
356 -id
=> 'authorised_value',
357 -values=> \
@authorised_values,
362 $row_data{value_builder
} = CGI
::scrolling_list
(-name
=>'value_builder',
363 -id
=>'value_builder',
364 -values=> \
@value_builder,
365 -default=>$data->{'value_builder'},
371 push(@loop_data, \
%row_data);
373 $template->param('use-heading-flags-p' => 1);
374 $template->param('heading-edit-subfields-p' => 1);
375 $template->param(action
=> "Edit subfields",
376 tagfield
=> $tagfield,
377 tagfieldinput
=> "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
379 more_subfields
=> $more_subfields,
380 more_tag
=> $tagfield);
382 # END $OP eq ADD_FORM
383 ################## ADD_VALIDATE ##################################
384 # called by add_form, used to insert/modify data in DB
385 } elsif ($op eq 'add_validate') {
386 $template->param(tagfield
=> "$input->param('tagfield')");
387 # 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)
388 # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
389 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)
390 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
391 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=?
392 where authtypecode=? and tagfield=? and tagsubfield=?");
393 my @tagsubfield = $input->param('tagsubfield');
394 my @liblibrarian = $input->param('liblibrarian');
395 my @libopac = $input->param('libopac');
396 my @kohafield = ''.$input->param('kohafield');
397 my @tab = $input->param('tab');
398 my @seealso = $input->param('seealso');
400 my @ohidden = $input->param('ohidden');
401 #my @ihidden = $input->param('ihidden');
402 #my @ehidden = $input->param('ehidden');
403 my @authorised_values = $input->param('authorised_value');
404 my $authtypecode = $input->param('authtypecode');
405 my @frameworkcodes = $input->param('frameworkcode');
406 my @value_builder =$input->param('value_builder');
407 for (my $i=0; $i<= $#tagsubfield ; $i++) {
408 my $tagfield =$input->param('tagfield');
409 my $tagsubfield =$tagsubfield[$i];
410 $tagsubfield="@" unless $tagsubfield ne '';
411 my $liblibrarian =$liblibrarian[$i];
412 my $libopac =$libopac[$i];
413 my $repeatable =$input->param("repeatable$i")?
1:0;
414 my $mandatory =$input->param("mandatory$i")?
1:0;
415 my $kohafield =$kohafield[$i];
417 my $seealso =$seealso[$i];
418 my $authorised_value =$authorised_values[$i];
419 my $frameworkcode =$frameworkcodes[$i];
420 my $value_builder=$value_builder[$i];
421 #my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens;
422 my $hidden = $ohidden[$i]; #collate from 3 hiddens;
423 my $isurl = $input->param("isurl$i")?
1:0;
425 unless (C4
::Context
->config('demo') eq 1) {
426 if (auth_subfield_structure_exists
($authtypecode, $tagfield, $tagsubfield)) {
427 $sth_update->execute(
450 $sth_insert->execute(
471 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
474 # END $OP eq ADD_VALIDATE
475 ################## DELETE_CONFIRM ##################################
476 # called by default form, used to confirm deletion of data in DB
477 } elsif ($op eq 'delete_confirm') {
478 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
479 $sth->execute($tagfield,$tagsubfield,$authtypecode);
480 my $data=$sth->fetchrow_hashref;
481 $template->param(liblibrarian
=> $data->{'liblibrarian'},
482 tagsubfield
=> $data->{'tagsubfield'},
483 delete_link
=> $script_name,
484 tagfield
=>$tagfield,
485 tagsubfield
=> $tagsubfield,
486 authtypecode
=> $authtypecode,
488 # END $OP eq DELETE_CONFIRM
489 ################## DELETE_CONFIRMED ##################################
490 # called by delete_confirm, used to effectively confirm deletion of data in DB
491 } elsif ($op eq 'delete_confirmed') {
492 unless (C4
::Context
->config('demo') eq 1) {
493 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
494 $sth->execute($tagfield,$tagsubfield,$authtypecode);
496 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
498 $template->param(tagfield
=> $tagfield);
499 # END $OP eq DELETE_CONFIRMED
500 ################## DEFAULT ##################################
502 my ($count,$results)=string_search
($tagfield,$authtypecode);
504 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
505 my %row_data; # get a fresh hash for the row data
506 $row_data{tagfield
} = $results->[$i]{'tagfield'};
507 $row_data{tagsubfield
} = $results->[$i]{'tagsubfield'};
508 $row_data{liblibrarian
} = $results->[$i]{'liblibrarian'};
509 $row_data{kohafield
} = $results->[$i]{'kohafield'};
510 $row_data{repeatable
} = $results->[$i]{'repeatable'};
511 $row_data{mandatory
} = $results->[$i]{'mandatory'};
512 $row_data{tab
} = $results->[$i]{'tab'};
513 $row_data{seealso
} = $results->[$i]{'seealso'};
514 $row_data{authorised_value
} = $results->[$i]{'authorised_value'};
515 $row_data{authtypecode
} = $results->[$i]{'authtypecode'};
516 $row_data{value_builder
} = $results->[$i]{'value_builder'};
517 $row_data{hidden
} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
518 $row_data{isurl
} = $results->[$i]{'isurl'};
519 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
520 if ($row_data{tab
} eq -1) {
521 $row_data{subfield_ignored
} = 1;
524 push(@loop_data, \
%row_data);
526 $template->param(loop => \
@loop_data);
527 $template->param(edit_tagfield
=> $tagfield,
528 edit_authtypecode
=> $authtypecode);
531 my $prevpage = $offset-$pagesize;
532 $template->param(prev
=>"<a href=\"$script_name?offset=$prevpage\">");
534 if ($offset+$pagesize<$count) {
535 my $nextpage =$offset+$pagesize;
536 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
538 } #---- END $OP eq DEFAULT
539 output_html_with_http_headers
$input, $cookie, $template->output;