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";
89 $tabsysprefs{AmazonAssocTag}="OPAC";
90 $tabsysprefs{AmazonContent}="OPAC";
91 $tabsysprefs{AmazonDevKey}="OPAC";
92 $tabsysprefs{AnonSuggestions}="OPAC";
93 $tabsysprefs{BiblioDefaultView}="OPAC";
94 $tabsysprefs{Disable_Dictionary}="OPAC";
95 $tabsysprefs{hidelostitems}="OPAC";
96 $tabsysprefs{LibraryName}="OPAC";
97 $tabsysprefs{opacbookbag}="OPAC";
98 $tabsysprefs{opaccolorstylesheet}="OPAC";
99 $tabsysprefs{opaccredits}="OPAC";
100 $tabsysprefs{opaclanguages}="OPAC";
101 $tabsysprefs{opaclanguagesdisplay}="OPAC";
102 $tabsysprefs{opaclargeimage}="OPAC";
103 $tabsysprefs{opaclayoutstylesheet}="OPAC";
104 $tabsysprefs{OpacNav}="OPAC";
105 $tabsysprefs{OpacPasswordChange}="OPAC";
106 $tabsysprefs{opacreadinghistory}="OPAC";
107 $tabsysprefs{opacsmallimage}="OPAC";
108 $tabsysprefs{opacstylesheet}="OPAC";
109 $tabsysprefs{opacthemes}="OPAC";
110 $tabsysprefs{opacuserlogin}="OPAC";
111 $tabsysprefs{SubscriptionHistory}="OPAC";
112 $tabsysprefs{suggestion}="OPAC";
113 $tabsysprefs{virtualshelves}="OPAC";
116 my ($env,$searchstring,$type)=@_;
117 my $dbh = C4::Context->dbh;
118 $searchstring=~ s/\'/\\\'/g;
119 my @data=split(' ',$searchstring);
124 foreach my $syspref (sort keys %tabsysprefs){
125 if ($tabsysprefs{$syspref} eq $type){
126 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
127 $sth->execute($syspref);
128 while (my $data=$sth->fetchrow_hashref){
129 $data->{value} =~ s/</</g;
130 $data->{value} =~ s/>/</g;
131 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
132 push(@results,$data);
139 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
140 foreach my $syspref (keys %tabsysprefs){
141 $strsth .= $dbh->quote($syspref).",";
144 $strsth .= " order by variable";
146 my $sth=$dbh->prepare($strsth);
148 while (my $data=$sth->fetchrow_hashref){
149 $data->{value}=substr($data->{value},0,100);
150 push(@results,$data);
155 return ($cnt,\@results);
160 my $searchfield=$input->param('searchfield');
161 my $offset=$input->param('offset');
162 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
164 my ($template, $borrowernumber, $cookie)
165 = get_template_and_user({template_name => "parameters/systempreferences.tmpl",
168 authnotrequired => 0,
169 flagsrequired => {parameters => 1},
173 my $op = $input->param('op');
174 $searchfield=~ s/\,//g;
177 $template->param(script_name => $script_name,
178 $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 if ($op eq 'update_and_reedit') {
185 foreach ($input->param) {
188 if (my $currentorder=$input->param('currentorder')) {
189 my @currentorder=split /\|/, $currentorder;
191 foreach my $param ($input->param) {
192 if ($param=~m#up-(\d+).x#) {
193 my $temp=$currentorder[$1];
194 $currentorder[$1]=$currentorder[$1-1];
195 $currentorder[$1-1]=$temp;
198 } elsif ($param=~m#down-(\d+).x#) {
199 my $temp=$currentorder[$1];
200 $currentorder[$1]=$currentorder[$1+1];
201 $currentorder[$1+1]=$temp;
206 $value=join ' ', @currentorder;
209 $template->param(script_name => $script_name,
210 $op => 1); # we show only the TMPL_VAR names $op
214 $template->param(script_name => $script_name,
215 else => 1); # we show only the TMPL_VAR names $op
218 my $dbh = C4::Context->dbh;
219 my $query="select * from systempreferences where variable=?";
220 my $sth=$dbh->prepare($query);
221 $sth->execute($input->param('variable'));
223 unless (C4::Context->config('demo') eq 1) {
224 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
225 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
229 unless (C4::Context->config('demo') eq 1) {
230 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
231 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
239 ################## ADD_FORM ##################################
240 # called by default. Used to create form to add or modify a record
242 if ($op eq 'add_form') {
243 #---- if primkey exists, it's a modify action, so read values to modify...
246 my $dbh = C4::Context->dbh;
247 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
248 $sth->execute($searchfield);
249 $data=$sth->fetchrow_hashref;
251 $template->param(modify => 1);
255 foreach my $option (split(/\|/, $data->{'options'})) {
257 $option eq $data->{'value'} and $selected=1;
258 push @options, { option => $option, selected => $selected };
260 if ($data->{'type'} eq 'Choice') {
261 $template->param('type-choice' => 1);
262 } elsif ($data->{'type'} eq 'YesNo') {
263 $template->param('type-yesno' => 1);
264 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
265 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
266 } elsif ($data->{'type'} eq 'Integer') {
267 $template->param('type-free' => 1);
268 $template->param('fieldlength' => $data->{'options'});
269 } elsif ($data->{'type'} eq 'Textarea') {
270 $template->param('type-textarea' => 1);
271 $data->{options} =~ /(.*)\|(.*)/;
272 $template->param('cols' => $1, 'rows' => $2);;
273 } elsif ($data->{'type'} eq 'Float') {
274 $template->param('type-free' => 1);
275 $template->param('fieldlength' => $data->{'options'});
276 } elsif ($data->{'type'} eq 'Themes') {
277 $template->param('type-choice' => 1);
279 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
281 my $currently_selected_themes;
283 foreach my $theme (split /\s+/, $data->{'value'}) {
284 push @options, { option => $theme, counter => $counter };
285 $currently_selected_themes->{$theme}=1;
288 foreach my $theme (getallthemes($type)) {
290 next if $currently_selected_themes->{$theme};
291 push @options, { option => $theme, counter => $counter };
294 } elsif ($data->{'type'} eq 'Languages') {
295 $template->param('type-choice' => 1);
298 my $currently_selected_languages;
300 foreach my $language (split /\s+/, $data->{'value'}) {
301 next if $language eq 'images';
302 push @options, { option => $language, counter => $counter };
303 $currently_selected_languages->{$language}=1;
306 foreach my $language (getalllanguages()) {
307 next if $language eq 'images';
309 next if $currently_selected_languages->{$language};
310 push @options, { option => $language, counter => $counter };
314 $template->param('type-free' => 1);
315 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
317 $template->param(explanation => $data->{'explanation'},
318 value => $data->{'value'},
319 type => $data->{'type'},
320 options => \@options,
321 preftype => $data->{'type'},
322 prefoptions => $data->{'options'},
323 searchfield => $searchfield);
325 ################## ADD_VALIDATE ##################################
326 # called by add_form, used to insert/modify data in DB
327 } elsif ($op eq 'add_validate') {
328 my $dbh = C4::Context->dbh;
329 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
330 $sth->execute($input->param('variable'));
332 unless (C4::Context->config('demo') eq 1) {
333 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
334 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
338 unless (C4::Context->config('demo') eq 1) {
339 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
340 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
345 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
347 ################## DELETE_CONFIRM ##################################
348 # called by default form, used to confirm deletion of data in DB
349 } elsif ($op eq 'delete_confirm') {
350 my $dbh = C4::Context->dbh;
351 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
352 $sth->execute($searchfield);
353 my $data=$sth->fetchrow_hashref;
355 $template->param(searchfield => $searchfield,
356 Tvalue => $data->{'value'},
359 # END $OP eq DELETE_CONFIRM
360 ################## DELETE_CONFIRMED ##################################
361 # called by delete_confirm, used to effectively confirm deletion of data in DB
362 } elsif ($op eq 'delete_confirmed') {
363 my $dbh = C4::Context->dbh;
364 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
365 $sth->execute($searchfield);
367 # END $OP eq DELETE_CONFIRMED
368 ################## DEFAULT ##################################
370 #Adding tab management for system preferences
371 my $tab=$input->param('tab');
374 my ($count,$results)=StringSearch($env,$searchfield,$tab);
377 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
383 my %row_data; # get a fresh hash for the row data
384 $row_data{variable} = $results->[$i]{'variable'};
385 $row_data{value} = $results->[$i]{'value'};
386 $row_data{explanation} = $results->[$i]{'explanation'};
387 $row_data{toggle} = $toggle;
388 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
389 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
390 push(@loop_data, \%row_data);
392 $tab=($tab?$tab:"Others");
393 $template->param(loop => \@loop_data, $tab => 1);
395 my $prevpage = $offset-$pagesize;
396 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
398 if ($offset+$pagesize<$count) {
399 my $nextpage =$offset+$pagesize;
400 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
402 } #---- END $OP eq DEFAULT
403 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
404 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
405 IntranetNav => C4::Context->preference("IntranetNav"),
407 output_html_with_http_headers $input, $cookie, $template->output;