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}="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 my ($env,$searchstring,$type)=@_;
83 my $dbh = C4::Context->dbh;
84 $searchstring=~ s/\'/\\\'/g;
85 my @data=split(' ',$searchstring);
90 foreach my $syspref (sort keys %tabsysprefs){
91 if ($tabsysprefs{$syspref} eq $type){
92 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
93 $sth->execute($syspref);
94 while (my $data=$sth->fetchrow_hashref){
102 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
103 foreach my $syspref (keys %tabsysprefs){
104 $strsth .= $dbh->quote($syspref).",";
107 $strsth .= " order by variable";
109 my $sth=$dbh->prepare($strsth);
111 while (my $data=$sth->fetchrow_hashref){
112 push(@results,$data);
117 return ($cnt,\@results);
122 my $searchfield=$input->param('searchfield');
123 my $offset=$input->param('offset');
124 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
126 my ($template, $borrowernumber, $cookie)
127 = get_template_and_user({template_name => "parameters/systempreferences.tmpl",
130 authnotrequired => 0,
131 flagsrequired => {parameters => 1},
135 my $op = $input->param('op');
136 $searchfield=~ s/\,//g;
139 $template->param(script_name => $script_name,
140 $op => 1,); # we show only the TMPL_VAR names $op
142 $template->param(script_name => $script_name,
143 else => 1,); # we show only the TMPL_VAR names $op
146 if ($op eq 'update_and_reedit') {
147 foreach ($input->param) {
150 if (my $currentorder=$input->param('currentorder')) {
151 my @currentorder=split /\|/, $currentorder;
153 foreach my $param ($input->param) {
154 if ($param=~m#up-(\d+).x#) {
155 my $temp=$currentorder[$1];
156 $currentorder[$1]=$currentorder[$1-1];
157 $currentorder[$1-1]=$temp;
160 } elsif ($param=~m#down-(\d+).x#) {
161 my $temp=$currentorder[$1];
162 $currentorder[$1]=$currentorder[$1+1];
163 $currentorder[$1+1]=$temp;
168 $value=join ' ', @currentorder;
171 $template->param(script_name => $script_name,
172 $op => 1); # we show only the TMPL_VAR names $op
176 $template->param(script_name => $script_name,
177 else => 1); # we show only the TMPL_VAR names $op
180 my $dbh = C4::Context->dbh;
181 my $query="select * from systempreferences where variable=?";
182 my $sth=$dbh->prepare($query);
183 $sth->execute($input->param('variable'));
185 unless (C4::Context->config('demo') eq 1) {
186 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
187 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
191 unless (C4::Context->config('demo') eq 1) {
192 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
193 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
201 ################## ADD_FORM ##################################
202 # called by default. Used to create form to add or modify a record
204 if ($op eq 'add_form') {
205 #---- if primkey exists, it's a modify action, so read values to modify...
208 my $dbh = C4::Context->dbh;
209 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
210 $sth->execute($searchfield);
211 $data=$sth->fetchrow_hashref;
213 $template->param(modify => 1);
217 foreach my $option (split(/\|/, $data->{'options'})) {
219 $option eq $data->{'value'} and $selected=1;
220 push @options, { option => $option, selected => $selected };
222 if ($data->{'type'} eq 'Choice') {
223 $template->param('type-choice' => 1);
224 } elsif ($data->{'type'} eq 'YesNo') {
225 $template->param('type-yesno' => 1);
226 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
227 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
228 } elsif ($data->{'type'} eq 'Integer') {
229 $template->param('type-free' => 1);
230 $template->param('fieldlength' => $data->{'options'});
231 } elsif ($data->{'type'} eq 'Textarea') {
232 $template->param('type-textarea' => 1);
233 $data->{options} =~ /(.*)\|(.*)/;
234 $template->param('cols' => $1, 'rows' => $2);;
235 } elsif ($data->{'type'} eq 'Float') {
236 $template->param('type-free' => 1);
237 $template->param('fieldlength' => $data->{'options'});
238 } elsif ($data->{'type'} eq 'Themes') {
239 $template->param('type-choice' => 1);
241 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
243 my $currently_selected_themes;
245 foreach my $theme (split /\s+/, $data->{'value'}) {
246 push @options, { option => $theme, counter => $counter };
247 $currently_selected_themes->{$theme}=1;
250 foreach my $theme (getallthemes($type)) {
252 next if $currently_selected_themes->{$theme};
253 push @options, { option => $theme, counter => $counter };
256 } elsif ($data->{'type'} eq 'Languages') {
257 $template->param('type-choice' => 1);
260 my $currently_selected_languages;
262 foreach my $language (split /\s+/, $data->{'value'}) {
263 next if $language eq 'images';
264 push @options, { option => $language, counter => $counter };
265 $currently_selected_languages->{$language}=1;
268 foreach my $language (getalllanguages()) {
269 next if $language eq 'images';
271 next if $currently_selected_languages->{$language};
272 push @options, { option => $language, counter => $counter };
276 $template->param('type-free' => 1);
277 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
279 $template->param(explanation => $data->{'explanation'},
280 value => $data->{'value'},
281 type => $data->{'type'},
282 options => \@options,
283 preftype => $data->{'type'},
284 prefoptions => $data->{'options'},
285 searchfield => $searchfield);
287 ################## ADD_VALIDATE ##################################
288 # called by add_form, used to insert/modify data in DB
289 } elsif ($op eq 'add_validate') {
290 my $dbh = C4::Context->dbh;
291 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
292 $sth->execute($input->param('variable'));
294 unless (C4::Context->config('demo') eq 1) {
295 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
296 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
300 unless (C4::Context->config('demo') eq 1) {
301 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
302 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
307 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl\"></html>";
309 ################## DELETE_CONFIRM ##################################
310 # called by default form, used to confirm deletion of data in DB
311 } elsif ($op eq 'delete_confirm') {
312 my $dbh = C4::Context->dbh;
313 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
314 $sth->execute($searchfield);
315 my $data=$sth->fetchrow_hashref;
317 $template->param(searchfield => $searchfield,
318 Tvalue => $data->{'value'},
321 # END $OP eq DELETE_CONFIRM
322 ################## DELETE_CONFIRMED ##################################
323 # called by delete_confirm, used to effectively confirm deletion of data in DB
324 } elsif ($op eq 'delete_confirmed') {
325 my $dbh = C4::Context->dbh;
326 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
327 $sth->execute($searchfield);
329 # END $OP eq DELETE_CONFIRMED
330 ################## DEFAULT ##################################
332 #Adding tab management for system preferences
333 my $tab=$input->param('tab');
335 if ($searchfield ne '') {
336 $template->param(searchfield => "<p>You Searched for <strong>$searchfield</strong></p>");
339 my ($count,$results)=StringSearch($env,$searchfield,$tab);
342 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
348 my %row_data; # get a fresh hash for the row data
349 $row_data{variable} = $results->[$i]{'variable'};
350 $row_data{value} = $results->[$i]{'value'};
351 $row_data{explanation} = $results->[$i]{'explanation'};
352 $row_data{toggle} = $toggle;
353 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
354 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
355 push(@loop_data, \%row_data);
357 $template->param(loop => \@loop_data, $tab => 1);
359 my $prevpage = $offset-$pagesize;
360 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
362 if ($offset+$pagesize<$count) {
363 my $nextpage =$offset+$pagesize;
364 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
366 } #---- END $OP eq DEFAULT
368 output_html_with_http_headers $input, $cookie, $template->output;