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
;
28 use Koha
::AuthorisedValues
;
30 use List
::MoreUtils
qw( uniq );
33 my ($searchstring,$authtypecode)=@_;
34 my $dbh = C4
::Context
->dbh;
35 $searchstring=~ s/\'/\\\'/g;
36 my @data=split(' ',$searchstring);
37 my $sth=$dbh->prepare("Select * from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield");
38 $sth->execute("$searchstring%",$authtypecode);
39 my $results = $sth->fetchall_arrayref({});
40 return (scalar(@
$results), $results);
43 sub auth_subfield_structure_exists
{
44 my ($authtypecode, $tagfield, $tagsubfield) = @_;
45 my $dbh = C4
::Context
->dbh;
46 my $sql = "select tagfield from auth_subfield_structure where authtypecode = ? and tagfield = ? and tagsubfield = ?";
47 my $rows = $dbh->selectall_arrayref($sql, {}, $authtypecode, $tagfield, $tagsubfield);
52 my $tagfield = $input->param('tagfield');
53 my $tagsubfield = $input->param('tagsubfield');
54 my $authtypecode = $input->param('authtypecode');
55 my $offset = $input->param('offset') || 0;
56 my $op = $input->param('op') || '';
57 my $script_name = "/cgi-bin/koha/admin/auth_subfields_structure.pl";
59 my ($template, $borrowernumber, $cookie) = get_template_and_user
(
60 { template_name
=> "admin/auth_subfields_structure.tt",
64 flagsrequired
=> { parameters
=> 'parameters_remaining_permissions' },
72 $template->param(script_name
=> $script_name,
74 authtypecode
=> $authtypecode,
75 $op => 1); # we show only the TMPL_VAR names $op
77 $template->param(script_name
=> $script_name,
79 authtypecode
=> $authtypecode,
80 else => 1); # we show only the TMPL_VAR names $op
83 my $dbh = C4
::Context
->dbh;
84 ################## ADD_FORM ##################################
85 # called by default. Used to create form to add or modify a record
86 if ($op eq 'add_form') {
87 # builds kohafield tables
90 my $sth2=$dbh->prepare("SHOW COLUMNS from auth_header");
92 while ((my $field) = $sth2->fetchrow_array) {
93 push @kohafields, "auth_header.".$field;
96 # build authorised value category list
97 my @authorised_value_categories = Koha
::AuthorisedValues
->new->categories;
98 unshift @authorised_value_categories, '';
99 push @authorised_value_categories, 'branches';
100 push @authorised_value_categories, 'itemtypes';
102 # build thesaurus categories list
103 my @authtypes = uniq
( "", map { $_->authtypecode } Koha
::Authority
::Types
->search );
105 # build value_builder list
106 my @value_builder=('');
108 # read value_builder directory.
109 # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
110 # on a standard install, /cgi-bin need to be added.
111 # test one, then the other
112 my $cgidir = C4
::Context
->config('intranetdir') ."/cgi-bin";
113 unless (opendir(DIR
, "$cgidir/cataloguing/value_builder")) {
114 $cgidir = C4
::Context
->config('intranetdir');
115 opendir(DIR
, "$cgidir/cataloguing/value_builder") || die "can't opendir $cgidir/value_builder: $!";
117 while (my $line = readdir(DIR
)) {
118 if ( $line =~ /\.pl$/ &&
119 $line !~ /EXAMPLE\.pl$/ ) { # documentation purposes
120 push (@value_builder,$line);
123 @value_builder= sort {$a cmp $b} @value_builder;
127 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
128 $sth->execute($tagfield,$authtypecode);
131 while ( my $data = $sth->fetchrow_hashref ) {
132 my %row_data; # get a fresh hash for the row data
133 $row_data{defaultvalue
} = $data->{defaultvalue
};
134 $row_data{tab
} = $data->{tab
};
135 $row_data{ohidden
} = $data->{'hidden'};
136 $row_data{tagsubfield
} = $data->{'tagsubfield'};
137 $row_data{liblibrarian
} = $data->{'liblibrarian'};
138 $row_data{libopac
} = $data->{'libopac'};
139 $row_data{seealso
} = $data->{'seealso'};
140 $row_data{kohafields
} = \
@kohafields;
141 $row_data{kohafield
} = $data->{'kohafield'};
142 $row_data{authorised_values
} = \
@authorised_value_categories;
143 $row_data{authorised_value
} = $data->{'authorised_value'};
144 $row_data{frameworkcodes
} = \
@authtypes;
145 $row_data{frameworkcode
} = $data->{'frameworkcode'};
146 $row_data{value_builders
} = \
@value_builder;
147 $row_data{value_builder
} = $data->{'value_builder'};
148 $row_data{repeatable
} = $data->{repeatable
};
149 $row_data{mandatory
} = $data->{mandatory
};
150 $row_data{hidden
} = $data->{hidden
};
151 $row_data{isurl
} = $data->{isurl
};
153 push( @loop_data, \
%row_data );
157 # Add a new row for the "New" tab
158 my %row_data; # get a fresh hash for the row data
159 $row_data{'new_subfield'} = 1;
160 $row_data{tab
} = -1; # ignore
161 $row_data{ohidden
} = 0; # show all
162 $row_data{tagsubfield
} = "";
163 $row_data{liblibrarian
} = "";
164 $row_data{libopac
} = "";
165 $row_data{seealso
} = "";
166 $row_data{hidden
} = "000";
167 $row_data{repeatable
} = 0;
168 $row_data{mandatory
} = 0;
169 $row_data{isurl
} = 0;
170 $row_data{kohafields
} = \
@kohafields,
171 $row_data{authorised_values
} = \
@authorised_value_categories;
172 $row_data{frameworkcodes
} = \
@authtypes;
173 $row_data{value_builders
} = \
@value_builder;
175 push( @loop_data, \
%row_data );
177 $template->param('use_heading_flags_p' => 1);
178 $template->param('heading_edit_subfields_p' => 1);
179 $template->param(action
=> "Edit subfields",
180 tagfield
=> $tagfield,
181 tagfieldinput
=> "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
183 more_tag
=> $tagfield);
185 # END $OP eq ADD_FORM
186 ################## ADD_VALIDATE ##################################
187 # called by add_form, used to insert/modify data in DB
188 } elsif ($op eq 'add_validate') {
189 $template->param(tagfield
=> "$input->param('tagfield')");
190 # 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)
191 # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
192 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)
193 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
194 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=?
195 where authtypecode=? and tagfield=? and tagsubfield=?");
196 my @tagsubfield = $input->multi_param('tagsubfield');
197 my @liblibrarian = $input->multi_param('liblibrarian');
198 my @libopac = $input->multi_param('libopac');
199 my @kohafield = ''.$input->param('kohafield');
200 my @tab = $input->multi_param('tab');
201 my @seealso = $input->multi_param('seealso');
202 my @ohidden = $input->multi_param('ohidden');
203 my @authorised_value_categories = $input->multi_param('authorised_value');
204 my $authtypecode = $input->param('authtypecode');
205 my @frameworkcodes = $input->multi_param('frameworkcode');
206 my @value_builder =$input->multi_param('value_builder');
207 my @defaultvalue = $input->multi_param('defaultvalue');
208 for (my $i=0; $i<= $#tagsubfield ; $i++) {
209 my $tagfield =$input->param('tagfield');
210 my $tagsubfield =$tagsubfield[$i];
211 $tagsubfield="@" unless $tagsubfield ne '';
212 my $liblibrarian =$liblibrarian[$i];
213 my $libopac =$libopac[$i];
214 my $repeatable =$input->param("repeatable$i")?
1:0;
215 my $mandatory =$input->param("mandatory$i")?
1:0;
216 my $kohafield =$kohafield[$i];
218 my $seealso =$seealso[$i];
219 my $authorised_value = $authorised_value_categories[$i];
220 my $frameworkcode =$frameworkcodes[$i];
221 my $value_builder=$value_builder[$i];
222 my $defaultvalue = $defaultvalue[$i];
223 my $hidden = $ohidden[$i]; #collate from 3 hiddens;
224 my $isurl = $input->param("isurl$i")?
1:0;
226 unless (C4
::Context
->config('demo') or C4
::Context
->config('demo') eq 1) {
227 if (auth_subfield_structure_exists
($authtypecode, $tagfield, $tagsubfield)) {
228 $sth_update->execute(
252 $sth_insert->execute(
274 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
277 # END $OP eq ADD_VALIDATE
278 ################## DELETE_CONFIRM ##################################
279 # called by default form, used to confirm deletion of data in DB
280 } elsif ($op eq 'delete_confirm') {
281 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
282 $sth->execute($tagfield,$tagsubfield,$authtypecode);
283 my $data=$sth->fetchrow_hashref;
284 $template->param(liblibrarian
=> $data->{'liblibrarian'},
285 tagsubfield
=> $data->{'tagsubfield'},
286 delete_link
=> $script_name,
287 tagfield
=>$tagfield,
288 tagsubfield
=> $tagsubfield,
289 authtypecode
=> $authtypecode,
291 # END $OP eq DELETE_CONFIRM
292 ################## DELETE_CONFIRMED ##################################
293 # called by delete_confirm, used to effectively confirm deletion of data in DB
294 } elsif ($op eq 'delete_confirmed') {
295 unless (C4
::Context
->config('demo') or C4
::Context
->config('demo') eq 1) {
296 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
297 $sth->execute($tagfield,$tagsubfield,$authtypecode);
299 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
301 # END $OP eq DELETE_CONFIRMED
302 ################## DEFAULT ##################################
304 my ($count,$results)=string_search
($tagfield,$authtypecode);
306 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
307 my %row_data; # get a fresh hash for the row data
308 $row_data{tagfield
} = $results->[$i]{'tagfield'};
309 $row_data{tagsubfield
} = $results->[$i]{'tagsubfield'};
310 $row_data{liblibrarian
} = $results->[$i]{'liblibrarian'};
311 $row_data{kohafield
} = $results->[$i]{'kohafield'};
312 $row_data{repeatable
} = $results->[$i]{'repeatable'};
313 $row_data{mandatory
} = $results->[$i]{'mandatory'};
314 $row_data{tab
} = $results->[$i]{'tab'};
315 $row_data{seealso
} = $results->[$i]{'seealso'};
316 $row_data{authorised_value
} = $results->[$i]{'authorised_value'};
317 $row_data{authtypecode
} = $results->[$i]{'authtypecode'};
318 $row_data{value_builder
} = $results->[$i]{'value_builder'};
319 $row_data{hidden
} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
320 $row_data{isurl
} = $results->[$i]{'isurl'};
321 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
322 if ($row_data{tab
} eq -1) {
323 $row_data{subfield_ignored
} = 1;
326 push(@loop_data, \
%row_data);
328 $template->param(loop => \
@loop_data);
329 $template->param(edit_tagfield
=> $tagfield,
330 edit_authtypecode
=> $authtypecode);
333 my $prevpage = $offset-$pagesize;
334 $template->param(prev
=>"<a href=\"$script_name?offset=$prevpage\">");
336 if ($offset+$pagesize<$count) {
337 my $nextpage =$offset+$pagesize;
338 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
340 } #---- END $OP eq DEFAULT
341 output_html_with_http_headers
$input, $cookie, $template->output;