3 #script to administer the systempref table
4 #written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
8 # this script use an $op to know what to do.
9 # if $op is empty or none of the above values,
10 # - the default screen is build (with all records, or filtered datas).
11 # - the user can clic on add, modify or delete record.
13 # - if primkey exists, this is a modification,so we read the $primkey record
14 # - builds the add/modify form
16 # - the user has just send datas, so we create/modify the record
18 # - we show the record having primkey=$primkey and ask for deletion validation form
19 # if $op=delete_confirm
20 # - we delete the record having primkey=$primkey
23 # Copyright 2000-2002 Katipo Communications
25 # This file is part of Koha.
27 # Koha is free software; you can redistribute it and/or modify it under the
28 # terms of the GNU General Public License as published by the Free Software
29 # Foundation; either version 2 of the License, or (at your option) any later
32 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
33 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
34 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
36 # You should have received a copy of the GNU General Public License along with
37 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
38 # Suite 330, Boston, MA 02111-1307 USA
46 use C4::Interface::CGI::Output;
53 my ($env,$searchstring,$type)=@_;
54 my $dbh = C4::Context->dbh;
55 $searchstring=~ s/\'/\\\'/g;
56 my @data=split(' ',$searchstring);
58 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
59 $sth->execute("$data[0]%");
62 while (my $data=$sth->fetchrow_hashref){
67 return ($cnt,\@results);
71 my $searchfield=$input->param('searchfield');
72 my $offset=$input->param('offset');
73 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
75 my ($template, $borrowernumber, $cookie)
76 = get_template_and_user({template_name => "parameters/systempreferences.tmpl",
80 flagsrequired => {parameters => 1},
84 my $op = $input->param('op');
85 $searchfield=~ s/\,//g;
88 $template->param(script_name => $script_name,
89 $op => 1); # we show only the TMPL_VAR names $op
91 $template->param(script_name => $script_name,
92 else => 1); # we show only the TMPL_VAR names $op
95 if ($op eq 'update_and_reedit') {
96 foreach ($input->param) {
99 if (my $currentorder=$input->param('currentorder')) {
100 my @currentorder=split /\|/, $currentorder;
102 foreach my $param ($input->param) {
103 if ($param=~m#up-(\d+).x#) {
104 my $temp=$currentorder[$1];
105 $currentorder[$1]=$currentorder[$1-1];
106 $currentorder[$1-1]=$temp;
109 } elsif ($param=~m#down-(\d+).x#) {
110 my $temp=$currentorder[$1];
111 $currentorder[$1]=$currentorder[$1+1];
112 $currentorder[$1+1]=$temp;
117 $value=join ' ', @currentorder;
120 $template->param(script_name => $script_name,
121 $op => 1); # we show only the TMPL_VAR names $op
125 $template->param(script_name => $script_name,
126 else => 1); # we show only the TMPL_VAR names $op
129 my $dbh = C4::Context->dbh;
130 my $query="select * from systempreferences where variable=?";
131 my $sth=$dbh->prepare($query);
132 $sth->execute($input->param('variable'));
134 unless (C4::Context->config('demo') eq 1) {
135 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
136 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
140 unless (C4::Context->config('demo') eq 1) {
141 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
142 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
150 ################## ADD_FORM ##################################
151 # called by default. Used to create form to add or modify a record
153 if ($op eq 'add_form') {
154 #---- if primkey exists, it's a modify action, so read values to modify...
157 my $dbh = C4::Context->dbh;
158 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
159 $sth->execute($searchfield);
160 $data=$sth->fetchrow_hashref;
162 $template->param(modify => 1);
166 foreach my $option (split(/\|/, $data->{'options'})) {
168 $option eq $data->{'value'} and $selected=1;
169 push @options, { option => $option, selected => $selected };
171 if ($data->{'type'} eq 'Choice') {
172 $template->param('type-choice' => 1);
173 } elsif ($data->{'type'} eq 'YesNo') {
174 $template->param('type-yesno' => 1);
175 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
176 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
177 } elsif ($data->{'type'} eq 'Integer') {
178 $template->param('type-free' => 1);
179 $template->param('fieldlength' => $data->{'options'});
180 } elsif ($data->{'type'} eq 'Textarea') {
181 $template->param('type-textarea' => 1);
182 $data->{options} =~ /(.*)\|(.*)/;
183 $template->param('cols' => $1, 'rows' => $2);;
184 } elsif ($data->{'type'} eq 'Float') {
185 $template->param('type-free' => 1);
186 $template->param('fieldlength' => $data->{'options'});
187 } elsif ($data->{'type'} eq 'Themes') {
188 $template->param('type-choice' => 1);
190 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
192 my $currently_selected_themes;
194 foreach my $theme (split /\s+/, $data->{'value'}) {
195 push @options, { option => $theme, counter => $counter };
196 $currently_selected_themes->{$theme}=1;
199 foreach my $theme (getallthemes($type)) {
201 next if $currently_selected_themes->{$theme};
202 push @options, { option => $theme, counter => $counter };
205 } elsif ($data->{'type'} eq 'Languages') {
206 $template->param('type-choice' => 1);
209 my $currently_selected_languages;
211 foreach my $language (split /\s+/, $data->{'value'}) {
212 next if $language eq 'images';
213 push @options, { option => $language, counter => $counter };
214 $currently_selected_languages->{$language}=1;
217 foreach my $language (getalllanguages()) {
218 next if $language eq 'images';
220 next if $currently_selected_languages->{$language};
221 push @options, { option => $language, counter => $counter };
225 $template->param('type-free' => 1);
226 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
228 $template->param(explanation => $data->{'explanation'},
229 value => $data->{'value'},
230 type => $data->{'type'},
231 options => \@options,
232 preftype => $data->{'type'},
233 prefoptions => $data->{'options'},
234 searchfield => $searchfield);
236 ################## ADD_VALIDATE ##################################
237 # called by add_form, used to insert/modify data in DB
238 } elsif ($op eq 'add_validate') {
239 my $dbh = C4::Context->dbh;
240 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
241 $sth->execute($input->param('variable'));
243 unless (C4::Context->config('demo') eq 1) {
244 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
245 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
249 unless (C4::Context->config('demo') eq 1) {
250 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
251 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
256 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl\"></html>";
258 ################## DELETE_CONFIRM ##################################
259 # called by default form, used to confirm deletion of data in DB
260 } elsif ($op eq 'delete_confirm') {
261 my $dbh = C4::Context->dbh;
262 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
263 $sth->execute($searchfield);
264 my $data=$sth->fetchrow_hashref;
266 $template->param(searchfield => $searchfield,
267 Tvalue => $data->{'value'},
270 # END $OP eq DELETE_CONFIRM
271 ################## DELETE_CONFIRMED ##################################
272 # called by delete_confirm, used to effectively confirm deletion of data in DB
273 } elsif ($op eq 'delete_confirmed') {
274 my $dbh = C4::Context->dbh;
275 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
276 $sth->execute($searchfield);
278 # END $OP eq DELETE_CONFIRMED
279 ################## DEFAULT ##################################
281 if ($searchfield ne '') {
282 $template->param(searchfield => "<p>You Searched for <strong>$searchfield</strong></p>");
285 my ($count,$results)=StringSearch($env,$searchfield,'web');
288 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
289 if ($toggle eq 'white'){
294 my %row_data; # get a fresh hash for the row data
295 $row_data{variable} = $results->[$i]{'variable'};
296 $row_data{value} = $results->[$i]{'value'};
297 $row_data{explanation} = $results->[$i]{'explanation'};
298 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
299 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
300 push(@loop_data, \%row_data);
302 $template->param(loop => \@loop_data);
304 my $prevpage = $offset-$pagesize;
305 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
307 if ($offset+$pagesize<$count) {
308 my $nextpage =$offset+$pagesize;
309 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
311 } #---- END $OP eq DEFAULT
313 output_html_with_http_headers $input, $cookie, $template->output;