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
53 # FIXME, shouldnt we store this stuff in the systempreferences table?
57 $tabsysprefs{acquisitions}="Acquisitions";
58 $tabsysprefs{gist}="Acquisitions";
60 $tabsysprefs{dateformat}="Admin";
61 $tabsysprefs{delimiter}="Admin";
62 $tabsysprefs{IndependantBranches}="Admin";
63 $tabsysprefs{insecure}="Admin";
64 $tabsysprefs{KohaAdmin}="Admin";
65 $tabsysprefs{KohaAdminEmailAddress}="Admin";
66 $tabsysprefs{MIME}="Admin";
67 $tabsysprefs{timeout}="Admin";
68 $tabsysprefs{Intranet_includes}="Admin";
69 $tabsysprefs{AutoLocation}="Admin";
72 $tabsysprefs{authoritysep}="Authorities";
73 $tabsysprefs{AuthDisplayHierarchy}="Authorities";
75 $tabsysprefs{advancedMARCEditor}="Catalogue";
76 $tabsysprefs{autoBarcode}="Catalogue";
77 $tabsysprefs{hide_marc}="Catalogue";
78 $tabsysprefs{IntranetBiblioDefaultView} = "Catalogue";
79 $tabsysprefs{ISBD}="Catalogue";
80 $tabsysprefs{itemcallnumber}="Catalogue";
81 $tabsysprefs{kohaspsuggest} = "Catalogue";
82 $tabsysprefs{LabelMARCView}="Catalogue";
83 $tabsysprefs{marc}="Catalogue";
84 $tabsysprefs{marcflavour}="Catalogue";
85 $tabsysprefs{serialsadditems}="Catalogue";
86 $tabsysprefs{sortbynonfiling}="Catalogue";
87 $tabsysprefs{MARCOrgCode}="Catalogue";
88 $tabsysprefs{z3950AuthorAuthFields}="Catalogue";
89 $tabsysprefs{z3950NormalizeAuthor}="Catalogue";
90 $tabsysprefs{Stemming}="Catalogue";
91 $tabsysprefs{WeightFields}="Catalogue";
92 $tabsysprefs{expandedSearchOption}="Catalogue";
93 $tabsysprefs{NoZebra}="Catalogue";
94 $tabsysprefs{NoZebraIndexes}="Catalogue";
95 $tabsysprefs{ReceiveBackIssues}="Catalogue";
98 $tabsysprefs{maxoutstanding}="Circulation";
99 $tabsysprefs{maxreserves}="Circulation";
100 $tabsysprefs{noissuescharge}="Circulation";
101 $tabsysprefs{IssuingInProcess}="Circulation";
102 $tabsysprefs{patronimages}="Circulation";
103 $tabsysprefs{printcirculationslips}="Circulation";
104 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
105 $tabsysprefs{SpecifyDueDate}="Circulation";
106 $tabsysprefs{AutomaticItemReturn}="Circulation";
107 $tabsysprefs{ReservesMaxPickUpDelay}="Circulation";
108 $tabsysprefs{TransfersMaxDaysWarning}="Circulation";
109 $tabsysprefs{useDaysMode}="Circulation";
112 $tabsysprefs{TemplateEncoding}="Intranet";
113 $tabsysprefs{template}="Intranet";
114 $tabsysprefs{intranetstylesheet}="Intranet";
115 $tabsysprefs{IntranetNav}="Intranet";
116 $tabsysprefs{intranetcolorstylesheet}="Intranet";
117 $tabsysprefs{intranetuserjs}="Intranet";
119 $tabsysprefs{automembernum}="Members";
120 $tabsysprefs{checkdigit}="Members";
121 $tabsysprefs{intranetreadinghistory}="Members";
122 $tabsysprefs{NotifyBorrowerDeparture}="Members";
123 $tabsysprefs{memberofinstitution}="Members";
124 $tabsysprefs{ReadingHistory}="Members";
125 $tabsysprefs{BorrowerMandatoryField}="Members";
126 $tabsysprefs{borrowerRelationship}="Members";
127 $tabsysprefs{BorrowersTitles}="Members";
128 $tabsysprefs{patronimages}="Members";
129 $tabsysprefs{MinPasswordLength}="Members";
130 $tabsysprefs{uppercasesurnames}="Members";
133 $tabsysprefs{AmazonAssocTag}="OPAC";
134 $tabsysprefs{AmazonContent}="OPAC";
135 $tabsysprefs{AmazonDevKey}="OPAC";
136 $tabsysprefs{BiblioDefaultView}="OPAC";
137 $tabsysprefs{LibraryName}="OPAC";
138 $tabsysprefs{opaccolorstylesheet}="OPAC";
139 $tabsysprefs{opaccredits}="OPAC";
140 $tabsysprefs{opaclanguages}="OPAC";
141 $tabsysprefs{opaclargeimage}="OPAC";
142 $tabsysprefs{opaclayoutstylesheet}="OPAC";
143 $tabsysprefs{OpacNav}="OPAC";
144 $tabsysprefs{opacsmallimage}="OPAC";
145 $tabsysprefs{opacstylesheet}="OPAC";
146 $tabsysprefs{opacthemes}="OPAC";
147 $tabsysprefs{opacuserjs}="OPAC";
148 $tabsysprefs{SubscriptionHistory}="OPAC";
149 $tabsysprefs{opacheader}="OPAC";
152 $tabsysprefs{Disable_Dictionary}="OPACFeatures";
153 $tabsysprefs{hidelostitems}="OPACFeatures";
154 $tabsysprefs{opacbookbag}="OPACFeatures";
155 $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
156 $tabsysprefs{OpacPasswordChange}="OPACFeatures";
157 $tabsysprefs{opacreadinghistory}="OPACFeatures";
158 $tabsysprefs{virtualshelves}="OPACFeatures";
159 $tabsysprefs{RequestOnOpac}="OPACFeatures";
160 $tabsysprefs{reviewson}="OPACFeatures";
161 $tabsysprefs{OpacTopissues}="OPACFeatures";
162 $tabsysprefs{OpacAuthorities}="OPACFeatures";
163 $tabsysprefs{OpacCloud}="OPACFeatures";
164 $tabsysprefs{opacuserlogin}="OPACFeatures";
165 $tabsysprefs{AnonSuggestions}="OPACFeatures";
166 $tabsysprefs{suggestion}="OPACFeatures";
167 $tabsysprefs{OpacTopissue}="OPACFeatures";
168 $tabsysprefs{OpacBrowser}="OPACFeatures";
171 $tabsysprefs{CataloguingLog} = "LOGFeatures";
172 $tabsysprefs{BorrowersLog} = "LOGFeatures";
173 $tabsysprefs{SubscriptionLog} = "LOGFeatures";
174 $tabsysprefs{IssueLog} = "LOGFeatures";
175 $tabsysprefs{ReturnLog} = "LOGFeatures";
176 $tabsysprefs{LetterLog} = "LOGFeatures";
177 $tabsysprefs{FinesLog} = "LOGFeatures";
180 my ($searchstring,$type)=@_;
181 my $dbh = C4::Context->dbh;
182 $searchstring=~ s/\'/\\\'/g;
183 my @data=split(' ',$searchstring);
188 foreach my $syspref (sort keys %tabsysprefs){
189 if ($tabsysprefs{$syspref} eq $type){
190 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
191 $sth->execute($syspref);
192 while (my $data=$sth->fetchrow_hashref){
193 $data->{value} =~ s/</</g;
194 $data->{value} =~ s/>/>/g;
195 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
196 push(@results,$data);
203 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
204 foreach my $syspref (keys %tabsysprefs){
205 $strsth .= $dbh->quote($syspref).",";
208 $strsth .= " order by variable";
209 my $sth=$dbh->prepare($strsth);
211 while (my $data=$sth->fetchrow_hashref){
212 $data->{value}=substr($data->{value},0,100);
213 push(@results,$data);
218 return ($cnt,\@results);
222 my $searchfield=$input->param('searchfield');
223 my $offset=$input->param('offset');
224 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
226 my ($template, $borrowernumber, $cookie)
227 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
230 authnotrequired => 0,
231 flagsrequired => {parameters => 1},
235 my $op = $input->param('op');
236 $searchfield=~ s/\,//g;
239 $template->param(script_name => $script_name,
240 $op => 1); # we show only the TMPL_VAR names $op
242 $template->param(script_name => $script_name,
243 else => 1); # we show only the TMPL_VAR names $op
246 if ($op eq 'update_and_reedit') {
247 foreach ($input->param) {
250 if (my $currentorder=$input->param('currentorder')) {
251 my @currentorder=split /\|/, $currentorder;
253 foreach my $param ($input->param) {
254 if ($param=~m#up-(\d+).x#) {
255 my $temp=$currentorder[$1];
256 $currentorder[$1]=$currentorder[$1-1];
257 $currentorder[$1-1]=$temp;
260 } elsif ($param=~m#down-(\d+).x#) {
261 my $temp=$currentorder[$1];
262 $currentorder[$1]=$currentorder[$1+1];
263 $currentorder[$1+1]=$temp;
268 $value=join ' ', @currentorder;
271 $template->param(script_name => $script_name,
272 $op => 1); # we show only the TMPL_VAR names $op
276 $template->param(script_name => $script_name,
277 else => 1); # we show only the TMPL_VAR names $op
280 my $dbh = C4::Context->dbh;
281 my $query="select * from systempreferences where variable=?";
282 my $sth=$dbh->prepare($query);
283 $sth->execute($input->param('variable'));
285 unless (C4::Context->config('demo') eq 1) {
286 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
287 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
291 unless (C4::Context->config('demo') eq 1) {
292 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
293 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
301 ################## ADD_FORM ##################################
302 # called by default. Used to create form to add or modify a record
304 if ($op eq 'add_form') {
305 #---- if primkey exists, it's a modify action, so read values to modify...
308 my $dbh = C4::Context->dbh;
309 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
310 $sth->execute($searchfield);
311 $data=$sth->fetchrow_hashref;
313 $template->param(modify => 1);
317 foreach my $option (split(/\|/, $data->{'options'})) {
319 $option eq $data->{'value'} and $selected=1;
320 push @options, { option => $option, selected => $selected };
322 if ($data->{'type'} eq 'Choice') {
323 $template->param('type-choice' => 1);
324 } elsif ($data->{'type'} eq 'YesNo') {
325 $template->param('type-yesno' => 1);
326 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
327 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
328 } elsif ($data->{'type'} eq 'Integer') {
329 $template->param('type-free' => 1);
330 $template->param('fieldlength' => $data->{'options'});
331 } elsif ($data->{'type'} eq 'Textarea') {
332 $template->param('type-textarea' => 1);
333 $data->{options} =~ /(.*)\|(.*)/;
334 $template->param('cols' => $1, 'rows' => $2);;
335 } elsif ($data->{'type'} eq 'Float') {
336 $template->param('type-free' => 1);
337 $template->param('fieldlength' => $data->{'options'});
338 } elsif ($data->{'type'} eq 'Themes') {
339 $template->param('type-choice' => 1);
341 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
343 my $currently_selected_themes;
345 foreach my $theme (split /\s+/, $data->{'value'}) {
346 push @options, { option => $theme, counter => $counter };
347 $currently_selected_themes->{$theme}=1;
350 foreach my $theme (getallthemes($type)) {
352 next if $currently_selected_themes->{$theme};
353 push @options, { option => $theme, counter => $counter };
356 } elsif ($data->{'type'} eq 'Languages') {
357 $template->param('type-choice' => 1);
360 my $currently_selected_languages;
362 foreach my $language (split /\s+/, $data->{'value'}) {
363 next if $language eq 'images';
364 push @options, { option => $language, counter => $counter };
365 $currently_selected_languages->{$language}=1;
368 my $langavail = getTranslatedLanguages();
369 foreach my $language (@$langavail) {
371 next if $currently_selected_languages->{$language->{'language_code'}};
372 #FIXME: could add language_name and language_locale_name for better display
373 push @options, { option => $language->{'language_code'}, counter => $counter };
377 $template->param('type-free' => 1);
378 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
380 $template->param(explanation => $data->{'explanation'},
381 value => $data->{'value'},
382 type => $data->{'type'},
383 options => \@options,
384 preftype => $data->{'type'},
385 prefoptions => $data->{'options'},
386 searchfield => $searchfield);
388 ################## ADD_VALIDATE ##################################
389 # called by add_form, used to insert/modify data in DB
390 } elsif ($op eq 'add_validate') {
391 my $dbh = C4::Context->dbh;
392 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
393 $sth->execute($input->param('variable'));
395 unless (C4::Context->config('demo') eq 1) {
396 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
397 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
401 unless (C4::Context->config('demo') eq 1) {
402 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
403 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
408 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
410 ################## DELETE_CONFIRM ##################################
411 # called by default form, used to confirm deletion of data in DB
412 } elsif ($op eq 'delete_confirm') {
413 my $dbh = C4::Context->dbh;
414 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
415 $sth->execute($searchfield);
416 my $data=$sth->fetchrow_hashref;
418 $template->param(searchfield => $searchfield,
419 Tvalue => $data->{'value'},
422 # END $OP eq DELETE_CONFIRM
423 ################## DELETE_CONFIRMED ##################################
424 # called by delete_confirm, used to effectively confirm deletion of data in DB
425 } elsif ($op eq 'delete_confirmed') {
426 my $dbh = C4::Context->dbh;
427 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
428 $sth->execute($searchfield);
430 # END $OP eq DELETE_CONFIRMED
431 ################## DEFAULT ##################################
433 #Adding tab management for system preferences
434 my $tab=$input->param('tab');
436 my ($count,$results)=StringSearch($searchfield,$tab);
439 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
445 my %row_data; # get a fresh hash for the row data
446 $row_data{variable} = $results->[$i]{'variable'};
447 $row_data{value} = $results->[$i]{'value'};
448 $row_data{explanation} = $results->[$i]{'explanation'};
449 $row_data{toggle} = $toggle;
450 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
451 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
452 push(@loop_data, \%row_data);
454 $tab=($tab?$tab:"Others");
455 $template->param(loop => \@loop_data, $tab => 1);
457 my $prevpage = $offset-$pagesize;
458 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
460 if ($offset+$pagesize<$count) {
461 my $nextpage =$offset+$pagesize;
462 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
464 $template->param( tab => $tab,
466 } #---- END $OP eq DEFAULT
467 output_html_with_http_headers $input, $cookie, $template->output;