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)
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
24 =head1 systempreferences.pl
27 this script use an $op to know what to do.
28 if $op is empty or none of the above values,
29 - the default screen is build (with all records, or filtered datas).
30 - the user can clic on add, modify or delete record.
32 - if primkey exists, this is a modification,so we read the $primkey record
33 - builds the add/modify form
35 - the user has just send datas, so we create/modify the record
37 - we show the record having primkey=$primkey and ask for deletion validation form
39 - we delete the record having primkey=$primkey
54 # FIXME, shouldnt we store this stuff in the systempreferences table?
58 $tabsysprefs{acquisitions}="Acquisitions";
59 $tabsysprefs{gist}="Acquisitions";
61 $tabsysprefs{dateformat}="Admin";
62 $tabsysprefs{delimiter}="Admin";
63 $tabsysprefs{IndependantBranches}="Admin";
64 $tabsysprefs{insecure}="Admin";
65 $tabsysprefs{KohaAdmin}="Admin";
66 $tabsysprefs{KohaAdminEmailAddress}="Admin";
67 $tabsysprefs{MIME}="Admin";
68 $tabsysprefs{timeout}="Admin";
69 $tabsysprefs{Intranet_includes}="Admin";
70 $tabsysprefs{AutoLocation}="Admin";
71 $tabsysprefs{DebugLevel}="Admin";
74 $tabsysprefs{authoritysep}="Authorities";
75 $tabsysprefs{AuthDisplayHierarchy}="Authorities";
77 $tabsysprefs{advancedMARCEditor}="Catalogue";
78 $tabsysprefs{autoBarcode}="Catalogue";
79 $tabsysprefs{hide_marc}="Catalogue";
80 $tabsysprefs{IntranetBiblioDefaultView} = "Catalogue";
81 $tabsysprefs{ISBD}="Catalogue";
82 $tabsysprefs{itemcallnumber}="Catalogue";
83 $tabsysprefs{kohaspsuggest} = "Catalogue";
84 $tabsysprefs{LabelMARCView}="Catalogue";
85 $tabsysprefs{marc}="Catalogue";
86 $tabsysprefs{marcflavour}="Catalogue";
87 $tabsysprefs{serialsadditems}="Catalogue";
88 $tabsysprefs{sortbynonfiling}="Catalogue";
89 $tabsysprefs{MARCOrgCode}="Catalogue";
90 $tabsysprefs{z3950AuthorAuthFields}="Catalogue";
91 $tabsysprefs{z3950NormalizeAuthor}="Catalogue";
92 $tabsysprefs{Stemming}="Catalogue";
93 $tabsysprefs{WeightFields}="Catalogue";
94 $tabsysprefs{expandedSearchOption}="Catalogue";
95 $tabsysprefs{NoZebra}="Catalogue";
96 $tabsysprefs{NoZebraIndexes}="Catalogue";
97 $tabsysprefs{ReceiveBackIssues}="Catalogue";
98 $tabsysprefs{DefaultClassificationSource}="Catalogue";
101 $tabsysprefs{maxoutstanding}="Circulation";
102 $tabsysprefs{maxreserves}="Circulation";
103 $tabsysprefs{noissuescharge}="Circulation";
104 $tabsysprefs{IssuingInProcess}="Circulation";
105 $tabsysprefs{patronimages}="Circulation";
106 $tabsysprefs{printcirculationslips}="Circulation";
107 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
108 $tabsysprefs{SpecifyDueDate}="Circulation";
109 $tabsysprefs{AutomaticItemReturn}="Circulation";
110 $tabsysprefs{ReservesMaxPickUpDelay}="Circulation";
111 $tabsysprefs{TransfersMaxDaysWarning}="Circulation";
112 $tabsysprefs{useDaysMode}="Circulation";
113 $tabsysprefs{ReservesNeedReturns}="Circulation";
114 $tabsysprefs{CircAutocompl}="Circulation";
117 $tabsysprefs{TemplateEncoding}="Intranet";
118 $tabsysprefs{template}="Intranet";
119 $tabsysprefs{intranetstylesheet}="Intranet";
120 $tabsysprefs{IntranetNav}="Intranet";
121 $tabsysprefs{intranetcolorstylesheet}="Intranet";
122 $tabsysprefs{intranetuserjs}="Intranet";
124 $tabsysprefs{automembernum}="Members";
125 $tabsysprefs{checkdigit}="Members";
126 $tabsysprefs{intranetreadinghistory}="Members";
127 $tabsysprefs{NotifyBorrowerDeparture}="Members";
128 $tabsysprefs{memberofinstitution}="Members";
129 $tabsysprefs{ReadingHistory}="Members";
130 $tabsysprefs{BorrowerMandatoryField}="Members";
131 $tabsysprefs{borrowerRelationship}="Members";
132 $tabsysprefs{BorrowersTitles}="Members";
133 $tabsysprefs{patronimages}="Members";
134 $tabsysprefs{MinPasswordLength}="Members";
135 $tabsysprefs{uppercasesurnames}="Members";
136 $tabsysprefs{NoReturnSetLost}="Members";
137 $tabsysprefs{MaxFine}="Members";
140 $tabsysprefs{AmazonAssocTag}="OPAC";
141 $tabsysprefs{AmazonContent}="OPAC";
142 $tabsysprefs{AmazonDevKey}="OPAC";
143 $tabsysprefs{BiblioDefaultView}="OPAC";
144 $tabsysprefs{LibraryName}="OPAC";
145 $tabsysprefs{opaccolorstylesheet}="OPAC";
146 $tabsysprefs{opaccredits}="OPAC";
147 $tabsysprefs{opaclanguages}="OPAC";
148 $tabsysprefs{opaclargeimage}="OPAC";
149 $tabsysprefs{opaclayoutstylesheet}="OPAC";
150 $tabsysprefs{OpacNav}="OPAC";
151 $tabsysprefs{opacsmallimage}="OPAC";
152 $tabsysprefs{opacstylesheet}="OPAC";
153 $tabsysprefs{opacthemes}="OPAC";
154 $tabsysprefs{opacuserjs}="OPAC";
155 $tabsysprefs{SubscriptionHistory}="OPAC";
156 $tabsysprefs{opacheader}="OPAC";
159 $tabsysprefs{Disable_Dictionary}="OPACFeatures";
160 $tabsysprefs{hidelostitems}="OPACFeatures";
161 $tabsysprefs{opacbookbag}="OPACFeatures";
162 $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
163 $tabsysprefs{OpacPasswordChange}="OPACFeatures";
164 $tabsysprefs{opacreadinghistory}="OPACFeatures";
165 $tabsysprefs{virtualshelves}="OPACFeatures";
166 $tabsysprefs{RequestOnOpac}="OPACFeatures";
167 $tabsysprefs{reviewson}="OPACFeatures";
168 $tabsysprefs{OpacTopissues}="OPACFeatures";
169 $tabsysprefs{OpacAuthorities}="OPACFeatures";
170 $tabsysprefs{OpacCloud}="OPACFeatures";
171 $tabsysprefs{opacuserlogin}="OPACFeatures";
172 $tabsysprefs{AnonSuggestions}="OPACFeatures";
173 $tabsysprefs{suggestion}="OPACFeatures";
174 $tabsysprefs{OpacTopissue}="OPACFeatures";
175 $tabsysprefs{OpacBrowser}="OPACFeatures";
178 $tabsysprefs{CataloguingLog} = "LOGFeatures";
179 $tabsysprefs{BorrowersLog} = "LOGFeatures";
180 $tabsysprefs{SubscriptionLog} = "LOGFeatures";
181 $tabsysprefs{IssueLog} = "LOGFeatures";
182 $tabsysprefs{ReturnLog} = "LOGFeatures";
183 $tabsysprefs{LetterLog} = "LOGFeatures";
184 $tabsysprefs{FinesLog} = "LOGFeatures";
187 my ($searchstring,$type)=@_;
188 my $dbh = C4::Context->dbh;
189 $searchstring=~ s/\'/\\\'/g;
190 my @data=split(' ',$searchstring);
195 foreach my $syspref (sort keys %tabsysprefs){
196 if ($tabsysprefs{$syspref} eq $type){
197 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
198 $sth->execute($syspref);
199 while (my $data=$sth->fetchrow_hashref){
200 $data->{value} =~ s/</</g;
201 $data->{value} =~ s/>/>/g;
202 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
203 push(@results,$data);
210 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
211 foreach my $syspref (keys %tabsysprefs){
212 $strsth .= $dbh->quote($syspref).",";
215 $strsth .= " order by variable";
216 my $sth=$dbh->prepare($strsth);
218 while (my $data=$sth->fetchrow_hashref){
219 $data->{value}=substr($data->{value},0,100);
220 push(@results,$data);
225 return ($cnt,\@results);
229 my $searchfield=$input->param('searchfield');
230 my $offset=$input->param('offset');
231 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
233 my ($template, $borrowernumber, $cookie)
234 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
237 authnotrequired => 0,
238 flagsrequired => {parameters => 1},
242 my $op = $input->param('op');
243 $searchfield=~ s/\,//g;
246 $template->param(script_name => $script_name,
247 $op => 1); # we show only the TMPL_VAR names $op
249 $template->param(script_name => $script_name,
250 else => 1); # we show only the TMPL_VAR names $op
253 if ($op eq 'update_and_reedit') {
254 foreach ($input->param) {
257 if (my $currentorder=$input->param('currentorder')) {
258 my @currentorder=split /\|/, $currentorder;
260 foreach my $param ($input->param) {
261 if ($param=~m#up-(\d+).x#) {
262 my $temp=$currentorder[$1];
263 $currentorder[$1]=$currentorder[$1-1];
264 $currentorder[$1-1]=$temp;
267 } elsif ($param=~m#down-(\d+).x#) {
268 my $temp=$currentorder[$1];
269 $currentorder[$1]=$currentorder[$1+1];
270 $currentorder[$1+1]=$temp;
275 $value=join ' ', @currentorder;
278 $template->param(script_name => $script_name,
279 $op => 1); # we show only the TMPL_VAR names $op
283 $template->param(script_name => $script_name,
284 else => 1); # we show only the TMPL_VAR names $op
287 my $dbh = C4::Context->dbh;
288 my $query="select * from systempreferences where variable=?";
289 my $sth=$dbh->prepare($query);
290 $sth->execute($input->param('variable'));
292 unless (C4::Context->config('demo') eq 1) {
293 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
294 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
298 unless (C4::Context->config('demo') eq 1) {
299 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
300 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
308 ################## ADD_FORM ##################################
309 # called by default. Used to create form to add or modify a record
311 if ($op eq 'add_form') {
312 #---- if primkey exists, it's a modify action, so read values to modify...
315 my $dbh = C4::Context->dbh;
316 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
317 $sth->execute($searchfield);
318 $data=$sth->fetchrow_hashref;
320 $template->param(modify => 1);
324 foreach my $option (split(/\|/, $data->{'options'})) {
326 $option eq $data->{'value'} and $selected=1;
327 push @options, { option => $option, selected => $selected };
329 if ($data->{'type'} eq 'Choice') {
330 $template->param('type-choice' => 1);
331 } elsif ($data->{'type'} eq 'YesNo') {
332 $template->param('type-yesno' => 1);
333 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
334 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
335 } elsif ($data->{'type'} eq 'Integer') {
336 $template->param('type-free' => 1);
337 $template->param('fieldlength' => $data->{'options'});
338 } elsif ($data->{'type'} eq 'Textarea') {
339 $template->param('type-textarea' => 1);
340 $data->{options} =~ /(.*)\|(.*)/;
341 $template->param('cols' => $1, 'rows' => $2);;
342 } elsif ($data->{'type'} eq 'Float') {
343 $template->param('type-free' => 1);
344 $template->param('fieldlength' => $data->{'options'});
345 } elsif ($data->{'type'} eq 'Themes') {
346 $template->param('type-choice' => 1);
348 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
350 my $currently_selected_themes;
352 foreach my $theme (split /\s+/, $data->{'value'}) {
353 push @options, { option => $theme, counter => $counter };
354 $currently_selected_themes->{$theme}=1;
357 foreach my $theme (getallthemes($type)) {
359 next if $currently_selected_themes->{$theme};
360 push @options, { option => $theme, counter => $counter };
363 } elsif ($data->{'type'} eq 'ClassSource') {
364 $template->param('type-choice' => 1);
367 my $sources = GetClassSources();
369 foreach my $cn_source (sort keys %$sources) {
370 if ($cn_source eq $data->{'value'}) {
371 push @options, { option => $cn_source, counter => $counter, selected => 1 };
373 push @options, { option => $cn_source, counter => $counter };
377 } elsif ($data->{'type'} eq 'Languages') {
378 $template->param('type-choice' => 1);
381 my $currently_selected_languages;
383 foreach my $language (split /\s+/, $data->{'value'}) {
384 next if $language eq 'images';
385 push @options, { option => $language, counter => $counter };
386 $currently_selected_languages->{$language}=1;
389 my $langavail = getTranslatedLanguages();
390 foreach my $language (@$langavail) {
392 next if $currently_selected_languages->{$language->{'language_code'}};
393 #FIXME: could add language_name and language_locale_name for better display
394 push @options, { option => $language->{'language_code'}, counter => $counter };
398 $template->param('type-free' => 1);
399 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
401 $template->param(explanation => $data->{'explanation'},
402 value => $data->{'value'},
403 type => $data->{'type'},
404 options => \@options,
405 preftype => $data->{'type'},
406 prefoptions => $data->{'options'},
407 searchfield => $searchfield);
409 ################## ADD_VALIDATE ##################################
410 # called by add_form, used to insert/modify data in DB
411 } elsif ($op eq 'add_validate') {
412 my $dbh = C4::Context->dbh;
413 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
414 $sth->execute($input->param('variable'));
416 unless (C4::Context->config('demo') eq 1) {
417 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
418 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
422 unless (C4::Context->config('demo') eq 1) {
423 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
424 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
429 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
431 ################## DELETE_CONFIRM ##################################
432 # called by default form, used to confirm deletion of data in DB
433 } elsif ($op eq 'delete_confirm') {
434 my $dbh = C4::Context->dbh;
435 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
436 $sth->execute($searchfield);
437 my $data=$sth->fetchrow_hashref;
439 $template->param(searchfield => $searchfield,
440 Tvalue => $data->{'value'},
443 # END $OP eq DELETE_CONFIRM
444 ################## DELETE_CONFIRMED ##################################
445 # called by delete_confirm, used to effectively confirm deletion of data in DB
446 } elsif ($op eq 'delete_confirmed') {
447 my $dbh = C4::Context->dbh;
448 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
449 $sth->execute($searchfield);
451 # END $OP eq DELETE_CONFIRMED
452 ################## DEFAULT ##################################
454 #Adding tab management for system preferences
455 my $tab=$input->param('tab');
457 my ($count,$results)=StringSearch($searchfield,$tab);
460 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
466 my %row_data; # get a fresh hash for the row data
467 $row_data{variable} = $results->[$i]{'variable'};
468 $row_data{value} = $results->[$i]{'value'};
469 $row_data{yes} = 1 if ($results->[$i]{'value'} == 1);
470 $row_data{yesno} = 1 if ($results->[$i]{'type'} eq 'YesNo');
471 $row_data{explanation} = $results->[$i]{'explanation'};
472 $row_data{toggle} = $toggle;
473 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
474 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
475 push(@loop_data, \%row_data);
477 $tab=($tab?$tab:"Others");
478 $template->param(loop => \@loop_data, $tab => 1);
480 my $prevpage = $offset-$pagesize;
481 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
483 if ($offset+$pagesize<$count) {
484 my $nextpage =$offset+$pagesize;
485 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
487 $template->param( tab => $tab,
489 } #---- END $OP eq DEFAULT
490 output_html_with_http_headers $input, $cookie, $template->output;