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";
62 $tabsysprefs{emailPurchaseSuggestions}="Acquisitions";
65 $tabsysprefs{singleBranchMode}="Admin";
66 $tabsysprefs{staffClientBaseURL}="Admin";
67 $tabsysprefs{Version}="Admin";
68 $tabsysprefs{OpacMaintenance}="Admin";
69 $tabsysprefs{FrameworksLoaded}="Admin";
70 $tabsysprefs{libraryAddress}="Admin";
71 $tabsysprefs{dateformat}="Admin";
72 $tabsysprefs{delimiter}="Admin";
73 $tabsysprefs{IndependantBranches}="Admin";
74 $tabsysprefs{HomeOrHoldingBranch}="Admin";
75 $tabsysprefs{insecure}="Admin";
76 $tabsysprefs{KohaAdmin}="Admin";
77 $tabsysprefs{KohaAdminEmailAddress}="Admin";
78 $tabsysprefs{MIME}="Admin";
79 $tabsysprefs{timeout}="Admin";
80 $tabsysprefs{Intranet_includes}="Admin";
81 $tabsysprefs{AutoLocation}="Admin";
82 $tabsysprefs{DebugLevel}="Admin";
83 $tabsysprefs{SessionStorage}="Admin";
84 $tabsysprefs{noItemTypeImages}="Admin";
87 $tabsysprefs{authoritysep}="Authorities";
88 $tabsysprefs{AuthDisplayHierarchy}="Authorities";
89 $tabsysprefs{dontmerge}="Authorities";
90 $tabsysprefs{BiblioAddsAuthorities}="Authorities";
92 $tabsysprefs{advancedMARCEditor}="Cataloguing";
93 $tabsysprefs{autoBarcode}="Cataloguing";
94 $tabsysprefs{hide_marc}="Cataloguing";
95 $tabsysprefs{IntranetBiblioDefaultView} = "Cataloguing";
96 $tabsysprefs{ISBD}="Cataloguing";
97 $tabsysprefs{itemcallnumber}="Cataloguing";
98 $tabsysprefs{LabelMARCView}="Cataloguing";
99 $tabsysprefs{marc}="Cataloguing";
100 $tabsysprefs{marcflavour}="Cataloguing";
101 $tabsysprefs{serialsadditems}="Cataloguing";
102 $tabsysprefs{MARCOrgCode}="Cataloguing";
103 $tabsysprefs{z3950AuthorAuthFields}="Cataloguing";
104 $tabsysprefs{z3950NormalizeAuthor}="Cataloguing";
105 $tabsysprefs{Stemming}="Cataloguing";
106 $tabsysprefs{WeightFields}="Cataloguing";
107 $tabsysprefs{NoZebra}="Cataloguing";
108 $tabsysprefs{NoZebraIndexes}="Cataloguing";
109 $tabsysprefs{ReceiveBackIssues}="Cataloguing";
110 $tabsysprefs{DefaultClassificationSource}="Cataloguing";
111 $tabsysprefs{RoutingSerials}="Cataloguing";
112 $tabsysprefs{'item-level_itypes'}="Cataloguing";
115 $tabsysprefs{maxoutstanding}="Circulation";
116 $tabsysprefs{maxreserves}="Circulation";
117 $tabsysprefs{noissuescharge}="Circulation";
118 $tabsysprefs{IssuingInProcess}="Circulation";
119 $tabsysprefs{patronimages}="Circulation";
120 $tabsysprefs{printcirculationslips}="Circulation";
121 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
122 $tabsysprefs{SpecifyDueDate}="Circulation";
123 $tabsysprefs{AutomaticItemReturn}="Circulation";
124 $tabsysprefs{ReservesMaxPickUpDelay}="Circulation";
125 $tabsysprefs{TransfersMaxDaysWarning}="Circulation";
126 $tabsysprefs{useDaysMode}="Circulation";
127 $tabsysprefs{ReservesNeedReturns}="Circulation";
128 $tabsysprefs{CircAutocompl}="Circulation";
129 $tabsysprefs{canreservefromotherbranches}="Circulation";
130 $tabsysprefs{finesMode}="Circulation";
131 $tabsysprefs{emailLibrarianWhenHoldIsPlaced}="Circulation";
132 $tabsysprefs{globalDueDate}="Circulation";
133 $tabsysprefs{holdCancelLength}="Circulation";
134 $tabsysprefs{itemBarcodeInputFilter}="Circulation";
135 $tabsysprefs{noOPACHolds}="Circulation";
136 $tabsysprefs{WebBasedSelfCheck}="Circulation";
137 $tabsysprefs{CircControl}="Circulation";
138 $tabsysprefs{finesCalendar}="Circulation";
140 $tabsysprefs{TemplateEncoding}="StaffClient";
141 $tabsysprefs{template}="StaffClient";
142 $tabsysprefs{intranetstylesheet}="StaffClient";
143 $tabsysprefs{IntranetNav}="StaffClient";
144 $tabsysprefs{intranetcolorstylesheet}="StaffClient";
145 $tabsysprefs{intranetuserjs}="StaffClient";
146 $tabsysprefs{yuipath}="StaffClient";
147 $tabsysprefs{IntranetmainUserblock}="StaffClient";
150 $tabsysprefs{automembernum}="Patrons";
151 $tabsysprefs{checkdigit}="Patrons";
152 $tabsysprefs{intranetreadinghistory}="Patrons";
153 $tabsysprefs{NotifyBorrowerDeparture}="Patrons";
154 $tabsysprefs{memberofinstitution}="Patrons";
155 $tabsysprefs{ReadingHistory}="Patrons";
156 $tabsysprefs{BorrowerMandatoryField}="Patrons";
157 $tabsysprefs{borrowerRelationship}="Patrons";
158 $tabsysprefs{BorrowersTitles}="Patrons";
159 $tabsysprefs{patronimages}="Patrons";
160 $tabsysprefs{MinPasswordLength}="Patrons";
161 $tabsysprefs{uppercasesurnames}="Patrons";
162 $tabsysprefs{NoReturnSetLost}="Patrons";
163 $tabsysprefs{MaxFine}="Patrons";
164 $tabsysprefs{NotifyBorrowerDeparture}="Patrons";
167 $tabsysprefs{FRBRizeEditions}="FRBR";
168 $tabsysprefs{XISBN}="FRBR";
169 $tabsysprefs{OCLCAffiliateID}="FRBR";
170 $tabsysprefs{XISBNDailyLimit}="FRBR";
171 $tabsysprefs{PINESISBN}="FRBR";
172 $tabsysprefs{ThingISBN}="FRBR";
173 $tabsysprefs{OPACFRBRizeEditions}="FRBR";
174 $tabsysprefs{XISBNAmazonSimilarItems}="FRBR";
177 $tabsysprefs{dateformat}="I18N/L10N";
178 $tabsysprefs{opaclanguages}="I18N/L10N";
179 $tabsysprefs{opacthemes}="I18N/L10N";
182 $tabsysprefs{defaultSortField}="Searching";
183 $tabsysprefs{defaultSortOrder}="Searching";
184 $tabsysprefs{maxItemsInSearchResults}="Searching";
185 $tabsysprefs{numSearchResults}="Searching";
186 $tabsysprefs{OPACdefaultSortField}="Searching";
187 $tabsysprefs{OPACdefaultSortOrder}="Searching";
188 $tabsysprefs{OPACItemsResultsDisplay}="Searching";
189 $tabsysprefs{OPACnumSearchResults}="Searching";
190 $tabsysprefs{QueryFuzzy}="Searching";
191 $tabsysprefs{QueryStemming}="Searching";
192 $tabsysprefs{QueryWeightFields}="Searching";
193 $tabsysprefs{expandedSearchOption}="Searching";
194 $tabsysprefs{sortbynonfiling}="Searching";
198 $tabsysprefs{AmazonAssocTag}="OPAC";
199 $tabsysprefs{AmazonSimilarItems}="OPAC";
200 $tabsysprefs{AmazonContent}="OPAC";
201 $tabsysprefs{OPACAmazonContent}="OPAC";
202 $tabsysprefs{AmazonDevKey}="OPAC";
203 $tabsysprefs{BiblioDefaultView}="OPAC";
204 $tabsysprefs{LibraryName}="OPAC";
205 $tabsysprefs{opaccolorstylesheet}="OPAC";
206 $tabsysprefs{opaccredits}="OPAC";
207 $tabsysprefs{opaclargeimage}="OPAC";
208 $tabsysprefs{opaclayoutstylesheet}="OPAC";
209 $tabsysprefs{OpacNav}="OPAC";
210 $tabsysprefs{opacsmallimage}="OPAC";
211 $tabsysprefs{opacstylesheet}="OPAC";
212 $tabsysprefs{opacthemes}="OPAC";
213 $tabsysprefs{opacuserjs}="OPAC";
214 $tabsysprefs{SubscriptionHistory}="OPAC";
215 $tabsysprefs{opacheader}="OPAC";
216 $tabsysprefs{OPACAmazonSimilarItems}="OPAC";
217 $tabsysprefs{OPACXISBNAmazonSimilarItems}="OPAC";
219 $tabsysprefs{hideBiblioNumber}="OPAC";
220 $tabsysprefs{noOPACUserLogin}="OPAC";
221 $tabsysprefs{OPACDisplayExtendedSubInfo}="OPAC";
222 $tabsysprefs{OpacMainUserBlock}="OPAC";
223 $tabsysprefs{OPACSubscriptionDisplay}="OPAC";
224 $tabsysprefs{OPACURLOpenInNewWindow}="OPAC";
225 $tabsysprefs{OPACUserCSS}="OPAC";
226 $tabsysprefs{OPACViewOthersSuggestions}="OPAC";
227 $tabsysprefs{URLLinkText}="OPAC";
230 $tabsysprefs{SearchMyLibraryFirst}="OPACFeatures";
231 $tabsysprefs{Disable_Dictionary}="OPACFeatures";
232 $tabsysprefs{hidelostitems}="OPACFeatures";
233 $tabsysprefs{opacbookbag}="OPACFeatures";
234 $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
235 $tabsysprefs{OpacPasswordChange}="OPACFeatures";
236 $tabsysprefs{opacreadinghistory}="OPACFeatures";
237 $tabsysprefs{virtualshelves}="OPACFeatures";
238 $tabsysprefs{RequestOnOpac}="OPACFeatures";
239 $tabsysprefs{reviewson}="OPACFeatures";
240 $tabsysprefs{OpacTopissues}="OPACFeatures";
241 $tabsysprefs{OpacAuthorities}="OPACFeatures";
242 $tabsysprefs{OpacCloud}="OPACFeatures";
243 $tabsysprefs{opacuserlogin}="OPACFeatures";
244 $tabsysprefs{AnonSuggestions}="OPACFeatures";
245 $tabsysprefs{suggestion}="OPACFeatures";
246 $tabsysprefs{OpacTopissue}="OPACFeatures";
247 $tabsysprefs{OpacBrowser}="OPACFeatures";
248 $tabsysprefs{kohaspsuggest} = "OPACFeatures";
251 $tabsysprefs{CataloguingLog} = "LOGFeatures";
252 $tabsysprefs{BorrowersLog} = "LOGFeatures";
253 $tabsysprefs{SubscriptionLog} = "LOGFeatures";
254 $tabsysprefs{IssueLog} = "LOGFeatures";
255 $tabsysprefs{ReturnLog} = "LOGFeatures";
256 $tabsysprefs{LetterLog} = "LOGFeatures";
257 $tabsysprefs{FinesLog} = "LOGFeatures";
260 my ($searchstring,$type)=@_;
261 my $dbh = C4::Context->dbh;
262 $searchstring=~ s/\'/\\\'/g;
263 my @data=split(' ',$searchstring);
268 # used for doing a plain-old sys-pref search
269 if ($type eq 'all' ){
270 my $sth=$dbh->prepare("SELECT * FROM systempreferences
271 WHERE variable LIKE ? OR explanation LIKE ?
273 $sth->execute("%$searchstring%", "%$searchstring%");
274 while (my $data=$sth->fetchrow_hashref){
275 $data->{value} =~ s/</</g;
276 $data->{value} =~ s/>/>/g;
277 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
278 push(@results,$data);
284 foreach my $syspref (sort keys %tabsysprefs){
285 if ($tabsysprefs{$syspref} eq $type){
286 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
287 $sth->execute($syspref);
288 while (my $data=$sth->fetchrow_hashref){
289 $data->{value} =~ s/</</g;
290 $data->{value} =~ s/>/>/g;
291 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
292 push(@results,$data);
299 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
300 foreach my $syspref (keys %tabsysprefs){
301 $strsth .= $dbh->quote($syspref).",";
304 $strsth .= " order by variable";
305 my $sth=$dbh->prepare($strsth);
307 while (my $data=$sth->fetchrow_hashref){
308 $data->{value}=substr($data->{value},0,100);
309 push(@results,$data);
314 return ($cnt,\@results);
318 my $searchfield=$input->param('searchfield');
319 my $offset=$input->param('offset');
320 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
322 my ($template, $borrowernumber, $cookie)
323 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
326 authnotrequired => 0,
327 flagsrequired => {parameters => 1},
331 my $op = $input->param('op');
332 $searchfield=~ s/\,//g;
335 $template->param(script_name => $script_name,
336 $op => 1); # we show only the TMPL_VAR names $op
338 $template->param(script_name => $script_name,
339 else => 1); # we show only the TMPL_VAR names $op
342 if ($op eq 'update_and_reedit') {
343 foreach ($input->param) {
346 if (my $currentorder=$input->param('currentorder')) {
347 my @currentorder=split /\|/, $currentorder;
349 foreach my $param ($input->param) {
350 if ($param=~m#up-(\d+).x#) {
351 my $temp=$currentorder[$1];
352 $currentorder[$1]=$currentorder[$1-1];
353 $currentorder[$1-1]=$temp;
356 } elsif ($param=~m#down-(\d+).x#) {
357 my $temp=$currentorder[$1];
358 $currentorder[$1]=$currentorder[$1+1];
359 $currentorder[$1+1]=$temp;
364 $value=join ' ', @currentorder;
367 $template->param(script_name => $script_name,
368 $op => 1); # we show only the TMPL_VAR names $op
372 $template->param(script_name => $script_name,
373 else => 1); # we show only the TMPL_VAR names $op
376 my $dbh = C4::Context->dbh;
377 my $query="select * from systempreferences where variable=?";
378 my $sth=$dbh->prepare($query);
379 $sth->execute($input->param('variable'));
381 unless (C4::Context->config('demo') eq 1) {
382 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
383 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
387 unless (C4::Context->config('demo') eq 1) {
388 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
389 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
397 ################## ADD_FORM ##################################
398 # called by default. Used to create form to add or modify a record
400 if ($op eq 'add_form') {
401 #---- if primkey exists, it's a modify action, so read values to modify...
404 my $dbh = C4::Context->dbh;
405 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
406 $sth->execute($searchfield);
407 $data=$sth->fetchrow_hashref;
409 $template->param(modify => 1);
410 # save tab to return to if user cancels edit
411 $template->param(return_tab => $tabsysprefs{$searchfield});
415 foreach my $option (split(/\|/, $data->{'options'})) {
417 $option eq $data->{'value'} and $selected=1;
418 push @options, { option => $option, selected => $selected };
420 if ($data->{'type'} eq 'Choice') {
421 $template->param('type-choice' => 1);
422 } elsif ($data->{'type'} eq 'YesNo') {
423 $template->param('type-yesno' => 1);
424 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
425 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
426 } elsif ($data->{'type'} eq 'Integer') {
427 $template->param('type-free' => 1);
428 $template->param('fieldlength' => $data->{'options'});
429 } elsif ($data->{'type'} eq 'Textarea') {
430 $template->param('type-textarea' => 1);
431 $data->{options} =~ /(.*)\|(.*)/;
432 $template->param('cols' => $1, 'rows' => $2);;
433 } elsif ($data->{'type'} eq 'Float') {
434 $template->param('type-free' => 1);
435 $template->param('fieldlength' => $data->{'options'});
436 } elsif ($data->{'type'} eq 'Themes') {
437 $template->param('type-choice' => 1);
439 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
441 my $currently_selected_themes;
443 foreach my $theme (split /\s+/, $data->{'value'}) {
444 push @options, { option => $theme, counter => $counter };
445 $currently_selected_themes->{$theme}=1;
448 foreach my $theme (getallthemes($type)) {
450 next if $currently_selected_themes->{$theme};
451 push @options, { option => $theme, counter => $counter };
454 } elsif ($data->{'type'} eq 'ClassSources') {
455 $template->param('type-choice' => 1);
458 my $sources = GetClassSources();
460 foreach my $cn_source (sort keys %$sources) {
461 if ($cn_source eq $data->{'value'}) {
462 push @options, { option => $cn_source, counter => $counter, selected => 1 };
464 push @options, { option => $cn_source, counter => $counter };
468 } elsif ($data->{'type'} eq 'Languages') {
469 $template->param('type-choice' => 1);
472 my $currently_selected_languages;
474 foreach my $language (split /\s+/, $data->{'value'}) {
475 next if $language eq 'images';
476 push @options, { option => $language, counter => $counter };
477 $currently_selected_languages->{$language}=1;
480 my $langavail = getTranslatedLanguages();
481 foreach my $language (@$langavail) {
483 next if $currently_selected_languages->{$language->{'language_code'}};
484 #FIXME: could add language_name and language_locale_name for better display
485 push @options, { option => $language->{'language_code'}, counter => $counter };
489 $template->param('type-free' => 1);
490 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
492 $template->param(explanation => $data->{'explanation'},
493 value => $data->{'value'},
494 type => $data->{'type'},
495 options => \@options,
496 preftype => $data->{'type'},
497 prefoptions => $data->{'options'},
498 searchfield => $searchfield);
500 ################## ADD_VALIDATE ##################################
501 # called by add_form, used to insert/modify data in DB
502 } elsif ($op eq 'add_validate') {
503 my $dbh = C4::Context->dbh;
504 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
505 $sth->execute($input->param('variable'));
507 unless (C4::Context->config('demo') eq 1) {
508 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
509 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
513 unless (C4::Context->config('demo') eq 1) {
514 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
515 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
520 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
522 ################## DELETE_CONFIRM ##################################
523 # called by default form, used to confirm deletion of data in DB
524 } elsif ($op eq 'delete_confirm') {
525 my $dbh = C4::Context->dbh;
526 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
527 $sth->execute($searchfield);
528 my $data=$sth->fetchrow_hashref;
530 $template->param(searchfield => $searchfield,
531 Tvalue => $data->{'value'},
534 # END $OP eq DELETE_CONFIRM
535 ################## DELETE_CONFIRMED ##################################
536 # called by delete_confirm, used to effectively confirm deletion of data in DB
537 } elsif ($op eq 'delete_confirmed') {
538 my $dbh = C4::Context->dbh;
539 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
540 $sth->execute($searchfield);
543 # END $OP eq DELETE_CONFIRMED
544 ################## DEFAULT ##################################
546 #Adding tab management for system preferences
547 my $tab=$input->param('tab');
548 $template->param($tab => 1);
549 my ($count,$results)=StringSearch($searchfield,$tab);
552 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
558 my %row_data; # get a fresh hash for the row data
559 $row_data{variable} = $results->[$i]{'variable'};
560 $row_data{value} = $results->[$i]{'value'};
561 $row_data{yes} = 1 if ($results->[$i]{'value'} == 1);
562 $row_data{yesno} = 1 if ($results->[$i]{'type'} eq 'YesNo');
563 $row_data{explanation} = $results->[$i]{'explanation'};
564 $row_data{toggle} = $toggle;
565 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
566 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
567 push(@loop_data, \%row_data);
569 $tab=($tab?$tab:"Others");
570 $template->param(loop => \@loop_data, $tab => 1);
572 my $prevpage = $offset-$pagesize;
573 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
575 if ($offset+$pagesize<$count) {
576 my $nextpage =$offset+$pagesize;
577 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
579 $template->param( tab => $tab,
581 } #---- END $OP eq DEFAULT
582 output_html_with_http_headers $input, $cookie, $template->output;