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
};
145 default => $data->{'tab'},
147 $row_data{ohidden
} = {
149 default => $data->{'hidden'}
151 #$row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
153 # -values=>['0','1','2'],
154 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
157 # -default=>substr($data->{'hidden'},1,1),
161 #$row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
163 # -values=>['0','1','2'],
164 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
167 # -default=>substr($data->{'hidden'}." ",2,1),
171 $row_data{tagsubfieldinput
} = "<input type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" id=\"tagsubfield\" />";
172 $row_data{tagsubfield
} = $data->{'tagsubfield'};
173 $row_data{liblibrarian
} = CGI
::escapeHTML
($data->{'liblibrarian'});
174 $row_data{libopac
} = CGI
::escapeHTML
($data->{'libopac'});
175 $row_data{seealso
} = CGI
::escapeHTML
($data->{'seealso'});
176 $row_data{kohafield
}= CGI
::scrolling_list
( -name
=>"kohafield",
178 -values=> \
@kohafields,
179 -default=> "$data->{'kohafield'}",
183 $row_data{authorised_value
} = CGI
::scrolling_list
(-name
=>'authorised_value',
184 -id
=>"authorised_value$i",
185 -values=> \
@authorised_values,
186 -default=>$data->{'authorised_value'},
191 $row_data{frameworkcode
} = CGI
::scrolling_list
(-name
=>'frameworkcode',
192 -id
=>"frameworkcode$i",
193 -values=> \
@authtypes,
194 -default=>$data->{'frameworkcode'},
199 $row_data{value_builder
} = CGI
::scrolling_list
(-name
=>'value_builder',
200 -id
=>"value_builder$i",
201 -values=> \
@value_builder,
202 -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':'',
225 push(@loop_data, \
%row_data);
228 # add more_subfields empty lines for add if needed
229 for (my $i=1;$i<=$more_subfields;$i++) {
230 my %row_data; # get a fresh hash for the row data
231 $row_data{'new_subfield'} = 1;
232 $row_data{tab
} = CGI
::scrolling_list
(-name
=>'tab',
235 [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
254 $row_data{ohidden
} = CGI
::scrolling_list
(-name
=>'ohidden',
256 #-values=>['0','1','2'],
257 #-labels => {'0'=>'Show','1'=>'Show Collapsed',
261 -labels
=> {'0'=>'Show All','-5'=>'Hide All',},
263 -default=>$data->{'hidden'},
269 #$row_data{ihidden} = CGI::scrolling_list(-name=>'ihidden',
271 # -values=>['0','1','2'],
272 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
279 #$row_data{ehidden} = CGI::scrolling_list(-name=>'ehidden',
281 # -values=>['0','1','2'],
282 # -labels => {'0'=>'Show','1'=>'Show Collapsed',
289 $row_data{tagsubfieldinput
} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" />";
290 $row_data{tagsubfieldinput
} =
291 "<label><input type=\"text\" name=\"tagsubfield\" value=\""
292 . $data->{'tagsubfield'}
293 . "\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" /></label>";
294 $row_data{tagsubfield
} = $data->{'tagsubfield'};
295 $row_data{liblibrarian
} = "";
296 $row_data{libopac
} = "";
297 $row_data{seealso
} = "";
298 $row_data{hidden
} = "000";
299 $row_data{repeatable
} = CGI
::checkbox
( -name
=> 'repeatable',
300 -id
=> "repeatable$i",
304 $row_data{mandatory
} = CGI
::checkbox
( -name
=> 'mandatory',
305 -id
=> "mandatory$i",
309 $row_data{isurl
} = CGI
::checkbox
(-name
=> 'isurl',
314 $row_data{kohafield
}= CGI
::scrolling_list
( -name
=>'kohafield',
315 -id
=> "kohafield$i",
316 -values=> \
@kohafields,
321 $row_data{frameworkcode
} = CGI
::scrolling_list
(-name
=>'frameworkcode',
322 -id
=>'frameworkcode',
323 -values=> \
@authtypes,
324 -default=>$data->{'frameworkcode'},
329 $row_data{authorised_value
} = CGI
::scrolling_list
(-name
=>'authorised_value',
330 -id
=> 'authorised_value',
331 -values=> \
@authorised_values,
336 $row_data{value_builder
} = CGI
::scrolling_list
(-name
=>'value_builder',
337 -id
=>'value_builder',
338 -values=> \
@value_builder,
339 -default=>$data->{'value_builder'},
345 push(@loop_data, \
%row_data);
347 $template->param('use_heading_flags_p' => 1);
348 $template->param('heading_edit_subfields_p' => 1);
349 $template->param(action
=> "Edit subfields",
350 tagfield
=> $tagfield,
351 tagfieldinput
=> "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
353 more_subfields
=> $more_subfields,
354 more_tag
=> $tagfield);
356 # END $OP eq ADD_FORM
357 ################## ADD_VALIDATE ##################################
358 # called by add_form, used to insert/modify data in DB
359 } elsif ($op eq 'add_validate') {
360 $template->param(tagfield
=> "$input->param('tagfield')");
361 # 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)
362 # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
363 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)
364 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
365 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=?
366 where authtypecode=? and tagfield=? and tagsubfield=?");
367 my @tagsubfield = $input->param('tagsubfield');
368 my @liblibrarian = $input->param('liblibrarian');
369 my @libopac = $input->param('libopac');
370 my @kohafield = ''.$input->param('kohafield');
371 my @tab = $input->param('tab');
372 my @seealso = $input->param('seealso');
374 my @ohidden = $input->param('ohidden');
375 #my @ihidden = $input->param('ihidden');
376 #my @ehidden = $input->param('ehidden');
377 my @authorised_values = $input->param('authorised_value');
378 my $authtypecode = $input->param('authtypecode');
379 my @frameworkcodes = $input->param('frameworkcode');
380 my @value_builder =$input->param('value_builder');
381 my @defaultvalue = $input->param('defaultvalue');
382 for (my $i=0; $i<= $#tagsubfield ; $i++) {
383 my $tagfield =$input->param('tagfield');
384 my $tagsubfield =$tagsubfield[$i];
385 $tagsubfield="@" unless $tagsubfield ne '';
386 my $liblibrarian =$liblibrarian[$i];
387 my $libopac =$libopac[$i];
388 my $repeatable =$input->param("repeatable$i")?
1:0;
389 my $mandatory =$input->param("mandatory$i")?
1:0;
390 my $kohafield =$kohafield[$i];
392 my $seealso =$seealso[$i];
393 my $authorised_value =$authorised_values[$i];
394 my $frameworkcode =$frameworkcodes[$i];
395 my $value_builder=$value_builder[$i];
396 my $defaultvalue = $defaultvalue[$i];
397 #my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens;
398 my $hidden = $ohidden[$i]; #collate from 3 hiddens;
399 my $isurl = $input->param("isurl$i")?
1:0;
401 unless (C4
::Context
->config('demo') eq 1) {
402 if (auth_subfield_structure_exists
($authtypecode, $tagfield, $tagsubfield)) {
403 $sth_update->execute(
427 $sth_insert->execute(
449 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
452 # END $OP eq ADD_VALIDATE
453 ################## DELETE_CONFIRM ##################################
454 # called by default form, used to confirm deletion of data in DB
455 } elsif ($op eq 'delete_confirm') {
456 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
457 $sth->execute($tagfield,$tagsubfield,$authtypecode);
458 my $data=$sth->fetchrow_hashref;
459 $template->param(liblibrarian
=> $data->{'liblibrarian'},
460 tagsubfield
=> $data->{'tagsubfield'},
461 delete_link
=> $script_name,
462 tagfield
=>$tagfield,
463 tagsubfield
=> $tagsubfield,
464 authtypecode
=> $authtypecode,
466 # END $OP eq DELETE_CONFIRM
467 ################## DELETE_CONFIRMED ##################################
468 # called by delete_confirm, used to effectively confirm deletion of data in DB
469 } elsif ($op eq 'delete_confirmed') {
470 unless (C4
::Context
->config('demo') eq 1) {
471 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
472 $sth->execute($tagfield,$tagsubfield,$authtypecode);
474 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
476 $template->param(tagfield
=> $tagfield);
477 # END $OP eq DELETE_CONFIRMED
478 ################## DEFAULT ##################################
480 my ($count,$results)=string_search
($tagfield,$authtypecode);
482 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
483 my %row_data; # get a fresh hash for the row data
484 $row_data{tagfield
} = $results->[$i]{'tagfield'};
485 $row_data{tagsubfield
} = $results->[$i]{'tagsubfield'};
486 $row_data{liblibrarian
} = $results->[$i]{'liblibrarian'};
487 $row_data{kohafield
} = $results->[$i]{'kohafield'};
488 $row_data{repeatable
} = $results->[$i]{'repeatable'};
489 $row_data{mandatory
} = $results->[$i]{'mandatory'};
490 $row_data{tab
} = $results->[$i]{'tab'};
491 $row_data{seealso
} = $results->[$i]{'seealso'};
492 $row_data{authorised_value
} = $results->[$i]{'authorised_value'};
493 $row_data{authtypecode
} = $results->[$i]{'authtypecode'};
494 $row_data{value_builder
} = $results->[$i]{'value_builder'};
495 $row_data{hidden
} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
496 $row_data{isurl
} = $results->[$i]{'isurl'};
497 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
498 if ($row_data{tab
} eq -1) {
499 $row_data{subfield_ignored
} = 1;
502 push(@loop_data, \
%row_data);
504 $template->param(loop => \
@loop_data);
505 $template->param(edit_tagfield
=> $tagfield,
506 edit_authtypecode
=> $authtypecode);
509 my $prevpage = $offset-$pagesize;
510 $template->param(prev
=>"<a href=\"$script_name?offset=$prevpage\">");
512 if ($offset+$pagesize<$count) {
513 my $nextpage =$offset+$pagesize;
514 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
516 } #---- END $OP eq DEFAULT
517 output_html_with_http_headers
$input, $cookie, $template->output;