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";
78 $tabsysprefs{maxoutstanding}="Circulation";
79 $tabsysprefs{maxreserves}="Circulation";
80 $tabsysprefs{noissuescharge}="Circulation";
81 $tabsysprefs{patronimages}="Circulation";
82 $tabsysprefs{printcirculationslips}="Circulation";
83 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
84 $tabsysprefs{allowrenewalsbefore}="Circulation";
85 $tabsysprefs{defaultBranch}="Circulation";
86 $tabsysprefs{strictrenewals}="Circulation";
88 $tabsysprefs{TemplateEncoding}="Intranet";
89 $tabsysprefs{template}="Intranet";
90 $tabsysprefs{intranetstylesheet}="Intranet";
91 $tabsysprefs{IntranetNav}="Intranet";
92 $tabsysprefs{intranetcolorstylesheet}="Intranet";
93 $tabsysprefs{Activate_Log}="Intranet";
94 $tabsysprefs{allowrenewalsbefore}="Intranet";
96 $tabsysprefs{zebrawait}="Intranet";
97 $tabsysprefs{retrieve_from}="Intranet";
98 $tabsysprefs{batchMode}="Intranet";
101 $tabsysprefs{automembernum}="Members";
102 $tabsysprefs{checkdigit}="Members";
103 $tabsysprefs{NotifyBorrowerDeparture}="Members";
105 $tabsysprefs{AmazonAssocTag}="OPAC";
106 $tabsysprefs{AmazonContent}="OPAC";
107 $tabsysprefs{AmazonDevKey}="OPAC";
108 $tabsysprefs{AnonSuggestions}="OPAC";
109 $tabsysprefs{BiblioDefaultView}="OPAC";
110 $tabsysprefs{Disable_Dictionary}="OPAC";
111 $tabsysprefs{hidelostitems}="OPAC";
112 $tabsysprefs{LibraryName}="OPAC";
113 $tabsysprefs{opacbookbag}="OPAC";
114 $tabsysprefs{opaccolorstylesheet}="OPAC";
115 $tabsysprefs{opaccredits}="OPAC";
116 $tabsysprefs{opaclanguages}="OPAC";
117 $tabsysprefs{opaclanguagesdisplay}="OPAC";
118 $tabsysprefs{opaclargeimage}="OPAC";
119 $tabsysprefs{opaclayoutstylesheet}="OPAC";
120 $tabsysprefs{OpacNav}="OPAC";
121 $tabsysprefs{OpacPasswordChange}="OPAC";
122 $tabsysprefs{opacreadinghistory}="OPAC";
123 $tabsysprefs{opacsmallimage}="OPAC";
124 $tabsysprefs{opacstylesheet}="OPAC";
125 $tabsysprefs{opacthemes}="OPAC";
126 $tabsysprefs{opacuserlogin}="OPAC";
127 $tabsysprefs{SubscriptionHistory}="OPAC";
128 $tabsysprefs{suggestion}="OPAC";
129 $tabsysprefs{virtualshelves}="OPAC";
130 $tabsysprefs{opacheader}="OPAC";
131 $tabsysprefs{allowrenewsfromopac}="OPAC";
134 my ($env,$searchstring,$type)=@_;
135 my $dbh = C4::Context->dbh;
136 $searchstring=~ s/\'/\\\'/g;
137 my @data=split(' ',$searchstring);
142 foreach my $syspref (sort keys %tabsysprefs){
143 if ($tabsysprefs{$syspref} eq $type){
144 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
145 $sth->execute($syspref);
146 while (my $data=$sth->fetchrow_hashref){
147 $data->{value} =~ s/</</g;
148 $data->{value} =~ s/>/</g;
149 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
150 push(@results,$data);
157 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
158 foreach my $syspref (keys %tabsysprefs){
159 $strsth .= $dbh->quote($syspref).",";
162 $strsth .= " order by variable";
164 my $sth=$dbh->prepare($strsth);
166 while (my $data=$sth->fetchrow_hashref){
167 $data->{value}=substr($data->{value},0,100);
168 push(@results,$data);
173 return ($cnt,\@results);
177 my $searchfield=$input->param('searchfield');
178 my $offset=$input->param('offset');
179 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
181 my ($template, $borrowernumber, $cookie)
182 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
185 authnotrequired => 0,
186 flagsrequired => {parameters => 1},
190 my $op = $input->param('op');
191 $searchfield=~ s/\,//g;
194 $template->param(script_name => $script_name,
195 $op => 1); # we show only the TMPL_VAR names $op
197 $template->param(script_name => $script_name,
198 else => 1); # we show only the TMPL_VAR names $op
201 if ($op eq 'update_and_reedit') {
202 foreach ($input->param) {
205 if (my $currentorder=$input->param('currentorder')) {
206 my @currentorder=split /\|/, $currentorder;
208 foreach my $param ($input->param) {
209 if ($param=~m#up-(\d+).x#) {
210 my $temp=$currentorder[$1];
211 $currentorder[$1]=$currentorder[$1-1];
212 $currentorder[$1-1]=$temp;
215 } elsif ($param=~m#down-(\d+).x#) {
216 my $temp=$currentorder[$1];
217 $currentorder[$1]=$currentorder[$1+1];
218 $currentorder[$1+1]=$temp;
223 $value=join ' ', @currentorder;
226 $template->param(script_name => $script_name,
227 $op => 1); # we show only the TMPL_VAR names $op
231 $template->param(script_name => $script_name,
232 else => 1); # we show only the TMPL_VAR names $op
235 my $dbh = C4::Context->dbh;
236 my $query="select * from systempreferences where variable=?";
237 my $sth=$dbh->prepare($query);
238 $sth->execute($input->param('variable'));
240 unless (C4::Context->config('demo') eq 1) {
241 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
242 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
246 unless (C4::Context->config('demo') eq 1) {
247 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
248 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
256 ################## ADD_FORM ##################################
257 # called by default. Used to create form to add or modify a record
259 if ($op eq 'add_form') {
260 #---- if primkey exists, it's a modify action, so read values to modify...
263 my $dbh = C4::Context->dbh;
264 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
265 $sth->execute($searchfield);
266 $data=$sth->fetchrow_hashref;
268 $template->param(modify => 1);
272 foreach my $option (split(/\|/, $data->{'options'})) {
274 $option eq $data->{'value'} and $selected=1;
275 push @options, { option => $option, selected => $selected };
277 if ($data->{'type'} eq 'Choice') {
278 $template->param('type-choice' => 1);
279 } elsif ($data->{'type'} eq 'YesNo') {
280 $template->param('type-yesno' => 1);
281 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
282 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
283 } elsif ($data->{'type'} eq 'Integer') {
284 $template->param('type-free' => 1);
285 $template->param('fieldlength' => $data->{'options'});
286 } elsif ($data->{'type'} eq 'Textarea') {
287 $template->param('type-textarea' => 1);
288 $data->{options} =~ /(.*)\|(.*)/;
289 $template->param('cols' => $1, 'rows' => $2);;
290 } elsif ($data->{'type'} eq 'Float') {
291 $template->param('type-free' => 1);
292 $template->param('fieldlength' => $data->{'options'});
293 } elsif ($data->{'type'} eq 'Themes') {
294 $template->param('type-choice' => 1);
296 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
298 my $currently_selected_themes;
300 foreach my $theme (split /\s+/, $data->{'value'}) {
301 push @options, { option => $theme, counter => $counter };
302 $currently_selected_themes->{$theme}=1;
305 foreach my $theme (getallthemes($type)) {
307 next if $currently_selected_themes->{$theme};
308 push @options, { option => $theme, counter => $counter };
311 } elsif ($data->{'type'} eq 'Languages') {
312 $template->param('type-choice' => 1);
315 my $currently_selected_languages;
317 foreach my $language (split /\s+/, $data->{'value'}) {
318 next if $language eq 'images';
319 push @options, { option => $language, counter => $counter };
320 $currently_selected_languages->{$language}=1;
323 foreach my $language (getalllanguages()) {
324 next if $language eq 'images';
326 next if $currently_selected_languages->{$language};
327 push @options, { option => $language, counter => $counter };
331 $template->param('type-free' => 1);
332 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
334 $template->param(explanation => $data->{'explanation'},
335 value => $data->{'value'},
336 type => $data->{'type'},
337 options => \@options,
338 preftype => $data->{'type'},
339 prefoptions => $data->{'options'},
340 searchfield => $searchfield);
342 ################## ADD_VALIDATE ##################################
343 # called by add_form, used to insert/modify data in DB
344 } elsif ($op eq 'add_validate') {
345 my $dbh = C4::Context->dbh;
346 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
347 $sth->execute($input->param('variable'));
349 unless (C4::Context->config('demo') eq 1) {
350 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
351 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
355 unless (C4::Context->config('demo') eq 1) {
356 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
357 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
362 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
364 ################## DELETE_CONFIRM ##################################
365 # called by default form, used to confirm deletion of data in DB
366 } elsif ($op eq 'delete_confirm') {
367 my $dbh = C4::Context->dbh;
368 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
369 $sth->execute($searchfield);
370 my $data=$sth->fetchrow_hashref;
372 $template->param(searchfield => $searchfield,
373 Tvalue => $data->{'value'},
376 # END $OP eq DELETE_CONFIRM
377 ################## DELETE_CONFIRMED ##################################
378 # called by delete_confirm, used to effectively confirm deletion of data in DB
379 } elsif ($op eq 'delete_confirmed') {
380 my $dbh = C4::Context->dbh;
381 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
382 $sth->execute($searchfield);
384 # END $OP eq DELETE_CONFIRMED
385 ################## DEFAULT ##################################
387 #Adding tab management for system preferences
388 my $tab=$input->param('tab');
391 my ($count,$results)=StringSearch($env,$searchfield,$tab);
394 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
400 my %row_data; # get a fresh hash for the row data
401 $row_data{variable} = $results->[$i]{'variable'};
402 $row_data{value} = $results->[$i]{'value'};
403 $row_data{explanation} = $results->[$i]{'explanation'};
404 $row_data{toggle} = $toggle;
405 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
406 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
407 push(@loop_data, \%row_data);
409 $tab=($tab?$tab:"Others");
410 $template->param(loop => \@loop_data, $tab => 1);
412 my $prevpage = $offset-$pagesize;
413 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
415 if ($offset+$pagesize<$count) {
416 my $nextpage =$offset+$pagesize;
417 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
419 } #---- END $OP eq DEFAULT
420 $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
421 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
422 IntranetNav => C4::Context->preference("IntranetNav"),
424 output_html_with_http_headers $input, $cookie, $template->output;