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
29 my ($searchstring,$authtypecode)=@_;
30 my $dbh = C4
::Context
->dbh;
31 $searchstring=~ s/\'/\\\'/g;
32 my @data=split(' ',$searchstring);
34 my $sth=$dbh->prepare("Select * from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield");
35 $sth->execute("$searchstring%",$authtypecode);
39 while (my $data=$sth->fetchrow_hashref){
45 return ($cnt,\
@results);
49 my $tagfield=$input->param('tagfield');
50 my $tagsubfield=$input->param('tagsubfield');
51 my $authtypecode=$input->param('authtypecode');
52 my $pkfield="tagfield";
53 my $offset=$input->param('offset');
54 my $script_name="/cgi-bin/koha/admin/auth_subfields_structure.pl";
56 my ($template, $borrowernumber, $cookie)
57 = get_template_and_user
({template_name
=> "admin/auth_subfields_structure.tmpl",
61 flagsrequired
=> {parameters
=> 1},
65 my $op = $input->param('op');
69 $template->param(script_name
=> $script_name,
71 authtypecode
=> $authtypecode,
72 $op => 1); # we show only the TMPL_VAR names $op
74 $template->param(script_name
=> $script_name,
76 authtypecode
=> $authtypecode,
77 else => 1); # we show only the TMPL_VAR names $op
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 $dbh = C4
::Context
->dbh;
85 my $more_subfields = $input->param("more_subfields")+1;
86 # builds kohafield tables
89 my $sth2=$dbh->prepare("SHOW COLUMNS from auth_header");
91 while ((my $field) = $sth2->fetchrow_array) {
92 push @kohafields, "auth_header.".$field;
95 # build authorised value list
97 $sth2 = $dbh->prepare("select distinct category from authorised_values");
99 my @authorised_values;
100 push @authorised_values,"";
101 while ((my $category) = $sth2->fetchrow_array) {
102 push @authorised_values, $category;
104 push (@authorised_values,"branches");
105 push (@authorised_values,"itemtypes");
107 # build thesaurus categories list
109 $sth2 = $dbh->prepare("select authtypecode from auth_types");
113 while ( ( my $authtypecode ) = $sth2->fetchrow_array ) {
114 push @authtypes, $authtypecode;
117 # build value_builder list
118 my @value_builder=('');
120 # read value_builder directory.
121 # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
122 # on a standard install, /cgi-bin need to be added.
123 # test one, then the other
124 my $cgidir = C4
::Context
->intranetdir ."/cgi-bin";
125 unless (opendir(DIR
, "$cgidir/cataloguing/value_builder")) {
126 $cgidir = C4
::Context
->intranetdir;
127 opendir(DIR
, "$cgidir/cataloguing/value_builder") || die "can't opendir $cgidir/value_builder: $!";
129 while (my $line = readdir(DIR
)) {
130 if ($line =~ /\.pl$/) {
131 push (@value_builder,$line);
134 @value_builder= sort {$a cmp $b} @value_builder;
138 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
139 $sth->execute($tagfield,$authtypecode);
143 while ($data =$sth->fetchrow_hashref) {
145 my %row_data; # get a fresh hash for the row data
151 $row_data{tab
} = CGI
::scrolling_list
(-name
=>'tab',
154 [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
168 -default=>$data->{'tab'},
173 $row_data{ohidden
} = CGI
::scrolling_list
(-name
=>'ohidden',
175 -values=>['0','1','2'],
176 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
179 -default=>substr($data->{'hidden'},0,1),
183 $row_data{ihidden
} = CGI
::scrolling_list
(-name
=>'ihidden',
185 -values=>['0','1','2'],
186 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
189 -default=>substr($data->{'hidden'},1,1),
193 $row_data{ehidden
} = CGI
::scrolling_list
(-name
=>'ehidden',
195 -values=>['0','1','2'],
196 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
199 -default=>substr($data->{'hidden'}." ",2,1),
203 $row_data{tagsubfieldinput
} = "<input type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" id=\"tagsubfield\" />";
204 $row_data{tagsubfield
} = $data->{'tagsubfield'};
205 $row_data{liblibrarian
} = CGI
::escapeHTML
($data->{'liblibrarian'});
206 $row_data{libopac
} = CGI
::escapeHTML
($data->{'libopac'});
207 $row_data{seealso
} = CGI
::escapeHTML
($data->{'seealso'});
208 $row_data{kohafield
}= CGI
::scrolling_list
( -name
=>"kohafield",
210 -values=> \
@kohafields,
211 -default=> "$data->{'kohafield'}",
215 $row_data{authorised_value
} = CGI
::scrolling_list
(-name
=>'authorised_value',
216 -id
=>"authorised_value$i",
217 -values=> \
@authorised_values,
218 -default=>$data->{'authorised_value'},
223 $row_data{frameworkcode
} = CGI
::scrolling_list
(-name
=>'frameworkcode',
224 -id
=>"frameworkcode$i",
225 -values=> \
@authtypes,
226 -default=>$data->{'frameworkcode'},
231 $row_data{value_builder
} = CGI
::scrolling_list
(-name
=>'value_builder',
232 -id
=>"value_builder$i",
233 -values=> \
@value_builder,
234 -default=>$data->{'value_builder'},
240 $row_data{repeatable
} = CGI
::checkbox
(-name
=>"repeatable$i",
241 -checked
=> $data->{'repeatable'}?
'checked':'',
244 -id
=> "repeatable$i");
245 $row_data{mandatory
} = CGI
::checkbox
(-name
=> "mandatory$i",
246 -checked
=> $data->{'mandatory'}?
'checked':'',
249 -id
=> "mandatory$i");
250 $row_data{hidden
} = CGI
::escapeHTML
($data->{hidden
}) ;
251 $row_data{isurl
} = CGI
::checkbox
( -name
=> "isurl$i",
253 -checked
=> $data->{'isurl'}?
'checked':'',
257 $row_data{toggle
} = $toggle;
258 push(@loop_data, \
%row_data);
261 # add more_subfields empty lines for add if needed
262 for (my $i=1;$i<=$more_subfields;$i++) {
263 my %row_data; # get a fresh hash for the row data
264 $row_data{'new_subfield'} = 1;
265 $row_data{tab
} = CGI
::scrolling_list
(-name
=>'tab',
268 [ '-1', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ],
287 $row_data{ohidden
} = CGI
::scrolling_list
(-name
=>'ohidden',
289 -values=>['0','1','2'],
290 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
298 $row_data{ihidden
} = CGI
::scrolling_list
(-name
=>'ihidden',
300 -values=>['0','1','2'],
301 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
308 $row_data{ehidden
} = CGI
::scrolling_list
(-name
=>'ehidden',
310 -values=>['0','1','2'],
311 -labels
=> {'0'=>'Show','1'=>'Show Collapsed',
318 $row_data{tagsubfieldinput
} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" />";
319 $row_data{tagsubfield
} = $data->{'tagsubfield'};
320 $row_data{liblibrarian
} = "";
321 $row_data{libopac
} = "";
322 $row_data{seealso
} = "";
323 $row_data{hidden
} = "000";
324 $row_data{repeatable
} = CGI
::checkbox
( -name
=> 'repeatable',
325 -id
=> "repeatable$i",
329 $row_data{mandatory
} = CGI
::checkbox
( -name
=> 'mandatory',
330 -id
=> "mandatory$i",
334 $row_data{isurl
} = CGI
::checkbox
(-name
=> 'isurl',
339 $row_data{kohafield
}= CGI
::scrolling_list
( -name
=>'kohafield',
340 -id
=> "kohafield$i",
341 -values=> \
@kohafields,
346 $row_data{frameworkcode
} = CGI
::scrolling_list
(-name
=>'frameworkcode',
347 -id
=>'frameworkcode',
348 -values=> \
@authtypes,
349 -default=>$data->{'frameworkcode'},
354 $row_data{authorised_value
} = CGI
::scrolling_list
(-name
=>'authorised_value',
355 -id
=> 'authorised_value',
356 -values=> \
@authorised_values,
361 $row_data{value_builder
} = CGI
::scrolling_list
(-name
=>'value_builder',
362 -id
=>'value_builder',
363 -values=> \
@value_builder,
364 -default=>$data->{'value_builder'},
369 $row_data{toggle
} = $toggle;
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 my $dbh = C4
::Context
->dbh;
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 @tagsubfield = $input->param('tagsubfield');
391 my @liblibrarian = $input->param('liblibrarian');
392 my @libopac = $input->param('libopac');
393 my @kohafield = ''.$input->param('kohafield');
394 my @tab = $input->param('tab');
395 my @seealso = $input->param('seealso');
397 my @ohidden = $input->param('ohidden');
398 my @ihidden = $input->param('ihidden');
399 my @ehidden = $input->param('ehidden');
400 my @authorised_values = $input->param('authorised_value');
401 my $authtypecode = $input->param('authtypecode');
402 my @frameworkcodes = $input->param('frameworkcode');
403 my @value_builder =$input->param('value_builder');
404 for (my $i=0; $i<= $#tagsubfield ; $i++) {
405 my $tagfield =$input->param('tagfield');
406 my $tagsubfield =$tagsubfield[$i];
407 $tagsubfield="@" unless $tagsubfield ne '';
408 my $liblibrarian =$liblibrarian[$i];
409 my $libopac =$libopac[$i];
410 my $repeatable =$input->param("repeatable$i")?
1:0;
411 my $mandatory =$input->param("mandatory$i")?
1:0;
412 my $kohafield =$kohafield[$i];
414 my $seealso =$seealso[$i];
415 my $authorised_value =$authorised_values[$i];
416 my $frameworkcode =$frameworkcodes[$i];
417 my $value_builder=$value_builder[$i];
418 my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens;
419 my $isurl = $input->param("isurl$i")?
1:0;
421 unless (C4
::Context
->config('demo') eq 1) {
422 $sth->execute($authtypecode,
442 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
445 # END $OP eq ADD_VALIDATE
446 ################## DELETE_CONFIRM ##################################
447 # called by default form, used to confirm deletion of data in DB
448 } elsif ($op eq 'delete_confirm') {
449 my $dbh = C4
::Context
->dbh;
450 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
451 #FIXME : called with 2 bind variables when 3 are needed
452 $sth->execute($tagfield,$tagsubfield);
453 my $data=$sth->fetchrow_hashref;
455 $template->param(liblibrarian
=> $data->{'liblibrarian'},
456 tagsubfield
=> $data->{'tagsubfield'},
457 delete_link
=> $script_name,
458 tagfield
=>$tagfield,
459 tagsubfield
=> $tagsubfield,
460 authtypecode
=> $authtypecode,
462 # END $OP eq DELETE_CONFIRM
463 ################## DELETE_CONFIRMED ##################################
464 # called by delete_confirm, used to effectively confirm deletion of data in DB
465 } elsif ($op eq 'delete_confirmed') {
466 my $dbh = C4
::Context
->dbh;
467 unless (C4
::Context
->config('demo') eq 1) {
468 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
469 $sth->execute($tagfield,$tagsubfield,$authtypecode);
472 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
474 $template->param(tagfield
=> $tagfield);
475 # END $OP eq DELETE_CONFIRMED
476 ################## DEFAULT ##################################
478 my ($count,$results)=StringSearch
($tagfield,$authtypecode);
481 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
487 my %row_data; # get a fresh hash for the row data
488 $row_data{tagfield
} = $results->[$i]{'tagfield'};
489 $row_data{tagsubfield
} = $results->[$i]{'tagsubfield'};
490 $row_data{liblibrarian
} = $results->[$i]{'liblibrarian'};
491 $row_data{kohafield
} = $results->[$i]{'kohafield'};
492 $row_data{repeatable
} = $results->[$i]{'repeatable'};
493 $row_data{mandatory
} = $results->[$i]{'mandatory'};
494 $row_data{tab
} = $results->[$i]{'tab'};
495 $row_data{seealso
} = $results->[$i]{'seealso'};
496 $row_data{authorised_value
} = $results->[$i]{'authorised_value'};
497 $row_data{authtypecode
} = $results->[$i]{'authtypecode'};
498 $row_data{value_builder
} = $results->[$i]{'value_builder'};
499 $row_data{hidden
} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
500 $row_data{isurl
} = $results->[$i]{'isurl'};
501 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
502 $row_data{toggle
} = $toggle;
503 if ($row_data{tab
} eq -1) {
504 $row_data{subfield_ignored
} = 1;
507 push(@loop_data, \
%row_data);
509 $template->param(loop => \
@loop_data);
510 $template->param(edit_tagfield
=> $tagfield,
511 edit_authtypecode
=> $authtypecode);
514 my $prevpage = $offset-$pagesize;
515 $template->param(prev
=>"<a href=\"$script_name?offset=$prevpage\">");
517 if ($offset+$pagesize<$count) {
518 my $nextpage =$offset+$pagesize;
519 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
521 } #---- END $OP eq DEFAULT
522 output_html_with_http_headers
$input, $cookie, $template->output;