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";
72 $tabsysprefs{SessionStorage}="Admin";
75 $tabsysprefs{authoritysep}="Authorities";
76 $tabsysprefs{AuthDisplayHierarchy}="Authorities";
77 $tabsysprefs{dontmerge}="Authorities";
78 $tabsysprefs{BiblioAddsAuthorities}="Authorities";
80 $tabsysprefs{advancedMARCEditor}="Catalogue";
81 $tabsysprefs{autoBarcode}="Catalogue";
82 $tabsysprefs{hide_marc}="Catalogue";
83 $tabsysprefs{IntranetBiblioDefaultView} = "Catalogue";
84 $tabsysprefs{ISBD}="Catalogue";
85 $tabsysprefs{itemcallnumber}="Catalogue";
86 $tabsysprefs{LabelMARCView}="Catalogue";
87 $tabsysprefs{marc}="Catalogue";
88 $tabsysprefs{marcflavour}="Catalogue";
89 $tabsysprefs{serialsadditems}="Catalogue";
90 $tabsysprefs{sortbynonfiling}="Catalogue";
91 $tabsysprefs{MARCOrgCode}="Catalogue";
92 $tabsysprefs{z3950AuthorAuthFields}="Catalogue";
93 $tabsysprefs{z3950NormalizeAuthor}="Catalogue";
94 $tabsysprefs{Stemming}="Catalogue";
95 $tabsysprefs{WeightFields}="Catalogue";
96 $tabsysprefs{expandedSearchOption}="Catalogue";
97 $tabsysprefs{NoZebra}="Catalogue";
98 $tabsysprefs{NoZebraIndexes}="Catalogue";
99 $tabsysprefs{ReceiveBackIssues}="Catalogue";
100 $tabsysprefs{DefaultClassificationSource}="Catalogue";
101 $tabsysprefs{RoutingSerials}="Catalogue";
104 $tabsysprefs{maxoutstanding}="Circulation";
105 $tabsysprefs{maxreserves}="Circulation";
106 $tabsysprefs{noissuescharge}="Circulation";
107 $tabsysprefs{IssuingInProcess}="Circulation";
108 $tabsysprefs{patronimages}="Circulation";
109 $tabsysprefs{printcirculationslips}="Circulation";
110 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
111 $tabsysprefs{SpecifyDueDate}="Circulation";
112 $tabsysprefs{AutomaticItemReturn}="Circulation";
113 $tabsysprefs{ReservesMaxPickUpDelay}="Circulation";
114 $tabsysprefs{TransfersMaxDaysWarning}="Circulation";
115 $tabsysprefs{useDaysMode}="Circulation";
116 $tabsysprefs{ReservesNeedReturns}="Circulation";
117 $tabsysprefs{CircAutocompl}="Circulation";
120 $tabsysprefs{TemplateEncoding}="Intranet";
121 $tabsysprefs{template}="Intranet";
122 $tabsysprefs{intranetstylesheet}="Intranet";
123 $tabsysprefs{IntranetNav}="Intranet";
124 $tabsysprefs{intranetcolorstylesheet}="Intranet";
125 $tabsysprefs{intranetuserjs}="Intranet";
126 $tabsysprefs{yuipath}="Intranet";
128 $tabsysprefs{automembernum}="Members";
129 $tabsysprefs{checkdigit}="Members";
130 $tabsysprefs{intranetreadinghistory}="Members";
131 $tabsysprefs{NotifyBorrowerDeparture}="Members";
132 $tabsysprefs{memberofinstitution}="Members";
133 $tabsysprefs{ReadingHistory}="Members";
134 $tabsysprefs{BorrowerMandatoryField}="Members";
135 $tabsysprefs{borrowerRelationship}="Members";
136 $tabsysprefs{BorrowersTitles}="Members";
137 $tabsysprefs{patronimages}="Members";
138 $tabsysprefs{MinPasswordLength}="Members";
139 $tabsysprefs{uppercasesurnames}="Members";
140 $tabsysprefs{NoReturnSetLost}="Members";
141 $tabsysprefs{MaxFine}="Members";
142 $tabsysprefs{NotifyBorrowerDeparture}="Members";
145 $tabsysprefs{AmazonAssocTag}="OPAC";
146 $tabsysprefs{AmazonContent}="OPAC";
147 $tabsysprefs{AmazonDevKey}="OPAC";
148 $tabsysprefs{BiblioDefaultView}="OPAC";
149 $tabsysprefs{LibraryName}="OPAC";
150 $tabsysprefs{opaccolorstylesheet}="OPAC";
151 $tabsysprefs{opaccredits}="OPAC";
152 $tabsysprefs{opaclanguages}="OPAC";
153 $tabsysprefs{opaclargeimage}="OPAC";
154 $tabsysprefs{opaclayoutstylesheet}="OPAC";
155 $tabsysprefs{OpacNav}="OPAC";
156 $tabsysprefs{opacsmallimage}="OPAC";
157 $tabsysprefs{opacstylesheet}="OPAC";
158 $tabsysprefs{opacthemes}="OPAC";
159 $tabsysprefs{opacuserjs}="OPAC";
160 $tabsysprefs{SubscriptionHistory}="OPAC";
161 $tabsysprefs{opacheader}="OPAC";
164 $tabsysprefs{SearchMyLibraryFirst}="OPACFeatures";
165 $tabsysprefs{Disable_Dictionary}="OPACFeatures";
166 $tabsysprefs{hidelostitems}="OPACFeatures";
167 $tabsysprefs{opacbookbag}="OPACFeatures";
168 $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
169 $tabsysprefs{OpacPasswordChange}="OPACFeatures";
170 $tabsysprefs{opacreadinghistory}="OPACFeatures";
171 $tabsysprefs{virtualshelves}="OPACFeatures";
172 $tabsysprefs{RequestOnOpac}="OPACFeatures";
173 $tabsysprefs{reviewson}="OPACFeatures";
174 $tabsysprefs{OpacTopissues}="OPACFeatures";
175 $tabsysprefs{OpacAuthorities}="OPACFeatures";
176 $tabsysprefs{OpacCloud}="OPACFeatures";
177 $tabsysprefs{opacuserlogin}="OPACFeatures";
178 $tabsysprefs{AnonSuggestions}="OPACFeatures";
179 $tabsysprefs{suggestion}="OPACFeatures";
180 $tabsysprefs{OpacTopissue}="OPACFeatures";
181 $tabsysprefs{OpacBrowser}="OPACFeatures";
182 $tabsysprefs{kohaspsuggest} = "OPACFeatures";
185 $tabsysprefs{CataloguingLog} = "LOGFeatures";
186 $tabsysprefs{BorrowersLog} = "LOGFeatures";
187 $tabsysprefs{SubscriptionLog} = "LOGFeatures";
188 $tabsysprefs{IssueLog} = "LOGFeatures";
189 $tabsysprefs{ReturnLog} = "LOGFeatures";
190 $tabsysprefs{LetterLog} = "LOGFeatures";
191 $tabsysprefs{FinesLog} = "LOGFeatures";
194 my ($searchstring,$type)=@_;
195 my $dbh = C4::Context->dbh;
196 $searchstring=~ s/\'/\\\'/g;
197 my @data=split(' ',$searchstring);
202 foreach my $syspref (sort keys %tabsysprefs){
203 if ($tabsysprefs{$syspref} eq $type){
204 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
205 $sth->execute($syspref);
206 while (my $data=$sth->fetchrow_hashref){
207 $data->{value} =~ s/</</g;
208 $data->{value} =~ s/>/>/g;
209 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
210 push(@results,$data);
217 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
218 foreach my $syspref (keys %tabsysprefs){
219 $strsth .= $dbh->quote($syspref).",";
222 $strsth .= " order by variable";
223 my $sth=$dbh->prepare($strsth);
225 while (my $data=$sth->fetchrow_hashref){
226 $data->{value}=substr($data->{value},0,100);
227 push(@results,$data);
232 return ($cnt,\@results);
236 my $searchfield=$input->param('searchfield');
237 my $offset=$input->param('offset');
238 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
240 my ($template, $borrowernumber, $cookie)
241 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
244 authnotrequired => 0,
245 flagsrequired => {parameters => 1},
249 my $op = $input->param('op');
250 $searchfield=~ s/\,//g;
253 $template->param(script_name => $script_name,
254 $op => 1); # we show only the TMPL_VAR names $op
256 $template->param(script_name => $script_name,
257 else => 1); # we show only the TMPL_VAR names $op
260 if ($op eq 'update_and_reedit') {
261 foreach ($input->param) {
264 if (my $currentorder=$input->param('currentorder')) {
265 my @currentorder=split /\|/, $currentorder;
267 foreach my $param ($input->param) {
268 if ($param=~m#up-(\d+).x#) {
269 my $temp=$currentorder[$1];
270 $currentorder[$1]=$currentorder[$1-1];
271 $currentorder[$1-1]=$temp;
274 } elsif ($param=~m#down-(\d+).x#) {
275 my $temp=$currentorder[$1];
276 $currentorder[$1]=$currentorder[$1+1];
277 $currentorder[$1+1]=$temp;
282 $value=join ' ', @currentorder;
285 $template->param(script_name => $script_name,
286 $op => 1); # we show only the TMPL_VAR names $op
290 $template->param(script_name => $script_name,
291 else => 1); # we show only the TMPL_VAR names $op
294 my $dbh = C4::Context->dbh;
295 my $query="select * from systempreferences where variable=?";
296 my $sth=$dbh->prepare($query);
297 $sth->execute($input->param('variable'));
299 unless (C4::Context->config('demo') eq 1) {
300 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
301 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
305 unless (C4::Context->config('demo') eq 1) {
306 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
307 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
315 ################## ADD_FORM ##################################
316 # called by default. Used to create form to add or modify a record
318 if ($op eq 'add_form') {
319 #---- if primkey exists, it's a modify action, so read values to modify...
322 my $dbh = C4::Context->dbh;
323 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
324 $sth->execute($searchfield);
325 $data=$sth->fetchrow_hashref;
327 $template->param(modify => 1);
331 foreach my $option (split(/\|/, $data->{'options'})) {
333 $option eq $data->{'value'} and $selected=1;
334 push @options, { option => $option, selected => $selected };
336 if ($data->{'type'} eq 'Choice') {
337 $template->param('type-choice' => 1);
338 } elsif ($data->{'type'} eq 'YesNo') {
339 $template->param('type-yesno' => 1);
340 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
341 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
342 } elsif ($data->{'type'} eq 'Integer') {
343 $template->param('type-free' => 1);
344 $template->param('fieldlength' => $data->{'options'});
345 } elsif ($data->{'type'} eq 'Textarea') {
346 $template->param('type-textarea' => 1);
347 $data->{options} =~ /(.*)\|(.*)/;
348 $template->param('cols' => $1, 'rows' => $2);;
349 } elsif ($data->{'type'} eq 'Float') {
350 $template->param('type-free' => 1);
351 $template->param('fieldlength' => $data->{'options'});
352 } elsif ($data->{'type'} eq 'Themes') {
353 $template->param('type-choice' => 1);
355 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
357 my $currently_selected_themes;
359 foreach my $theme (split /\s+/, $data->{'value'}) {
360 push @options, { option => $theme, counter => $counter };
361 $currently_selected_themes->{$theme}=1;
364 foreach my $theme (getallthemes($type)) {
366 next if $currently_selected_themes->{$theme};
367 push @options, { option => $theme, counter => $counter };
370 } elsif ($data->{'type'} eq 'ClassSources') {
371 $template->param('type-choice' => 1);
374 my $sources = GetClassSources();
376 foreach my $cn_source (sort keys %$sources) {
377 if ($cn_source eq $data->{'value'}) {
378 push @options, { option => $cn_source, counter => $counter, selected => 1 };
380 push @options, { option => $cn_source, counter => $counter };
384 } elsif ($data->{'type'} eq 'Languages') {
385 $template->param('type-choice' => 1);
388 my $currently_selected_languages;
390 foreach my $language (split /\s+/, $data->{'value'}) {
391 next if $language eq 'images';
392 push @options, { option => $language, counter => $counter };
393 $currently_selected_languages->{$language}=1;
396 my $langavail = getTranslatedLanguages();
397 foreach my $language (@$langavail) {
399 next if $currently_selected_languages->{$language->{'language_code'}};
400 #FIXME: could add language_name and language_locale_name for better display
401 push @options, { option => $language->{'language_code'}, counter => $counter };
405 $template->param('type-free' => 1);
406 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
408 $template->param(explanation => $data->{'explanation'},
409 value => $data->{'value'},
410 type => $data->{'type'},
411 options => \@options,
412 preftype => $data->{'type'},
413 prefoptions => $data->{'options'},
414 searchfield => $searchfield);
416 ################## ADD_VALIDATE ##################################
417 # called by add_form, used to insert/modify data in DB
418 } elsif ($op eq 'add_validate') {
419 my $dbh = C4::Context->dbh;
420 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
421 $sth->execute($input->param('variable'));
423 unless (C4::Context->config('demo') eq 1) {
424 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
425 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
429 unless (C4::Context->config('demo') eq 1) {
430 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
431 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
436 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
438 ################## DELETE_CONFIRM ##################################
439 # called by default form, used to confirm deletion of data in DB
440 } elsif ($op eq 'delete_confirm') {
441 my $dbh = C4::Context->dbh;
442 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
443 $sth->execute($searchfield);
444 my $data=$sth->fetchrow_hashref;
446 $template->param(searchfield => $searchfield,
447 Tvalue => $data->{'value'},
450 # END $OP eq DELETE_CONFIRM
451 ################## DELETE_CONFIRMED ##################################
452 # called by delete_confirm, used to effectively confirm deletion of data in DB
453 } elsif ($op eq 'delete_confirmed') {
454 my $dbh = C4::Context->dbh;
455 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
456 $sth->execute($searchfield);
458 # END $OP eq DELETE_CONFIRMED
459 ################## DEFAULT ##################################
461 #Adding tab management for system preferences
462 my $tab=$input->param('tab');
464 my ($count,$results)=StringSearch($searchfield,$tab);
467 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
473 my %row_data; # get a fresh hash for the row data
474 $row_data{variable} = $results->[$i]{'variable'};
475 $row_data{value} = $results->[$i]{'value'};
476 $row_data{yes} = 1 if ($results->[$i]{'value'} == 1);
477 $row_data{yesno} = 1 if ($results->[$i]{'type'} eq 'YesNo');
478 $row_data{explanation} = $results->[$i]{'explanation'};
479 $row_data{toggle} = $toggle;
480 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
481 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
482 push(@loop_data, \%row_data);
484 $tab=($tab?$tab:"Others");
485 $template->param(loop => \@loop_data, $tab => 1);
487 my $prevpage = $offset-$pagesize;
488 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
490 if ($offset+$pagesize<$count) {
491 my $nextpage =$offset+$pagesize;
492 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
494 $template->param( tab => $tab,
496 } #---- END $OP eq DEFAULT
497 output_html_with_http_headers $input, $cookie, $template->output;