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";
55 $tabsysprefs{dateformat}="Admin";
56 $tabsysprefs{insecure}="Admin";
57 $tabsysprefs{KohaAdmin}="Admin";
59 $tabsysprefs{authoritysep}="Authorities";
61 $tabsysprefs{advancedMARCEditor}="Catalogue";
62 $tabsysprefs{autoBarcode}="Catalogue";
63 $tabsysprefs{hide_marc}="Catalogue";
64 $tabsysprefs{IntranetBiblioDefaultView} = "Catalogue";
65 $tabsysprefs{ISBD}="Catalogue";
66 $tabsysprefs{itemcallnumber}="Catalogue";
67 $tabsysprefs{LabelMARCView}="Catalogue";
68 $tabsysprefs{marc}="Catalogue";
69 $tabsysprefs{marcflavour}="Catalogue";
70 $tabsysprefs{serialsadditems}="Catalogue";
71 $tabsysprefs{sortbynonfiling}="Catalogue";
72 $tabsysprefs{MARCOrgCode}="Catalogue";
73 $tabsysprefs{z3950AuthorAuthFields}="Catalogue";
74 $tabsysprefs{z3950NormalizeAuthor}="Catalogue";
75 $tabsysprefs{SQLorZEBRA}="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";
83 $tabsysprefs{allowrenewalsbefore}="Circulation";
84 $tabsysprefs{defaultBranch}="Circulation";
85 $tabsysprefs{strictrenewals}="Circulation";
87 $tabsysprefs{TemplateEncoding}="Intranet";
88 $tabsysprefs{template}="Intranet";
89 $tabsysprefs{intranetstylesheet}="Intranet";
90 $tabsysprefs{IntranetNav}="Intranet";
91 $tabsysprefs{intranetcolorstylesheet}="Intranet";
92 $tabsysprefs{Activate_Log}="Intranet";
93 $tabsysprefs{allowrenewalsbefore}="Intranet";
95 $tabsysprefs{zebrawait}="Intranet";
96 $tabsysprefs{retrieve_from}="Intranet";
97 $tabsysprefs{batchMode}="Intranet";
100 $tabsysprefs{automembernum}="Members";
101 $tabsysprefs{checkdigit}="Members";
102 $tabsysprefs{NotifyBorrowerDeparture}="Members";
104 $tabsysprefs{AmazonAssocTag}="OPAC";
105 $tabsysprefs{AmazonContent}="OPAC";
106 $tabsysprefs{AmazonDevKey}="OPAC";
107 $tabsysprefs{AnonSuggestions}="OPAC";
108 $tabsysprefs{BiblioDefaultView}="OPAC";
109 $tabsysprefs{Disable_Dictionary}="OPAC";
110 $tabsysprefs{hidelostitems}="OPAC";
111 $tabsysprefs{LibraryName}="OPAC";
112 $tabsysprefs{opacbookbag}="OPAC";
113 $tabsysprefs{opaccolorstylesheet}="OPAC";
114 $tabsysprefs{opaccredits}="OPAC";
115 $tabsysprefs{opaclanguages}="OPAC";
116 $tabsysprefs{opaclanguagesdisplay}="OPAC";
117 $tabsysprefs{opaclargeimage}="OPAC";
118 $tabsysprefs{opaclayoutstylesheet}="OPAC";
119 $tabsysprefs{OpacNav}="OPAC";
120 $tabsysprefs{OpacPasswordChange}="OPAC";
121 $tabsysprefs{opacreadinghistory}="OPAC";
122 $tabsysprefs{opacsmallimage}="OPAC";
123 $tabsysprefs{opacstylesheet}="OPAC";
124 $tabsysprefs{opacthemes}="OPAC";
125 $tabsysprefs{opacuserlogin}="OPAC";
126 $tabsysprefs{SubscriptionHistory}="OPAC";
127 $tabsysprefs{suggestion}="OPAC";
128 $tabsysprefs{virtualshelves}="OPAC";
129 $tabsysprefs{opacheader}="OPAC";
130 $tabsysprefs{allowrenewsfromopac}="OPAC";
133 my ($env,$searchstring,$type)=@_;
134 my $dbh = C4::Context->dbh;
135 $searchstring=~ s/\'/\\\'/g;
136 my @data=split(' ',$searchstring);
141 foreach my $syspref (sort keys %tabsysprefs){
142 if ($tabsysprefs{$syspref} eq $type){
143 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
144 $sth->execute($syspref);
145 while (my $data=$sth->fetchrow_hashref){
146 $data->{value} =~ s/</</g;
147 $data->{value} =~ s/>/</g;
148 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
149 push(@results,$data);
156 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
157 foreach my $syspref (keys %tabsysprefs){
158 $strsth .= $dbh->quote($syspref).",";
161 $strsth .= " order by variable";
163 my $sth=$dbh->prepare($strsth);
165 while (my $data=$sth->fetchrow_hashref){
166 $data->{value}=substr($data->{value},0,100);
167 push(@results,$data);
172 return ($cnt,\@results);
176 my $searchfield=$input->param('searchfield');
177 my $offset=$input->param('offset');
178 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
180 my ($template, $borrowernumber, $cookie)
181 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
184 authnotrequired => 0,
185 flagsrequired => {parameters => 1},
189 my $op = $input->param('op');
190 $searchfield=~ s/\,//g;
193 $template->param(script_name => $script_name,
194 $op => 1); # we show only the TMPL_VAR names $op
196 $template->param(script_name => $script_name,
197 else => 1); # we show only the TMPL_VAR names $op
200 if ($op eq 'update_and_reedit') {
201 foreach ($input->param) {
204 if (my $currentorder=$input->param('currentorder')) {
205 my @currentorder=split /\|/, $currentorder;
207 foreach my $param ($input->param) {
208 if ($param=~m#up-(\d+).x#) {
209 my $temp=$currentorder[$1];
210 $currentorder[$1]=$currentorder[$1-1];
211 $currentorder[$1-1]=$temp;
214 } elsif ($param=~m#down-(\d+).x#) {
215 my $temp=$currentorder[$1];
216 $currentorder[$1]=$currentorder[$1+1];
217 $currentorder[$1+1]=$temp;
222 $value=join ' ', @currentorder;
225 $template->param(script_name => $script_name,
226 $op => 1); # we show only the TMPL_VAR names $op
230 $template->param(script_name => $script_name,
231 else => 1); # we show only the TMPL_VAR names $op
234 my $dbh = C4::Context->dbh;
235 my $query="select * from systempreferences where variable=?";
236 my $sth=$dbh->prepare($query);
237 $sth->execute($input->param('variable'));
239 unless (C4::Context->config('demo') eq 1) {
240 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
241 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
245 unless (C4::Context->config('demo') eq 1) {
246 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
247 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
255 ################## ADD_FORM ##################################
256 # called by default. Used to create form to add or modify a record
258 if ($op eq 'add_form') {
259 #---- if primkey exists, it's a modify action, so read values to modify...
262 my $dbh = C4::Context->dbh;
263 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
264 $sth->execute($searchfield);
265 $data=$sth->fetchrow_hashref;
267 $template->param(modify => 1);
271 foreach my $option (split(/\|/, $data->{'options'})) {
273 $option eq $data->{'value'} and $selected=1;
274 push @options, { option => $option, selected => $selected };
276 if ($data->{'type'} eq 'Choice') {
277 $template->param('type-choice' => 1);
278 } elsif ($data->{'type'} eq 'YesNo') {
279 $template->param('type-yesno' => 1);
280 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
281 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
282 } elsif ($data->{'type'} eq 'Integer') {
283 $template->param('type-free' => 1);
284 $template->param('fieldlength' => $data->{'options'});
285 } elsif ($data->{'type'} eq 'Textarea') {
286 $template->param('type-textarea' => 1);
287 $data->{options} =~ /(.*)\|(.*)/;
288 $template->param('cols' => $1, 'rows' => $2);;
289 } elsif ($data->{'type'} eq 'Float') {
290 $template->param('type-free' => 1);
291 $template->param('fieldlength' => $data->{'options'});
292 } elsif ($data->{'type'} eq 'Themes') {
293 $template->param('type-choice' => 1);
295 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
297 my $currently_selected_themes;
299 foreach my $theme (split /\s+/, $data->{'value'}) {
300 push @options, { option => $theme, counter => $counter };
301 $currently_selected_themes->{$theme}=1;
304 foreach my $theme (getallthemes($type)) {
306 next if $currently_selected_themes->{$theme};
307 push @options, { option => $theme, counter => $counter };
310 } elsif ($data->{'type'} eq 'Languages') {
311 $template->param('type-choice' => 1);
314 my $currently_selected_languages;
316 foreach my $language (split /\s+/, $data->{'value'}) {
317 next if $language eq 'images';
318 push @options, { option => $language, counter => $counter };
319 $currently_selected_languages->{$language}=1;
322 foreach my $language (getalllanguages()) {
323 next if $language eq 'images';
325 next if $currently_selected_languages->{$language};
326 push @options, { option => $language, counter => $counter };
330 $template->param('type-free' => 1);
331 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
333 $template->param(explanation => $data->{'explanation'},
334 value => $data->{'value'},
335 type => $data->{'type'},
336 options => \@options,
337 preftype => $data->{'type'},
338 prefoptions => $data->{'options'},
339 searchfield => $searchfield);
341 ################## ADD_VALIDATE ##################################
342 # called by add_form, used to insert/modify data in DB
343 } elsif ($op eq 'add_validate') {
344 my $dbh = C4::Context->dbh;
345 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
346 $sth->execute($input->param('variable'));
348 unless (C4::Context->config('demo') eq 1) {
349 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
350 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
354 unless (C4::Context->config('demo') eq 1) {
355 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
356 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
361 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
363 ################## DELETE_CONFIRM ##################################
364 # called by default form, used to confirm deletion of data in DB
365 } elsif ($op eq 'delete_confirm') {
366 my $dbh = C4::Context->dbh;
367 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
368 $sth->execute($searchfield);
369 my $data=$sth->fetchrow_hashref;
371 $template->param(searchfield => $searchfield,
372 Tvalue => $data->{'value'},
375 # END $OP eq DELETE_CONFIRM
376 ################## DELETE_CONFIRMED ##################################
377 # called by delete_confirm, used to effectively confirm deletion of data in DB
378 } elsif ($op eq 'delete_confirmed') {
379 my $dbh = C4::Context->dbh;
380 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
381 $sth->execute($searchfield);
383 # END $OP eq DELETE_CONFIRMED
384 ################## DEFAULT ##################################
386 #Adding tab management for system preferences
387 my $tab=$input->param('tab');
390 my ($count,$results)=StringSearch($env,$searchfield,$tab);
393 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
399 my %row_data; # get a fresh hash for the row data
400 $row_data{variable} = $results->[$i]{'variable'};
401 $row_data{value} = $results->[$i]{'value'};
402 $row_data{explanation} = $results->[$i]{'explanation'};
403 $row_data{toggle} = $toggle;
404 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
405 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
406 push(@loop_data, \%row_data);
408 $tab=($tab?$tab:"Others");
409 $template->param(loop => \@loop_data, $tab => 1);
411 my $prevpage = $offset-$pagesize;
412 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
414 if ($offset+$pagesize<$count) {
415 my $nextpage =$offset+$pagesize;
416 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
418 } #---- END $OP eq DEFAULT
419 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
420 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
421 IntranetNav => C4::Context->preference("IntranetNav"),
423 output_html_with_http_headers $input, $cookie, $template->output;