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";
132 $tabsysprefs{AmazonAssocTag}="OPAC";
133 $tabsysprefs{AmazonContent}="OPAC";
134 $tabsysprefs{AmazonDevKey}="OPAC";
135 $tabsysprefs{BiblioDefaultView}="OPAC";
136 $tabsysprefs{LibraryName}="OPAC";
137 $tabsysprefs{opaccolorstylesheet}="OPAC";
138 $tabsysprefs{opaccredits}="OPAC";
139 $tabsysprefs{opaclanguages}="OPAC";
140 $tabsysprefs{opaclargeimage}="OPAC";
141 $tabsysprefs{opaclayoutstylesheet}="OPAC";
142 $tabsysprefs{OpacNav}="OPAC";
143 $tabsysprefs{opacsmallimage}="OPAC";
144 $tabsysprefs{opacstylesheet}="OPAC";
145 $tabsysprefs{opacthemes}="OPAC";
146 $tabsysprefs{opacuserjs}="OPAC";
147 $tabsysprefs{SubscriptionHistory}="OPAC";
148 $tabsysprefs{opacheader}="OPAC";
151 $tabsysprefs{Disable_Dictionary}="OPACFeatures";
152 $tabsysprefs{hidelostitems}="OPACFeatures";
153 $tabsysprefs{opacbookbag}="OPACFeatures";
154 $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
155 $tabsysprefs{OpacPasswordChange}="OPACFeatures";
156 $tabsysprefs{opacreadinghistory}="OPACFeatures";
157 $tabsysprefs{virtualshelves}="OPACFeatures";
158 $tabsysprefs{RequestOnOpac}="OPACFeatures";
159 $tabsysprefs{reviewson}="OPACFeatures";
160 $tabsysprefs{OpacTopissues}="OPACFeatures";
161 $tabsysprefs{OpacAuthorities}="OPACFeatures";
162 $tabsysprefs{OpacCloud}="OPACFeatures";
163 $tabsysprefs{opacuserlogin}="OPACFeatures";
164 $tabsysprefs{AnonSuggestions}="OPACFeatures";
165 $tabsysprefs{suggestion}="OPACFeatures";
166 $tabsysprefs{OpacTopissue}="OPACFeatures";
167 $tabsysprefs{OpacBrowser}="OPACFeatures";
170 $tabsysprefs{CataloguingLog} = "LOGFeatures";
171 $tabsysprefs{BorrowersLog} = "LOGFeatures";
172 $tabsysprefs{SubscriptionLog} = "LOGFeatures";
173 $tabsysprefs{IssueLog} = "LOGFeatures";
174 $tabsysprefs{ReturnLog} = "LOGFeatures";
175 $tabsysprefs{LetterLog} = "LOGFeatures";
176 $tabsysprefs{FinesLog} = "LOGFeatures";
179 my ($searchstring,$type)=@_;
180 my $dbh = C4::Context->dbh;
181 $searchstring=~ s/\'/\\\'/g;
182 my @data=split(' ',$searchstring);
187 foreach my $syspref (sort keys %tabsysprefs){
188 if ($tabsysprefs{$syspref} eq $type){
189 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
190 $sth->execute($syspref);
191 while (my $data=$sth->fetchrow_hashref){
192 $data->{value} =~ s/</</g;
193 $data->{value} =~ s/>/>/g;
194 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
195 push(@results,$data);
202 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
203 foreach my $syspref (keys %tabsysprefs){
204 $strsth .= $dbh->quote($syspref).",";
207 $strsth .= " order by variable";
208 my $sth=$dbh->prepare($strsth);
210 while (my $data=$sth->fetchrow_hashref){
211 $data->{value}=substr($data->{value},0,100);
212 push(@results,$data);
217 return ($cnt,\@results);
221 my $searchfield=$input->param('searchfield');
222 my $offset=$input->param('offset');
223 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
225 my ($template, $borrowernumber, $cookie)
226 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
229 authnotrequired => 0,
230 flagsrequired => {parameters => 1},
234 my $op = $input->param('op');
235 $searchfield=~ s/\,//g;
238 $template->param(script_name => $script_name,
239 $op => 1); # we show only the TMPL_VAR names $op
241 $template->param(script_name => $script_name,
242 else => 1); # we show only the TMPL_VAR names $op
245 if ($op eq 'update_and_reedit') {
246 foreach ($input->param) {
249 if (my $currentorder=$input->param('currentorder')) {
250 my @currentorder=split /\|/, $currentorder;
252 foreach my $param ($input->param) {
253 if ($param=~m#up-(\d+).x#) {
254 my $temp=$currentorder[$1];
255 $currentorder[$1]=$currentorder[$1-1];
256 $currentorder[$1-1]=$temp;
259 } elsif ($param=~m#down-(\d+).x#) {
260 my $temp=$currentorder[$1];
261 $currentorder[$1]=$currentorder[$1+1];
262 $currentorder[$1+1]=$temp;
267 $value=join ' ', @currentorder;
270 $template->param(script_name => $script_name,
271 $op => 1); # we show only the TMPL_VAR names $op
275 $template->param(script_name => $script_name,
276 else => 1); # we show only the TMPL_VAR names $op
279 my $dbh = C4::Context->dbh;
280 my $query="select * from systempreferences where variable=?";
281 my $sth=$dbh->prepare($query);
282 $sth->execute($input->param('variable'));
284 unless (C4::Context->config('demo') eq 1) {
285 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
286 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
290 unless (C4::Context->config('demo') eq 1) {
291 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
292 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
300 ################## ADD_FORM ##################################
301 # called by default. Used to create form to add or modify a record
303 if ($op eq 'add_form') {
304 #---- if primkey exists, it's a modify action, so read values to modify...
307 my $dbh = C4::Context->dbh;
308 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
309 $sth->execute($searchfield);
310 $data=$sth->fetchrow_hashref;
312 $template->param(modify => 1);
316 foreach my $option (split(/\|/, $data->{'options'})) {
318 $option eq $data->{'value'} and $selected=1;
319 push @options, { option => $option, selected => $selected };
321 if ($data->{'type'} eq 'Choice') {
322 $template->param('type-choice' => 1);
323 } elsif ($data->{'type'} eq 'YesNo') {
324 $template->param('type-yesno' => 1);
325 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
326 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
327 } elsif ($data->{'type'} eq 'Integer') {
328 $template->param('type-free' => 1);
329 $template->param('fieldlength' => $data->{'options'});
330 } elsif ($data->{'type'} eq 'Textarea') {
331 $template->param('type-textarea' => 1);
332 $data->{options} =~ /(.*)\|(.*)/;
333 $template->param('cols' => $1, 'rows' => $2);;
334 } elsif ($data->{'type'} eq 'Float') {
335 $template->param('type-free' => 1);
336 $template->param('fieldlength' => $data->{'options'});
337 } elsif ($data->{'type'} eq 'Themes') {
338 $template->param('type-choice' => 1);
340 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
342 my $currently_selected_themes;
344 foreach my $theme (split /\s+/, $data->{'value'}) {
345 push @options, { option => $theme, counter => $counter };
346 $currently_selected_themes->{$theme}=1;
349 foreach my $theme (getallthemes($type)) {
351 next if $currently_selected_themes->{$theme};
352 push @options, { option => $theme, counter => $counter };
355 } elsif ($data->{'type'} eq 'Languages') {
356 $template->param('type-choice' => 1);
359 my $currently_selected_languages;
361 foreach my $language (split /\s+/, $data->{'value'}) {
362 next if $language eq 'images';
363 push @options, { option => $language, counter => $counter };
364 $currently_selected_languages->{$language}=1;
367 my $langavail = getTranslatedLanguages();
368 foreach my $language (@$langavail) {
370 next if $currently_selected_languages->{$language->{'language_code'}};
371 #FIXME: could add language_name and language_locale_name for better display
372 push @options, { option => $language->{'language_code'}, counter => $counter };
376 $template->param('type-free' => 1);
377 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
379 $template->param(explanation => $data->{'explanation'},
380 value => $data->{'value'},
381 type => $data->{'type'},
382 options => \@options,
383 preftype => $data->{'type'},
384 prefoptions => $data->{'options'},
385 searchfield => $searchfield);
387 ################## ADD_VALIDATE ##################################
388 # called by add_form, used to insert/modify data in DB
389 } elsif ($op eq 'add_validate') {
390 my $dbh = C4::Context->dbh;
391 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
392 $sth->execute($input->param('variable'));
394 unless (C4::Context->config('demo') eq 1) {
395 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
396 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
400 unless (C4::Context->config('demo') eq 1) {
401 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
402 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
407 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
409 ################## DELETE_CONFIRM ##################################
410 # called by default form, used to confirm deletion of data in DB
411 } elsif ($op eq 'delete_confirm') {
412 my $dbh = C4::Context->dbh;
413 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
414 $sth->execute($searchfield);
415 my $data=$sth->fetchrow_hashref;
417 $template->param(searchfield => $searchfield,
418 Tvalue => $data->{'value'},
421 # END $OP eq DELETE_CONFIRM
422 ################## DELETE_CONFIRMED ##################################
423 # called by delete_confirm, used to effectively confirm deletion of data in DB
424 } elsif ($op eq 'delete_confirmed') {
425 my $dbh = C4::Context->dbh;
426 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
427 $sth->execute($searchfield);
429 # END $OP eq DELETE_CONFIRMED
430 ################## DEFAULT ##################################
432 #Adding tab management for system preferences
433 my $tab=$input->param('tab');
435 my ($count,$results)=StringSearch($searchfield,$tab);
438 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
444 my %row_data; # get a fresh hash for the row data
445 $row_data{variable} = $results->[$i]{'variable'};
446 $row_data{value} = $results->[$i]{'value'};
447 $row_data{explanation} = $results->[$i]{'explanation'};
448 $row_data{toggle} = $toggle;
449 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
450 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
451 push(@loop_data, \%row_data);
453 $tab=($tab?$tab:"Others");
454 $template->param(loop => \@loop_data, $tab => 1);
456 my $prevpage = $offset-$pagesize;
457 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
459 if ($offset+$pagesize<$count) {
460 my $nextpage =$offset+$pagesize;
461 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
463 $template->param( tab => $tab,
465 } #---- END $OP eq DEFAULT
466 output_html_with_http_headers $input, $cookie, $template->output;