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>.
29 my ($searchstring,$authtypecode)=@_;
30 my $dbh = C4
::Context
->dbh;
31 $searchstring=~ s/\'/\\\'/g;
32 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);
35 my $results = $sth->fetchall_arrayref({});
36 return (scalar(@
$results), $results);
39 sub auth_subfield_structure_exists
{
40 my ($authtypecode, $tagfield, $tagsubfield) = @_;
41 my $dbh = C4
::Context
->dbh;
42 my $sql = "select tagfield from auth_subfield_structure where authtypecode = ? and tagfield = ? and tagsubfield = ?";
43 my $rows = $dbh->selectall_arrayref($sql, {}, $authtypecode, $tagfield, $tagsubfield);
48 my $tagfield = $input->param('tagfield');
49 my $tagsubfield = $input->param('tagsubfield');
50 my $authtypecode = $input->param('authtypecode');
51 my $offset = $input->param('offset') || 0;
52 my $op = $input->param('op') || '';
53 my $script_name = "/cgi-bin/koha/admin/auth_subfields_structure.pl";
55 my ($template, $borrowernumber, $cookie) = get_template_and_user
(
56 { template_name
=> "admin/auth_subfields_structure.tt",
60 flagsrequired
=> { parameters
=> 'parameters_remaining_permissions' },
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 my $dbh = C4
::Context
->dbh;
80 ################## ADD_FORM ##################################
81 # called by default. Used to create form to add or modify a record
82 if ($op eq 'add_form') {
83 # builds kohafield tables
86 my $sth2=$dbh->prepare("SHOW COLUMNS from auth_header");
88 while ((my $field) = $sth2->fetchrow_array) {
89 push @kohafields, "auth_header.".$field;
92 # build authorised value list
93 my $authorised_values = C4
::Koha
::GetAuthorisedValueCategories
;
94 unshift @
$authorised_values, '';
95 push @
$authorised_values, 'branches';
96 push @
$authorised_values, 'itemtypes';
98 # build thesaurus categories list
99 my @authtypes = (sort keys %{C4
::Koha
::getauthtypes
()});
101 # build value_builder list
102 my @value_builder=('');
104 # read value_builder directory.
105 # 2 cases here : on CVS install, $cgidir does not need a /cgi-bin
106 # on a standard install, /cgi-bin need to be added.
107 # test one, then the other
108 my $cgidir = C4
::Context
->config('intranetdir') ."/cgi-bin";
109 unless (opendir(DIR
, "$cgidir/cataloguing/value_builder")) {
110 $cgidir = C4
::Context
->config('intranetdir');
111 opendir(DIR
, "$cgidir/cataloguing/value_builder") || die "can't opendir $cgidir/value_builder: $!";
113 while (my $line = readdir(DIR
)) {
114 if ( $line =~ /\.pl$/ &&
115 $line !~ /EXAMPLE\.pl$/ ) { # documentation purposes
116 push (@value_builder,$line);
119 @value_builder= sort {$a cmp $b} @value_builder;
123 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
124 $sth->execute($tagfield,$authtypecode);
127 while ( my $data = $sth->fetchrow_hashref ) {
128 my %row_data; # get a fresh hash for the row data
129 $row_data{defaultvalue
} = $data->{defaultvalue
};
130 $row_data{tab
} = $data->{tab
};
131 $row_data{ohidden
} = $data->{'hidden'};
132 $row_data{tagsubfield
} = $data->{'tagsubfield'};
133 $row_data{liblibrarian
} = $data->{'liblibrarian'};
134 $row_data{libopac
} = $data->{'libopac'};
135 $row_data{seealso
} = $data->{'seealso'};
136 $row_data{kohafields
} = \
@kohafields;
137 $row_data{kohafield
} = $data->{'kohafield'};
138 $row_data{authorised_values
} = $authorised_values;
139 $row_data{authorised_value
} = $data->{'authorised_value'};
140 $row_data{frameworkcodes
} = \
@authtypes;
141 $row_data{frameworkcode
} = $data->{'frameworkcode'};
142 $row_data{value_builders
} = \
@value_builder;
143 $row_data{value_builder
} = $data->{'value_builder'};
144 $row_data{repeatable
} = $data->{repeatable
};
145 $row_data{mandatory
} = $data->{mandatory
};
146 $row_data{hidden
} = $data->{hidden
};
147 $row_data{isurl
} = $data->{isurl
};
149 push( @loop_data, \
%row_data );
153 # Add a new row for the "New" tab
154 my %row_data; # get a fresh hash for the row data
155 $row_data{'new_subfield'} = 1;
156 $row_data{tab
} = -1; # ignore
157 $row_data{ohidden
} = 0; # show all
158 $row_data{tagsubfield
} = "";
159 $row_data{liblibrarian
} = "";
160 $row_data{libopac
} = "";
161 $row_data{seealso
} = "";
162 $row_data{hidden
} = "000";
163 $row_data{repeatable
} = 0;
164 $row_data{mandatory
} = 0;
165 $row_data{isurl
} = 0;
166 $row_data{kohafields
} = \
@kohafields,
167 $row_data{authorised_values
} = $authorised_values;
168 $row_data{frameworkcodes
} = \
@authtypes;
169 $row_data{value_builders
} = \
@value_builder;
171 push( @loop_data, \
%row_data );
173 $template->param('use_heading_flags_p' => 1);
174 $template->param('heading_edit_subfields_p' => 1);
175 $template->param(action
=> "Edit subfields",
176 tagfield
=> $tagfield,
177 tagfieldinput
=> "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\" />",
179 more_tag
=> $tagfield);
181 # END $OP eq ADD_FORM
182 ################## ADD_VALIDATE ##################################
183 # called by add_form, used to insert/modify data in DB
184 } elsif ($op eq 'add_validate') {
185 $template->param(tagfield
=> "$input->param('tagfield')");
186 # 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)
187 # values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
188 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)
189 values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
190 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=?
191 where authtypecode=? and tagfield=? and tagsubfield=?");
192 my @tagsubfield = $input->param('tagsubfield');
193 my @liblibrarian = $input->param('liblibrarian');
194 my @libopac = $input->param('libopac');
195 my @kohafield = ''.$input->param('kohafield');
196 my @tab = $input->param('tab');
197 my @seealso = $input->param('seealso');
198 my @ohidden = $input->param('ohidden');
199 my @authorised_values = $input->param('authorised_value');
200 my $authtypecode = $input->param('authtypecode');
201 my @frameworkcodes = $input->param('frameworkcode');
202 my @value_builder =$input->param('value_builder');
203 my @defaultvalue = $input->param('defaultvalue');
204 for (my $i=0; $i<= $#tagsubfield ; $i++) {
205 my $tagfield =$input->param('tagfield');
206 my $tagsubfield =$tagsubfield[$i];
207 $tagsubfield="@" unless $tagsubfield ne '';
208 my $liblibrarian =$liblibrarian[$i];
209 my $libopac =$libopac[$i];
210 my $repeatable =$input->param("repeatable$i")?
1:0;
211 my $mandatory =$input->param("mandatory$i")?
1:0;
212 my $kohafield =$kohafield[$i];
214 my $seealso =$seealso[$i];
215 my $authorised_value =$authorised_values[$i];
216 my $frameworkcode =$frameworkcodes[$i];
217 my $value_builder=$value_builder[$i];
218 my $defaultvalue = $defaultvalue[$i];
219 my $hidden = $ohidden[$i]; #collate from 3 hiddens;
220 my $isurl = $input->param("isurl$i")?
1:0;
222 unless (C4
::Context
->config('demo') or C4
::Context
->config('demo') eq 1) {
223 if (auth_subfield_structure_exists
($authtypecode, $tagfield, $tagsubfield)) {
224 $sth_update->execute(
248 $sth_insert->execute(
270 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
273 # END $OP eq ADD_VALIDATE
274 ################## DELETE_CONFIRM ##################################
275 # called by default form, used to confirm deletion of data in DB
276 } elsif ($op eq 'delete_confirm') {
277 my $sth=$dbh->prepare("select * from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
278 $sth->execute($tagfield,$tagsubfield,$authtypecode);
279 my $data=$sth->fetchrow_hashref;
280 $template->param(liblibrarian
=> $data->{'liblibrarian'},
281 tagsubfield
=> $data->{'tagsubfield'},
282 delete_link
=> $script_name,
283 tagfield
=>$tagfield,
284 tagsubfield
=> $tagsubfield,
285 authtypecode
=> $authtypecode,
287 # END $OP eq DELETE_CONFIRM
288 ################## DELETE_CONFIRMED ##################################
289 # called by delete_confirm, used to effectively confirm deletion of data in DB
290 } elsif ($op eq 'delete_confirmed') {
291 unless (C4
::Context
->config('demo') or C4
::Context
->config('demo') eq 1) {
292 my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
293 $sth->execute($tagfield,$tagsubfield,$authtypecode);
295 print $input->redirect("/cgi-bin/koha/admin/auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode");
297 # END $OP eq DELETE_CONFIRMED
298 ################## DEFAULT ##################################
300 my ($count,$results)=string_search
($tagfield,$authtypecode);
302 for (my $i=$offset; $i < ($offset+$pagesize<$count?
$offset+$pagesize:$count); $i++){
303 my %row_data; # get a fresh hash for the row data
304 $row_data{tagfield
} = $results->[$i]{'tagfield'};
305 $row_data{tagsubfield
} = $results->[$i]{'tagsubfield'};
306 $row_data{liblibrarian
} = $results->[$i]{'liblibrarian'};
307 $row_data{kohafield
} = $results->[$i]{'kohafield'};
308 $row_data{repeatable
} = $results->[$i]{'repeatable'};
309 $row_data{mandatory
} = $results->[$i]{'mandatory'};
310 $row_data{tab
} = $results->[$i]{'tab'};
311 $row_data{seealso
} = $results->[$i]{'seealso'};
312 $row_data{authorised_value
} = $results->[$i]{'authorised_value'};
313 $row_data{authtypecode
} = $results->[$i]{'authtypecode'};
314 $row_data{value_builder
} = $results->[$i]{'value_builder'};
315 $row_data{hidden
} = $results->[$i]{'hidden'} if($results->[$i]{'hidden'} gt "000") ;
316 $row_data{isurl
} = $results->[$i]{'isurl'};
317 $row_data{delete} = "$script_name?op=delete_confirm&tagfield=$tagfield&tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
318 if ($row_data{tab
} eq -1) {
319 $row_data{subfield_ignored
} = 1;
322 push(@loop_data, \
%row_data);
324 $template->param(loop => \
@loop_data);
325 $template->param(edit_tagfield
=> $tagfield,
326 edit_authtypecode
=> $authtypecode);
329 my $prevpage = $offset-$pagesize;
330 $template->param(prev
=>"<a href=\"$script_name?offset=$prevpage\">");
332 if ($offset+$pagesize<$count) {
333 my $nextpage =$offset+$pagesize;
334 $template->param(next => "<a href=\"$script_name?offset=$nextpage\">");
336 } #---- END $OP eq DEFAULT
337 output_html_with_http_headers
$input, $cookie, $template->output;