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;
52 $tabsysprefs{acquisitions}="Acquisitions";
53 $tabsysprefs{gist}="Acquisitions";
54 $tabsysprefs{authoritysep}="Authorities";
55 $tabsysprefs{ISBD}="Catalogue";
56 $tabsysprefs{marc}="Catalogue";
57 $tabsysprefs{marcflavour}="Catalogue";
58 $tabsysprefs{SubscriptionHistory}="Catalogue";
59 $tabsysprefs{maxoutstanding}="Circulation";
60 $tabsysprefs{printcirculationslips}="Circulation";
61 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
62 $tabsysprefs{suggestion}="Acquisitions";
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";
77 $tabsysprefs{itemcallnumber}="Catalogue";
78 $tabsysprefs{maxreserves}="Circulation";
79 $tabsysprefs{virtualshelves}="OPAC";
82 $tabsysprefs{acquisitions}="Acquisitions";
83 $tabsysprefs{gist}="Acquisitions";
84 $tabsysprefs{authoritysep}="Authorities";
85 $tabsysprefs{ISBD}="Catalogue";
86 $tabsysprefs{marc}="Catalogue";
87 $tabsysprefs{marcflavour}="Catalogue";
88 $tabsysprefs{SubscriptionHistory}="Catalogue";
89 $tabsysprefs{maxoutstanding}="Circulation";
90 $tabsysprefs{printcirculationslips}="Circulation";
91 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
92 $tabsysprefs{suggestion}="Acquisitions";
93 $tabsysprefs{automembernum}="Members";
94 $tabsysprefs{noissuescharge}="Circulation";
95 $tabsysprefs{opacthemes}="OPAC";
96 $tabsysprefs{opaclanguages}="OPAC";
97 $tabsysprefs{LibraryName}="OPAC";
98 $tabsysprefs{opacstylesheet}="OPAC";
99 $tabsysprefs{BiblioDefaultView}="OPAC";
100 $tabsysprefs{hidelostitem}="OPAC";
101 $tabsysprefs{KohaAdmin}="Admin";
102 $tabsysprefs{checkdigit}="Admin";
103 $tabsysprefs{dateformat}="Admin";
104 $tabsysprefs{insecure}="Admin";
105 $tabsysprefs{ldapinfos}="Admin";
106 $tabsysprefs{ldapserver}="Admin";
107 $tabsysprefs{itemcallnumber}="Catalogue";
108 $tabsysprefs{maxreserves}="Circulation";
109 $tabsysprefs{virtualshelves}="OPAC";
112 my ($env,$searchstring,$type)=@_;
113 my $dbh = C4::Context->dbh;
114 $searchstring=~ s/\'/\\\'/g;
115 my @data=split(' ',$searchstring);
120 foreach my $syspref (sort keys %tabsysprefs){
121 if ($tabsysprefs{$syspref} eq $type){
122 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
123 $sth->execute($syspref);
124 while (my $data=$sth->fetchrow_hashref){
125 push(@results,$data);
132 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
133 foreach my $syspref (keys %tabsysprefs){
134 $strsth .= $dbh->quote($syspref).",";
137 $strsth .= " order by variable";
139 my $sth=$dbh->prepare($strsth);
141 while (my $data=$sth->fetchrow_hashref){
142 push(@results,$data);
147 return ($cnt,\@results);
152 my $searchfield=$input->param('searchfield');
153 my $offset=$input->param('offset');
154 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
156 my ($template, $borrowernumber, $cookie)
157 = get_template_and_user({template_name => "parameters/systempreferences.tmpl",
160 authnotrequired => 0,
161 flagsrequired => {parameters => 1},
165 my $op = $input->param('op');
166 $searchfield=~ s/\,//g;
169 $template->param(script_name => $script_name,
170 $op => 1,); # we show only the TMPL_VAR names $op
172 $template->param(script_name => $script_name,
173 else => 1,); # we show only the TMPL_VAR names $op
176 if ($op eq 'update_and_reedit') {
177 foreach ($input->param) {
180 if (my $currentorder=$input->param('currentorder')) {
181 my @currentorder=split /\|/, $currentorder;
183 foreach my $param ($input->param) {
184 if ($param=~m#up-(\d+).x#) {
185 my $temp=$currentorder[$1];
186 $currentorder[$1]=$currentorder[$1-1];
187 $currentorder[$1-1]=$temp;
190 } elsif ($param=~m#down-(\d+).x#) {
191 my $temp=$currentorder[$1];
192 $currentorder[$1]=$currentorder[$1+1];
193 $currentorder[$1+1]=$temp;
198 $value=join ' ', @currentorder;
201 $template->param(script_name => $script_name,
202 $op => 1); # we show only the TMPL_VAR names $op
206 $template->param(script_name => $script_name,
207 else => 1); # we show only the TMPL_VAR names $op
210 my $dbh = C4::Context->dbh;
211 my $query="select * from systempreferences where variable=?";
212 my $sth=$dbh->prepare($query);
213 $sth->execute($input->param('variable'));
215 unless (C4::Context->config('demo') eq 1) {
216 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
217 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
221 unless (C4::Context->config('demo') eq 1) {
222 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
223 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
231 ################## ADD_FORM ##################################
232 # called by default. Used to create form to add or modify a record
234 if ($op eq 'add_form') {
235 #---- if primkey exists, it's a modify action, so read values to modify...
238 my $dbh = C4::Context->dbh;
239 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
240 $sth->execute($searchfield);
241 $data=$sth->fetchrow_hashref;
243 $template->param(modify => 1);
247 foreach my $option (split(/\|/, $data->{'options'})) {
249 $option eq $data->{'value'} and $selected=1;
250 push @options, { option => $option, selected => $selected };
252 if ($data->{'type'} eq 'Choice') {
253 $template->param('type-choice' => 1);
254 } elsif ($data->{'type'} eq 'YesNo') {
255 $template->param('type-yesno' => 1);
256 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
257 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
258 } elsif ($data->{'type'} eq 'Integer') {
259 $template->param('type-free' => 1);
260 $template->param('fieldlength' => $data->{'options'});
261 } elsif ($data->{'type'} eq 'Textarea') {
262 $template->param('type-textarea' => 1);
263 $data->{options} =~ /(.*)\|(.*)/;
264 $template->param('cols' => $1, 'rows' => $2);;
265 } elsif ($data->{'type'} eq 'Float') {
266 $template->param('type-free' => 1);
267 $template->param('fieldlength' => $data->{'options'});
268 } elsif ($data->{'type'} eq 'Themes') {
269 $template->param('type-choice' => 1);
271 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
273 my $currently_selected_themes;
275 foreach my $theme (split /\s+/, $data->{'value'}) {
276 push @options, { option => $theme, counter => $counter };
277 $currently_selected_themes->{$theme}=1;
280 foreach my $theme (getallthemes($type)) {
282 next if $currently_selected_themes->{$theme};
283 push @options, { option => $theme, counter => $counter };
286 } elsif ($data->{'type'} eq 'Languages') {
287 $template->param('type-choice' => 1);
290 my $currently_selected_languages;
292 foreach my $language (split /\s+/, $data->{'value'}) {
293 next if $language eq 'images';
294 push @options, { option => $language, counter => $counter };
295 $currently_selected_languages->{$language}=1;
298 foreach my $language (getalllanguages()) {
299 next if $language eq 'images';
301 next if $currently_selected_languages->{$language};
302 push @options, { option => $language, counter => $counter };
306 $template->param('type-free' => 1);
307 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
309 $template->param(explanation => $data->{'explanation'},
310 value => $data->{'value'},
311 type => $data->{'type'},
312 options => \@options,
313 preftype => $data->{'type'},
314 prefoptions => $data->{'options'},
315 searchfield => $searchfield);
317 ################## ADD_VALIDATE ##################################
318 # called by add_form, used to insert/modify data in DB
319 } elsif ($op eq 'add_validate') {
320 my $dbh = C4::Context->dbh;
321 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
322 $sth->execute($input->param('variable'));
324 unless (C4::Context->config('demo') eq 1) {
325 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
326 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
330 unless (C4::Context->config('demo') eq 1) {
331 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
332 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
337 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl\"></html>";
339 ################## DELETE_CONFIRM ##################################
340 # called by default form, used to confirm deletion of data in DB
341 } elsif ($op eq 'delete_confirm') {
342 my $dbh = C4::Context->dbh;
343 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
344 $sth->execute($searchfield);
345 my $data=$sth->fetchrow_hashref;
347 $template->param(searchfield => $searchfield,
348 Tvalue => $data->{'value'},
351 # END $OP eq DELETE_CONFIRM
352 ################## DELETE_CONFIRMED ##################################
353 # called by delete_confirm, used to effectively confirm deletion of data in DB
354 } elsif ($op eq 'delete_confirmed') {
355 my $dbh = C4::Context->dbh;
356 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
357 $sth->execute($searchfield);
359 # END $OP eq DELETE_CONFIRMED
360 ################## DEFAULT ##################################
362 #Adding tab management for system preferences
363 my $tab=$input->param('tab');
366 my ($count,$results)=StringSearch($env,$searchfield,$tab);
369 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
375 my %row_data; # get a fresh hash for the row data
376 $row_data{variable} = $results->[$i]{'variable'};
377 $row_data{value} = $results->[$i]{'value'};
378 $row_data{explanation} = $results->[$i]{'explanation'};
379 $row_data{toggle} = $toggle;
380 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
381 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
382 push(@loop_data, \%row_data);
384 $tab=($tab?$tab:"Others");
385 $template->param(loop => \@loop_data, $tab => 1);
387 my $prevpage = $offset-$pagesize;
388 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
390 if ($offset+$pagesize<$count) {
391 my $nextpage =$offset+$pagesize;
392 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
394 } #---- END $OP eq DEFAULT
396 output_html_with_http_headers $input, $cookie, $template->output;