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
21 # with Koha; if not, write to the Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
51 use C4::Languages qw(getTranslatedLanguages);
55 use YAML::Syck qw( Dump LoadFile );
58 # use Smart::Comments;
60 # FIXME, shouldnt we store this stuff in the systempreferences table?
62 # FIXME: This uses hash in a backwards way. What we really want is:
63 # $tabsysprefs{key} = $array_ref;
65 # $tabsysprefs{Cataloguing} = [qw(autoBarcode ISBD marc ...)];
67 # Because some things *should* be on more than one tab.
68 # And the tabname is the unique part (the key).
73 $tabsysprefs{gist}="Acquisitions";
74 $tabsysprefs{emailPurchaseSuggestions}="Acquisitions";
75 $tabsysprefs{RenewSerialAddsSuggestion}="Acquisitions";
76 $tabsysprefs{AcqCreateItem}="Acquisitions";
77 $tabsysprefs{OrderPdfFormat}="Acquisitions";
78 $tabsysprefs{CurrencyFormat}="Acquisitions";
79 $tabsysprefs{AcqViewBaskets}="Acquisitions";
82 $tabsysprefs{singleBranchMode} = "Admin";
83 $tabsysprefs{staffClientBaseURL} = "Admin";
84 $tabsysprefs{Version} = "Admin";
85 $tabsysprefs{OpacMaintenance} = "Admin";
86 $tabsysprefs{FrameworksLoaded} = "Admin";
87 $tabsysprefs{delimiter} = "Admin";
88 $tabsysprefs{IndependantBranches} = "Admin";
89 $tabsysprefs{insecure} = "Admin";
90 $tabsysprefs{KohaAdmin} = "Admin";
91 $tabsysprefs{KohaAdminEmailAddress} = "Admin";
92 $tabsysprefs{timeout} = "Admin";
93 $tabsysprefs{Intranet_includes} = "Admin";
94 $tabsysprefs{AutoLocation} = "Admin";
95 $tabsysprefs{DebugLevel} = "Admin";
96 $tabsysprefs{SessionStorage} = "Admin";
98 # This script is deprecated so all of these prefs are lumped here to avoid their being displayed in the local use prefs tab
100 $tabsysprefs{noItemTypeImages} = "Admin";
101 $tabsysprefs{OPACBaseURL} = "Admin";
102 $tabsysprefs{AnonymousPatron} = "Admin";
103 $tabsysprefs{casAuthentication} = "Admin";
104 $tabsysprefs{casLogout} = "Admin";
105 $tabsysprefs{casServerUrl} = "Admin";
106 $tabsysprefs{Disable_Dictionary} = "Admin";
107 $tabsysprefs{EnableOpacSearchHistory} = "Admin";
108 $tabsysprefs{Intranetbookbag} = "Admin";
109 $tabsysprefs{maxitemsinSearchResults} = "Admin";
110 $tabsysprefs{noOPACUserLogin} = "Admin";
111 $tabsysprefs{'OAI-PMH:ConfFile'} = "Admin";
112 $tabsysprefs{OpacAddMastheadLibraryPulldown} = "Admin";
113 $tabsysprefs{opaclargeimage} = "Admin";
114 $tabsysprefs{OPACXSLTDetailsDisplay} = "Admin";
115 $tabsysprefs{OPACXSLTResultsDisplay} = "Admin";
116 $tabsysprefs{PDFFontType} = "Admin";
117 $tabsysprefs{PrintNoticesMaxLines} = "Admin";
118 $tabsysprefs{ReservesControlBranch} = "Admin";
119 $tabsysprefs{ResultsDisplay} = "Admin";
120 $tabsysprefs{NoReturnSetLost} = "Admin";
121 $tabsysprefs{SearchURL} = "Admin";
122 $tabsysprefs{ShowPictures} = "Admin";
123 $tabsysprefs{soundon} = "Admin";
124 $tabsysprefs{SpineLabelShowPrintOnBibDetails} = "Admin";
125 $tabsysprefs{WebBasedSelfCheckHeader} = "Admin";
126 $tabsysprefs{WebBasedSelfCheckTimeout} = "Admin";
129 $tabsysprefs{authoritysep} = "Authorities";
130 $tabsysprefs{AuthDisplayHierarchy} = "Authorities";
131 $tabsysprefs{dontmerge} = "Authorities";
132 $tabsysprefs{BiblioAddsAuthorities} = "Authorities";
135 $tabsysprefs{advancedMARCeditor} = "Cataloging";
136 $tabsysprefs{autoBarcode} = "Cataloging";
137 $tabsysprefs{hide_marc} = "Cataloging";
138 $tabsysprefs{IntranetBiblioDefaultView} = "Cataloging";
139 $tabsysprefs{ISBD} = "Cataloging";
140 $tabsysprefs{itemcallnumber} = "Cataloging";
141 $tabsysprefs{LabelMARCView} = "Cataloging";
142 $tabsysprefs{marcflavour} = "Cataloging";
143 $tabsysprefs{MARCOrgCode} = "Cataloging";
144 $tabsysprefs{z3950AuthorAuthFields} = "Cataloging";
145 $tabsysprefs{z3950NormalizeAuthor} = "Cataloging";
146 $tabsysprefs{Stemming} = "Cataloging";
147 $tabsysprefs{WeightFields} = "Cataloging";
148 $tabsysprefs{NoZebra} = "Cataloging";
149 $tabsysprefs{NoZebraIndexes} = "Cataloging";
150 $tabsysprefs{ReceiveBackIssues} = "Cataloging";
151 $tabsysprefs{DefaultClassificationSource} = "Cataloging";
152 $tabsysprefs{RoutingSerials} = "Cataloging";
153 $tabsysprefs{'item-level_itypes'} = "Cataloging";
154 $tabsysprefs{OpacSuppression} = "Cataloging";
155 $tabsysprefs{SpineLabelFormat} = "Cataloging";
156 $tabsysprefs{SpineLabelAutoPrint} = "Cataloging";
159 $tabsysprefs{maxoutstanding} = "Circulation";
160 $tabsysprefs{maxreserves} = "Circulation";
161 $tabsysprefs{noissuescharge} = "Circulation";
162 $tabsysprefs{IssuingInProcess} = "Circulation";
163 $tabsysprefs{patronimages} = "Circulation";
164 $tabsysprefs{printcirculationslips} = "Circulation";
165 $tabsysprefs{ReturnBeforeExpiry} = "Circulation";
166 $tabsysprefs{SpecifyDueDate} = "Circulation";
167 $tabsysprefs{AutomaticItemReturn} = "Circulation";
168 $tabsysprefs{ReservesMaxPickUpDelay} = "Circulation";
169 $tabsysprefs{TransfersMaxDaysWarning} = "Circulation";
170 $tabsysprefs{useDaysMode} = "Circulation";
171 $tabsysprefs{ReservesNeedReturns} = "Circulation";
172 $tabsysprefs{CircAutocompl} = "Circulation";
173 $tabsysprefs{AllowRenewalLimitOverride} = "Circulation";
174 $tabsysprefs{canreservefromotherbranches} = "Circulation";
175 $tabsysprefs{finesMode} = "Circulation";
176 $tabsysprefs{numReturnedItemsToShow} = "Circulation";
177 $tabsysprefs{emailLibrarianWhenHoldIsPlaced} = "Circulation";
178 $tabsysprefs{itemBarcodeInputFilter} = "Circulation";
179 $tabsysprefs{WebBasedSelfCheck} = "Circulation";
180 $tabsysprefs{ShowPatronImageInWebBasedSelfCheck} = "Circulation";
181 $tabsysprefs{CircControl} = "Circulation";
182 $tabsysprefs{finesCalendar} = "Circulation";
183 $tabsysprefs{previousIssuesDefaultSortOrder} = "Circulation";
184 $tabsysprefs{todaysIssuesDefaultSortOrder} = "Circulation";
185 $tabsysprefs{HomeOrHoldingBranch} = "Circulation";
186 $tabsysprefs{HomeOrHoldingBranchReturn} = "Circulation";
187 $tabsysprefs{RandomizeHoldsQueueWeight} = "Circulation";
188 $tabsysprefs{StaticHoldsQueueWeight} = "Circulation";
189 $tabsysprefs{AllowOnShelfHolds} = "Circulation";
190 $tabsysprefs{AllowHoldsOnDamagedItems} = "Circulation";
191 $tabsysprefs{UseBranchTransferLimits} = "Circulation";
192 $tabsysprefs{AllowHoldPolicyOverride} = "Circulation";
193 $tabsysprefs{BranchTransferLimitsType} = "Circulation";
194 $tabsysprefs{AllowNotForLoanOverride} = "Circulation";
195 $tabsysprefs{RenewalPeriodBase} = "Circulation";
196 $tabsysprefs{FilterBeforeOverdueReport} = "Circulation";
197 $tabsysprefs{AllowHoldDateInFuture} = "Circulation";
198 $tabsysprefs{OPACFineNoRenewals} = "Circulation";
199 $tabsysprefs{InProcessingToShelvingCart} = "Circulation";
200 $tabsysprefs{NewItemsDefaultLocation} = "Circulation";
201 $tabsysprefs{ReturnToShelvingCart} = "Circulation";
202 $tabsysprefs{DisplayClearScreenButton} = "Circulation";
203 $tabsysprefs{AllowAllMessageDeletion} = "Circulation";
204 $tabsysprefs{OverdueNoticeBcc} = "Circulation";
205 $tabsysprefs{OverduesBlockCirc} = "Circulation";
209 $tabsysprefs{template} = "StaffClient";
210 $tabsysprefs{intranetstylesheet} = "StaffClient";
211 $tabsysprefs{IntranetNav} = "StaffClient";
212 $tabsysprefs{intranetcolorstylesheet} = "StaffClient";
213 $tabsysprefs{intranetuserjs} = "StaffClient";
214 $tabsysprefs{yuipath} = "StaffClient";
215 $tabsysprefs{IntranetmainUserblock} = "StaffClient";
216 $tabsysprefs{viewMARC} = "StaffClient";
217 $tabsysprefs{viewLabeledMARC} = "StaffClient";
218 $tabsysprefs{viewISBD} = "StaffClient";
221 $tabsysprefs{autoMemberNum} = "Patrons";
222 $tabsysprefs{checkdigit} = "Patrons";
223 $tabsysprefs{intranetreadinghistory} = "Patrons";
224 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
225 $tabsysprefs{memberofinstitution} = "Patrons";
226 $tabsysprefs{BorrowerMandatoryField} = "Patrons";
227 $tabsysprefs{BorrowerUnwantedField} = "Patrons";
228 $tabsysprefs{borrowerRelationship} = "Patrons";
229 $tabsysprefs{BorrowersTitles} = "Patrons";
230 $tabsysprefs{patronimages} = "Patrons";
231 $tabsysprefs{minPasswordLength} = "Patrons";
232 $tabsysprefs{uppercasesurnames} = "Patrons";
233 $tabsysprefs{MaxFine} = "Patrons";
234 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
235 $tabsysprefs{AddPatronLists} = "Patrons";
236 $tabsysprefs{PatronsPerPage} = "Patrons";
237 $tabsysprefs{ExtendedPatronAttributes} = "Patrons";
238 $tabsysprefs{AutoEmailOpacUser} = "Patrons";
239 $tabsysprefs{AutoEmailPrimaryAddress} = "Patrons";
240 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
241 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
242 $tabsysprefs{HidePatronName} = "Patrons";
246 $tabsysprefs{dateformat} = "I18N/L10N";
247 $tabsysprefs{opaclanguages} = "I18N/L10N";
248 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
249 $tabsysprefs{language} = "I18N/L10N";
252 $tabsysprefs{defaultSortField} = "Searching";
253 $tabsysprefs{defaultSortOrder} = "Searching";
254 $tabsysprefs{numSearchResults} = "Searching";
255 $tabsysprefs{OPACdefaultSortField} = "Searching";
256 $tabsysprefs{OPACdefaultSortOrder} = "Searching";
257 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
258 $tabsysprefs{OPACnumSearchResults} = "Searching";
259 $tabsysprefs{QueryFuzzy} = "Searching";
260 $tabsysprefs{QueryStemming} = "Searching";
261 $tabsysprefs{QueryWeightFields} = "Searching";
262 $tabsysprefs{expandedSearchOption} = "Searching";
263 $tabsysprefs{QueryAutoTruncate} = "Searching";
264 $tabsysprefs{QueryRemoveStopwords} = "Searching";
265 $tabsysprefs{AdvancedSearchTypes} = "Searching";
266 $tabsysprefs{DisplayMultiPlaceHold} = "Searching";
269 $tabsysprefs{AmazonCoverImages} = "EnhancedContent";
270 $tabsysprefs{OPACAmazonCoverImages} = "EnhancedContent";
271 $tabsysprefs{AmazonLocale} = "EnhancedContent";
272 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
275 $tabsysprefs{Babeltheque} = "EnhancedContent";
278 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
279 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
280 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
281 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
283 # Library Thing for Libraries
284 $tabsysprefs{LibraryThingForLibrariesID} = "EnhancedContent";
285 $tabsysprefs{LibraryThingForLibrariesEnabled} = "EnhancedContent";
286 $tabsysprefs{LibraryThingForLibrariesTabbedView} = "EnhancedContent";
289 $tabsysprefs{SyndeticsClientCode} = 'EnhancedContent';
290 $tabsysprefs{SyndeticsEnabled} = 'EnhancedContent';
291 $tabsysprefs{SyndeticsCoverImages} = 'EnhancedContent';
292 $tabsysprefs{SyndeticsTOC} = 'EnhancedContent';
293 $tabsysprefs{SyndeticsSummary} = 'EnhancedContent';
294 $tabsysprefs{SyndeticsEditions} = 'EnhancedContent';
295 $tabsysprefs{SyndeticsExcerpt} = 'EnhancedContent';
296 $tabsysprefs{SyndeticsReviews} = 'EnhancedContent';
297 $tabsysprefs{SyndeticsAuthorNotes} = 'EnhancedContent';
298 $tabsysprefs{SyndeticsAwards} = 'EnhancedContent';
299 $tabsysprefs{SyndeticsSeries} = 'EnhancedContent';
300 $tabsysprefs{SyndeticsCoverImageSize} = 'EnhancedContent';
304 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
305 $tabsysprefs{XISBN} = "EnhancedContent";
306 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
307 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
308 $tabsysprefs{ThingISBN} = "EnhancedContent";
309 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
312 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
313 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
314 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
315 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
316 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
317 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
318 $tabsysprefs{TagsModeration} = 'EnhancedContent';
319 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
320 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
323 $tabsysprefs{BiblioDefaultView} = "OPAC";
324 $tabsysprefs{LibraryName} = "OPAC";
325 $tabsysprefs{opaccolorstylesheet} = "OPAC";
326 $tabsysprefs{opaccredits} = "OPAC";
327 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
328 $tabsysprefs{OpacNav} = "OPAC";
329 $tabsysprefs{opacsmallimage} = "OPAC";
330 $tabsysprefs{opacthemes} = "OPAC";
331 $tabsysprefs{opacuserjs} = "OPAC";
332 $tabsysprefs{opacheader} = "OPAC";
333 $tabsysprefs{hideBiblioNumber} = "OPAC";
334 $tabsysprefs{OpacMainUserBlock} = "OPAC";
335 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
336 $tabsysprefs{OPACUserCSS} = "OPAC";
337 $tabsysprefs{OPACHighlightedWords} = "OPAC";
338 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
339 $tabsysprefs{URLLinkText} = "OPAC";
340 $tabsysprefs{OPACSearchForTitleIn} = "OPAC";
341 $tabsysprefs{OPACShelfBrowser} = "OPAC";
342 $tabsysprefs{OPACShowHoldQueueDetails} = "OPAC";
343 $tabsysprefs{OPACAllowHoldDateInFuture} = "OPAC";
344 $tabsysprefs{OPACPatronDetails} = "OPAC";
345 $tabsysprefs{OPACFinesTab} = "OPAC";
346 $tabsysprefs{DisplayOPACiconsXSLT} = "OPAC";
347 $tabsysprefs{AutoSelfCheckAllowed} = "OPAC";
348 $tabsysprefs{AutoSelfCheckID} = "OPAC";
349 $tabsysprefs{AutoSelfCheckPass} = "OPAC";
352 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
353 $tabsysprefs{hidelostitems} = "OPAC";
354 $tabsysprefs{opacbookbag} = "OPAC";
355 $tabsysprefs{OpacPasswordChange} = "OPAC";
356 $tabsysprefs{opacreadinghistory} = "OPAC";
357 $tabsysprefs{virtualshelves} = "OPAC";
358 $tabsysprefs{RequestOnOpac} = "OPAC";
359 $tabsysprefs{reviewson} = "OPAC";
360 $tabsysprefs{OpacTopissues} = "OPAC";
361 $tabsysprefs{OpacAuthorities} = "OPAC";
362 $tabsysprefs{OpacCloud} = "OPAC";
363 $tabsysprefs{opacuserlogin} = "OPAC";
364 $tabsysprefs{AnonSuggestions} = "OPAC";
365 $tabsysprefs{suggestion} = "OPAC";
366 $tabsysprefs{OpacTopissue} = "OPAC";
367 $tabsysprefs{OpacBrowser} = "OPAC";
368 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
369 $tabsysprefs{OPACItemHolds} = "OPAC";
370 $tabsysprefs{OPACGroupResults} = "OPAC";
371 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
372 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
373 $tabsysprefs{OPACShowCheckoutName} = "OPAC";
374 $tabsysprefs{AllowPurchaseSuggestionBranchChoice} = "OPAC";
377 $tabsysprefs{RoutingListAddReserves} = "Serials";
378 $tabsysprefs{OPACSerialIssueDisplayCount} = "Serials";
379 $tabsysprefs{StaffSerialIssueDisplayCount} = "Serials";
380 $tabsysprefs{RenewSerialAddsSuggestion} = "Serials";
381 $tabsysprefs{SubscriptionHistory} = "Serials";
384 $tabsysprefs{CataloguingLog} = "Logs";
385 $tabsysprefs{BorrowersLog} = "Logs";
386 $tabsysprefs{SubscriptionLog} = "Logs";
387 $tabsysprefs{IssueLog} = "Logs";
388 $tabsysprefs{ReturnLog} = "Logs";
389 $tabsysprefs{LetterLog} = "Logs";
390 $tabsysprefs{FinesLog} = "Logs";
393 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
394 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
395 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
398 $tabsysprefs{'ILS-DI'} = "ILS-DI";
399 $tabsysprefs{'ILS-DI:AuthorizedIPs'} = "Admin";
403 $tabsysprefs{'ImageLimit'} = "Creators";
406 my ( $searchstring, $type ) = @_;
407 my $dbh = C4::Context->dbh;
408 $searchstring =~ s/\'/\\\'/g;
409 my @data = split( ' ', $searchstring );
415 # used for doing a plain-old sys-pref search
416 if ( $type && $type ne 'all' ) {
417 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
418 if ( $tabsysprefs{$syspref} eq $type ) {
419 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
420 $sth->execute($syspref);
421 while ( my $data = $sth->fetchrow_hashref ) {
422 $data->{shortvalue} = $data->{value};
423 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
424 push( @results, $data );
433 if ( $type and $type eq 'all' ) {
434 $sth = $dbh->prepare( "
436 FROM systempreferences
437 WHERE variable LIKE ? OR explanation LIKE ?
438 ORDER BY VARIABLE" );
439 $sth->execute( "%$searchstring%", "%$searchstring%" );
441 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable in (";
443 for my $name ( get_local_prefs() ) {
444 $strsth .= ',' unless $first;
445 $strsth .= "'$name'";
448 $strsth .= ") order by variable";
449 $sth = $dbh->prepare($strsth);
453 while ( my $data = $sth->fetchrow_hashref ) {
454 $data->{shortvalue} = $data->{value};
455 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
456 push( @results, $data );
462 return ( $cnt, \@results );
470 if ( defined $data->{'options'} ) {
471 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
473 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
474 push @options, { option => $option, selected => $selected };
478 $params->{'prefoptions'} = $data->{'options'};
480 if ( not defined( $data->{'type'} ) ) {
481 $params->{'type_free'} = 1;
482 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
483 } elsif ( $data->{'type'} eq 'Upload' ) {
484 $params->{'type_upload'} = 1;
485 } elsif ( $data->{'type'} eq 'Choice' ) {
486 $params->{'type_choice'} = 1;
487 } elsif ( $data->{'type'} eq 'YesNo' ) {
488 $params->{'type_yesno'} = 1;
489 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
490 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
491 $params->{'value_yes'} = 1;
493 $params->{'value_no'} = 1;
495 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
496 $params->{'type_free'} = 1;
497 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
498 } elsif ( $data->{'type'} eq 'Textarea' ) {
499 $params->{'type_textarea'} = 1;
500 $data->{options} =~ /(.*)\|(.*)/;
501 $params->{'cols'} = $1;
502 $params->{'rows'} = $2;
503 } elsif ( $data->{'type'} eq 'Themes' ) {
504 $params->{'type_choice'} = 1;
506 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
508 my $currently_selected_themes;
510 foreach my $theme ( split /\s+/, $data->{'value'} ) {
511 push @options, { option => $theme, counter => $counter };
512 $currently_selected_themes->{$theme} = 1;
515 foreach my $theme ( getallthemes($type) ) {
517 next if $currently_selected_themes->{$theme};
518 push @options, { option => $theme, counter => $counter };
521 } elsif ( $data->{'type'} eq 'ClassSources' ) {
522 $params->{'type_choice'} = 1;
525 my $sources = GetClassSources();
527 foreach my $cn_source ( sort keys %$sources ) {
528 if ( $cn_source eq $data->{'value'} ) {
529 push @options, { option => $cn_source, counter => $counter, selected => 1 };
531 push @options, { option => $cn_source, counter => $counter };
535 } elsif ( $data->{'type'} eq 'Languages' ) {
536 my $currently_selected_languages;
537 foreach my $language ( split /\s+/, $data->{'value'} ) {
538 $currently_selected_languages->{$language} = 1;
542 my $lang = $params->{'lang'};
545 if ( $data->{'variable'} =~ /opac/ ) {
549 $theme = C4::Context->preference('opacthemes');
552 # this is the staff client
553 $interface = 'intranet';
554 $theme = C4::Context->preference('template');
556 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
558 $params->{'languages_loop'} = $languages_loop;
559 $params->{'type_langselector'} = 1;
561 $params->{'type_free'} = 1;
562 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
565 if ( $params->{'type_choice'} || $params->{'type_free'} || $params->{'type_yesno'} ) {
566 $params->{'oneline'} = 1;
569 $params->{'preftype'} = $data->{'type'};
570 $params->{'options'} = \@options;
576 my $searchfield = $input->param('searchfield') || '';
577 my $Tvalue = $input->param('Tvalue');
578 my $offset = $input->param('offset') || 0;
579 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
581 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
582 { template_name => "admin/systempreferences.tmpl",
585 authnotrequired => 0,
586 flagsrequired => { parameters => 'parameters_remaining_permissions' },
591 my $op = $input->param('op') || '';
592 $searchfield =~ s/\,//g;
596 script_name => $script_name,
598 ); # we show only the TMPL_VAR names $op
601 script_name => $script_name,
603 ); # we show only the TMPL_VAR names $op
606 if ( $op eq 'update_and_reedit' ) {
607 foreach ( $input->param ) {
610 if ( my $currentorder = $input->param('currentorder') ) {
611 my @currentorder = split /\|/, $currentorder;
612 my $orderchanged = 0;
613 foreach my $param ( $input->param ) {
614 if ( $param =~ m#up-(\d+).x# ) {
615 my $temp = $currentorder[$1];
616 $currentorder[$1] = $currentorder[ $1 - 1 ];
617 $currentorder[ $1 - 1 ] = $temp;
620 } elsif ( $param =~ m#down-(\d+).x# ) {
621 my $temp = $currentorder[$1];
622 $currentorder[$1] = $currentorder[ $1 + 1 ];
623 $currentorder[ $1 + 1 ] = $temp;
628 $value = join ' ', @currentorder;
632 script_name => $script_name,
634 ); # we show only the TMPL_VAR names $op
639 script_name => $script_name,
641 ); # we show only the TMPL_VAR names $op
644 my $dbh = C4::Context->dbh;
645 my $query = "select * from systempreferences where variable=?";
646 my $sth = $dbh->prepare($query);
647 $sth->execute( $input->param('variable') );
649 unless ( C4::Context->config('demo') ) {
650 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
651 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
653 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
656 unless ( C4::Context->config('demo') ) {
657 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
658 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
660 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
667 ################## ADD_FORM ##################################
668 # called by default. Used to create form to add or modify a record
670 if ( $op eq 'add_form' ) {
672 #---- if primkey exists, it's a modify action, so read values to modify...
675 my $dbh = C4::Context->dbh;
676 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
677 $sth->execute($searchfield);
678 $data = $sth->fetchrow_hashref;
680 $template->param( modify => 1 );
682 # save tab to return to if user cancels edit
683 $template->param( return_tab => $tabsysprefs{$searchfield} );
686 $data->{'lang'} = $template->param('lang');
687 my $prefparams = GetPrefParams($data);
688 $template->param( %$prefparams );
689 $template->param( searchfield => $searchfield );
691 ################## ADD_VALIDATE ##################################
692 # called by add_form, used to insert/modify data in DB
693 } elsif ( $op eq 'add_validate' ) {
694 my $dbh = C4::Context->dbh;
695 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
696 $sth->execute( $input->param('variable') );
698 # to handle multiple values
701 # handle multiple value strings (separated by ',')
702 my $params = $input->Vars;
703 if ( defined $params->{'value'} ) {
705 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
708 for my $vl (@values) {
713 $value = $params->{'value'};
717 if ( $input->param('preftype') eq 'Upload' ) {
718 my $lgtfh = $input->upload('value');
719 $value = join '', <$lgtfh>;
720 $value = encode_base64($value);
724 unless ( C4::Context->config('demo') ) {
725 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
726 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
728 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
731 unless ( C4::Context->config('demo') ) {
732 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
733 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
735 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
739 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=\"></html>";
741 ################## DELETE_CONFIRM ##################################
742 # called by default form, used to confirm deletion of data in DB
743 } elsif ( $op eq 'delete_confirm' ) {
744 my $dbh = C4::Context->dbh;
745 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
746 $sth->execute($searchfield);
747 my $data = $sth->fetchrow_hashref;
750 searchfield => $searchfield,
751 Tvalue => $data->{'value'},
754 # END $OP eq DELETE_CONFIRM
755 ################## DELETE_CONFIRMED ##################################
756 # called by delete_confirm, used to effectively confirm deletion of data in DB
757 } elsif ( $op eq 'delete_confirmed' ) {
758 my $dbh = C4::Context->dbh;
759 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
760 $sth->execute($searchfield);
761 my $logstring = $searchfield . " | " . $Tvalue;
762 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
765 # END $OP eq DELETE_CONFIRMED
766 ################## DEFAULT ##################################
768 #Adding tab management for system preferences
769 my $tab = $input->param('tab');
770 $template->param( $tab => 1 );
771 my ( $count, $results ) = StringSearch( $searchfield, $tab );
773 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
774 my $row_data = $results->[$i];
775 $row_data->{'lang'} = $template->param('lang');
776 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
777 $row_data->{edit} = "$script_name?op=add_form&searchfield=" . $results->[$i]{'variable'};
778 $row_data->{delete} = "$script_name?op=delete_confirm&searchfield=" . $results->[$i]{'variable'};
779 push( @loop_data, $row_data );
781 $tab = ( $tab ? $tab : "local_use" );
782 $template->param( loop => \@loop_data, $tab => 1 );
784 my $prevpage = $offset - $pagesize;
785 $template->param( "<a href=$script_name?offset=" . $prevpage . '<< Prev</a>' );
787 if ( $offset + $pagesize < $count ) {
788 my $nextpage = $offset + $pagesize;
789 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next >></a>' );
791 $template->param( tab => $tab, );
792 } #---- END $OP eq DEFAULT
793 output_html_with_http_headers $input, $cookie, $template->output;
796 # Return an array containing all preferences defined in current Koha instance
799 sub get_prefs_from_files {
800 my $context = C4::Context->new();
801 my $path_pref_en = $context->config('intrahtdocs') .
802 '/prog/en/modules/admin/preferences';
803 # Get all .pref file names
804 opendir ( my $fh, $path_pref_en );
805 my @pref_files = grep { /.pref/ } readdir($fh);
811 for my $pref ( @$prefs ) {
812 for my $element ( @$pref ) {
813 if ( ref( $element) eq 'HASH' ) {
814 my $name = $element->{pref};
822 for my $file (@pref_files) {
823 my $pref = LoadFile( "$path_pref_en/$file" );
824 for my $tab ( keys %$pref ) {
825 my $content = $pref->{$tab};
826 if ( ref($content) eq 'ARRAY' ) {
830 for my $section ( keys %$content ) {
831 my $syspref = $content->{$section};
840 # Return an array containg all preferences defined in DB
842 sub get_prefs_from_db {
843 my $dbh = C4::Context->dbh;
844 my $sth = $dbh->prepare("SELECT variable FROM systempreferences");
847 while ( (my $name) = $sth->fetchrow_array ) {
848 push @names, $name if $name;
854 # Return an array containing all local preferences: those which are defined in
855 # DB and not defined in Koha .pref files.
857 sub get_local_prefs {
858 my @prefs_file = get_prefs_from_files();
859 my @prefs_db = get_prefs_from_db();
861 my %prefs_file = map { $_ => 1 } @prefs_file;
863 foreach my $name (@prefs_db) {
864 push @names, $name unless $prefs_file{$name};