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 # Fix me, shouldnt we store this stuff in the systempreferences table?
56 $tabsysprefs{acquisitions}="Acquisitions";
57 $tabsysprefs{gist}="Acquisitions";
59 $tabsysprefs{dateformat}="Admin";
60 $tabsysprefs{insecure}="Admin";
61 $tabsysprefs{KohaAdmin}="Admin";
63 $tabsysprefs{authoritysep}="Authorities";
65 $tabsysprefs{advancedMARCEditor}="Catalogue";
66 $tabsysprefs{autoBarcode}="Catalogue";
67 $tabsysprefs{hide_marc}="Catalogue";
68 $tabsysprefs{IntranetBiblioDefaultView} = "Catalogue";
69 $tabsysprefs{ISBD}="Catalogue";
70 $tabsysprefs{itemcallnumber}="Catalogue";
71 $tabsysprefs{LabelMARCView}="Catalogue";
72 $tabsysprefs{marc}="Catalogue";
73 $tabsysprefs{marcflavour}="Catalogue";
74 $tabsysprefs{serialsadditems}="Catalogue";
75 $tabsysprefs{sortbynonfiling}="Catalogue";
77 $tabsysprefs{maxoutstanding}="Circulation";
78 $tabsysprefs{maxreserves}="Circulation";
79 $tabsysprefs{noissuescharge}="Circulation";
80 $tabsysprefs{patronimages}="Circulation";
81 $tabsysprefs{printcirculationslips}="Circulation";
82 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
84 $tabsysprefs{automembernum}="Members";
85 $tabsysprefs{checkdigit}="Members";
86 $tabsysprefs{NotifyBorrowerDeparture}="Members";
87 $tabsysprefs{memberofinstitution}="Members";
88 $tabsysprefs{ReadingHistory}="Members";
90 $tabsysprefs{AmazonAssocTag}="OPAC";
91 $tabsysprefs{AmazonContent}="OPAC";
92 $tabsysprefs{AmazonDevKey}="OPAC";
93 $tabsysprefs{AnonSuggestions}="OPAC";
94 $tabsysprefs{BiblioDefaultView}="OPAC";
95 $tabsysprefs{Disable_Dictionary}="OPAC";
96 $tabsysprefs{hidelostitems}="OPAC";
97 $tabsysprefs{LibraryName}="OPAC";
98 $tabsysprefs{opacbookbag}="OPAC";
99 $tabsysprefs{opaccolorstylesheet}="OPAC";
100 $tabsysprefs{opaccredits}="OPAC";
101 $tabsysprefs{opaclanguages}="OPAC";
102 $tabsysprefs{opaclanguagesdisplay}="OPAC";
103 $tabsysprefs{opaclargeimage}="OPAC";
104 $tabsysprefs{opaclayoutstylesheet}="OPAC";
105 $tabsysprefs{OpacNav}="OPAC";
106 $tabsysprefs{OpacPasswordChange}="OPAC";
107 $tabsysprefs{opacreadinghistory}="OPAC";
108 $tabsysprefs{opacsmallimage}="OPAC";
109 $tabsysprefs{opacstylesheet}="OPAC";
110 $tabsysprefs{opacthemes}="OPAC";
111 $tabsysprefs{opacuserlogin}="OPAC";
112 $tabsysprefs{SubscriptionHistory}="OPAC";
113 $tabsysprefs{suggestion}="OPAC";
114 $tabsysprefs{virtualshelves}="OPAC";
117 my ($env,$searchstring,$type)=@_;
118 my $dbh = C4::Context->dbh;
119 $searchstring=~ s/\'/\\\'/g;
120 my @data=split(' ',$searchstring);
125 foreach my $syspref (sort keys %tabsysprefs){
126 if ($tabsysprefs{$syspref} eq $type){
127 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
128 $sth->execute($syspref);
129 while (my $data=$sth->fetchrow_hashref){
130 $data->{value} =~ s/</</g;
131 $data->{value} =~ s/>/</g;
132 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
133 push(@results,$data);
140 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
141 foreach my $syspref (keys %tabsysprefs){
142 $strsth .= $dbh->quote($syspref).",";
145 $strsth .= " order by variable";
147 my $sth=$dbh->prepare($strsth);
149 while (my $data=$sth->fetchrow_hashref){
150 $data->{value}=substr($data->{value},0,100);
151 push(@results,$data);
156 return ($cnt,\@results);
161 my $searchfield=$input->param('searchfield');
162 my $offset=$input->param('offset');
163 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
165 my ($template, $borrowernumber, $cookie)
166 = get_template_and_user({template_name => "parameters/systempreferences.tmpl",
169 authnotrequired => 0,
170 flagsrequired => {parameters => 1},
174 my $op = $input->param('op');
175 $searchfield=~ s/\,//g;
178 $template->param(script_name => $script_name,
179 $op => 1,); # we show only the TMPL_VAR names $op
181 $template->param(script_name => $script_name,
182 else => 1,); # we show only the TMPL_VAR names $op
185 if ($op eq 'update_and_reedit') {
186 foreach ($input->param) {
189 if (my $currentorder=$input->param('currentorder')) {
190 my @currentorder=split /\|/, $currentorder;
192 foreach my $param ($input->param) {
193 if ($param=~m#up-(\d+).x#) {
194 my $temp=$currentorder[$1];
195 $currentorder[$1]=$currentorder[$1-1];
196 $currentorder[$1-1]=$temp;
199 } elsif ($param=~m#down-(\d+).x#) {
200 my $temp=$currentorder[$1];
201 $currentorder[$1]=$currentorder[$1+1];
202 $currentorder[$1+1]=$temp;
207 $value=join ' ', @currentorder;
210 $template->param(script_name => $script_name,
211 $op => 1); # we show only the TMPL_VAR names $op
215 $template->param(script_name => $script_name,
216 else => 1); # we show only the TMPL_VAR names $op
219 my $dbh = C4::Context->dbh;
220 my $query="select * from systempreferences where variable=?";
221 my $sth=$dbh->prepare($query);
222 $sth->execute($input->param('variable'));
224 unless (C4::Context->config('demo') eq 1) {
225 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
226 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
230 unless (C4::Context->config('demo') eq 1) {
231 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
232 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
240 ################## ADD_FORM ##################################
241 # called by default. Used to create form to add or modify a record
243 if ($op eq 'add_form') {
244 #---- if primkey exists, it's a modify action, so read values to modify...
247 my $dbh = C4::Context->dbh;
248 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
249 $sth->execute($searchfield);
250 $data=$sth->fetchrow_hashref;
252 $template->param(modify => 1);
256 foreach my $option (split(/\|/, $data->{'options'})) {
258 $option eq $data->{'value'} and $selected=1;
259 push @options, { option => $option, selected => $selected };
261 if ($data->{'type'} eq 'Choice') {
262 $template->param('type-choice' => 1);
263 } elsif ($data->{'type'} eq 'YesNo') {
264 $template->param('type-yesno' => 1);
265 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
266 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
267 } elsif ($data->{'type'} eq 'Integer') {
268 $template->param('type-free' => 1);
269 $template->param('fieldlength' => $data->{'options'});
270 } elsif ($data->{'type'} eq 'Textarea') {
271 $template->param('type-textarea' => 1);
272 $data->{options} =~ /(.*)\|(.*)/;
273 $template->param('cols' => $1, 'rows' => $2);;
274 } elsif ($data->{'type'} eq 'Float') {
275 $template->param('type-free' => 1);
276 $template->param('fieldlength' => $data->{'options'});
277 } elsif ($data->{'type'} eq 'Themes') {
278 $template->param('type-choice' => 1);
280 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
282 my $currently_selected_themes;
284 foreach my $theme (split /\s+/, $data->{'value'}) {
285 push @options, { option => $theme, counter => $counter };
286 $currently_selected_themes->{$theme}=1;
289 foreach my $theme (getallthemes($type)) {
291 next if $currently_selected_themes->{$theme};
292 push @options, { option => $theme, counter => $counter };
295 } elsif ($data->{'type'} eq 'Languages') {
296 $template->param('type-choice' => 1);
299 my $currently_selected_languages;
301 foreach my $language (split /\s+/, $data->{'value'}) {
302 next if $language eq 'images';
303 push @options, { option => $language, counter => $counter };
304 $currently_selected_languages->{$language}=1;
307 foreach my $language (getalllanguages()) {
308 next if $language eq 'images';
310 next if $currently_selected_languages->{$language};
311 push @options, { option => $language, counter => $counter };
315 $template->param('type-free' => 1);
316 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
318 $template->param(explanation => $data->{'explanation'},
319 value => $data->{'value'},
320 type => $data->{'type'},
321 options => \@options,
322 preftype => $data->{'type'},
323 prefoptions => $data->{'options'},
324 searchfield => $searchfield);
326 ################## ADD_VALIDATE ##################################
327 # called by add_form, used to insert/modify data in DB
328 } elsif ($op eq 'add_validate') {
329 my $dbh = C4::Context->dbh;
330 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
331 $sth->execute($input->param('variable'));
333 unless (C4::Context->config('demo') eq 1) {
334 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
335 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
339 unless (C4::Context->config('demo') eq 1) {
340 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
341 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
346 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
348 ################## DELETE_CONFIRM ##################################
349 # called by default form, used to confirm deletion of data in DB
350 } elsif ($op eq 'delete_confirm') {
351 my $dbh = C4::Context->dbh;
352 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
353 $sth->execute($searchfield);
354 my $data=$sth->fetchrow_hashref;
356 $template->param(searchfield => $searchfield,
357 Tvalue => $data->{'value'},
360 # END $OP eq DELETE_CONFIRM
361 ################## DELETE_CONFIRMED ##################################
362 # called by delete_confirm, used to effectively confirm deletion of data in DB
363 } elsif ($op eq 'delete_confirmed') {
364 my $dbh = C4::Context->dbh;
365 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
366 $sth->execute($searchfield);
368 # END $OP eq DELETE_CONFIRMED
369 ################## DEFAULT ##################################
371 #Adding tab management for system preferences
372 my $tab=$input->param('tab');
375 my ($count,$results)=StringSearch($env,$searchfield,$tab);
378 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
384 my %row_data; # get a fresh hash for the row data
385 $row_data{variable} = $results->[$i]{'variable'};
386 $row_data{value} = $results->[$i]{'value'};
387 $row_data{explanation} = $results->[$i]{'explanation'};
388 $row_data{toggle} = $toggle;
389 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
390 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
391 push(@loop_data, \%row_data);
393 $tab=($tab?$tab:"Others");
394 $template->param(loop => \@loop_data, $tab => 1);
396 my $prevpage = $offset-$pagesize;
397 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
399 if ($offset+$pagesize<$count) {
400 my $nextpage =$offset+$pagesize;
401 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
403 } #---- END $OP eq DEFAULT
404 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
405 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
406 IntranetNav => C4::Context->preference("IntranetNav"),
408 output_html_with_http_headers $input, $cookie, $template->output;