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";
78 $tabsysprefs{advancedMARCEditor}="Catalogue";
79 $tabsysprefs{autoBarcode}="Catalogue";
80 $tabsysprefs{hide_marc}="Catalogue";
81 $tabsysprefs{IntranetBiblioDefaultView} = "Catalogue";
82 $tabsysprefs{ISBD}="Catalogue";
83 $tabsysprefs{itemcallnumber}="Catalogue";
84 $tabsysprefs{kohaspsuggest} = "Catalogue";
85 $tabsysprefs{LabelMARCView}="Catalogue";
86 $tabsysprefs{marc}="Catalogue";
87 $tabsysprefs{marcflavour}="Catalogue";
88 $tabsysprefs{serialsadditems}="Catalogue";
89 $tabsysprefs{sortbynonfiling}="Catalogue";
90 $tabsysprefs{MARCOrgCode}="Catalogue";
91 $tabsysprefs{z3950AuthorAuthFields}="Catalogue";
92 $tabsysprefs{z3950NormalizeAuthor}="Catalogue";
93 $tabsysprefs{Stemming}="Catalogue";
94 $tabsysprefs{WeightFields}="Catalogue";
95 $tabsysprefs{expandedSearchOption}="Catalogue";
96 $tabsysprefs{NoZebra}="Catalogue";
97 $tabsysprefs{NoZebraIndexes}="Catalogue";
98 $tabsysprefs{ReceiveBackIssues}="Catalogue";
99 $tabsysprefs{DefaultClassificationSource}="Catalogue";
100 $tabsysprefs{SearchMyLibraryFirst}="Catalogue";
101 $tabsysprefs{RoutingSerials}="Catalogue";
102 $tabsysprefs{BiblioAddsAuthorities}="Catalogue";
105 $tabsysprefs{maxoutstanding}="Circulation";
106 $tabsysprefs{maxreserves}="Circulation";
107 $tabsysprefs{noissuescharge}="Circulation";
108 $tabsysprefs{IssuingInProcess}="Circulation";
109 $tabsysprefs{patronimages}="Circulation";
110 $tabsysprefs{printcirculationslips}="Circulation";
111 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
112 $tabsysprefs{SpecifyDueDate}="Circulation";
113 $tabsysprefs{AutomaticItemReturn}="Circulation";
114 $tabsysprefs{ReservesMaxPickUpDelay}="Circulation";
115 $tabsysprefs{TransfersMaxDaysWarning}="Circulation";
116 $tabsysprefs{useDaysMode}="Circulation";
117 $tabsysprefs{ReservesNeedReturns}="Circulation";
118 $tabsysprefs{CircAutocompl}="Circulation";
121 $tabsysprefs{TemplateEncoding}="Intranet";
122 $tabsysprefs{template}="Intranet";
123 $tabsysprefs{intranetstylesheet}="Intranet";
124 $tabsysprefs{IntranetNav}="Intranet";
125 $tabsysprefs{intranetcolorstylesheet}="Intranet";
126 $tabsysprefs{intranetuserjs}="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{Disable_Dictionary}="OPACFeatures";
165 $tabsysprefs{hidelostitems}="OPACFeatures";
166 $tabsysprefs{opacbookbag}="OPACFeatures";
167 $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
168 $tabsysprefs{OpacPasswordChange}="OPACFeatures";
169 $tabsysprefs{opacreadinghistory}="OPACFeatures";
170 $tabsysprefs{virtualshelves}="OPACFeatures";
171 $tabsysprefs{RequestOnOpac}="OPACFeatures";
172 $tabsysprefs{reviewson}="OPACFeatures";
173 $tabsysprefs{OpacTopissues}="OPACFeatures";
174 $tabsysprefs{OpacAuthorities}="OPACFeatures";
175 $tabsysprefs{OpacCloud}="OPACFeatures";
176 $tabsysprefs{opacuserlogin}="OPACFeatures";
177 $tabsysprefs{AnonSuggestions}="OPACFeatures";
178 $tabsysprefs{suggestion}="OPACFeatures";
179 $tabsysprefs{OpacTopissue}="OPACFeatures";
180 $tabsysprefs{OpacBrowser}="OPACFeatures";
183 $tabsysprefs{CataloguingLog} = "LOGFeatures";
184 $tabsysprefs{BorrowersLog} = "LOGFeatures";
185 $tabsysprefs{SubscriptionLog} = "LOGFeatures";
186 $tabsysprefs{IssueLog} = "LOGFeatures";
187 $tabsysprefs{ReturnLog} = "LOGFeatures";
188 $tabsysprefs{LetterLog} = "LOGFeatures";
189 $tabsysprefs{FinesLog} = "LOGFeatures";
192 my ($searchstring,$type)=@_;
193 my $dbh = C4::Context->dbh;
194 $searchstring=~ s/\'/\\\'/g;
195 my @data=split(' ',$searchstring);
200 foreach my $syspref (sort keys %tabsysprefs){
201 if ($tabsysprefs{$syspref} eq $type){
202 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
203 $sth->execute($syspref);
204 while (my $data=$sth->fetchrow_hashref){
205 $data->{value} =~ s/</</g;
206 $data->{value} =~ s/>/>/g;
207 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
208 push(@results,$data);
215 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
216 foreach my $syspref (keys %tabsysprefs){
217 $strsth .= $dbh->quote($syspref).",";
220 $strsth .= " order by variable";
221 my $sth=$dbh->prepare($strsth);
223 while (my $data=$sth->fetchrow_hashref){
224 $data->{value}=substr($data->{value},0,100);
225 push(@results,$data);
230 return ($cnt,\@results);
234 my $searchfield=$input->param('searchfield');
235 my $offset=$input->param('offset');
236 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
238 my ($template, $borrowernumber, $cookie)
239 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
242 authnotrequired => 0,
243 flagsrequired => {parameters => 1},
247 my $op = $input->param('op');
248 $searchfield=~ s/\,//g;
251 $template->param(script_name => $script_name,
252 $op => 1); # we show only the TMPL_VAR names $op
254 $template->param(script_name => $script_name,
255 else => 1); # we show only the TMPL_VAR names $op
258 if ($op eq 'update_and_reedit') {
259 foreach ($input->param) {
262 if (my $currentorder=$input->param('currentorder')) {
263 my @currentorder=split /\|/, $currentorder;
265 foreach my $param ($input->param) {
266 if ($param=~m#up-(\d+).x#) {
267 my $temp=$currentorder[$1];
268 $currentorder[$1]=$currentorder[$1-1];
269 $currentorder[$1-1]=$temp;
272 } elsif ($param=~m#down-(\d+).x#) {
273 my $temp=$currentorder[$1];
274 $currentorder[$1]=$currentorder[$1+1];
275 $currentorder[$1+1]=$temp;
280 $value=join ' ', @currentorder;
283 $template->param(script_name => $script_name,
284 $op => 1); # we show only the TMPL_VAR names $op
288 $template->param(script_name => $script_name,
289 else => 1); # we show only the TMPL_VAR names $op
292 my $dbh = C4::Context->dbh;
293 my $query="select * from systempreferences where variable=?";
294 my $sth=$dbh->prepare($query);
295 $sth->execute($input->param('variable'));
297 unless (C4::Context->config('demo') eq 1) {
298 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
299 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
303 unless (C4::Context->config('demo') eq 1) {
304 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
305 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
313 ################## ADD_FORM ##################################
314 # called by default. Used to create form to add or modify a record
316 if ($op eq 'add_form') {
317 #---- if primkey exists, it's a modify action, so read values to modify...
320 my $dbh = C4::Context->dbh;
321 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
322 $sth->execute($searchfield);
323 $data=$sth->fetchrow_hashref;
325 $template->param(modify => 1);
329 foreach my $option (split(/\|/, $data->{'options'})) {
331 $option eq $data->{'value'} and $selected=1;
332 push @options, { option => $option, selected => $selected };
334 if ($data->{'type'} eq 'Choice') {
335 $template->param('type-choice' => 1);
336 } elsif ($data->{'type'} eq 'YesNo') {
337 $template->param('type-yesno' => 1);
338 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
339 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
340 } elsif ($data->{'type'} eq 'Integer') {
341 $template->param('type-free' => 1);
342 $template->param('fieldlength' => $data->{'options'});
343 } elsif ($data->{'type'} eq 'Textarea') {
344 $template->param('type-textarea' => 1);
345 $data->{options} =~ /(.*)\|(.*)/;
346 $template->param('cols' => $1, 'rows' => $2);;
347 } elsif ($data->{'type'} eq 'Float') {
348 $template->param('type-free' => 1);
349 $template->param('fieldlength' => $data->{'options'});
350 } elsif ($data->{'type'} eq 'Themes') {
351 $template->param('type-choice' => 1);
353 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
355 my $currently_selected_themes;
357 foreach my $theme (split /\s+/, $data->{'value'}) {
358 push @options, { option => $theme, counter => $counter };
359 $currently_selected_themes->{$theme}=1;
362 foreach my $theme (getallthemes($type)) {
364 next if $currently_selected_themes->{$theme};
365 push @options, { option => $theme, counter => $counter };
368 } elsif ($data->{'type'} eq 'ClassSource') {
369 $template->param('type-choice' => 1);
372 my $sources = GetClassSources();
374 foreach my $cn_source (sort keys %$sources) {
375 if ($cn_source eq $data->{'value'}) {
376 push @options, { option => $cn_source, counter => $counter, selected => 1 };
378 push @options, { option => $cn_source, counter => $counter };
382 } elsif ($data->{'type'} eq 'Languages') {
383 $template->param('type-choice' => 1);
386 my $currently_selected_languages;
388 foreach my $language (split /\s+/, $data->{'value'}) {
389 next if $language eq 'images';
390 push @options, { option => $language, counter => $counter };
391 $currently_selected_languages->{$language}=1;
394 my $langavail = getTranslatedLanguages();
395 foreach my $language (@$langavail) {
397 next if $currently_selected_languages->{$language->{'language_code'}};
398 #FIXME: could add language_name and language_locale_name for better display
399 push @options, { option => $language->{'language_code'}, counter => $counter };
403 $template->param('type-free' => 1);
404 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
406 $template->param(explanation => $data->{'explanation'},
407 value => $data->{'value'},
408 type => $data->{'type'},
409 options => \@options,
410 preftype => $data->{'type'},
411 prefoptions => $data->{'options'},
412 searchfield => $searchfield);
414 ################## ADD_VALIDATE ##################################
415 # called by add_form, used to insert/modify data in DB
416 } elsif ($op eq 'add_validate') {
417 my $dbh = C4::Context->dbh;
418 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
419 $sth->execute($input->param('variable'));
421 unless (C4::Context->config('demo') eq 1) {
422 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
423 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
427 unless (C4::Context->config('demo') eq 1) {
428 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
429 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
434 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
436 ################## DELETE_CONFIRM ##################################
437 # called by default form, used to confirm deletion of data in DB
438 } elsif ($op eq 'delete_confirm') {
439 my $dbh = C4::Context->dbh;
440 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
441 $sth->execute($searchfield);
442 my $data=$sth->fetchrow_hashref;
444 $template->param(searchfield => $searchfield,
445 Tvalue => $data->{'value'},
448 # END $OP eq DELETE_CONFIRM
449 ################## DELETE_CONFIRMED ##################################
450 # called by delete_confirm, used to effectively confirm deletion of data in DB
451 } elsif ($op eq 'delete_confirmed') {
452 my $dbh = C4::Context->dbh;
453 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
454 $sth->execute($searchfield);
456 # END $OP eq DELETE_CONFIRMED
457 ################## DEFAULT ##################################
459 #Adding tab management for system preferences
460 my $tab=$input->param('tab');
462 my ($count,$results)=StringSearch($searchfield,$tab);
465 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
471 my %row_data; # get a fresh hash for the row data
472 $row_data{variable} = $results->[$i]{'variable'};
473 $row_data{value} = $results->[$i]{'value'};
474 $row_data{yes} = 1 if ($results->[$i]{'value'} == 1);
475 $row_data{yesno} = 1 if ($results->[$i]{'type'} eq 'YesNo');
476 $row_data{explanation} = $results->[$i]{'explanation'};
477 $row_data{toggle} = $toggle;
478 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
479 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
480 push(@loop_data, \%row_data);
482 $tab=($tab?$tab:"Others");
483 $template->param(loop => \@loop_data, $tab => 1);
485 my $prevpage = $offset-$pagesize;
486 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
488 if ($offset+$pagesize<$count) {
489 my $nextpage =$offset+$pagesize;
490 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
492 $template->param( tab => $tab,
494 } #---- END $OP eq DEFAULT
495 output_html_with_http_headers $input, $cookie, $template->output;