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{autoBarcode}="Catalogue";
58 $tabsysprefs{marcflavour}="Catalogue";
59 $tabsysprefs{SubscriptionHistory}="OPAC";
60 $tabsysprefs{maxoutstanding}="Circulation";
61 $tabsysprefs{printcirculationslips}="Circulation";
62 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
63 $tabsysprefs{suggestion}="OPAC";
64 $tabsysprefs{automembernum}="Members";
65 $tabsysprefs{noissuescharge}="Circulation";
66 $tabsysprefs{opacthemes}="OPAC";
67 $tabsysprefs{opaclanguages}="OPAC";
68 $tabsysprefs{LibraryName}="OPAC";
69 $tabsysprefs{opacstylesheet}="OPAC";
70 $tabsysprefs{BiblioDefaultView}="OPAC";
71 $tabsysprefs{opaclargeimage}="OPAC";
72 $tabsysprefs{opacsmallimage}="OPAC";
73 $tabsysprefs{hidelostitems}="OPAC";
74 $tabsysprefs{KohaAdmin}="Admin";
75 $tabsysprefs{checkdigit}="Members";
76 $tabsysprefs{dateformat}="Admin";
77 $tabsysprefs{insecure}="Admin";
78 $tabsysprefs{ldapinfos}="Admin";
79 $tabsysprefs{ldapserver}="Admin";
80 $tabsysprefs{itemcallnumber}="Catalogue";
81 $tabsysprefs{maxreserves}="Circulation";
82 $tabsysprefs{virtualshelves}="OPAC";
83 $tabsysprefs{hide_marc}="Catalogue";
86 my ($env,$searchstring,$type)=@_;
87 my $dbh = C4::Context->dbh;
88 $searchstring=~ s/\'/\\\'/g;
89 my @data=split(' ',$searchstring);
94 foreach my $syspref (sort keys %tabsysprefs){
95 if ($tabsysprefs{$syspref} eq $type){
96 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
97 $sth->execute($syspref);
98 while (my $data=$sth->fetchrow_hashref){
106 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
107 foreach my $syspref (keys %tabsysprefs){
108 $strsth .= $dbh->quote($syspref).",";
111 $strsth .= " order by variable";
113 my $sth=$dbh->prepare($strsth);
115 while (my $data=$sth->fetchrow_hashref){
116 push(@results,$data);
121 return ($cnt,\@results);
126 my $searchfield=$input->param('searchfield');
127 my $offset=$input->param('offset');
128 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
130 my ($template, $borrowernumber, $cookie)
131 = get_template_and_user({template_name => "parameters/systempreferences.tmpl",
134 authnotrequired => 0,
135 flagsrequired => {parameters => 1},
139 my $op = $input->param('op');
140 $searchfield=~ s/\,//g;
143 $template->param(script_name => $script_name,
144 $op => 1,); # we show only the TMPL_VAR names $op
146 $template->param(script_name => $script_name,
147 else => 1,); # we show only the TMPL_VAR names $op
150 if ($op eq 'update_and_reedit') {
151 foreach ($input->param) {
154 if (my $currentorder=$input->param('currentorder')) {
155 my @currentorder=split /\|/, $currentorder;
157 foreach my $param ($input->param) {
158 if ($param=~m#up-(\d+).x#) {
159 my $temp=$currentorder[$1];
160 $currentorder[$1]=$currentorder[$1-1];
161 $currentorder[$1-1]=$temp;
164 } elsif ($param=~m#down-(\d+).x#) {
165 my $temp=$currentorder[$1];
166 $currentorder[$1]=$currentorder[$1+1];
167 $currentorder[$1+1]=$temp;
172 $value=join ' ', @currentorder;
175 $template->param(script_name => $script_name,
176 $op => 1); # we show only the TMPL_VAR names $op
180 $template->param(script_name => $script_name,
181 else => 1); # we show only the TMPL_VAR names $op
184 my $dbh = C4::Context->dbh;
185 my $query="select * from systempreferences where variable=?";
186 my $sth=$dbh->prepare($query);
187 $sth->execute($input->param('variable'));
189 unless (C4::Context->config('demo') eq 1) {
190 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
191 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
195 unless (C4::Context->config('demo') eq 1) {
196 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
197 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
205 ################## ADD_FORM ##################################
206 # called by default. Used to create form to add or modify a record
208 if ($op eq 'add_form') {
209 #---- if primkey exists, it's a modify action, so read values to modify...
212 my $dbh = C4::Context->dbh;
213 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
214 $sth->execute($searchfield);
215 $data=$sth->fetchrow_hashref;
217 $template->param(modify => 1);
221 foreach my $option (split(/\|/, $data->{'options'})) {
223 $option eq $data->{'value'} and $selected=1;
224 push @options, { option => $option, selected => $selected };
226 if ($data->{'type'} eq 'Choice') {
227 $template->param('type-choice' => 1);
228 } elsif ($data->{'type'} eq 'YesNo') {
229 $template->param('type-yesno' => 1);
230 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
231 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
232 } elsif ($data->{'type'} eq 'Integer') {
233 $template->param('type-free' => 1);
234 $template->param('fieldlength' => $data->{'options'});
235 } elsif ($data->{'type'} eq 'Textarea') {
236 $template->param('type-textarea' => 1);
237 $data->{options} =~ /(.*)\|(.*)/;
238 $template->param('cols' => $1, 'rows' => $2);;
239 } elsif ($data->{'type'} eq 'Float') {
240 $template->param('type-free' => 1);
241 $template->param('fieldlength' => $data->{'options'});
242 } elsif ($data->{'type'} eq 'Themes') {
243 $template->param('type-choice' => 1);
245 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
247 my $currently_selected_themes;
249 foreach my $theme (split /\s+/, $data->{'value'}) {
250 push @options, { option => $theme, counter => $counter };
251 $currently_selected_themes->{$theme}=1;
254 foreach my $theme (getallthemes($type)) {
256 next if $currently_selected_themes->{$theme};
257 push @options, { option => $theme, counter => $counter };
260 } elsif ($data->{'type'} eq 'Languages') {
261 $template->param('type-choice' => 1);
264 my $currently_selected_languages;
266 foreach my $language (split /\s+/, $data->{'value'}) {
267 next if $language eq 'images';
268 push @options, { option => $language, counter => $counter };
269 $currently_selected_languages->{$language}=1;
272 foreach my $language (getalllanguages()) {
273 next if $language eq 'images';
275 next if $currently_selected_languages->{$language};
276 push @options, { option => $language, counter => $counter };
280 $template->param('type-free' => 1);
281 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
283 $template->param(explanation => $data->{'explanation'},
284 value => $data->{'value'},
285 type => $data->{'type'},
286 options => \@options,
287 preftype => $data->{'type'},
288 prefoptions => $data->{'options'},
289 searchfield => $searchfield);
291 ################## ADD_VALIDATE ##################################
292 # called by add_form, used to insert/modify data in DB
293 } elsif ($op eq 'add_validate') {
294 my $dbh = C4::Context->dbh;
295 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
296 $sth->execute($input->param('variable'));
298 unless (C4::Context->config('demo') eq 1) {
299 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
300 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
304 unless (C4::Context->config('demo') eq 1) {
305 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
306 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
311 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
313 ################## DELETE_CONFIRM ##################################
314 # called by default form, used to confirm deletion of data in DB
315 } elsif ($op eq 'delete_confirm') {
316 my $dbh = C4::Context->dbh;
317 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
318 $sth->execute($searchfield);
319 my $data=$sth->fetchrow_hashref;
321 $template->param(searchfield => $searchfield,
322 Tvalue => $data->{'value'},
325 # END $OP eq DELETE_CONFIRM
326 ################## DELETE_CONFIRMED ##################################
327 # called by delete_confirm, used to effectively confirm deletion of data in DB
328 } elsif ($op eq 'delete_confirmed') {
329 my $dbh = C4::Context->dbh;
330 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
331 $sth->execute($searchfield);
333 # END $OP eq DELETE_CONFIRMED
334 ################## DEFAULT ##################################
336 #Adding tab management for system preferences
337 my $tab=$input->param('tab');
340 my ($count,$results)=StringSearch($env,$searchfield,$tab);
343 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
349 my %row_data; # get a fresh hash for the row data
350 $row_data{variable} = $results->[$i]{'variable'};
351 $row_data{value} = $results->[$i]{'value'};
352 $row_data{explanation} = $results->[$i]{'explanation'};
353 $row_data{toggle} = $toggle;
354 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
355 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
356 push(@loop_data, \%row_data);
358 $tab=($tab?$tab:"Others");
359 $template->param(loop => \@loop_data, $tab => 1);
361 my $prevpage = $offset-$pagesize;
362 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
364 if ($offset+$pagesize<$count) {
365 my $nextpage =$offset+$pagesize;
366 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
368 } #---- END $OP eq DEFAULT
370 output_html_with_http_headers $input, $cookie, $template->output;