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";
139 $tabsysprefs{TemplateEncoding}="StaffClient";
140 $tabsysprefs{template}="StaffClient";
141 $tabsysprefs{intranetstylesheet}="StaffClient";
142 $tabsysprefs{IntranetNav}="StaffClient";
143 $tabsysprefs{intranetcolorstylesheet}="StaffClient";
144 $tabsysprefs{intranetuserjs}="StaffClient";
145 $tabsysprefs{yuipath}="StaffClient";
146 $tabsysprefs{IntranetmainUserblock}="StaffClient";
149 $tabsysprefs{automembernum}="Patrons";
150 $tabsysprefs{checkdigit}="Patrons";
151 $tabsysprefs{intranetreadinghistory}="Patrons";
152 $tabsysprefs{NotifyBorrowerDeparture}="Patrons";
153 $tabsysprefs{memberofinstitution}="Patrons";
154 $tabsysprefs{ReadingHistory}="Patrons";
155 $tabsysprefs{BorrowerMandatoryField}="Patrons";
156 $tabsysprefs{borrowerRelationship}="Patrons";
157 $tabsysprefs{BorrowersTitles}="Patrons";
158 $tabsysprefs{patronimages}="Patrons";
159 $tabsysprefs{MinPasswordLength}="Patrons";
160 $tabsysprefs{uppercasesurnames}="Patrons";
161 $tabsysprefs{NoReturnSetLost}="Patrons";
162 $tabsysprefs{MaxFine}="Patrons";
163 $tabsysprefs{NotifyBorrowerDeparture}="Patrons";
166 $tabsysprefs{FRBRizeEditions}="FRBR";
167 $tabsysprefs{XISBN}="FRBR";
168 $tabsysprefs{OCLCAffiliateID}="FRBR";
169 $tabsysprefs{XISBNDailyLimit}="FRBR";
170 $tabsysprefs{PINESISBN}="FRBR";
171 $tabsysprefs{ThingISBN}="FRBR";
172 $tabsysprefs{OPACFRBRizeEditions}="FRBR";
173 $tabsysprefs{XISBNAmazonSimilarItems}="FRBR";
176 $tabsysprefs{dateformat}="I18N/L10N";
177 $tabsysprefs{opaclanguages}="I18N/L10N";
178 $tabsysprefs{opacthemes}="I18N/L10N";
181 $tabsysprefs{defaultSortField}="Searching";
182 $tabsysprefs{defaultSortOrder}="Searching";
183 $tabsysprefs{maxItemsInSearchResults}="Searching";
184 $tabsysprefs{numSearchResults}="Searching";
185 $tabsysprefs{OPACdefaultSortField}="Searching";
186 $tabsysprefs{OPACdefaultSortOrder}="Searching";
187 $tabsysprefs{OPACItemsResultsDisplay}="Searching";
188 $tabsysprefs{OPACnumSearchResults}="Searching";
189 $tabsysprefs{QueryFuzzy}="Searching";
190 $tabsysprefs{QueryStemming}="Searching";
191 $tabsysprefs{QueryWeightFields}="Searching";
192 $tabsysprefs{expandedSearchOption}="Searching";
193 $tabsysprefs{sortbynonfiling}="Searching";
197 $tabsysprefs{AmazonAssocTag}="OPAC";
198 $tabsysprefs{AmazonSimilarItems}="OPAC";
199 $tabsysprefs{AmazonContent}="OPAC";
200 $tabsysprefs{OPACAmazonContent}="OPAC";
201 $tabsysprefs{AmazonDevKey}="OPAC";
202 $tabsysprefs{BiblioDefaultView}="OPAC";
203 $tabsysprefs{LibraryName}="OPAC";
204 $tabsysprefs{opaccolorstylesheet}="OPAC";
205 $tabsysprefs{opaccredits}="OPAC";
206 $tabsysprefs{opaclargeimage}="OPAC";
207 $tabsysprefs{opaclayoutstylesheet}="OPAC";
208 $tabsysprefs{OpacNav}="OPAC";
209 $tabsysprefs{opacsmallimage}="OPAC";
210 $tabsysprefs{opacstylesheet}="OPAC";
211 $tabsysprefs{opacthemes}="OPAC";
212 $tabsysprefs{opacuserjs}="OPAC";
213 $tabsysprefs{SubscriptionHistory}="OPAC";
214 $tabsysprefs{opacheader}="OPAC";
215 $tabsysprefs{OPACAmazonSimilarItems}="OPAC";
216 $tabsysprefs{OPACXISBNAmazonSimilarItems}="OPAC";
218 $tabsysprefs{hideBiblioNumber}="OPAC";
219 $tabsysprefs{noOPACUserLogin}="OPAC";
220 $tabsysprefs{OPACDisplayExtendedSubInfo}="OPAC";
221 $tabsysprefs{OpacMainUserBlock}="OPAC";
222 $tabsysprefs{OPACSubscriptionDisplay}="OPAC";
223 $tabsysprefs{OPACURLOpenInNewWindow}="OPAC";
224 $tabsysprefs{OPACUserCSS}="OPAC";
225 $tabsysprefs{OPACViewOthersSuggestions}="OPAC";
226 $tabsysprefs{URLLinkText}="OPAC";
229 $tabsysprefs{SearchMyLibraryFirst}="OPACFeatures";
230 $tabsysprefs{Disable_Dictionary}="OPACFeatures";
231 $tabsysprefs{hidelostitems}="OPACFeatures";
232 $tabsysprefs{opacbookbag}="OPACFeatures";
233 $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
234 $tabsysprefs{OpacPasswordChange}="OPACFeatures";
235 $tabsysprefs{opacreadinghistory}="OPACFeatures";
236 $tabsysprefs{virtualshelves}="OPACFeatures";
237 $tabsysprefs{RequestOnOpac}="OPACFeatures";
238 $tabsysprefs{reviewson}="OPACFeatures";
239 $tabsysprefs{OpacTopissues}="OPACFeatures";
240 $tabsysprefs{OpacAuthorities}="OPACFeatures";
241 $tabsysprefs{OpacCloud}="OPACFeatures";
242 $tabsysprefs{opacuserlogin}="OPACFeatures";
243 $tabsysprefs{AnonSuggestions}="OPACFeatures";
244 $tabsysprefs{suggestion}="OPACFeatures";
245 $tabsysprefs{OpacTopissue}="OPACFeatures";
246 $tabsysprefs{OpacBrowser}="OPACFeatures";
247 $tabsysprefs{kohaspsuggest} = "OPACFeatures";
250 $tabsysprefs{CataloguingLog} = "LOGFeatures";
251 $tabsysprefs{BorrowersLog} = "LOGFeatures";
252 $tabsysprefs{SubscriptionLog} = "LOGFeatures";
253 $tabsysprefs{IssueLog} = "LOGFeatures";
254 $tabsysprefs{ReturnLog} = "LOGFeatures";
255 $tabsysprefs{LetterLog} = "LOGFeatures";
256 $tabsysprefs{FinesLog} = "LOGFeatures";
259 my ($searchstring,$type)=@_;
260 my $dbh = C4::Context->dbh;
261 $searchstring=~ s/\'/\\\'/g;
262 my @data=split(' ',$searchstring);
267 # used for doing a plain-old sys-pref search
268 if ($type eq 'all' ){
269 my $sth=$dbh->prepare("SELECT * FROM systempreferences
270 WHERE variable LIKE ? OR explanation LIKE ?
272 $sth->execute("%$searchstring%", "%$searchstring%");
273 while (my $data=$sth->fetchrow_hashref){
274 $data->{value} =~ s/</</g;
275 $data->{value} =~ s/>/>/g;
276 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
277 push(@results,$data);
283 foreach my $syspref (sort keys %tabsysprefs){
284 if ($tabsysprefs{$syspref} eq $type){
285 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
286 $sth->execute($syspref);
287 while (my $data=$sth->fetchrow_hashref){
288 $data->{value} =~ s/</</g;
289 $data->{value} =~ s/>/>/g;
290 $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
291 push(@results,$data);
298 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
299 foreach my $syspref (keys %tabsysprefs){
300 $strsth .= $dbh->quote($syspref).",";
303 $strsth .= " order by variable";
304 my $sth=$dbh->prepare($strsth);
306 while (my $data=$sth->fetchrow_hashref){
307 $data->{value}=substr($data->{value},0,100);
308 push(@results,$data);
313 return ($cnt,\@results);
317 my $searchfield=$input->param('searchfield');
318 my $offset=$input->param('offset');
319 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
321 my ($template, $borrowernumber, $cookie)
322 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
325 authnotrequired => 0,
326 flagsrequired => {parameters => 1},
330 my $op = $input->param('op');
331 $searchfield=~ s/\,//g;
334 $template->param(script_name => $script_name,
335 $op => 1); # we show only the TMPL_VAR names $op
337 $template->param(script_name => $script_name,
338 else => 1); # we show only the TMPL_VAR names $op
341 if ($op eq 'update_and_reedit') {
342 foreach ($input->param) {
345 if (my $currentorder=$input->param('currentorder')) {
346 my @currentorder=split /\|/, $currentorder;
348 foreach my $param ($input->param) {
349 if ($param=~m#up-(\d+).x#) {
350 my $temp=$currentorder[$1];
351 $currentorder[$1]=$currentorder[$1-1];
352 $currentorder[$1-1]=$temp;
355 } elsif ($param=~m#down-(\d+).x#) {
356 my $temp=$currentorder[$1];
357 $currentorder[$1]=$currentorder[$1+1];
358 $currentorder[$1+1]=$temp;
363 $value=join ' ', @currentorder;
366 $template->param(script_name => $script_name,
367 $op => 1); # we show only the TMPL_VAR names $op
371 $template->param(script_name => $script_name,
372 else => 1); # we show only the TMPL_VAR names $op
375 my $dbh = C4::Context->dbh;
376 my $query="select * from systempreferences where variable=?";
377 my $sth=$dbh->prepare($query);
378 $sth->execute($input->param('variable'));
380 unless (C4::Context->config('demo') eq 1) {
381 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
382 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
386 unless (C4::Context->config('demo') eq 1) {
387 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
388 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
396 ################## ADD_FORM ##################################
397 # called by default. Used to create form to add or modify a record
399 if ($op eq 'add_form') {
400 #---- if primkey exists, it's a modify action, so read values to modify...
403 my $dbh = C4::Context->dbh;
404 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
405 $sth->execute($searchfield);
406 $data=$sth->fetchrow_hashref;
408 $template->param(modify => 1);
409 # save tab to return to if user cancels edit
410 $template->param(return_tab => $tabsysprefs{$searchfield});
414 foreach my $option (split(/\|/, $data->{'options'})) {
416 $option eq $data->{'value'} and $selected=1;
417 push @options, { option => $option, selected => $selected };
419 if ($data->{'type'} eq 'Choice') {
420 $template->param('type-choice' => 1);
421 } elsif ($data->{'type'} eq 'YesNo') {
422 $template->param('type-yesno' => 1);
423 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
424 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
425 } elsif ($data->{'type'} eq 'Integer') {
426 $template->param('type-free' => 1);
427 $template->param('fieldlength' => $data->{'options'});
428 } elsif ($data->{'type'} eq 'Textarea') {
429 $template->param('type-textarea' => 1);
430 $data->{options} =~ /(.*)\|(.*)/;
431 $template->param('cols' => $1, 'rows' => $2);;
432 } elsif ($data->{'type'} eq 'Float') {
433 $template->param('type-free' => 1);
434 $template->param('fieldlength' => $data->{'options'});
435 } elsif ($data->{'type'} eq 'Themes') {
436 $template->param('type-choice' => 1);
438 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
440 my $currently_selected_themes;
442 foreach my $theme (split /\s+/, $data->{'value'}) {
443 push @options, { option => $theme, counter => $counter };
444 $currently_selected_themes->{$theme}=1;
447 foreach my $theme (getallthemes($type)) {
449 next if $currently_selected_themes->{$theme};
450 push @options, { option => $theme, counter => $counter };
453 } elsif ($data->{'type'} eq 'ClassSources') {
454 $template->param('type-choice' => 1);
457 my $sources = GetClassSources();
459 foreach my $cn_source (sort keys %$sources) {
460 if ($cn_source eq $data->{'value'}) {
461 push @options, { option => $cn_source, counter => $counter, selected => 1 };
463 push @options, { option => $cn_source, counter => $counter };
467 } elsif ($data->{'type'} eq 'Languages') {
468 $template->param('type-choice' => 1);
471 my $currently_selected_languages;
473 foreach my $language (split /\s+/, $data->{'value'}) {
474 next if $language eq 'images';
475 push @options, { option => $language, counter => $counter };
476 $currently_selected_languages->{$language}=1;
479 my $langavail = getTranslatedLanguages();
480 foreach my $language (@$langavail) {
482 next if $currently_selected_languages->{$language->{'language_code'}};
483 #FIXME: could add language_name and language_locale_name for better display
484 push @options, { option => $language->{'language_code'}, counter => $counter };
488 $template->param('type-free' => 1);
489 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
491 $template->param(explanation => $data->{'explanation'},
492 value => $data->{'value'},
493 type => $data->{'type'},
494 options => \@options,
495 preftype => $data->{'type'},
496 prefoptions => $data->{'options'},
497 searchfield => $searchfield);
499 ################## ADD_VALIDATE ##################################
500 # called by add_form, used to insert/modify data in DB
501 } elsif ($op eq 'add_validate') {
502 my $dbh = C4::Context->dbh;
503 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
504 $sth->execute($input->param('variable'));
506 unless (C4::Context->config('demo') eq 1) {
507 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
508 $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
512 unless (C4::Context->config('demo') eq 1) {
513 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
514 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
519 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
521 ################## DELETE_CONFIRM ##################################
522 # called by default form, used to confirm deletion of data in DB
523 } elsif ($op eq 'delete_confirm') {
524 my $dbh = C4::Context->dbh;
525 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
526 $sth->execute($searchfield);
527 my $data=$sth->fetchrow_hashref;
529 $template->param(searchfield => $searchfield,
530 Tvalue => $data->{'value'},
533 # END $OP eq DELETE_CONFIRM
534 ################## DELETE_CONFIRMED ##################################
535 # called by delete_confirm, used to effectively confirm deletion of data in DB
536 } elsif ($op eq 'delete_confirmed') {
537 my $dbh = C4::Context->dbh;
538 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
539 $sth->execute($searchfield);
542 # END $OP eq DELETE_CONFIRMED
543 ################## DEFAULT ##################################
545 #Adding tab management for system preferences
546 my $tab=$input->param('tab');
547 $template->param($tab => 1);
548 my ($count,$results)=StringSearch($searchfield,$tab);
551 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
557 my %row_data; # get a fresh hash for the row data
558 $row_data{variable} = $results->[$i]{'variable'};
559 $row_data{value} = $results->[$i]{'value'};
560 $row_data{yes} = 1 if ($results->[$i]{'value'} == 1);
561 $row_data{yesno} = 1 if ($results->[$i]{'type'} eq 'YesNo');
562 $row_data{explanation} = $results->[$i]{'explanation'};
563 $row_data{toggle} = $toggle;
564 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
565 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
566 push(@loop_data, \%row_data);
568 $tab=($tab?$tab:"Others");
569 $template->param(loop => \@loop_data, $tab => 1);
571 my $prevpage = $offset-$pagesize;
572 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
574 if ($offset+$pagesize<$count) {
575 my $nextpage =$offset+$pagesize;
576 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
578 $template->param( tab => $tab,
580 } #---- END $OP eq DEFAULT
581 output_html_with_http_headers $input, $cookie, $template->output;