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
45 use C4::Interface::CGI::Output;
52 my ($env,$searchstring,$type)=@_;
53 my $dbh = C4::Context->dbh;
54 $searchstring=~ s/\'/\\\'/g;
55 my @data=split(' ',$searchstring);
57 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
58 $sth->execute("$data[0]%");
61 while (my $data=$sth->fetchrow_hashref){
66 return ($cnt,\@results);
70 my $searchfield=$input->param('searchfield');
71 my $offset=$input->param('offset');
72 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
74 my ($template, $borrowernumber, $cookie)
75 = get_template_and_user({template_name => "parameters/systempreferences.tmpl",
79 flagsrequired => {parameters => 1},
83 my $op = $input->param('op');
84 $searchfield=~ s/\,//g;
87 $template->param(script_name => $script_name,
88 $op => 1); # we show only the TMPL_VAR names $op
90 $template->param(script_name => $script_name,
91 else => 1); # we show only the TMPL_VAR names $op
94 if ($op eq 'update_and_reedit') {
95 foreach ($input->param) {
98 if (my $currentorder=$input->param('currentorder')) {
99 my @currentorder=split /\|/, $currentorder;
101 foreach my $param ($input->param) {
102 if ($param=~m#up-(\d+).x#) {
103 my $temp=$currentorder[$1];
104 $currentorder[$1]=$currentorder[$1-1];
105 $currentorder[$1-1]=$temp;
108 } elsif ($param=~m#down-(\d+).x#) {
109 my $temp=$currentorder[$1];
110 $currentorder[$1]=$currentorder[$1+1];
111 $currentorder[$1+1]=$temp;
116 $value=join ' ', @currentorder;
119 $template->param(script_name => $script_name,
120 $op => 1); # we show only the TMPL_VAR names $op
124 $template->param(script_name => $script_name,
125 else => 1); # we show only the TMPL_VAR names $op
128 my $dbh = C4::Context->dbh;
129 my $query="select * from systempreferences where variable=?";
130 my $sth=$dbh->prepare($query);
131 $sth->execute($input->param('variable'));
133 unless (C4::Context->config('demo') eq 1) {
134 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=? where variable=?");
135 $sth->execute($value, $input->param('explanation'), $input->param('variable'));
139 unless (C4::Context->config('demo') eq 1) {
140 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?)");
141 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'));
149 ################## ADD_FORM ##################################
150 # called by default. Used to create form to add or modify a record
152 if ($op eq 'add_form') {
153 #---- if primkey exists, it's a modify action, so read values to modify...
156 my $dbh = C4::Context->dbh;
157 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
158 $sth->execute($searchfield);
159 $data=$sth->fetchrow_hashref;
161 $template->param(modify => 1);
165 foreach my $option (split(/\|/, $data->{'options'})) {
167 $option eq $data->{'value'} and $selected=1;
168 push @options, { option => $option, selected => $selected };
170 if ($data->{'type'} eq 'Choice') {
171 $template->param('type-choice' => 1);
172 } elsif ($data->{'type'} eq 'YesNo') {
173 $template->param('type-yesno' => 1);
174 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
175 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
176 } elsif ($data->{'type'} eq 'free') {
177 $template->param('type-free' => 1);
178 $template->param('fieldlength' => $data->{'options'});
179 } elsif ($data->{'type'} eq 'Integer') {
180 $template->param('type-free' => 1);
181 $template->param('fieldlength' => $data->{'options'});
182 } elsif ($data->{'type'} eq 'Float') {
183 $template->param('type-free' => 1);
184 $template->param('fieldlength' => $data->{'options'});
185 } elsif ($data->{'type'} eq 'Themes') {
186 $template->param('type-reorderlist' => 1);
188 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
190 my $currently_selected_themes;
192 foreach my $theme (split /\s+/, $data->{'value'}) {
193 push @options, { option => $theme, counter => $counter };
194 $currently_selected_themes->{$theme}=1;
197 foreach my $theme (getallthemes($type)) {
199 next if $currently_selected_themes->{$theme};
200 push @options, { option => $theme, counter => $counter };
203 } elsif ($data->{'type'} eq 'Languages') {
204 $template->param('type-reorderlist' => 1);
207 my $currently_selected_languages;
209 foreach my $language (split /\s+/, $data->{'value'}) {
210 next if $language eq 'images';
211 push @options, { option => $language, counter => $counter };
212 $currently_selected_languages->{$language}=1;
215 foreach my $language (getalllanguages()) {
216 next if $language eq 'images';
218 next if $currently_selected_languages->{$language};
219 push @options, { option => $language, counter => $counter };
223 $template->param(explanation => $data->{'explanation'},
224 value => $data->{'value'},
225 type => $data->{'type'},
226 options => \@options,
227 searchfield => $searchfield);
229 ################## ADD_VALIDATE ##################################
230 # called by add_form, used to insert/modify data in DB
231 } elsif ($op eq 'add_validate') {
232 my $dbh = C4::Context->dbh;
233 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
234 $sth->execute($input->param('variable'));
236 unless (C4::Context->config('demo') eq 1) {
237 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=? where variable=?");
238 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('variable'));
242 unless (C4::Context->config('demo') eq 1) {
243 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?)");
244 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'));
249 ################## DELETE_CONFIRM ##################################
250 # called by default form, used to confirm deletion of data in DB
251 } elsif ($op eq 'delete_confirm') {
252 my $dbh = C4::Context->dbh;
253 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
254 $sth->execute($searchfield);
255 my $data=$sth->fetchrow_hashref;
257 $template->param(searchfield => $searchfield,
258 Tvalue => $data->{'value'},
261 # END $OP eq DELETE_CONFIRM
262 ################## DELETE_CONFIRMED ##################################
263 # called by delete_confirm, used to effectively confirm deletion of data in DB
264 } elsif ($op eq 'delete_confirmed') {
265 my $dbh = C4::Context->dbh;
266 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
267 $sth->execute($searchfield);
269 # END $OP eq DELETE_CONFIRMED
270 ################## DEFAULT ##################################
272 if ($searchfield ne '') {
273 $template->param(searchfield => "<p>You Searched for <strong>$searchfield</strong></p>");
276 my ($count,$results)=StringSearch($env,$searchfield,'web');
279 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
280 if ($toggle eq 'white'){
285 my %row_data; # get a fresh hash for the row data
286 $row_data{variable} = $results->[$i]{'variable'};
287 $row_data{value} = $results->[$i]{'value'};
288 $row_data{explanation} = $results->[$i]{'explanation'};
289 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
290 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
291 push(@loop_data, \%row_data);
293 $template->param(loop => \@loop_data);
295 my $prevpage = $offset-$pagesize;
296 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
298 if ($offset+$pagesize<$count) {
299 my $nextpage =$offset+$pagesize;
300 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
302 } #---- END $OP eq DEFAULT
304 output_html_with_http_headers $input, $cookie, $template->output;