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 $tabsysprefs{acquisitions}="Acquisitions";
54 $tabsysprefs{gist}="Acquisitions";
55 $tabsysprefs{authoritysep}="Authorities";
56 $tabsysprefs{ISBD}="Catalogue";
57 $tabsysprefs{marc}="Catalogue";
58 $tabsysprefs{marcflavour}="Catalogue";
59 $tabsysprefs{SubscriptionHistory}="Catalogue";
60 $tabsysprefs{maxoutstanding}="Circulation";
61 $tabsysprefs{printcirculationslips}="Circulation";
62 $tabsysprefs{suggestion}="Circulation";
63 $tabsysprefs{automembernum}="Members";
64 $tabsysprefs{noissuescharge}="Circulation";
65 $tabsysprefs{opacthemes}="OPAC";
66 $tabsysprefs{opaclanguages}="OPAC";
67 $tabsysprefs{LibraryName}="OPAC";
68 $tabsysprefs{opacstylesheet}="OPAC";
69 $tabsysprefs{BiblioDefaultView}="OPAC";
70 $tabsysprefs{hidelostitem}="OPAC";
71 $tabsysprefs{KohaAdmin}="Admin";
72 $tabsysprefs{checkdigit}="Admin";
73 $tabsysprefs{dateformat}="Admin";
74 $tabsysprefs{insecure}="Admin";
75 $tabsysprefs{ldapinfos}="Admin";
76 $tabsysprefs{ldapserver}="Admin";
79 my ($env,$searchstring,$type)=@_;
80 my $dbh = C4::Context->dbh;
81 $searchstring=~ s/\'/\\\'/g;
82 my @data=split(' ',$searchstring);
87 foreach my $syspref (sort keys %tabsysprefs){
88 if ($tabsysprefs{$syspref} eq $type){
89 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
90 $sth->execute($syspref);
91 while (my $data=$sth->fetchrow_hashref){
99 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
100 foreach my $syspref (keys %tabsysprefs){
101 $strsth .= $dbh->quote($syspref).",";
104 $strsth .= " order by variable";
106 my $sth=$dbh->prepare($strsth);
108 while (my $data=$sth->fetchrow_hashref){
109 push(@results,$data);
114 return ($cnt,\@results);
119 my $searchfield=$input->param('searchfield');
120 my $offset=$input->param('offset');
121 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
123 my ($template, $borrowernumber, $cookie)
124 = get_template_and_user({template_name => "parameters/systempreferences.tmpl",
127 authnotrequired => 0,
128 flagsrequired => {parameters => 1},
132 my $op = $input->param('op');
133 $searchfield=~ s/\,//g;
136 $template->param(script_name => $script_name,
137 $op => 1); # we show only the TMPL_VAR names $op
139 $template->param(script_name => $script_name,
140 else => 1); # we show only the TMPL_VAR names $op
143 if ($op eq 'update_and_reedit') {
144 foreach ($input->param) {
147 if (my $currentorder=$input->param('currentorder')) {
148 my @currentorder=split /\|/, $currentorder;
150 foreach my $param ($input->param) {
151 if ($param=~m#up-(\d+).x#) {
152 my $temp=$currentorder[$1];
153 $currentorder[$1]=$currentorder[$1-1];
154 $currentorder[$1-1]=$temp;
157 } elsif ($param=~m#down-(\d+).x#) {
158 my $temp=$currentorder[$1];
159 $currentorder[$1]=$currentorder[$1+1];
160 $currentorder[$1+1]=$temp;
165 $value=join ' ', @currentorder;
168 $template->param(script_name => $script_name,
169 $op => 1); # we show only the TMPL_VAR names $op
173 $template->param(script_name => $script_name,
174 else => 1); # we show only the TMPL_VAR names $op
177 my $dbh = C4::Context->dbh;
178 my $query="select * from systempreferences where variable=?";
179 my $sth=$dbh->prepare($query);
180 $sth->execute($input->param('variable'));
182 unless (C4::Context->config('demo') eq 1) {
183 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
184 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
188 unless (C4::Context->config('demo') eq 1) {
189 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
190 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
198 ################## ADD_FORM ##################################
199 # called by default. Used to create form to add or modify a record
201 if ($op eq 'add_form') {
202 #---- if primkey exists, it's a modify action, so read values to modify...
205 my $dbh = C4::Context->dbh;
206 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
207 $sth->execute($searchfield);
208 $data=$sth->fetchrow_hashref;
210 $template->param(modify => 1);
214 foreach my $option (split(/\|/, $data->{'options'})) {
216 $option eq $data->{'value'} and $selected=1;
217 push @options, { option => $option, selected => $selected };
219 if ($data->{'type'} eq 'Choice') {
220 $template->param('type-choice' => 1);
221 } elsif ($data->{'type'} eq 'YesNo') {
222 $template->param('type-yesno' => 1);
223 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
224 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
225 } elsif ($data->{'type'} eq 'Integer') {
226 $template->param('type-free' => 1);
227 $template->param('fieldlength' => $data->{'options'});
228 } elsif ($data->{'type'} eq 'Textarea') {
229 $template->param('type-textarea' => 1);
230 $data->{options} =~ /(.*)\|(.*)/;
231 $template->param('cols' => $1, 'rows' => $2);;
232 } elsif ($data->{'type'} eq 'Float') {
233 $template->param('type-free' => 1);
234 $template->param('fieldlength' => $data->{'options'});
235 } elsif ($data->{'type'} eq 'Themes') {
236 $template->param('type-choice' => 1);
238 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
240 my $currently_selected_themes;
242 foreach my $theme (split /\s+/, $data->{'value'}) {
243 push @options, { option => $theme, counter => $counter };
244 $currently_selected_themes->{$theme}=1;
247 foreach my $theme (getallthemes($type)) {
249 next if $currently_selected_themes->{$theme};
250 push @options, { option => $theme, counter => $counter };
253 } elsif ($data->{'type'} eq 'Languages') {
254 $template->param('type-choice' => 1);
257 my $currently_selected_languages;
259 foreach my $language (split /\s+/, $data->{'value'}) {
260 next if $language eq 'images';
261 push @options, { option => $language, counter => $counter };
262 $currently_selected_languages->{$language}=1;
265 foreach my $language (getalllanguages()) {
266 next if $language eq 'images';
268 next if $currently_selected_languages->{$language};
269 push @options, { option => $language, counter => $counter };
273 $template->param('type-free' => 1);
274 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
276 $template->param(explanation => $data->{'explanation'},
277 value => $data->{'value'},
278 type => $data->{'type'},
279 options => \@options,
280 preftype => $data->{'type'},
281 prefoptions => $data->{'options'},
282 searchfield => $searchfield);
284 ################## ADD_VALIDATE ##################################
285 # called by add_form, used to insert/modify data in DB
286 } elsif ($op eq 'add_validate') {
287 my $dbh = C4::Context->dbh;
288 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
289 $sth->execute($input->param('variable'));
291 unless (C4::Context->config('demo') eq 1) {
292 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
293 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
297 unless (C4::Context->config('demo') eq 1) {
298 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
299 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
304 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl\"></html>";
306 ################## DELETE_CONFIRM ##################################
307 # called by default form, used to confirm deletion of data in DB
308 } elsif ($op eq 'delete_confirm') {
309 my $dbh = C4::Context->dbh;
310 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
311 $sth->execute($searchfield);
312 my $data=$sth->fetchrow_hashref;
314 $template->param(searchfield => $searchfield,
315 Tvalue => $data->{'value'},
318 # END $OP eq DELETE_CONFIRM
319 ################## DELETE_CONFIRMED ##################################
320 # called by delete_confirm, used to effectively confirm deletion of data in DB
321 } elsif ($op eq 'delete_confirmed') {
322 my $dbh = C4::Context->dbh;
323 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
324 $sth->execute($searchfield);
326 # END $OP eq DELETE_CONFIRMED
327 ################## DEFAULT ##################################
329 #Adding tab management for system preferences
330 my $tab=$input->param('tab');
332 if ($searchfield ne '') {
333 $template->param(searchfield => "<p>You Searched for <strong>$searchfield</strong></p>");
336 my ($count,$results)=StringSearch($env,$searchfield,$tab);
339 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
345 my %row_data; # get a fresh hash for the row data
346 $row_data{variable} = $results->[$i]{'variable'};
347 $row_data{value} = $results->[$i]{'value'};
348 $row_data{explanation} = $results->[$i]{'explanation'};
349 $row_data{toggle} = $toggle;
350 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
351 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
352 push(@loop_data, \%row_data);
354 $template->param(loop => \@loop_data);
356 my $prevpage = $offset-$pagesize;
357 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
359 if ($offset+$pagesize<$count) {
360 my $nextpage =$offset+$pagesize;
361 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
363 } #---- END $OP eq DEFAULT
365 output_html_with_http_headers $input, $cookie, $template->output;