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";
88 $tabsysprefs{AmazonAssocTag}="OPAC";
89 $tabsysprefs{AmazonContent}="OPAC";
90 $tabsysprefs{AmazonDevKey}="OPAC";
91 $tabsysprefs{AnonSuggestions}="OPAC";
92 $tabsysprefs{BiblioDefaultView}="OPAC";
93 $tabsysprefs{Disable_Dictionary}="OPAC";
94 $tabsysprefs{hidelostitems}="OPAC";
95 $tabsysprefs{LibraryName}="OPAC";
96 $tabsysprefs{opacbookbag}="OPAC";
97 $tabsysprefs{opaccolorstylesheet}="OPAC";
98 $tabsysprefs{opaccredits}="OPAC";
99 $tabsysprefs{opaclanguages}="OPAC";
100 $tabsysprefs{opaclanguagesdisplay}="OPAC";
101 $tabsysprefs{opaclargeimage}="OPAC";
102 $tabsysprefs{opaclayoutstylesheet}="OPAC";
103 $tabsysprefs{OpacNav}="OPAC";
104 $tabsysprefs{OpacPasswordChange}="OPAC";
105 $tabsysprefs{opacreadinghistory}="OPAC";
106 $tabsysprefs{opacsmallimage}="OPAC";
107 $tabsysprefs{opacstylesheet}="OPAC";
108 $tabsysprefs{opacthemes}="OPAC";
109 $tabsysprefs{opacuserlogin}="OPAC";
110 $tabsysprefs{SubscriptionHistory}="OPAC";
111 $tabsysprefs{suggestion}="OPAC";
112 $tabsysprefs{virtualshelves}="OPAC";
115 my ($env,$searchstring,$type)=@_;
116 my $dbh = C4::Context->dbh;
117 $searchstring=~ s/\'/\\\'/g;
118 my @data=split(' ',$searchstring);
123 foreach my $syspref (sort keys %tabsysprefs){
124 if ($tabsysprefs{$syspref} eq $type){
125 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
126 $sth->execute($syspref);
127 while (my $data=$sth->fetchrow_hashref){
128 $data->{value} =~ s/</</g;
129 $data->{value} =~ s/>/</g;
130 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
131 push(@results,$data);
138 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
139 foreach my $syspref (keys %tabsysprefs){
140 $strsth .= $dbh->quote($syspref).",";
143 $strsth .= " order by variable";
145 my $sth=$dbh->prepare($strsth);
147 while (my $data=$sth->fetchrow_hashref){
148 $data->{value}=substr($data->{value},0,100);
149 push(@results,$data);
154 return ($cnt,\@results);
159 my $searchfield=$input->param('searchfield');
160 my $offset=$input->param('offset');
161 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
163 my ($template, $borrowernumber, $cookie)
164 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
167 authnotrequired => 0,
168 flagsrequired => {parameters => 1},
172 my $op = $input->param('op');
173 $searchfield=~ s/\,//g;
176 $template->param(script_name => $script_name,
177 $op => 1,); # we show only the TMPL_VAR names $op
179 $template->param(script_name => $script_name,
180 else => 1,); # we show only the TMPL_VAR names $op
183 if ($op eq 'update_and_reedit') {
184 foreach ($input->param) {
187 if (my $currentorder=$input->param('currentorder')) {
188 my @currentorder=split /\|/, $currentorder;
190 foreach my $param ($input->param) {
191 if ($param=~m#up-(\d+).x#) {
192 my $temp=$currentorder[$1];
193 $currentorder[$1]=$currentorder[$1-1];
194 $currentorder[$1-1]=$temp;
197 } elsif ($param=~m#down-(\d+).x#) {
198 my $temp=$currentorder[$1];
199 $currentorder[$1]=$currentorder[$1+1];
200 $currentorder[$1+1]=$temp;
205 $value=join ' ', @currentorder;
208 $template->param(script_name => $script_name,
209 $op => 1); # we show only the TMPL_VAR names $op
213 $template->param(script_name => $script_name,
214 else => 1); # we show only the TMPL_VAR names $op
217 my $dbh = C4::Context->dbh;
218 my $query="select * from systempreferences where variable=?";
219 my $sth=$dbh->prepare($query);
220 $sth->execute($input->param('variable'));
222 unless (C4::Context->config('demo') eq 1) {
223 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
224 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
228 unless (C4::Context->config('demo') eq 1) {
229 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
230 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
238 ################## ADD_FORM ##################################
239 # called by default. Used to create form to add or modify a record
241 if ($op eq 'add_form') {
242 #---- if primkey exists, it's a modify action, so read values to modify...
245 my $dbh = C4::Context->dbh;
246 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
247 $sth->execute($searchfield);
248 $data=$sth->fetchrow_hashref;
250 $template->param(modify => 1);
254 foreach my $option (split(/\|/, $data->{'options'})) {
256 $option eq $data->{'value'} and $selected=1;
257 push @options, { option => $option, selected => $selected };
259 if ($data->{'type'} eq 'Choice') {
260 $template->param('type-choice' => 1);
261 } elsif ($data->{'type'} eq 'YesNo') {
262 $template->param('type-yesno' => 1);
263 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
264 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
265 } elsif ($data->{'type'} eq 'Integer') {
266 $template->param('type-free' => 1);
267 $template->param('fieldlength' => $data->{'options'});
268 } elsif ($data->{'type'} eq 'Textarea') {
269 $template->param('type-textarea' => 1);
270 $data->{options} =~ /(.*)\|(.*)/;
271 $template->param('cols' => $1, 'rows' => $2);;
272 } elsif ($data->{'type'} eq 'Float') {
273 $template->param('type-free' => 1);
274 $template->param('fieldlength' => $data->{'options'});
275 } elsif ($data->{'type'} eq 'Themes') {
276 $template->param('type-choice' => 1);
278 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
280 my $currently_selected_themes;
282 foreach my $theme (split /\s+/, $data->{'value'}) {
283 push @options, { option => $theme, counter => $counter };
284 $currently_selected_themes->{$theme}=1;
287 foreach my $theme (getallthemes($type)) {
289 next if $currently_selected_themes->{$theme};
290 push @options, { option => $theme, counter => $counter };
293 } elsif ($data->{'type'} eq 'Languages') {
294 $template->param('type-choice' => 1);
297 my $currently_selected_languages;
299 foreach my $language (split /\s+/, $data->{'value'}) {
300 next if $language eq 'images';
301 push @options, { option => $language, counter => $counter };
302 $currently_selected_languages->{$language}=1;
305 foreach my $language (getalllanguages()) {
306 next if $language eq 'images';
308 next if $currently_selected_languages->{$language};
309 push @options, { option => $language, counter => $counter };
313 $template->param('type-free' => 1);
314 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
316 $template->param(explanation => $data->{'explanation'},
317 value => $data->{'value'},
318 type => $data->{'type'},
319 options => \@options,
320 preftype => $data->{'type'},
321 prefoptions => $data->{'options'},
322 searchfield => $searchfield);
324 ################## ADD_VALIDATE ##################################
325 # called by add_form, used to insert/modify data in DB
326 } elsif ($op eq 'add_validate') {
327 my $dbh = C4::Context->dbh;
328 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
329 $sth->execute($input->param('variable'));
331 unless (C4::Context->config('demo') eq 1) {
332 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
333 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
337 unless (C4::Context->config('demo') eq 1) {
338 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
339 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
344 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
346 ################## DELETE_CONFIRM ##################################
347 # called by default form, used to confirm deletion of data in DB
348 } elsif ($op eq 'delete_confirm') {
349 my $dbh = C4::Context->dbh;
350 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
351 $sth->execute($searchfield);
352 my $data=$sth->fetchrow_hashref;
354 $template->param(searchfield => $searchfield,
355 Tvalue => $data->{'value'},
358 # END $OP eq DELETE_CONFIRM
359 ################## DELETE_CONFIRMED ##################################
360 # called by delete_confirm, used to effectively confirm deletion of data in DB
361 } elsif ($op eq 'delete_confirmed') {
362 my $dbh = C4::Context->dbh;
363 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
364 $sth->execute($searchfield);
366 # END $OP eq DELETE_CONFIRMED
367 ################## DEFAULT ##################################
369 #Adding tab management for system preferences
370 my $tab=$input->param('tab');
373 my ($count,$results)=StringSearch($env,$searchfield,$tab);
376 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
382 my %row_data; # get a fresh hash for the row data
383 $row_data{variable} = $results->[$i]{'variable'};
384 $row_data{value} = $results->[$i]{'value'};
385 $row_data{explanation} = $results->[$i]{'explanation'};
386 $row_data{toggle} = $toggle;
387 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
388 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
389 push(@loop_data, \%row_data);
391 $tab=($tab?$tab:"Others");
392 $template->param(loop => \@loop_data, $tab => 1);
394 my $prevpage = $offset-$pagesize;
395 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
397 if ($offset+$pagesize<$count) {
398 my $nextpage =$offset+$pagesize;
399 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
401 } #---- END $OP eq DEFAULT
402 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
403 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
404 IntranetNav => C4::Context->preference("IntranetNav"),
406 output_html_with_http_headers $input, $cookie, $template->output;