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>.
27 use Koha
::Authority
::Types
;
29 use List
::MoreUtils
qw( uniq );
32 my ($searchstring,$authtypecode)=@_;
33 my $dbh = C4
::Context
->dbh;
34 $searchstring=~ s/\'/\\\'/g;
35 my @data=split(' ',$searchstring);
36 my $sth=$dbh->prepare("Select * from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield");
37 $sth->execute("$searchstring%",$authtypecode);
38 my $results = $sth->fetchall_arrayref({});
39 return (scalar(@
$results), $results);
42 sub auth_subfield_structure_exists
{
43 my ($authtypecode, $tagfield, $tagsubfield) = @_;
44 my $dbh = C4
::Context
->dbh;
45 my $sql = "select tagfield from auth_subfield_structure where authtypecode = ? and tagfield = ? and tagsubfield = ?";
46 my $rows = $dbh->selectall_arrayref($sql, {}, $authtypecode, $tagfield, $tagsubfield);
51 my $tagfield = $input->param('tagfield');
52 my $tagsubfield = $input->param('tagsubfield');
53 my $authtypecode = $input->param('authtypecode');
54 my $offset = $input->param('offset') || 0;
55 my $op = $input->param('op') || '';
56 my $script_name = "/cgi-bin/koha/admin/auth_subfields_structure.pl";
58 my ($template, $borrowernumber, $cookie) = get_template_and_user
(
59 { template_name
=> "admin/auth_subfields_structure.tt",
63 flagsrequired
=> { parameters
=> 'parameters_remaining_permissions' },
71 $template->param(script_name
=> $script_name,
73 authtypecode
=> $authtypecode,
74 $op => 1); # we show only the TMPL_VAR names $op
76 $template->param(script_name
=> $script_name,
78 authtypecode
=> $authtypecode,
79 else => 1); # we show only the TMPL_VAR names $op
82 my $dbh = C4
::Context
->dbh;
83 ################## ADD_FORM ##################################
84 # called by default. Used to create form to add or modify a record
85 if ($op eq 'add_form') {
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 = uniq
( "", map { $_->authtypecode } Koha
::Authority
::Types
->search );
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 ( my $data = $sth->fetchrow_hashref ) {
131 my %row_data; # get a fresh hash for the row data
132 $row_data{defaultvalue
} = $data->{defaultvalue
};
133 $row_data{tab
} = $data->{tab
};
134 $row_data{ohidden
} = $data->{'hidden'};
135 $row_data{tagsubfield
} = $data->{'tagsubfield'};
136 $row_data{liblibrarian
} = $data->{'liblibrarian'};
137 $row_data{libopac
} = $data->{'libopac'};
138 $row_data{seealso
} = $data->{'seealso'};
139 $row_data{kohafields
} = \
@kohafields;
140 $row_data{kohafield
} = $data->{'kohafield'};
141 $row_data{authorised_values
} = $authorised_values;
142 $row_data{authorised_value
} = $data->{'authorised_value'};
143 $row_data{frameworkcodes
} = \
@authtypes;
144 $row_data{frameworkcode
} = $data->{'frameworkcode'};
145 $row_data{value_builders
} = \
@value_builder;
146 $row_data{value_builder
} = $data->{'value_builder'};
147 $row_data{repeatable
} = $data->{repeatable
};
148 $row_data{mandatory
} = $data->{mandatory
};
149 $row_data{hidden
} = $data->{hidden
};
150 $row_data{isurl
} = $data->{isurl
};
152 push( @loop_data, \
%row_data );
156 # Add a new row for the "New" tab
157 my %row_data; # get a fresh hash for the row data
158 $row_data{'new_subfield'} = 1;
159 $row_data{tab
} = -1; # ignore
160 $row_data{ohidden
} = 0; # show all
161 $row_data{tagsubfield
} = "";
162 $row_data{liblibrarian
} = "";
163 $row_data{libopac
} = "";
164 $row_data{seealso
} = "";
165 $row_data{hidden
} = "000";
166 $row_data{repeatable
} = 0;
167 $row_data{mandatory
} = 0;
168 $row_data{isurl
} = 0;
169 $row_data{kohafields
} = \
@kohafields,
170 $row_data{authorised_values
} = $authorised_values;
171 $row_data{frameworkcodes
} = \
@authtypes;
172 $row_data{value_builders
} = \
@value_builder;
174 push( @loop_data, \
%row_data );
176 $template->param('use_heading_flags_p' => 1);
177 $template->param('heading_edit_subfields_p' => 1);
178 $template->param(action
=> "Edit subfields",
179 tagfield
=> $tagfield,
180 tagfieldinput
=> "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
182 more_tag
=> $tagfield);
184 # END $OP eq ADD_FORM
185 ################## ADD_VALIDATE ##################################
186 # called by add_form, used to insert/modify data in DB
187 } elsif ($op eq 'add_validate') {
188 $template->param(tagfield
=> "$input->param('tagfield')");
189 # 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)
190 # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
191 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)
192 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
193 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=?
194 where authtypecode=? and tagfield=? and tagsubfield=?");
195 my @tagsubfield = $input->multi_param('tagsubfield');
196 my @liblibrarian = $input->multi_param('liblibrarian');
197 my @libopac = $input->multi_param('libopac');
198 my @kohafield = ''.$input->param('kohafield');
199 my @tab = $input->multi_param('tab');
200 my @seealso = $input->multi_param('seealso');
201 my @ohidden = $input->multi_param('ohidden');
202 my @authorised_values = $input->multi_param('authorised_value');
203 my $authtypecode = $input->param('authtypecode');
204 my @frameworkcodes = $input->multi_param('frameworkcode');
205 my @value_builder =$input->multi_param('value_builder');
206 my @defaultvalue = $input->multi_param('defaultvalue');
207 for (my $i=0; $i<= $#tagsubfield ; $i++) {
208 my $tagfield =$input->param('tagfield');
209 my $tagsubfield =$tagsubfield[$i];
210 $tagsubfield="@" unless $tagsubfield ne '';
211 my $liblibrarian =$liblibrarian[$i];
212 my $libopac =$libopac[$i];
213 my $repeatable =$input->param("repeatable$i")?
1:0;
214 my $mandatory =$input->param("mandatory$i")?
1:0;
215 my $kohafield =$kohafield[$i];
217 my $seealso =$seealso[$i];
218 my $authorised_value =$authorised_values[$i];
219 my $frameworkcode =$frameworkcodes[$i];
220 my $value_builder=$value_builder[$i];
221 my $defaultvalue = $defaultvalue[$i];
222 my $hidden = $ohidden[$i]; #collate from 3 hiddens;
223 my $isurl = $input->param("isurl$i")?
1:0;
225 unless (C4
::Context
->config('demo') or C4
::Context
->config('demo') eq 1) {
226 if (auth_subfield_structure_exists
($authtypecode, $tagfield, $tagsubfield)) {
227 $sth_update->execute(
251 $sth_insert->execute(
273 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
276 # END $OP eq ADD_VALIDATE
277 ################## DELETE_CONFIRM ##################################
278 # called by default form, used to confirm deletion of data in DB
279 } elsif ($op eq 'delete_confirm') {
280 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
281 $sth->execute($tagfield,$tagsubfield,$authtypecode);
282 my $data=$sth->fetchrow_hashref;
283 $template->param(liblibrarian
=> $data->{'liblibrarian'},
284 tagsubfield
=> $data->{'tagsubfield'},
285 delete_link
=> $script_name,
286 tagfield
=>$tagfield,
287 tagsubfield
=> $tagsubfield,
288 authtypecode
=> $authtypecode,
290 # END $OP eq DELETE_CONFIRM
291 ################## DELETE_CONFIRMED ##################################
292 # called by delete_confirm, used to effectively confirm deletion of data in DB
293 } elsif ($op eq 'delete_confirmed') {
294 unless (C4
::Context
->config('demo') or C4
::Context
->config('demo') eq 1) {
295 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
296 $sth->execute($tagfield,$tagsubfield,$authtypecode);
298 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
300 # END $OP eq DELETE_CONFIRMED
301 ################## DEFAULT ##################################
303 my ($count,$results)=string_search
($tagfield,$authtypecode);
305 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
306 my %row_data; # get a fresh hash for the row data
307 $row_data{tagfield
} = $results->[$i]{'tagfield'};
308 $row_data{tagsubfield
} = $results->[$i]{'tagsubfield'};
309 $row_data{liblibrarian
} = $results->[$i]{'liblibrarian'};
310 $row_data{kohafield
} = $results->[$i]{'kohafield'};
311 $row_data{repeatable
} = $results->[$i]{'repeatable'};
312 $row_data{mandatory
} = $results->[$i]{'mandatory'};
313 $row_data{tab
} = $results->[$i]{'tab'};
314 $row_data{seealso
} = $results->[$i]{'seealso'};
315 $row_data{authorised_value
} = $results->[$i]{'authorised_value'};
316 $row_data{authtypecode
} = $results->[$i]{'authtypecode'};
317 $row_data{value_builder
} = $results->[$i]{'value_builder'};
318 $row_data{hidden
} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
319 $row_data{isurl
} = $results->[$i]{'isurl'};
320 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
321 if ($row_data{tab
} eq -1) {
322 $row_data{subfield_ignored
} = 1;
325 push(@loop_data, \
%row_data);
327 $template->param(loop => \
@loop_data);
328 $template->param(edit_tagfield
=> $tagfield,
329 edit_authtypecode
=> $authtypecode);
332 my $prevpage = $offset-$pagesize;
333 $template->param(prev
=>"<a href=\"$script_name?offset=$prevpage\">");
335 if ($offset+$pagesize<$count) {
336 my $nextpage =$offset+$pagesize;
337 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
339 } #---- END $OP eq DEFAULT
340 output_html_with_http_headers
$input, $cookie, $template->output;