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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
28 my ($searchstring,$authtypecode)=@_;
29 my $dbh = C4
::Context
->dbh;
30 $searchstring=~ s/\'/\\\'/g;
31 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);
38 while (my $data=$sth->fetchrow_hashref){
44 return ($cnt,\
@results);
48 my $tagfield=$input->param('tagfield');
49 my $tagsubfield=$input->param('tagsubfield');
50 my $authtypecode=$input->param('authtypecode');
51 my $pkfield="tagfield";
52 my $offset=$input->param('offset');
53 my $script_name="/cgi-bin/koha/admin/auth_subfields_structure.pl";
55 my ($template, $borrowernumber, $cookie)
56 = get_template_and_user
({template_name
=> "admin/auth_subfields_structure.tmpl",
60 flagsrequired
=> {parameters
=> 1},
64 my $op = $input->param('op');
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 ################## ADD_FORM ##################################
80 # called by default. Used to create form to add or modify a record
81 if ($op eq 'add_form') {
83 my $dbh = C4
::Context
->dbh;
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
96 $sth2 = $dbh->prepare("select distinct category from authorised_values");
98 my @authorised_values;
99 push @authorised_values,"";
100 while ((my $category) = $sth2->fetchrow_array) {
101 push @authorised_values, $category;
103 push (@authorised_values,"branches");
104 push (@authorised_values,"itemtypes");
106 # build thesaurus categories list
108 $sth2 = $dbh->prepare("select authtypecode from auth_types");
112 while ( ( my $authtypecode ) = $sth2->fetchrow_array ) {
113 push @authtypes, $authtypecode;
116 # build value_builder list
117 my @value_builder=('');
119 # read value_builder directory.
120 # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
121 # on a standard install, /cgi-bin need to be added.
122 # test one, then the other
123 my $cgidir = C4
::Context
->intranetdir ."/cgi-bin";
124 unless (opendir(DIR
, "$cgidir/cataloguing/value_builder")) {
125 $cgidir = C4
::Context
->intranetdir;
126 opendir(DIR
, "$cgidir/cataloguing/value_builder") || die "can't opendir $cgidir/value_builder: $!";
128 while (my $line = readdir(DIR
)) {
129 if ($line =~ /\.pl$/) {
130 push (@value_builder,$line);
133 @value_builder= sort {$a cmp $b} @value_builder;
137 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
138 $sth->execute($tagfield,$authtypecode);
142 while ($data =$sth->fetchrow_hashref) {
144 my %row_data; # get a fresh hash for the row data
150 $row_data{tab
} = CGI
::scrolling_list
(-name
=>'tab',
153 [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
167 -default=>$data->{'tab'},
172 $row_data{ohidden
} = CGI
::scrolling_list
(-name
=>'ohidden',
174 -values=>['0','1','2'],
175 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
178 -default=>substr($data->{'hidden'},0,1),
182 $row_data{ihidden
} = CGI
::scrolling_list
(-name
=>'ihidden',
184 -values=>['0','1','2'],
185 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
188 -default=>substr($data->{'hidden'},1,1),
192 $row_data{ehidden
} = CGI
::scrolling_list
(-name
=>'ehidden',
194 -values=>['0','1','2'],
195 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
198 -default=>substr($data->{'hidden'}." ",2,1),
202 $row_data{tagsubfieldinput
} = "<input type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" id=\"tagsubfield\" />";
203 $row_data{tagsubfield
} = $data->{'tagsubfield'};
204 $row_data{liblibrarian
} = CGI
::escapeHTML
($data->{'liblibrarian'});
205 $row_data{libopac
} = CGI
::escapeHTML
($data->{'libopac'});
206 $row_data{seealso
} = CGI
::escapeHTML
($data->{'seealso'});
207 $row_data{kohafield
}= CGI
::scrolling_list
( -name
=>"kohafield",
209 -values=> \
@kohafields,
210 -default=> "$data->{'kohafield'}",
214 $row_data{authorised_value
} = CGI
::scrolling_list
(-name
=>'authorised_value',
215 -id
=>"authorised_value$i",
216 -values=> \
@authorised_values,
217 -default=>$data->{'authorised_value'},
222 $row_data{frameworkcode
} = CGI
::scrolling_list
(-name
=>'frameworkcode',
223 -id
=>"frameworkcode$i",
224 -values=> \
@authtypes,
225 -default=>$data->{'frameworkcode'},
230 $row_data{value_builder
} = CGI
::scrolling_list
(-name
=>'value_builder',
231 -id
=>"value_builder$i",
232 -values=> \
@value_builder,
233 -default=>$data->{'value_builder'},
239 $row_data{repeatable
} = CGI
::checkbox
(-name
=>"repeatable$i",
240 -checked
=> $data->{'repeatable'}?
'checked':'',
243 -id
=> "repeatable$i");
244 $row_data{mandatory
} = CGI
::checkbox
(-name
=> "mandatory$i",
245 -checked
=> $data->{'mandatory'}?
'checked':'',
248 -id
=> "mandatory$i");
249 $row_data{hidden
} = CGI
::escapeHTML
($data->{hidden
}) ;
250 $row_data{isurl
} = CGI
::checkbox
( -name
=> "isurl$i",
252 -checked
=> $data->{'isurl'}?
'checked':'',
256 $row_data{toggle
} = $toggle;
257 push(@loop_data, \
%row_data);
260 # add more_subfields empty lines for add if needed
261 for (my $i=1;$i<=$more_subfields;$i++) {
262 my %row_data; # get a fresh hash for the row data
263 $row_data{'new_subfield'} = 1;
264 $row_data{tab
} = CGI
::scrolling_list
(-name
=>'tab',
267 [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
286 $row_data{ohidden
} = CGI
::scrolling_list
(-name
=>'ohidden',
288 -values=>['0','1','2'],
289 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
297 $row_data{ihidden
} = CGI
::scrolling_list
(-name
=>'ihidden',
299 -values=>['0','1','2'],
300 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
307 $row_data{ehidden
} = CGI
::scrolling_list
(-name
=>'ehidden',
309 -values=>['0','1','2'],
310 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
317 $row_data{tagsubfieldinput
} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" />";
318 $row_data{tagsubfield
} = $data->{'tagsubfield'};
319 $row_data{liblibrarian
} = "";
320 $row_data{libopac
} = "";
321 $row_data{seealso
} = "";
322 $row_data{hidden
} = "000";
323 $row_data{repeatable
} = CGI
::checkbox
( -name
=> 'repeatable',
324 -id
=> "repeatable$i",
328 $row_data{mandatory
} = CGI
::checkbox
( -name
=> 'mandatory',
329 -id
=> "mandatory$i",
333 $row_data{isurl
} = CGI
::checkbox
(-name
=> 'isurl',
338 $row_data{kohafield
}= CGI
::scrolling_list
( -name
=>'kohafield',
339 -id
=> "kohafield$i",
340 -values=> \
@kohafields,
345 $row_data{frameworkcode
} = CGI
::scrolling_list
(-name
=>'frameworkcode',
346 -id
=>'frameworkcode',
347 -values=> \
@authtypes,
348 -default=>$data->{'frameworkcode'},
353 $row_data{authorised_value
} = CGI
::scrolling_list
(-name
=>'authorised_value',
354 -id
=> 'authorised_value',
355 -values=> \
@authorised_values,
360 $row_data{value_builder
} = CGI
::scrolling_list
(-name
=>'value_builder',
361 -id
=>'value_builder',
362 -values=> \
@value_builder,
363 -default=>$data->{'value_builder'},
368 $row_data{toggle
} = $toggle;
370 push(@loop_data, \
%row_data);
372 $template->param('use-heading-flags-p' => 1);
373 $template->param('heading-edit-subfields-p' => 1);
374 $template->param(action
=> "Edit subfields",
375 tagfield
=> $tagfield,
376 tagfieldinput
=> "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
378 more_subfields
=> $more_subfields,
379 more_tag
=> $tagfield);
381 # END $OP eq ADD_FORM
382 ################## ADD_VALIDATE ##################################
383 # called by add_form, used to insert/modify data in DB
384 } elsif ($op eq 'add_validate') {
385 my $dbh = C4
::Context
->dbh;
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 @tagsubfield = $input->param('tagsubfield');
390 my @liblibrarian = $input->param('liblibrarian');
391 my @libopac = $input->param('libopac');
392 my @kohafield = ''.$input->param('kohafield');
393 my @tab = $input->param('tab');
394 my @seealso = $input->param('seealso');
396 my @ohidden = $input->param('ohidden');
397 my @ihidden = $input->param('ihidden');
398 my @ehidden = $input->param('ehidden');
399 my @authorised_values = $input->param('authorised_value');
400 my $authtypecode = $input->param('authtypecode');
401 my @frameworkcodes = $input->param('frameworkcode');
402 my @value_builder =$input->param('value_builder');
403 for (my $i=0; $i<= $#tagsubfield ; $i++) {
404 my $tagfield =$input->param('tagfield');
405 my $tagsubfield =$tagsubfield[$i];
406 $tagsubfield="@" unless $tagsubfield ne '';
407 my $liblibrarian =$liblibrarian[$i];
408 my $libopac =$libopac[$i];
409 my $repeatable =$input->param("repeatable$i")?
1:0;
410 my $mandatory =$input->param("mandatory$i")?
1:0;
411 my $kohafield =$kohafield[$i];
413 my $seealso =$seealso[$i];
414 my $authorised_value =$authorised_values[$i];
415 my $frameworkcode =$frameworkcodes[$i];
416 my $value_builder=$value_builder[$i];
417 my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens;
418 my $isurl = $input->param("isurl$i")?
1:0;
420 unless (C4
::Context
->config('demo') eq 1) {
421 $sth->execute($authtypecode,
441 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
444 # END $OP eq ADD_VALIDATE
445 ################## DELETE_CONFIRM ##################################
446 # called by default form, used to confirm deletion of data in DB
447 } elsif ($op eq 'delete_confirm') {
448 my $dbh = C4
::Context
->dbh;
449 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
450 $sth->execute($tagfield,$tagsubfield,$authtypecode);
451 my $data=$sth->fetchrow_hashref;
453 $template->param(liblibrarian
=> $data->{'liblibrarian'},
454 tagsubfield
=> $data->{'tagsubfield'},
455 delete_link
=> $script_name,
456 tagfield
=>$tagfield,
457 tagsubfield
=> $tagsubfield,
458 authtypecode
=> $authtypecode,
460 # END $OP eq DELETE_CONFIRM
461 ################## DELETE_CONFIRMED ##################################
462 # called by delete_confirm, used to effectively confirm deletion of data in DB
463 } elsif ($op eq 'delete_confirmed') {
464 my $dbh = C4
::Context
->dbh;
465 unless (C4
::Context
->config('demo') eq 1) {
466 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
467 $sth->execute($tagfield,$tagsubfield,$authtypecode);
470 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
472 $template->param(tagfield
=> $tagfield);
473 # END $OP eq DELETE_CONFIRMED
474 ################## DEFAULT ##################################
476 my ($count,$results)=StringSearch
($tagfield,$authtypecode);
479 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
485 my %row_data; # get a fresh hash for the row data
486 $row_data{tagfield
} = $results->[$i]{'tagfield'};
487 $row_data{tagsubfield
} = $results->[$i]{'tagsubfield'};
488 $row_data{liblibrarian
} = $results->[$i]{'liblibrarian'};
489 $row_data{kohafield
} = $results->[$i]{'kohafield'};
490 $row_data{repeatable
} = $results->[$i]{'repeatable'};
491 $row_data{mandatory
} = $results->[$i]{'mandatory'};
492 $row_data{tab
} = $results->[$i]{'tab'};
493 $row_data{seealso
} = $results->[$i]{'seealso'};
494 $row_data{authorised_value
} = $results->[$i]{'authorised_value'};
495 $row_data{authtypecode
} = $results->[$i]{'authtypecode'};
496 $row_data{value_builder
} = $results->[$i]{'value_builder'};
497 $row_data{hidden
} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
498 $row_data{isurl
} = $results->[$i]{'isurl'};
499 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
500 $row_data{toggle
} = $toggle;
501 if ($row_data{tab
} eq -1) {
502 $row_data{subfield_ignored
} = 1;
505 push(@loop_data, \
%row_data);
507 $template->param(loop => \
@loop_data);
508 $template->param(edit_tagfield
=> $tagfield,
509 edit_authtypecode
=> $authtypecode);
512 my $prevpage = $offset-$pagesize;
513 $template->param(prev
=>"<a href=\"$script_name?offset=$prevpage\">");
515 if ($offset+$pagesize<$count) {
516 my $nextpage =$offset+$pagesize;
517 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
519 } #---- END $OP eq DEFAULT
520 output_html_with_http_headers
$input, $cookie, $template->output;