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
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
21 #use warnings; FIXME - Bug 2505
30 my ($searchstring,$authtypecode)=@_;
31 my $dbh = C4
::Context
->dbh;
32 $searchstring=~ s/\'/\\\'/g;
33 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);
36 my $results = $sth->fetchall_arrayref({});
37 return (scalar(@
$results), $results);
40 sub auth_subfield_structure_exists
{
41 my ($authtypecode, $tagfield, $tagsubfield) = @_;
42 my $dbh = C4
::Context
->dbh;
43 my $sql = "select tagfield from auth_subfield_structure where authtypecode = ? and tagfield = ? and tagsubfield = ?";
44 my $rows = $dbh->selectall_arrayref($sql, {}, $authtypecode, $tagfield, $tagsubfield);
49 my $tagfield = $input->param('tagfield');
50 my $tagsubfield = $input->param('tagsubfield');
51 my $authtypecode = $input->param('authtypecode');
52 my $offset = $input->param('offset');
53 my $op = $input->param('op') || '';
54 my $script_name = "/cgi-bin/koha/admin/auth_subfields_structure.pl";
56 my ($template, $borrowernumber, $cookie) = get_template_and_user
(
57 { template_name
=> "admin/auth_subfields_structure.tt",
61 flagsrequired
=> { parameters
=> 'parameters_remaining_permissions' },
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 my $dbh = C4
::Context
->dbh;
81 ################## ADD_FORM ##################################
82 # called by default. Used to create form to add or modify a record
83 if ($op eq 'add_form') {
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
96 my $authorised_values = C4
::Koha
::GetAuthorisedValueCategories
;
97 unshift @
$authorised_values, '';
98 push @
$authorised_values, 'branches';
99 push @
$authorised_values, 'itemtypes';
101 # build thesaurus categories list
102 my @authtypes = (sort keys %{C4
::Koha
::getauthtypes
()});
104 # build value_builder list
105 my @value_builder=('');
107 # read value_builder directory.
108 # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
109 # on a standard install, /cgi-bin need to be added.
110 # test one, then the other
111 my $cgidir = C4
::Context
->config('intranetdir') ."/cgi-bin";
112 unless (opendir(DIR
, "$cgidir/cataloguing/value_builder")) {
113 $cgidir = C4
::Context
->config('intranetdir');
114 opendir(DIR
, "$cgidir/cataloguing/value_builder") || die "can't opendir $cgidir/value_builder: $!";
116 while (my $line = readdir(DIR
)) {
117 if ( $line =~ /\.pl$/ &&
118 $line !~ /EXAMPLE\.pl$/ ) { # documentation purposes
119 push (@value_builder,$line);
122 @value_builder= sort {$a cmp $b} @value_builder;
126 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
127 $sth->execute($tagfield,$authtypecode);
130 while ($data =$sth->fetchrow_hashref) {
132 my %row_data; # get a fresh hash for the row data
133 $row_data{defaultvalue
} = $data->{defaultvalue
};
136 default => $data->{'tab'},
138 $row_data{ohidden
} = {
140 default => $data->{'hidden'}
142 $row_data{tagsubfieldinput
} = "<input type=\"hidden\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" id=\"tagsubfield\" />";
143 $row_data{tagsubfield
} = $data->{'tagsubfield'};
144 $row_data{liblibrarian
} = CGI
::escapeHTML
($data->{'liblibrarian'});
145 $row_data{libopac
} = CGI
::escapeHTML
($data->{'libopac'});
146 $row_data{seealso
} = CGI
::escapeHTML
($data->{'seealso'});
147 $row_data{kohafield
} = {
149 values => \
@kohafields,
150 default => "$data->{'kohafield'}",
152 $row_data{authorised_value
} = {
153 id
=> "authorised_value$i",
154 values => $authorised_values,
155 default => $data->{'authorised_value'},
157 $row_data{frameworkcode
} = {
158 id
=> "frameworkcode$i",
159 values => \
@authtypes,
160 default => $data->{'frameworkcode'},
162 $row_data{value_builder
} = {
163 id
=> "value_builder$i",
164 values => \
@value_builder,
165 default => $data->{'value_builder'},
168 $row_data{repeatable
} = CGI
::checkbox
(-name
=>"repeatable$i",
169 -checked
=> $data->{'repeatable'}?
'checked':'',
172 -id
=> "repeatable$i");
173 $row_data{mandatory
} = CGI
::checkbox
(-name
=> "mandatory$i",
174 -checked
=> $data->{'mandatory'}?
'checked':'',
177 -id
=> "mandatory$i");
178 $row_data{hidden
} = CGI
::escapeHTML
($data->{hidden
}) ;
179 $row_data{isurl
} = CGI
::checkbox
( -name
=> "isurl$i",
181 -checked
=> $data->{'isurl'}?
'checked':'',
185 push(@loop_data, \
%row_data);
188 # add more_subfields empty lines for add if needed
189 for (my $i=1;$i<=$more_subfields;$i++) {
190 my %row_data; # get a fresh hash for the row data
191 $row_data{'new_subfield'} = 1;
194 default => $data->{'tab'},
196 $row_data{ohidden
} = {
198 default => $data->{'hidden'}
201 $row_data{tagsubfieldinput
} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" />";
202 $row_data{tagsubfieldinput
} =
203 "<label><input type=\"text\" name=\"tagsubfield\" value=\""
204 . $data->{'tagsubfield'}
205 . "\" size=\"1\" id=\"tagsubfield\" maxlength=\"1\" /></label>";
206 $row_data{tagsubfield
} = $data->{'tagsubfield'};
207 $row_data{liblibrarian
} = "";
208 $row_data{libopac
} = "";
209 $row_data{seealso
} = "";
210 $row_data{hidden
} = "000";
211 $row_data{repeatable
} = CGI
::checkbox
( -name
=> 'repeatable',
212 -id
=> "repeatable$i",
216 $row_data{mandatory
} = CGI
::checkbox
( -name
=> 'mandatory',
217 -id
=> "mandatory$i",
221 $row_data{isurl
} = CGI
::checkbox
(-name
=> 'isurl',
226 $row_data{kohafield
} = {
228 values => \
@kohafields,
231 $row_data{authorised_value
} = {
232 id
=> "authorised_value",
233 values => $authorised_values,
236 $row_data{frameworkcode
} = {
237 id
=> "frameworkcode",
238 values => \
@authtypes,
239 default => $data->{'frameworkcode'},
241 $row_data{value_builder
} = {
242 id
=> "value_builder",
243 values => \
@value_builder,
244 default => $data->{'value_builder'},
248 push(@loop_data, \
%row_data);
250 $template->param('use_heading_flags_p' => 1);
251 $template->param('heading_edit_subfields_p' => 1);
252 $template->param(action
=> "Edit subfields",
253 tagfield
=> $tagfield,
254 tagfieldinput
=> "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
256 more_subfields
=> $more_subfields,
257 more_tag
=> $tagfield);
259 # END $OP eq ADD_FORM
260 ################## ADD_VALIDATE ##################################
261 # called by add_form, used to insert/modify data in DB
262 } elsif ($op eq 'add_validate') {
263 $template->param(tagfield
=> "$input->param('tagfield')");
264 # 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)
265 # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
266 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)
267 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
268 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=?
269 where authtypecode=? and tagfield=? and tagsubfield=?");
270 my @tagsubfield = $input->param('tagsubfield');
271 my @liblibrarian = $input->param('liblibrarian');
272 my @libopac = $input->param('libopac');
273 my @kohafield = ''.$input->param('kohafield');
274 my @tab = $input->param('tab');
275 my @seealso = $input->param('seealso');
277 my @ohidden = $input->param('ohidden');
278 #my @ihidden = $input->param('ihidden');
279 #my @ehidden = $input->param('ehidden');
280 my @authorised_values = $input->param('authorised_value');
281 my $authtypecode = $input->param('authtypecode');
282 my @frameworkcodes = $input->param('frameworkcode');
283 my @value_builder =$input->param('value_builder');
284 my @defaultvalue = $input->param('defaultvalue');
285 for (my $i=0; $i<= $#tagsubfield ; $i++) {
286 my $tagfield =$input->param('tagfield');
287 my $tagsubfield =$tagsubfield[$i];
288 $tagsubfield="@" unless $tagsubfield ne '';
289 my $liblibrarian =$liblibrarian[$i];
290 my $libopac =$libopac[$i];
291 my $repeatable =$input->param("repeatable$i")?
1:0;
292 my $mandatory =$input->param("mandatory$i")?
1:0;
293 my $kohafield =$kohafield[$i];
295 my $seealso =$seealso[$i];
296 my $authorised_value =$authorised_values[$i];
297 my $frameworkcode =$frameworkcodes[$i];
298 my $value_builder=$value_builder[$i];
299 my $defaultvalue = $defaultvalue[$i];
300 #my $hidden = $ohidden[$i].$ihidden[$i].$ehidden[$i]; #collate from 3 hiddens;
301 my $hidden = $ohidden[$i]; #collate from 3 hiddens;
302 my $isurl = $input->param("isurl$i")?
1:0;
304 unless (C4
::Context
->config('demo') eq 1) {
305 if (auth_subfield_structure_exists
($authtypecode, $tagfield, $tagsubfield)) {
306 $sth_update->execute(
330 $sth_insert->execute(
352 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
355 # END $OP eq ADD_VALIDATE
356 ################## DELETE_CONFIRM ##################################
357 # called by default form, used to confirm deletion of data in DB
358 } elsif ($op eq 'delete_confirm') {
359 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
360 $sth->execute($tagfield,$tagsubfield,$authtypecode);
361 my $data=$sth->fetchrow_hashref;
362 $template->param(liblibrarian
=> $data->{'liblibrarian'},
363 tagsubfield
=> $data->{'tagsubfield'},
364 delete_link
=> $script_name,
365 tagfield
=>$tagfield,
366 tagsubfield
=> $tagsubfield,
367 authtypecode
=> $authtypecode,
369 # END $OP eq DELETE_CONFIRM
370 ################## DELETE_CONFIRMED ##################################
371 # called by delete_confirm, used to effectively confirm deletion of data in DB
372 } elsif ($op eq 'delete_confirmed') {
373 unless (C4
::Context
->config('demo') eq 1) {
374 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
375 $sth->execute($tagfield,$tagsubfield,$authtypecode);
377 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
379 # END $OP eq DELETE_CONFIRMED
380 ################## DEFAULT ##################################
382 my ($count,$results)=string_search
($tagfield,$authtypecode);
384 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
385 my %row_data; # get a fresh hash for the row data
386 $row_data{tagfield
} = $results->[$i]{'tagfield'};
387 $row_data{tagsubfield
} = $results->[$i]{'tagsubfield'};
388 $row_data{liblibrarian
} = $results->[$i]{'liblibrarian'};
389 $row_data{kohafield
} = $results->[$i]{'kohafield'};
390 $row_data{repeatable
} = $results->[$i]{'repeatable'};
391 $row_data{mandatory
} = $results->[$i]{'mandatory'};
392 $row_data{tab
} = $results->[$i]{'tab'};
393 $row_data{seealso
} = $results->[$i]{'seealso'};
394 $row_data{authorised_value
} = $results->[$i]{'authorised_value'};
395 $row_data{authtypecode
} = $results->[$i]{'authtypecode'};
396 $row_data{value_builder
} = $results->[$i]{'value_builder'};
397 $row_data{hidden
} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
398 $row_data{isurl
} = $results->[$i]{'isurl'};
399 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
400 if ($row_data{tab
} eq -1) {
401 $row_data{subfield_ignored
} = 1;
404 push(@loop_data, \
%row_data);
406 $template->param(loop => \
@loop_data);
407 $template->param(edit_tagfield
=> $tagfield,
408 edit_authtypecode
=> $authtypecode);
411 my $prevpage = $offset-$pagesize;
412 $template->param(prev
=>"<a href=\"$script_name?offset=$prevpage\">");
414 if ($offset+$pagesize<$count) {
415 my $nextpage =$offset+$pagesize;
416 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
418 } #---- END $OP eq DEFAULT
419 output_html_with_http_headers
$input, $cookie, $template->output;