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{IssuingInProcess}="Circulation";
81 $tabsysprefs{patronimages}="Circulation";
82 $tabsysprefs{printcirculationslips}="Circulation";
83 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
85 $tabsysprefs{automembernum}="Members";
86 $tabsysprefs{checkdigit}="Members";
87 $tabsysprefs{NotifyBorrowerDeparture}="Members";
88 $tabsysprefs{memberofinstitution}="Members";
89 $tabsysprefs{ReadingHistory}="Members";
91 $tabsysprefs{AmazonAssocTag}="OPAC";
92 $tabsysprefs{AmazonContent}="OPAC";
93 $tabsysprefs{AmazonDevKey}="OPAC";
94 $tabsysprefs{AnonSuggestions}="OPAC";
95 $tabsysprefs{BiblioDefaultView}="OPAC";
96 $tabsysprefs{Disable_Dictionary}="OPAC";
97 $tabsysprefs{hidelostitems}="OPAC";
98 $tabsysprefs{LibraryName}="OPAC";
99 $tabsysprefs{opacbookbag}="OPAC";
100 $tabsysprefs{opaccolorstylesheet}="OPAC";
101 $tabsysprefs{opaccredits}="OPAC";
102 $tabsysprefs{opaclanguages}="OPAC";
103 $tabsysprefs{opaclanguagesdisplay}="OPAC";
104 $tabsysprefs{opaclargeimage}="OPAC";
105 $tabsysprefs{opaclayoutstylesheet}="OPAC";
106 $tabsysprefs{OpacNav}="OPAC";
107 $tabsysprefs{OpacPasswordChange}="OPAC";
108 $tabsysprefs{opacreadinghistory}="OPAC";
109 $tabsysprefs{opacsmallimage}="OPAC";
110 $tabsysprefs{opacstylesheet}="OPAC";
111 $tabsysprefs{opacthemes}="OPAC";
112 $tabsysprefs{opacuserlogin}="OPAC";
113 $tabsysprefs{SubscriptionHistory}="OPAC";
114 $tabsysprefs{suggestion}="OPAC";
115 $tabsysprefs{virtualshelves}="OPAC";
118 my ($env,$searchstring,$type)=@_;
119 my $dbh = C4::Context->dbh;
120 $searchstring=~ s/\'/\\\'/g;
121 my @data=split(' ',$searchstring);
126 foreach my $syspref (sort keys %tabsysprefs){
127 if ($tabsysprefs{$syspref} eq $type){
128 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
129 $sth->execute($syspref);
130 while (my $data=$sth->fetchrow_hashref){
131 $data->{value} =~ s/</</g;
132 $data->{value} =~ s/>/</g;
133 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
134 push(@results,$data);
141 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
142 foreach my $syspref (keys %tabsysprefs){
143 $strsth .= $dbh->quote($syspref).",";
146 $strsth .= " order by variable";
148 my $sth=$dbh->prepare($strsth);
150 while (my $data=$sth->fetchrow_hashref){
151 $data->{value}=substr($data->{value},0,100);
152 push(@results,$data);
157 return ($cnt,\@results);
162 my $searchfield=$input->param('searchfield');
163 my $offset=$input->param('offset');
164 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
166 my ($template, $borrowernumber, $cookie)
167 = get_template_and_user({template_name => "parameters/systempreferences.tmpl",
170 authnotrequired => 0,
171 flagsrequired => {parameters => 1},
175 my $op = $input->param('op');
176 $searchfield=~ s/\,//g;
179 $template->param(script_name => $script_name,
180 $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 if ($op eq 'update_and_reedit') {
187 foreach ($input->param) {
190 if (my $currentorder=$input->param('currentorder')) {
191 my @currentorder=split /\|/, $currentorder;
193 foreach my $param ($input->param) {
194 if ($param=~m#up-(\d+).x#) {
195 my $temp=$currentorder[$1];
196 $currentorder[$1]=$currentorder[$1-1];
197 $currentorder[$1-1]=$temp;
200 } elsif ($param=~m#down-(\d+).x#) {
201 my $temp=$currentorder[$1];
202 $currentorder[$1]=$currentorder[$1+1];
203 $currentorder[$1+1]=$temp;
208 $value=join ' ', @currentorder;
211 $template->param(script_name => $script_name,
212 $op => 1); # we show only the TMPL_VAR names $op
216 $template->param(script_name => $script_name,
217 else => 1); # we show only the TMPL_VAR names $op
220 my $dbh = C4::Context->dbh;
221 my $query="select * from systempreferences where variable=?";
222 my $sth=$dbh->prepare($query);
223 $sth->execute($input->param('variable'));
225 unless (C4::Context->config('demo') eq 1) {
226 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
227 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
231 unless (C4::Context->config('demo') eq 1) {
232 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
233 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
241 ################## ADD_FORM ##################################
242 # called by default. Used to create form to add or modify a record
244 if ($op eq 'add_form') {
245 #---- if primkey exists, it's a modify action, so read values to modify...
248 my $dbh = C4::Context->dbh;
249 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
250 $sth->execute($searchfield);
251 $data=$sth->fetchrow_hashref;
253 $template->param(modify => 1);
257 foreach my $option (split(/\|/, $data->{'options'})) {
259 $option eq $data->{'value'} and $selected=1;
260 push @options, { option => $option, selected => $selected };
262 if ($data->{'type'} eq 'Choice') {
263 $template->param('type-choice' => 1);
264 } elsif ($data->{'type'} eq 'YesNo') {
265 $template->param('type-yesno' => 1);
266 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
267 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
268 } elsif ($data->{'type'} eq 'Integer') {
269 $template->param('type-free' => 1);
270 $template->param('fieldlength' => $data->{'options'});
271 } elsif ($data->{'type'} eq 'Textarea') {
272 $template->param('type-textarea' => 1);
273 $data->{options} =~ /(.*)\|(.*)/;
274 $template->param('cols' => $1, 'rows' => $2);;
275 } elsif ($data->{'type'} eq 'Float') {
276 $template->param('type-free' => 1);
277 $template->param('fieldlength' => $data->{'options'});
278 } elsif ($data->{'type'} eq 'Themes') {
279 $template->param('type-choice' => 1);
281 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
283 my $currently_selected_themes;
285 foreach my $theme (split /\s+/, $data->{'value'}) {
286 push @options, { option => $theme, counter => $counter };
287 $currently_selected_themes->{$theme}=1;
290 foreach my $theme (getallthemes($type)) {
292 next if $currently_selected_themes->{$theme};
293 push @options, { option => $theme, counter => $counter };
296 } elsif ($data->{'type'} eq 'Languages') {
297 $template->param('type-choice' => 1);
300 my $currently_selected_languages;
302 foreach my $language (split /\s+/, $data->{'value'}) {
303 next if $language eq 'images';
304 push @options, { option => $language, counter => $counter };
305 $currently_selected_languages->{$language}=1;
308 foreach my $language (getalllanguages()) {
309 next if $language eq 'images';
311 next if $currently_selected_languages->{$language};
312 push @options, { option => $language, counter => $counter };
316 $template->param('type-free' => 1);
317 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
319 $template->param(explanation => $data->{'explanation'},
320 value => $data->{'value'},
321 type => $data->{'type'},
322 options => \@options,
323 preftype => $data->{'type'},
324 prefoptions => $data->{'options'},
325 searchfield => $searchfield);
327 ################## ADD_VALIDATE ##################################
328 # called by add_form, used to insert/modify data in DB
329 } elsif ($op eq 'add_validate') {
330 my $dbh = C4::Context->dbh;
331 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
332 $sth->execute($input->param('variable'));
334 unless (C4::Context->config('demo') eq 1) {
335 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
336 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
340 unless (C4::Context->config('demo') eq 1) {
341 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
342 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
347 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
349 ################## DELETE_CONFIRM ##################################
350 # called by default form, used to confirm deletion of data in DB
351 } elsif ($op eq 'delete_confirm') {
352 my $dbh = C4::Context->dbh;
353 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
354 $sth->execute($searchfield);
355 my $data=$sth->fetchrow_hashref;
357 $template->param(searchfield => $searchfield,
358 Tvalue => $data->{'value'},
361 # END $OP eq DELETE_CONFIRM
362 ################## DELETE_CONFIRMED ##################################
363 # called by delete_confirm, used to effectively confirm deletion of data in DB
364 } elsif ($op eq 'delete_confirmed') {
365 my $dbh = C4::Context->dbh;
366 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
367 $sth->execute($searchfield);
369 # END $OP eq DELETE_CONFIRMED
370 ################## DEFAULT ##################################
372 #Adding tab management for system preferences
373 my $tab=$input->param('tab');
376 my ($count,$results)=StringSearch($env,$searchfield,$tab);
379 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
385 my %row_data; # get a fresh hash for the row data
386 $row_data{variable} = $results->[$i]{'variable'};
387 $row_data{value} = $results->[$i]{'value'};
388 $row_data{explanation} = $results->[$i]{'explanation'};
389 $row_data{toggle} = $toggle;
390 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
391 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
392 push(@loop_data, \%row_data);
394 $tab=($tab?$tab:"Others");
395 $template->param(loop => \@loop_data, $tab => 1);
397 my $prevpage = $offset-$pagesize;
398 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
400 if ($offset+$pagesize<$count) {
401 my $nextpage =$offset+$pagesize;
402 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
404 } #---- END $OP eq DEFAULT
405 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
406 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
407 IntranetNav => C4::Context->preference("IntranetNav"),
409 output_html_with_http_headers $input, $cookie, $template->output;