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";
84 $tabsysprefs{NotifyBorrowerDeparture}="Members";
85 $tabsysprefs{OpacPasswordChange}="OPAC";
88 my ($env,$searchstring,$type)=@_;
89 my $dbh = C4::Context->dbh;
90 $searchstring=~ s/\'/\\\'/g;
91 my @data=split(' ',$searchstring);
96 foreach my $syspref (sort keys %tabsysprefs){
97 if ($tabsysprefs{$syspref} eq $type){
98 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
99 $sth->execute($syspref);
100 while (my $data=$sth->fetchrow_hashref){
101 push(@results,$data);
108 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
109 foreach my $syspref (keys %tabsysprefs){
110 $strsth .= $dbh->quote($syspref).",";
113 $strsth .= " order by variable";
115 my $sth=$dbh->prepare($strsth);
117 while (my $data=$sth->fetchrow_hashref){
118 push(@results,$data);
123 return ($cnt,\@results);
128 my $searchfield=$input->param('searchfield');
129 my $offset=$input->param('offset');
130 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
132 my ($template, $borrowernumber, $cookie)
133 = get_template_and_user({template_name => "parameters/systempreferences.tmpl",
136 authnotrequired => 0,
137 flagsrequired => {parameters => 1},
141 my $op = $input->param('op');
142 $searchfield=~ s/\,//g;
145 $template->param(script_name => $script_name,
146 $op => 1,); # we show only the TMPL_VAR names $op
148 $template->param(script_name => $script_name,
149 else => 1,); # we show only the TMPL_VAR names $op
152 if ($op eq 'update_and_reedit') {
153 foreach ($input->param) {
156 if (my $currentorder=$input->param('currentorder')) {
157 my @currentorder=split /\|/, $currentorder;
159 foreach my $param ($input->param) {
160 if ($param=~m#up-(\d+).x#) {
161 my $temp=$currentorder[$1];
162 $currentorder[$1]=$currentorder[$1-1];
163 $currentorder[$1-1]=$temp;
166 } elsif ($param=~m#down-(\d+).x#) {
167 my $temp=$currentorder[$1];
168 $currentorder[$1]=$currentorder[$1+1];
169 $currentorder[$1+1]=$temp;
174 $value=join ' ', @currentorder;
177 $template->param(script_name => $script_name,
178 $op => 1); # we show only the TMPL_VAR names $op
182 $template->param(script_name => $script_name,
183 else => 1); # we show only the TMPL_VAR names $op
186 my $dbh = C4::Context->dbh;
187 my $query="select * from systempreferences where variable=?";
188 my $sth=$dbh->prepare($query);
189 $sth->execute($input->param('variable'));
191 unless (C4::Context->config('demo') eq 1) {
192 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
193 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
197 unless (C4::Context->config('demo') eq 1) {
198 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
199 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
207 ################## ADD_FORM ##################################
208 # called by default. Used to create form to add or modify a record
210 if ($op eq 'add_form') {
211 #---- if primkey exists, it's a modify action, so read values to modify...
214 my $dbh = C4::Context->dbh;
215 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
216 $sth->execute($searchfield);
217 $data=$sth->fetchrow_hashref;
219 $template->param(modify => 1);
223 foreach my $option (split(/\|/, $data->{'options'})) {
225 $option eq $data->{'value'} and $selected=1;
226 push @options, { option => $option, selected => $selected };
228 if ($data->{'type'} eq 'Choice') {
229 $template->param('type-choice' => 1);
230 } elsif ($data->{'type'} eq 'YesNo') {
231 $template->param('type-yesno' => 1);
232 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
233 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
234 } elsif ($data->{'type'} eq 'Integer') {
235 $template->param('type-free' => 1);
236 $template->param('fieldlength' => $data->{'options'});
237 } elsif ($data->{'type'} eq 'Textarea') {
238 $template->param('type-textarea' => 1);
239 $data->{options} =~ /(.*)\|(.*)/;
240 $template->param('cols' => $1, 'rows' => $2);;
241 } elsif ($data->{'type'} eq 'Float') {
242 $template->param('type-free' => 1);
243 $template->param('fieldlength' => $data->{'options'});
244 } elsif ($data->{'type'} eq 'Themes') {
245 $template->param('type-choice' => 1);
247 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
249 my $currently_selected_themes;
251 foreach my $theme (split /\s+/, $data->{'value'}) {
252 push @options, { option => $theme, counter => $counter };
253 $currently_selected_themes->{$theme}=1;
256 foreach my $theme (getallthemes($type)) {
258 next if $currently_selected_themes->{$theme};
259 push @options, { option => $theme, counter => $counter };
262 } elsif ($data->{'type'} eq 'Languages') {
263 $template->param('type-choice' => 1);
266 my $currently_selected_languages;
268 foreach my $language (split /\s+/, $data->{'value'}) {
269 next if $language eq 'images';
270 push @options, { option => $language, counter => $counter };
271 $currently_selected_languages->{$language}=1;
274 foreach my $language (getalllanguages()) {
275 next if $language eq 'images';
277 next if $currently_selected_languages->{$language};
278 push @options, { option => $language, counter => $counter };
282 $template->param('type-free' => 1);
283 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
285 $template->param(explanation => $data->{'explanation'},
286 value => $data->{'value'},
287 type => $data->{'type'},
288 options => \@options,
289 preftype => $data->{'type'},
290 prefoptions => $data->{'options'},
291 searchfield => $searchfield);
293 ################## ADD_VALIDATE ##################################
294 # called by add_form, used to insert/modify data in DB
295 } elsif ($op eq 'add_validate') {
296 my $dbh = C4::Context->dbh;
297 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
298 $sth->execute($input->param('variable'));
300 unless (C4::Context->config('demo') eq 1) {
301 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
302 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
306 unless (C4::Context->config('demo') eq 1) {
307 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
308 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
313 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
315 ################## DELETE_CONFIRM ##################################
316 # called by default form, used to confirm deletion of data in DB
317 } elsif ($op eq 'delete_confirm') {
318 my $dbh = C4::Context->dbh;
319 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
320 $sth->execute($searchfield);
321 my $data=$sth->fetchrow_hashref;
323 $template->param(searchfield => $searchfield,
324 Tvalue => $data->{'value'},
327 # END $OP eq DELETE_CONFIRM
328 ################## DELETE_CONFIRMED ##################################
329 # called by delete_confirm, used to effectively confirm deletion of data in DB
330 } elsif ($op eq 'delete_confirmed') {
331 my $dbh = C4::Context->dbh;
332 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
333 $sth->execute($searchfield);
335 # END $OP eq DELETE_CONFIRMED
336 ################## DEFAULT ##################################
338 #Adding tab management for system preferences
339 my $tab=$input->param('tab');
342 my ($count,$results)=StringSearch($env,$searchfield,$tab);
345 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
351 my %row_data; # get a fresh hash for the row data
352 $row_data{variable} = $results->[$i]{'variable'};
353 $row_data{value} = $results->[$i]{'value'};
354 $row_data{explanation} = $results->[$i]{'explanation'};
355 $row_data{toggle} = $toggle;
356 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
357 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
358 push(@loop_data, \%row_data);
360 $tab=($tab?$tab:"Others");
361 $template->param(loop => \@loop_data, $tab => 1);
363 my $prevpage = $offset-$pagesize;
364 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
366 if ($offset+$pagesize<$count) {
367 my $nextpage =$offset+$pagesize;
368 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
370 } #---- END $OP eq DEFAULT
372 output_html_with_http_headers $input, $cookie, $template->output;