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
50 use C4::Interface::CGI::Output;
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";
73 $tabsysprefs{authoritysep}="Authorities";
74 $tabsysprefs{AuthDisplayHierarchy}="Authorities";
76 $tabsysprefs{advancedMARCEditor}="Catalogue";
77 $tabsysprefs{autoBarcode}="Catalogue";
78 $tabsysprefs{hide_marc}="Catalogue";
79 $tabsysprefs{IntranetBiblioDefaultView} = "Catalogue";
80 $tabsysprefs{ISBD}="Catalogue";
81 $tabsysprefs{itemcallnumber}="Catalogue";
82 $tabsysprefs{kohaspsuggest} = "Catalogue";
83 $tabsysprefs{LabelMARCView}="Catalogue";
84 $tabsysprefs{marc}="Catalogue";
85 $tabsysprefs{marcflavour}="Catalogue";
86 $tabsysprefs{serialsadditems}="Catalogue";
87 $tabsysprefs{sortbynonfiling}="Catalogue";
88 $tabsysprefs{MARCOrgCode}="Catalogue";
89 $tabsysprefs{z3950AuthorAuthFields}="Catalogue";
90 $tabsysprefs{z3950NormalizeAuthor}="Catalogue";
91 $tabsysprefs{Stemming}="Catalogue";
92 $tabsysprefs{WeightFields}="Catalogue";
93 $tabsysprefs{expandedSearchOption}="Catalogue";
96 $tabsysprefs{maxoutstanding}="Circulation";
97 $tabsysprefs{maxreserves}="Circulation";
98 $tabsysprefs{noissuescharge}="Circulation";
99 $tabsysprefs{IssuingInProcess}="Circulation";
100 $tabsysprefs{patronimages}="Circulation";
101 $tabsysprefs{printcirculationslips}="Circulation";
102 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
103 $tabsysprefs{SpecifyDueDate}="Circulation";
104 $tabsysprefs{AutomaticItemReturn}="Circulation";
105 $tabsysprefs{ReservesMaxPickUpDelay}="Circulation";
106 $tabsysprefs{TransfersMaxDaysWarning}="Circulation";
107 $tabsysprefs{useDaysMode}="Circulation";
110 $tabsysprefs{TemplateEncoding}="Intranet";
111 $tabsysprefs{template}="Intranet";
112 $tabsysprefs{intranetstylesheet}="Intranet";
113 $tabsysprefs{IntranetNav}="Intranet";
114 $tabsysprefs{intranetcolorstylesheet}="Intranet";
115 $tabsysprefs{intranetuserjs}="Intranet";
117 $tabsysprefs{automembernum}="Members";
118 $tabsysprefs{checkdigit}="Members";
119 $tabsysprefs{intranetreadinghistory}="Members";
120 $tabsysprefs{NotifyBorrowerDeparture}="Members";
121 $tabsysprefs{memberofinstitution}="Members";
122 $tabsysprefs{ReadingHistory}="Members";
123 $tabsysprefs{BorrowerMandatoryField}="Members";
124 $tabsysprefs{borrowerRelationship}="Members";
125 $tabsysprefs{BorrowersTitles}="Members";
126 $tabsysprefs{patronimages}="Members";
129 $tabsysprefs{AmazonAssocTag}="OPAC";
130 $tabsysprefs{AmazonContent}="OPAC";
131 $tabsysprefs{AmazonDevKey}="OPAC";
132 $tabsysprefs{BiblioDefaultView}="OPAC";
133 $tabsysprefs{LibraryName}="OPAC";
134 $tabsysprefs{opaccolorstylesheet}="OPAC";
135 $tabsysprefs{opaccredits}="OPAC";
136 $tabsysprefs{opaclanguages}="OPAC";
137 $tabsysprefs{opaclargeimage}="OPAC";
138 $tabsysprefs{opaclayoutstylesheet}="OPAC";
139 $tabsysprefs{OpacNav}="OPAC";
140 $tabsysprefs{opacsmallimage}="OPAC";
141 $tabsysprefs{opacstylesheet}="OPAC";
142 $tabsysprefs{opacthemes}="OPAC";
143 $tabsysprefs{opacuserjs}="OPAC";
144 $tabsysprefs{SubscriptionHistory}="OPAC";
145 $tabsysprefs{opacheader}="OPAC";
148 $tabsysprefs{Disable_Dictionary}="OPACFeatures";
149 $tabsysprefs{hidelostitems}="OPACFeatures";
150 $tabsysprefs{opacbookbag}="OPACFeatures";
151 $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
152 $tabsysprefs{OpacPasswordChange}="OPACFeatures";
153 $tabsysprefs{opacreadinghistory}="OPACFeatures";
154 $tabsysprefs{virtualshelves}="OPACFeatures";
155 $tabsysprefs{RequestOnOpac}="OPACFeatures";
156 $tabsysprefs{reviewson}="OPACFeatures";
157 $tabsysprefs{OpacTopissues}="OPACFeatures";
158 $tabsysprefs{OpacAuthorities}="OPACFeatures";
159 $tabsysprefs{OpacCloud}="OPACFeatures";
160 $tabsysprefs{opacuserlogin}="OPACFeatures";
161 $tabsysprefs{AnonSuggestions}="OPACFeatures";
162 $tabsysprefs{suggestion}="OPACFeatures";
163 $tabsysprefs{OpacTopissue}="OPACFeatures";
164 $tabsysprefs{OpacBrowser}="OPACFeatures";
167 $tabsysprefs{CataloguingLog} = "LOGFeatures";
168 $tabsysprefs{BorrowersLog} = "LOGFeatures";
169 $tabsysprefs{SubscriptionLog} = "LOGFeatures";
170 $tabsysprefs{IssueLog} = "LOGFeatures";
171 $tabsysprefs{ReturnLog} = "LOGFeatures";
172 $tabsysprefs{LetterLog} = "LOGFeatures";
173 $tabsysprefs{FinesLog} = "LOGFeatures";
176 my ($env,$searchstring,$type)=@_;
177 my $dbh = C4::Context->dbh;
178 $searchstring=~ s/\'/\\\'/g;
179 my @data=split(' ',$searchstring);
184 foreach my $syspref (sort keys %tabsysprefs){
185 if ($tabsysprefs{$syspref} eq $type){
186 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
187 $sth->execute($syspref);
188 while (my $data=$sth->fetchrow_hashref){
189 $data->{value} =~ s/</</g;
190 $data->{value} =~ s/>/>/g;
191 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
192 push(@results,$data);
199 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
200 foreach my $syspref (keys %tabsysprefs){
201 $strsth .= $dbh->quote($syspref).",";
204 $strsth .= " order by variable";
205 my $sth=$dbh->prepare($strsth);
207 while (my $data=$sth->fetchrow_hashref){
208 $data->{value}=substr($data->{value},0,100);
209 push(@results,$data);
214 return ($cnt,\@results);
218 my $searchfield=$input->param('searchfield');
219 my $offset=$input->param('offset');
220 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
222 my ($template, $borrowernumber, $cookie)
223 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
226 authnotrequired => 0,
227 flagsrequired => {parameters => 1},
231 my $op = $input->param('op');
232 $searchfield=~ s/\,//g;
235 $template->param(script_name => $script_name,
236 $op => 1); # we show only the TMPL_VAR names $op
238 $template->param(script_name => $script_name,
239 else => 1); # we show only the TMPL_VAR names $op
242 if ($op eq 'update_and_reedit') {
243 foreach ($input->param) {
246 if (my $currentorder=$input->param('currentorder')) {
247 my @currentorder=split /\|/, $currentorder;
249 foreach my $param ($input->param) {
250 if ($param=~m#up-(\d+).x#) {
251 my $temp=$currentorder[$1];
252 $currentorder[$1]=$currentorder[$1-1];
253 $currentorder[$1-1]=$temp;
256 } elsif ($param=~m#down-(\d+).x#) {
257 my $temp=$currentorder[$1];
258 $currentorder[$1]=$currentorder[$1+1];
259 $currentorder[$1+1]=$temp;
264 $value=join ' ', @currentorder;
267 $template->param(script_name => $script_name,
268 $op => 1); # we show only the TMPL_VAR names $op
272 $template->param(script_name => $script_name,
273 else => 1); # we show only the TMPL_VAR names $op
276 my $dbh = C4::Context->dbh;
277 my $query="select * from systempreferences where variable=?";
278 my $sth=$dbh->prepare($query);
279 $sth->execute($input->param('variable'));
281 unless (C4::Context->config('demo') eq 1) {
282 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
283 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
287 unless (C4::Context->config('demo') eq 1) {
288 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
289 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
297 ################## ADD_FORM ##################################
298 # called by default. Used to create form to add or modify a record
300 if ($op eq 'add_form') {
301 #---- if primkey exists, it's a modify action, so read values to modify...
304 my $dbh = C4::Context->dbh;
305 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
306 $sth->execute($searchfield);
307 $data=$sth->fetchrow_hashref;
309 $template->param(modify => 1);
313 foreach my $option (split(/\|/, $data->{'options'})) {
315 $option eq $data->{'value'} and $selected=1;
316 push @options, { option => $option, selected => $selected };
318 if ($data->{'type'} eq 'Choice') {
319 $template->param('type-choice' => 1);
320 } elsif ($data->{'type'} eq 'YesNo') {
321 $template->param('type-yesno' => 1);
322 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
323 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
324 } elsif ($data->{'type'} eq 'Integer') {
325 $template->param('type-free' => 1);
326 $template->param('fieldlength' => $data->{'options'});
327 } elsif ($data->{'type'} eq 'Textarea') {
328 $template->param('type-textarea' => 1);
329 $data->{options} =~ /(.*)\|(.*)/;
330 $template->param('cols' => $1, 'rows' => $2);;
331 } elsif ($data->{'type'} eq 'Float') {
332 $template->param('type-free' => 1);
333 $template->param('fieldlength' => $data->{'options'});
334 } elsif ($data->{'type'} eq 'Themes') {
335 $template->param('type-choice' => 1);
337 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
339 my $currently_selected_themes;
341 foreach my $theme (split /\s+/, $data->{'value'}) {
342 push @options, { option => $theme, counter => $counter };
343 $currently_selected_themes->{$theme}=1;
346 foreach my $theme (getallthemes($type)) {
348 next if $currently_selected_themes->{$theme};
349 push @options, { option => $theme, counter => $counter };
352 } elsif ($data->{'type'} eq 'Languages') {
353 $template->param('type-choice' => 1);
356 my $currently_selected_languages;
358 foreach my $language (split /\s+/, $data->{'value'}) {
359 next if $language eq 'images';
360 push @options, { option => $language, counter => $counter };
361 $currently_selected_languages->{$language}=1;
364 my $langavail = getTranslatedLanguages();
365 foreach my $language (@$langavail) {
367 next if $currently_selected_languages->{$language->{'language_code'}};
368 #FIXME: could add language_name and language_locale_name for better display
369 push @options, { option => $language->{'language_code'}, counter => $counter };
373 $template->param('type-free' => 1);
374 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
376 $template->param(explanation => $data->{'explanation'},
377 value => $data->{'value'},
378 type => $data->{'type'},
379 options => \@options,
380 preftype => $data->{'type'},
381 prefoptions => $data->{'options'},
382 searchfield => $searchfield);
384 ################## ADD_VALIDATE ##################################
385 # called by add_form, used to insert/modify data in DB
386 } elsif ($op eq 'add_validate') {
387 my $dbh = C4::Context->dbh;
388 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
389 $sth->execute($input->param('variable'));
391 unless (C4::Context->config('demo') eq 1) {
392 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
393 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
397 unless (C4::Context->config('demo') eq 1) {
398 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
399 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
404 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
406 ################## DELETE_CONFIRM ##################################
407 # called by default form, used to confirm deletion of data in DB
408 } elsif ($op eq 'delete_confirm') {
409 my $dbh = C4::Context->dbh;
410 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
411 $sth->execute($searchfield);
412 my $data=$sth->fetchrow_hashref;
414 $template->param(searchfield => $searchfield,
415 Tvalue => $data->{'value'},
418 # END $OP eq DELETE_CONFIRM
419 ################## DELETE_CONFIRMED ##################################
420 # called by delete_confirm, used to effectively confirm deletion of data in DB
421 } elsif ($op eq 'delete_confirmed') {
422 my $dbh = C4::Context->dbh;
423 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
424 $sth->execute($searchfield);
426 # END $OP eq DELETE_CONFIRMED
427 ################## DEFAULT ##################################
429 #Adding tab management for system preferences
430 my $tab=$input->param('tab');
433 my ($count,$results)=StringSearch($env,$searchfield,$tab);
436 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
442 my %row_data; # get a fresh hash for the row data
443 $row_data{variable} = $results->[$i]{'variable'};
444 $row_data{value} = $results->[$i]{'value'};
445 $row_data{explanation} = $results->[$i]{'explanation'};
446 $row_data{toggle} = $toggle;
447 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
448 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
449 push(@loop_data, \%row_data);
451 $tab=($tab?$tab:"Others");
452 $template->param(loop => \@loop_data, $tab => 1);
454 my $prevpage = $offset-$pagesize;
455 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
457 if ($offset+$pagesize<$count) {
458 my $nextpage =$offset+$pagesize;
459 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
461 $template->param( tab => $tab,
463 } #---- END $OP eq DEFAULT
464 output_html_with_http_headers $input, $cookie, $template->output;