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 # use Smart::Comments;
56 # FIXME, shouldnt we store this stuff in the systempreferences table?
60 $tabsysprefs{acquisitions}="Acquisitions";
61 $tabsysprefs{gist}="Acquisitions";
63 $tabsysprefs{dateformat}="Admin";
64 $tabsysprefs{delimiter}="Admin";
65 $tabsysprefs{IndependantBranches}="Admin";
66 $tabsysprefs{HomeOrHoldingBranch}="Admin";
67 $tabsysprefs{insecure}="Admin";
68 $tabsysprefs{KohaAdmin}="Admin";
69 $tabsysprefs{KohaAdminEmailAddress}="Admin";
70 $tabsysprefs{MIME}="Admin";
71 $tabsysprefs{timeout}="Admin";
72 $tabsysprefs{Intranet_includes}="Admin";
73 $tabsysprefs{AutoLocation}="Admin";
74 $tabsysprefs{DebugLevel}="Admin";
75 $tabsysprefs{SessionStorage}="Admin";
78 $tabsysprefs{authoritysep}="Authorities";
79 $tabsysprefs{AuthDisplayHierarchy}="Authorities";
80 $tabsysprefs{dontmerge}="Authorities";
81 $tabsysprefs{BiblioAddsAuthorities}="Authorities";
83 $tabsysprefs{advancedMARCEditor}="Catalogue";
84 $tabsysprefs{autoBarcode}="Catalogue";
85 $tabsysprefs{hide_marc}="Catalogue";
86 $tabsysprefs{IntranetBiblioDefaultView} = "Catalogue";
87 $tabsysprefs{ISBD}="Catalogue";
88 $tabsysprefs{itemcallnumber}="Catalogue";
89 $tabsysprefs{LabelMARCView}="Catalogue";
90 $tabsysprefs{marc}="Catalogue";
91 $tabsysprefs{marcflavour}="Catalogue";
92 $tabsysprefs{serialsadditems}="Catalogue";
93 $tabsysprefs{sortbynonfiling}="Catalogue";
94 $tabsysprefs{MARCOrgCode}="Catalogue";
95 $tabsysprefs{z3950AuthorAuthFields}="Catalogue";
96 $tabsysprefs{z3950NormalizeAuthor}="Catalogue";
97 $tabsysprefs{Stemming}="Catalogue";
98 $tabsysprefs{WeightFields}="Catalogue";
99 $tabsysprefs{expandedSearchOption}="Catalogue";
100 $tabsysprefs{NoZebra}="Catalogue";
101 $tabsysprefs{NoZebraIndexes}="Catalogue";
102 $tabsysprefs{ReceiveBackIssues}="Catalogue";
103 $tabsysprefs{DefaultClassificationSource}="Catalogue";
104 $tabsysprefs{RoutingSerials}="Catalogue";
105 $tabsysprefs{'item-level_itypes'}="Catalogue";
108 $tabsysprefs{maxoutstanding}="Circulation";
109 $tabsysprefs{maxreserves}="Circulation";
110 $tabsysprefs{noissuescharge}="Circulation";
111 $tabsysprefs{IssuingInProcess}="Circulation";
112 $tabsysprefs{patronimages}="Circulation";
113 $tabsysprefs{printcirculationslips}="Circulation";
114 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
115 $tabsysprefs{SpecifyDueDate}="Circulation";
116 $tabsysprefs{AutomaticItemReturn}="Circulation";
117 $tabsysprefs{ReservesMaxPickUpDelay}="Circulation";
118 $tabsysprefs{TransfersMaxDaysWarning}="Circulation";
119 $tabsysprefs{useDaysMode}="Circulation";
120 $tabsysprefs{ReservesNeedReturns}="Circulation";
121 $tabsysprefs{CircAutocompl}="Circulation";
122 $tabsysprefs{canreservefromotherbranches}="Circulation";
125 $tabsysprefs{TemplateEncoding}="Intranet";
126 $tabsysprefs{template}="Intranet";
127 $tabsysprefs{intranetstylesheet}="Intranet";
128 $tabsysprefs{IntranetNav}="Intranet";
129 $tabsysprefs{intranetcolorstylesheet}="Intranet";
130 $tabsysprefs{intranetuserjs}="Intranet";
131 $tabsysprefs{yuipath}="Intranet";
132 $tabsysprefs{IntranetmainUserblock}="Intranet";
135 $tabsysprefs{automembernum}="Members";
136 $tabsysprefs{checkdigit}="Members";
137 $tabsysprefs{intranetreadinghistory}="Members";
138 $tabsysprefs{NotifyBorrowerDeparture}="Members";
139 $tabsysprefs{memberofinstitution}="Members";
140 $tabsysprefs{ReadingHistory}="Members";
141 $tabsysprefs{BorrowerMandatoryField}="Members";
142 $tabsysprefs{borrowerRelationship}="Members";
143 $tabsysprefs{BorrowersTitles}="Members";
144 $tabsysprefs{patronimages}="Members";
145 $tabsysprefs{MinPasswordLength}="Members";
146 $tabsysprefs{uppercasesurnames}="Members";
147 $tabsysprefs{NoReturnSetLost}="Members";
148 $tabsysprefs{MaxFine}="Members";
149 $tabsysprefs{NotifyBorrowerDeparture}="Members";
151 $tabsysprefs{FRBRizeEditions}="FRBR";
152 $tabsysprefs{XISBN}="FRBR";
153 $tabsysprefs{OCLCAffiliateID}="FRBR";
154 $tabsysprefs{XISBNDailyLimit}="FRBR";
155 $tabsysprefs{PINESISBN}="FRBR";
156 $tabsysprefs{ThingISBN}="FRBR";
157 $tabsysprefs{OPACFRBRizeEditions}="FRBR";
158 $tabsysprefs{XISBNAmazonSimilarItems}="FRBR";
161 $tabsysprefs{AmazonAssocTag}="OPAC";
162 $tabsysprefs{AmazonSimilarItems}="OPAC";
163 $tabsysprefs{AmazonContent}="OPAC";
164 $tabsysprefs{OPACAmazonContent}="OPAC";
165 $tabsysprefs{AmazonDevKey}="OPAC";
166 $tabsysprefs{BiblioDefaultView}="OPAC";
167 $tabsysprefs{LibraryName}="OPAC";
168 $tabsysprefs{opaccolorstylesheet}="OPAC";
169 $tabsysprefs{opaccredits}="OPAC";
170 $tabsysprefs{opaclanguages}="OPAC";
171 $tabsysprefs{opaclargeimage}="OPAC";
172 $tabsysprefs{opaclayoutstylesheet}="OPAC";
173 $tabsysprefs{OpacNav}="OPAC";
174 $tabsysprefs{opacsmallimage}="OPAC";
175 $tabsysprefs{opacstylesheet}="OPAC";
176 $tabsysprefs{opacthemes}="OPAC";
177 $tabsysprefs{opacuserjs}="OPAC";
178 $tabsysprefs{SubscriptionHistory}="OPAC";
179 $tabsysprefs{opacheader}="OPAC";
180 $tabsysprefs{OPACAmazonSimilarItems}="OPAC";
181 $tabsysprefs{OPACXISBNAmazonSimilarItems}="OPAC";
184 $tabsysprefs{SearchMyLibraryFirst}="OPACFeatures";
185 $tabsysprefs{Disable_Dictionary}="OPACFeatures";
186 $tabsysprefs{hidelostitems}="OPACFeatures";
187 $tabsysprefs{opacbookbag}="OPACFeatures";
188 $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
189 $tabsysprefs{OpacPasswordChange}="OPACFeatures";
190 $tabsysprefs{opacreadinghistory}="OPACFeatures";
191 $tabsysprefs{virtualshelves}="OPACFeatures";
192 $tabsysprefs{RequestOnOpac}="OPACFeatures";
193 $tabsysprefs{reviewson}="OPACFeatures";
194 $tabsysprefs{OpacTopissues}="OPACFeatures";
195 $tabsysprefs{OpacAuthorities}="OPACFeatures";
196 $tabsysprefs{OpacCloud}="OPACFeatures";
197 $tabsysprefs{opacuserlogin}="OPACFeatures";
198 $tabsysprefs{AnonSuggestions}="OPACFeatures";
199 $tabsysprefs{suggestion}="OPACFeatures";
200 $tabsysprefs{OpacTopissue}="OPACFeatures";
201 $tabsysprefs{OpacBrowser}="OPACFeatures";
202 $tabsysprefs{kohaspsuggest} = "OPACFeatures";
205 $tabsysprefs{CataloguingLog} = "LOGFeatures";
206 $tabsysprefs{BorrowersLog} = "LOGFeatures";
207 $tabsysprefs{SubscriptionLog} = "LOGFeatures";
208 $tabsysprefs{IssueLog} = "LOGFeatures";
209 $tabsysprefs{ReturnLog} = "LOGFeatures";
210 $tabsysprefs{LetterLog} = "LOGFeatures";
211 $tabsysprefs{FinesLog} = "LOGFeatures";
214 my ($searchstring,$type)=@_;
215 my $dbh = C4::Context->dbh;
216 $searchstring=~ s/\'/\\\'/g;
217 my @data=split(' ',$searchstring);
222 # used for doing a plain-old sys-pref search
223 if ($type eq 'all' ){
224 my $sth=$dbh->prepare("SELECT * FROM systempreferences
225 WHERE variable LIKE ? OR explanation LIKE ?
227 $sth->execute("%$searchstring%", "%$searchstring%");
228 while (my $data=$sth->fetchrow_hashref){
229 $data->{value} =~ s/</</g;
230 $data->{value} =~ s/>/>/g;
231 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
232 push(@results,$data);
238 foreach my $syspref (sort keys %tabsysprefs){
239 if ($tabsysprefs{$syspref} eq $type){
240 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
241 $sth->execute($syspref);
242 while (my $data=$sth->fetchrow_hashref){
243 $data->{value} =~ s/</</g;
244 $data->{value} =~ s/>/>/g;
245 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
246 push(@results,$data);
253 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
254 foreach my $syspref (keys %tabsysprefs){
255 $strsth .= $dbh->quote($syspref).",";
258 $strsth .= " order by variable";
259 my $sth=$dbh->prepare($strsth);
261 while (my $data=$sth->fetchrow_hashref){
262 $data->{value}=substr($data->{value},0,100);
263 push(@results,$data);
268 return ($cnt,\@results);
272 my $searchfield=$input->param('searchfield');
273 my $offset=$input->param('offset');
274 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
276 my ($template, $borrowernumber, $cookie)
277 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
280 authnotrequired => 0,
281 flagsrequired => {parameters => 1},
285 my $op = $input->param('op');
286 $searchfield=~ s/\,//g;
289 $template->param(script_name => $script_name,
290 $op => 1); # we show only the TMPL_VAR names $op
292 $template->param(script_name => $script_name,
293 else => 1); # we show only the TMPL_VAR names $op
296 if ($op eq 'update_and_reedit') {
297 foreach ($input->param) {
300 if (my $currentorder=$input->param('currentorder')) {
301 my @currentorder=split /\|/, $currentorder;
303 foreach my $param ($input->param) {
304 if ($param=~m#up-(\d+).x#) {
305 my $temp=$currentorder[$1];
306 $currentorder[$1]=$currentorder[$1-1];
307 $currentorder[$1-1]=$temp;
310 } elsif ($param=~m#down-(\d+).x#) {
311 my $temp=$currentorder[$1];
312 $currentorder[$1]=$currentorder[$1+1];
313 $currentorder[$1+1]=$temp;
318 $value=join ' ', @currentorder;
321 $template->param(script_name => $script_name,
322 $op => 1); # we show only the TMPL_VAR names $op
326 $template->param(script_name => $script_name,
327 else => 1); # we show only the TMPL_VAR names $op
330 my $dbh = C4::Context->dbh;
331 my $query="select * from systempreferences where variable=?";
332 my $sth=$dbh->prepare($query);
333 $sth->execute($input->param('variable'));
335 unless (C4::Context->config('demo') eq 1) {
336 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
337 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
341 unless (C4::Context->config('demo') eq 1) {
342 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
343 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
351 ################## ADD_FORM ##################################
352 # called by default. Used to create form to add or modify a record
354 if ($op eq 'add_form') {
355 #---- if primkey exists, it's a modify action, so read values to modify...
358 my $dbh = C4::Context->dbh;
359 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
360 $sth->execute($searchfield);
361 $data=$sth->fetchrow_hashref;
363 $template->param(modify => 1);
364 # save tab to return to if user cancels edit
365 $template->param(return_tab => $tabsysprefs{$searchfield});
369 foreach my $option (split(/\|/, $data->{'options'})) {
371 $option eq $data->{'value'} and $selected=1;
372 push @options, { option => $option, selected => $selected };
374 if ($data->{'type'} eq 'Choice') {
375 $template->param('type-choice' => 1);
376 } elsif ($data->{'type'} eq 'YesNo') {
377 $template->param('type-yesno' => 1);
378 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
379 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
380 } elsif ($data->{'type'} eq 'Integer') {
381 $template->param('type-free' => 1);
382 $template->param('fieldlength' => $data->{'options'});
383 } elsif ($data->{'type'} eq 'Textarea') {
384 $template->param('type-textarea' => 1);
385 $data->{options} =~ /(.*)\|(.*)/;
386 $template->param('cols' => $1, 'rows' => $2);;
387 } elsif ($data->{'type'} eq 'Float') {
388 $template->param('type-free' => 1);
389 $template->param('fieldlength' => $data->{'options'});
390 } elsif ($data->{'type'} eq 'Themes') {
391 $template->param('type-choice' => 1);
393 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
395 my $currently_selected_themes;
397 foreach my $theme (split /\s+/, $data->{'value'}) {
398 push @options, { option => $theme, counter => $counter };
399 $currently_selected_themes->{$theme}=1;
402 foreach my $theme (getallthemes($type)) {
404 next if $currently_selected_themes->{$theme};
405 push @options, { option => $theme, counter => $counter };
408 } elsif ($data->{'type'} eq 'ClassSources') {
409 $template->param('type-choice' => 1);
412 my $sources = GetClassSources();
414 foreach my $cn_source (sort keys %$sources) {
415 if ($cn_source eq $data->{'value'}) {
416 push @options, { option => $cn_source, counter => $counter, selected => 1 };
418 push @options, { option => $cn_source, counter => $counter };
422 } elsif ($data->{'type'} eq 'Languages') {
423 $template->param('type-choice' => 1);
426 my $currently_selected_languages;
428 foreach my $language (split /\s+/, $data->{'value'}) {
429 next if $language eq 'images';
430 push @options, { option => $language, counter => $counter };
431 $currently_selected_languages->{$language}=1;
434 my $langavail = getTranslatedLanguages();
435 foreach my $language (@$langavail) {
437 next if $currently_selected_languages->{$language->{'language_code'}};
438 #FIXME: could add language_name and language_locale_name for better display
439 push @options, { option => $language->{'language_code'}, counter => $counter };
443 $template->param('type-free' => 1);
444 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
446 $template->param(explanation => $data->{'explanation'},
447 value => $data->{'value'},
448 type => $data->{'type'},
449 options => \@options,
450 preftype => $data->{'type'},
451 prefoptions => $data->{'options'},
452 searchfield => $searchfield);
454 ################## ADD_VALIDATE ##################################
455 # called by add_form, used to insert/modify data in DB
456 } elsif ($op eq 'add_validate') {
457 my $dbh = C4::Context->dbh;
458 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
459 $sth->execute($input->param('variable'));
461 unless (C4::Context->config('demo') eq 1) {
462 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
463 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
467 unless (C4::Context->config('demo') eq 1) {
468 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
469 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
474 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
476 ################## DELETE_CONFIRM ##################################
477 # called by default form, used to confirm deletion of data in DB
478 } elsif ($op eq 'delete_confirm') {
479 my $dbh = C4::Context->dbh;
480 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
481 $sth->execute($searchfield);
482 my $data=$sth->fetchrow_hashref;
484 $template->param(searchfield => $searchfield,
485 Tvalue => $data->{'value'},
488 # END $OP eq DELETE_CONFIRM
489 ################## DELETE_CONFIRMED ##################################
490 # called by delete_confirm, used to effectively confirm deletion of data in DB
491 } elsif ($op eq 'delete_confirmed') {
492 my $dbh = C4::Context->dbh;
493 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
494 $sth->execute($searchfield);
497 # END $OP eq DELETE_CONFIRMED
498 ################## DEFAULT ##################################
500 #Adding tab management for system preferences
501 my $tab=$input->param('tab');
502 my ($count,$results)=StringSearch($searchfield,$tab);
505 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
511 my %row_data; # get a fresh hash for the row data
512 $row_data{variable} = $results->[$i]{'variable'};
513 $row_data{value} = $results->[$i]{'value'};
514 $row_data{yes} = 1 if ($results->[$i]{'value'} == 1);
515 $row_data{yesno} = 1 if ($results->[$i]{'type'} eq 'YesNo');
516 $row_data{explanation} = $results->[$i]{'explanation'};
517 $row_data{toggle} = $toggle;
518 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
519 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
520 push(@loop_data, \%row_data);
522 $tab=($tab?$tab:"Others");
523 $template->param(loop => \@loop_data, $tab => 1);
525 my $prevpage = $offset-$pagesize;
526 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
528 if ($offset+$pagesize<$count) {
529 my $nextpage =$offset+$pagesize;
530 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
532 $template->param( tab => $tab,
534 } #---- END $OP eq DEFAULT
535 output_html_with_http_headers $input, $cookie, $template->output;