Bug 7108 - OPAC Translations Display Patch
[koha.git] / admin / systempreferences.pl
blob78d0768d0dc5bbfe0320ab942b1f633e271e36b5
1 #!/usr/bin/perl
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
14 # version.
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
26 ALSO :
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.
31 if $op=add_form
32 - if primkey exists, this is a modification,so we read the $primkey record
33 - builds the add/modify form
34 if $op=add_validate
35 - the user has just send datas, so we create/modify the record
36 if $op=delete_form
37 - we show the record having primkey=$primkey and ask for deletion validation form
38 if $op=delete_confirm
39 - we delete the record having primkey=$primkey
41 =cut
43 use strict;
44 use warnings;
46 use CGI;
47 use MIME::Base64;
48 use C4::Auth;
49 use C4::Context;
50 use C4::Koha;
51 use C4::Languages qw(getTranslatedLanguages);
52 use C4::ClassSource;
53 use C4::Log;
54 use C4::Output;
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;
64 # like
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).
70 my %tabsysprefs;
72 # Acquisitions
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";
81 # Admin
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 depricated 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";
128 # Authorities
129 $tabsysprefs{authoritysep} = "Authorities";
130 $tabsysprefs{AuthDisplayHierarchy} = "Authorities";
131 $tabsysprefs{dontmerge} = "Authorities";
132 $tabsysprefs{BiblioAddsAuthorities} = "Authorities";
134 # Cataloguing
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";
158 # Circulation
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";
208 # Staff Client
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";
220 # Patrons
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{borrowerRelationship} = "Patrons";
228 $tabsysprefs{BorrowersTitles} = "Patrons";
229 $tabsysprefs{patronimages} = "Patrons";
230 $tabsysprefs{minPasswordLength} = "Patrons";
231 $tabsysprefs{uppercasesurnames} = "Patrons";
232 $tabsysprefs{MaxFine} = "Patrons";
233 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
234 $tabsysprefs{AddPatronLists} = "Patrons";
235 $tabsysprefs{PatronsPerPage} = "Patrons";
236 $tabsysprefs{ExtendedPatronAttributes} = "Patrons";
237 $tabsysprefs{AutoEmailOpacUser} = "Patrons";
238 $tabsysprefs{AutoEmailPrimaryAddress} = "Patrons";
239 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
240 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
241 $tabsysprefs{HidePatronName} = "Patrons";
244 # I18N/L10N
245 $tabsysprefs{dateformat} = "I18N/L10N";
246 $tabsysprefs{opaclanguages} = "I18N/L10N";
247 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
248 $tabsysprefs{language} = "I18N/L10N";
250 # Searching
251 $tabsysprefs{defaultSortField} = "Searching";
252 $tabsysprefs{defaultSortOrder} = "Searching";
253 $tabsysprefs{numSearchResults} = "Searching";
254 $tabsysprefs{OPACdefaultSortField} = "Searching";
255 $tabsysprefs{OPACdefaultSortOrder} = "Searching";
256 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
257 $tabsysprefs{OPACnumSearchResults} = "Searching";
258 $tabsysprefs{QueryFuzzy} = "Searching";
259 $tabsysprefs{QueryStemming} = "Searching";
260 $tabsysprefs{QueryWeightFields} = "Searching";
261 $tabsysprefs{expandedSearchOption} = "Searching";
262 $tabsysprefs{QueryAutoTruncate} = "Searching";
263 $tabsysprefs{QueryRemoveStopwords} = "Searching";
264 $tabsysprefs{AdvancedSearchTypes} = "Searching";
265 $tabsysprefs{DisplayMultiPlaceHold} = "Searching";
267 # EnhancedContent
268 $tabsysprefs{AmazonEnabled} = "EnhancedContent";
269 $tabsysprefs{OPACAmazonEnabled} = "EnhancedContent";
270 $tabsysprefs{AmazonCoverImages} = "EnhancedContent";
271 $tabsysprefs{OPACAmazonCoverImages} = "EnhancedContent";
272 $tabsysprefs{AWSAccessKeyID} = "EnhancedContent";
273 $tabsysprefs{AWSPrivateKey} = "EnhancedContent";
274 $tabsysprefs{AmazonLocale} = "EnhancedContent";
275 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
276 $tabsysprefs{AmazonSimilarItems} = "EnhancedContent";
277 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
278 $tabsysprefs{AmazonReviews} = "EnhancedContent";
279 $tabsysprefs{OPACAmazonReviews} = "EnhancedContent";
281 # Babelthèque
282 $tabsysprefs{Babeltheque} = "EnhancedContent";
284 # Baker & Taylor
285 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
286 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
287 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
288 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
290 # Library Thing for Libraries
291 $tabsysprefs{LibraryThingForLibrariesID} = "EnhancedContent";
292 $tabsysprefs{LibraryThingForLibrariesEnabled} = "EnhancedContent";
293 $tabsysprefs{LibraryThingForLibrariesTabbedView} = "EnhancedContent";
295 # Syndetics
296 $tabsysprefs{SyndeticsClientCode} = 'EnhancedContent';
297 $tabsysprefs{SyndeticsEnabled} = 'EnhancedContent';
298 $tabsysprefs{SyndeticsCoverImages} = 'EnhancedContent';
299 $tabsysprefs{SyndeticsTOC} = 'EnhancedContent';
300 $tabsysprefs{SyndeticsSummary} = 'EnhancedContent';
301 $tabsysprefs{SyndeticsEditions} = 'EnhancedContent';
302 $tabsysprefs{SyndeticsExcerpt} = 'EnhancedContent';
303 $tabsysprefs{SyndeticsReviews} = 'EnhancedContent';
304 $tabsysprefs{SyndeticsAuthorNotes} = 'EnhancedContent';
305 $tabsysprefs{SyndeticsAwards} = 'EnhancedContent';
306 $tabsysprefs{SyndeticsSeries} = 'EnhancedContent';
307 $tabsysprefs{SyndeticsCoverImageSize} = 'EnhancedContent';
310 # FRBR
311 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
312 $tabsysprefs{XISBN} = "EnhancedContent";
313 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
314 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
315 $tabsysprefs{ThingISBN} = "EnhancedContent";
316 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
318 # Tags
319 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
320 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
321 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
322 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
323 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
324 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
325 $tabsysprefs{TagsModeration} = 'EnhancedContent';
326 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
327 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
329 # OPAC
330 $tabsysprefs{BiblioDefaultView} = "OPAC";
331 $tabsysprefs{LibraryName} = "OPAC";
332 $tabsysprefs{opaccolorstylesheet} = "OPAC";
333 $tabsysprefs{opaccredits} = "OPAC";
334 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
335 $tabsysprefs{OpacNav} = "OPAC";
336 $tabsysprefs{opacsmallimage} = "OPAC";
337 $tabsysprefs{opacstylesheet} = "OPAC";
338 $tabsysprefs{opacthemes} = "OPAC";
339 $tabsysprefs{opacuserjs} = "OPAC";
340 $tabsysprefs{opacheader} = "OPAC";
341 $tabsysprefs{hideBiblioNumber} = "OPAC";
342 $tabsysprefs{OpacMainUserBlock} = "OPAC";
343 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
344 $tabsysprefs{OPACUserCSS} = "OPAC";
345 $tabsysprefs{OPACHighlightedWords} = "OPAC";
346 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
347 $tabsysprefs{URLLinkText} = "OPAC";
348 $tabsysprefs{OPACSearchForTitleIn} = "OPAC";
349 $tabsysprefs{OPACShelfBrowser} = "OPAC";
350 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
351 $tabsysprefs{OPACAllowHoldDateInFuture} = "OPAC";
352 $tabsysprefs{OPACPatronDetails} = "OPAC";
353 $tabsysprefs{OPACFinesTab} = "OPAC";
354 $tabsysprefs{DisplayOPACiconsXSLT} = "OPAC";
355 $tabsysprefs{AutoSelfCheckAllowed} = "OPAC";
356 $tabsysprefs{AutoSelfCheckID} = "OPAC";
357 $tabsysprefs{AutoSelfCheckPass} = "OPAC";
359 # OPAC
360 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
361 $tabsysprefs{hidelostitems} = "OPAC";
362 $tabsysprefs{opacbookbag} = "OPAC";
363 $tabsysprefs{OpacPasswordChange} = "OPAC";
364 $tabsysprefs{opacreadinghistory} = "OPAC";
365 $tabsysprefs{virtualshelves} = "OPAC";
366 $tabsysprefs{RequestOnOpac} = "OPAC";
367 $tabsysprefs{reviewson} = "OPAC";
368 $tabsysprefs{OpacTopissues} = "OPAC";
369 $tabsysprefs{OpacAuthorities} = "OPAC";
370 $tabsysprefs{OpacCloud} = "OPAC";
371 $tabsysprefs{opacuserlogin} = "OPAC";
372 $tabsysprefs{AnonSuggestions} = "OPAC";
373 $tabsysprefs{suggestion} = "OPAC";
374 $tabsysprefs{OpacTopissue} = "OPAC";
375 $tabsysprefs{OpacBrowser} = "OPAC";
376 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
377 $tabsysprefs{OPACItemHolds} = "OPAC";
378 $tabsysprefs{OPACGroupResults} = "OPAC";
379 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
380 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
381 $tabsysprefs{OPACShowCheckoutName} = "OPAC";
382 $tabsysprefs{AllowPurchaseSuggestionBranchChoice} = "OPAC";
384 # Serials
385 $tabsysprefs{RoutingListAddReserves} = "Serials";
386 $tabsysprefs{OPACSerialIssueDisplayCount} = "Serials";
387 $tabsysprefs{StaffSerialIssueDisplayCount} = "Serials";
388 $tabsysprefs{RenewSerialAddsSuggestion} = "Serials";
389 $tabsysprefs{SubscriptionHistory} = "Serials";
391 # LOGFeatures
392 $tabsysprefs{CataloguingLog} = "Logs";
393 $tabsysprefs{BorrowersLog} = "Logs";
394 $tabsysprefs{SubscriptionLog} = "Logs";
395 $tabsysprefs{IssueLog} = "Logs";
396 $tabsysprefs{ReturnLog} = "Logs";
397 $tabsysprefs{LetterLog} = "Logs";
398 $tabsysprefs{FinesLog} = "Logs";
400 # OAI-PMH variables
401 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
402 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
403 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
405 # ILS-DI variables
406 $tabsysprefs{'ILS-DI'} = "ILS-DI";
407 $tabsysprefs{'ILS-DI:AuthorizedIPs'} = "Admin";
409 # Creator variables
411 $tabsysprefs{'ImageLimit'} = "Creators";
413 sub StringSearch {
414 my ( $searchstring, $type ) = @_;
415 my $dbh = C4::Context->dbh;
416 $searchstring =~ s/\'/\\\'/g;
417 my @data = split( ' ', $searchstring );
418 my $count = @data;
419 my @results;
420 my $cnt = 0;
421 my $sth;
423 # used for doing a plain-old sys-pref search
424 if ( $type && $type ne 'all' ) {
425 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
426 if ( $tabsysprefs{$syspref} eq $type ) {
427 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
428 $sth->execute($syspref);
429 while ( my $data = $sth->fetchrow_hashref ) {
430 $data->{shortvalue} = $data->{value};
431 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
432 push( @results, $data );
433 $cnt++;
435 $sth->finish;
438 } else {
439 my $sth;
441 if ( $type and $type eq 'all' ) {
442 $sth = $dbh->prepare( "
443 SELECT *
444 FROM systempreferences
445 WHERE variable LIKE ? OR explanation LIKE ?
446 ORDER BY VARIABLE" );
447 $sth->execute( "%$searchstring%", "%$searchstring%" );
448 } else {
449 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable in (";
450 my $first = 1;
451 for my $name ( get_local_prefs() ) {
452 $strsth .= ',' unless $first;
453 $strsth .= "'$name'";
454 $first = 0;
456 $strsth .= ") order by variable";
457 $sth = $dbh->prepare($strsth);
458 $sth->execute();
461 while ( my $data = $sth->fetchrow_hashref ) {
462 $data->{shortvalue} = $data->{value};
463 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
464 push( @results, $data );
465 $cnt++;
468 $sth->finish;
470 return ( $cnt, \@results );
473 sub GetPrefParams {
474 my $data = shift;
475 my $params = $data;
476 my @options;
478 if ( defined $data->{'options'} ) {
479 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
480 my $selected = '0';
481 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
482 push @options, { option => $option, selected => $selected };
486 $params->{'prefoptions'} = $data->{'options'};
488 if ( not defined( $data->{'type'} ) ) {
489 $params->{'type_free'} = 1;
490 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
491 } elsif ( $data->{'type'} eq 'Upload' ) {
492 $params->{'type_upload'} = 1;
493 } elsif ( $data->{'type'} eq 'Choice' ) {
494 $params->{'type_choice'} = 1;
495 } elsif ( $data->{'type'} eq 'YesNo' ) {
496 $params->{'type_yesno'} = 1;
497 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
498 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
499 $params->{'value_yes'} = 1;
500 } else {
501 $params->{'value_no'} = 1;
503 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
504 $params->{'type_free'} = 1;
505 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
506 } elsif ( $data->{'type'} eq 'Textarea' ) {
507 $params->{'type_textarea'} = 1;
508 $data->{options} =~ /(.*)\|(.*)/;
509 $params->{'cols'} = $1;
510 $params->{'rows'} = $2;
511 } elsif ( $data->{'type'} eq 'Themes' ) {
512 $params->{'type_choice'} = 1;
513 my $type = '';
514 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
515 @options = ();
516 my $currently_selected_themes;
517 my $counter = 0;
518 foreach my $theme ( split /\s+/, $data->{'value'} ) {
519 push @options, { option => $theme, counter => $counter };
520 $currently_selected_themes->{$theme} = 1;
521 $counter++;
523 foreach my $theme ( getallthemes($type) ) {
524 my $selected = '0';
525 next if $currently_selected_themes->{$theme};
526 push @options, { option => $theme, counter => $counter };
527 $counter++;
529 } elsif ( $data->{'type'} eq 'ClassSources' ) {
530 $params->{'type_choice'} = 1;
531 my $type = '';
532 @options = ();
533 my $sources = GetClassSources();
534 my $counter = 0;
535 foreach my $cn_source ( sort keys %$sources ) {
536 if ( $cn_source eq $data->{'value'} ) {
537 push @options, { option => $cn_source, counter => $counter, selected => 1 };
538 } else {
539 push @options, { option => $cn_source, counter => $counter };
541 $counter++;
543 } elsif ( $data->{'type'} eq 'Languages' ) {
544 my $currently_selected_languages;
545 foreach my $language ( split /\s+/, $data->{'value'} ) {
546 $currently_selected_languages->{$language} = 1;
549 # current language
550 my $lang = $params->{'lang'};
551 my $theme;
552 my $interface;
553 if ( $data->{'variable'} =~ /opac/ ) {
555 # this is the OPAC
556 $interface = 'opac';
557 $theme = C4::Context->preference('opacthemes');
558 } else {
560 # this is the staff client
561 $interface = 'intranet';
562 $theme = C4::Context->preference('template');
564 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
566 $params->{'languages_loop'} = $languages_loop;
567 $params->{'type_langselector'} = 1;
568 } else {
569 $params->{'type_free'} = 1;
570 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
573 if ( $params->{'type_choice'} || $params->{'type_free'} || $params->{'type_yesno'} ) {
574 $params->{'oneline'} = 1;
577 $params->{'preftype'} = $data->{'type'};
578 $params->{'options'} = \@options;
580 return $params;
583 my $input = new CGI;
584 my $searchfield = $input->param('searchfield') || '';
585 my $Tvalue = $input->param('Tvalue');
586 my $offset = $input->param('offset') || 0;
587 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
589 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
590 { template_name => "admin/systempreferences.tmpl",
591 query => $input,
592 type => "intranet",
593 authnotrequired => 0,
594 flagsrequired => { parameters => 1 },
595 debug => 1,
598 my $pagesize = 100;
599 my $op = $input->param('op') || '';
600 $searchfield =~ s/\,//g;
602 if ($op) {
603 $template->param(
604 script_name => $script_name,
605 $op => 1
606 ); # we show only the TMPL_VAR names $op
607 } else {
608 $template->param(
609 script_name => $script_name,
610 else => 1
611 ); # we show only the TMPL_VAR names $op
614 if ( $op eq 'update_and_reedit' ) {
615 foreach ( $input->param ) {
617 my $value = '';
618 if ( my $currentorder = $input->param('currentorder') ) {
619 my @currentorder = split /\|/, $currentorder;
620 my $orderchanged = 0;
621 foreach my $param ( $input->param ) {
622 if ( $param =~ m#up-(\d+).x# ) {
623 my $temp = $currentorder[$1];
624 $currentorder[$1] = $currentorder[ $1 - 1 ];
625 $currentorder[ $1 - 1 ] = $temp;
626 $orderchanged = 1;
627 last;
628 } elsif ( $param =~ m#down-(\d+).x# ) {
629 my $temp = $currentorder[$1];
630 $currentorder[$1] = $currentorder[ $1 + 1 ];
631 $currentorder[ $1 + 1 ] = $temp;
632 $orderchanged = 1;
633 last;
636 $value = join ' ', @currentorder;
637 if ($orderchanged) {
638 $op = 'add_form';
639 $template->param(
640 script_name => $script_name,
641 $op => 1
642 ); # we show only the TMPL_VAR names $op
643 } else {
644 $op = '';
645 $searchfield = '';
646 $template->param(
647 script_name => $script_name,
648 else => 1
649 ); # we show only the TMPL_VAR names $op
652 my $dbh = C4::Context->dbh;
653 my $query = "select * from systempreferences where variable=?";
654 my $sth = $dbh->prepare($query);
655 $sth->execute( $input->param('variable') );
656 if ( $sth->rows ) {
657 unless ( C4::Context->config('demo') ) {
658 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
659 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
660 $sth->finish;
661 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
663 } else {
664 unless ( C4::Context->config('demo') ) {
665 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
666 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
667 $sth->finish;
668 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
671 $sth->finish;
675 ################## ADD_FORM ##################################
676 # called by default. Used to create form to add or modify a record
678 if ( $op eq 'add_form' ) {
680 #---- if primkey exists, it's a modify action, so read values to modify...
681 my $data;
682 if ($searchfield) {
683 my $dbh = C4::Context->dbh;
684 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
685 $sth->execute($searchfield);
686 $data = $sth->fetchrow_hashref;
687 $sth->finish;
688 $template->param( modify => 1 );
690 # save tab to return to if user cancels edit
691 $template->param( return_tab => $tabsysprefs{$searchfield} );
694 $data->{'lang'} = $template->param('lang');
696 $template->param( GetPrefParams($data) );
698 $template->param( searchfield => $searchfield );
700 ################## ADD_VALIDATE ##################################
701 # called by add_form, used to insert/modify data in DB
702 } elsif ( $op eq 'add_validate' ) {
703 my $dbh = C4::Context->dbh;
704 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
705 $sth->execute( $input->param('variable') );
707 # to handle multiple values
708 my $value;
710 # handle multiple value strings (separated by ',')
711 my $params = $input->Vars;
712 if ( defined $params->{'value'} ) {
713 my @values = ();
714 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
715 if (@values) {
716 $value = "";
717 for my $vl (@values) {
718 $value .= "$vl,";
720 $value =~ s/,$//;
721 } else {
722 $value = $params->{'value'};
726 if ( $input->param('preftype') eq 'Upload' ) {
727 my $lgtfh = $input->upload('value');
728 $value = join '', <$lgtfh>;
729 $value = encode_base64($value);
732 if ( $sth->rows ) {
733 unless ( C4::Context->config('demo') ) {
734 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
735 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
736 $sth->finish;
737 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
739 } else {
740 unless ( C4::Context->config('demo') ) {
741 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
742 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
743 $sth->finish;
744 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
747 $sth->finish;
748 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
749 exit;
750 ################## DELETE_CONFIRM ##################################
751 # called by default form, used to confirm deletion of data in DB
752 } elsif ( $op eq 'delete_confirm' ) {
753 my $dbh = C4::Context->dbh;
754 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
755 $sth->execute($searchfield);
756 my $data = $sth->fetchrow_hashref;
757 $sth->finish;
758 $template->param(
759 searchfield => $searchfield,
760 Tvalue => $data->{'value'},
763 # END $OP eq DELETE_CONFIRM
764 ################## DELETE_CONFIRMED ##################################
765 # called by delete_confirm, used to effectively confirm deletion of data in DB
766 } elsif ( $op eq 'delete_confirmed' ) {
767 my $dbh = C4::Context->dbh;
768 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
769 $sth->execute($searchfield);
770 my $logstring = $searchfield . " | " . $Tvalue;
771 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
772 $sth->finish;
774 # END $OP eq DELETE_CONFIRMED
775 ################## DEFAULT ##################################
776 } else { # DEFAULT
777 #Adding tab management for system preferences
778 my $tab = $input->param('tab');
779 $template->param( $tab => 1 );
780 my ( $count, $results ) = StringSearch( $searchfield, $tab );
781 my @loop_data = ();
782 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
783 my $row_data = $results->[$i];
784 $row_data->{'lang'} = $template->param('lang');
785 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
786 $row_data->{edit} = "$script_name?op=add_form&amp;searchfield=" . $results->[$i]{'variable'};
787 $row_data->{delete} = "$script_name?op=delete_confirm&amp;searchfield=" . $results->[$i]{'variable'};
788 push( @loop_data, $row_data );
790 $tab = ( $tab ? $tab : "local_use" );
791 $template->param( loop => \@loop_data, $tab => 1 );
792 if ( $offset > 0 ) {
793 my $prevpage = $offset - $pagesize;
794 $template->param( "<a href=$script_name?offset=" . $prevpage . '&lt;&lt; Prev</a>' );
796 if ( $offset + $pagesize < $count ) {
797 my $nextpage = $offset + $pagesize;
798 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next &gt;&gt;</a>' );
800 $template->param( tab => $tab, );
801 } #---- END $OP eq DEFAULT
802 output_html_with_http_headers $input, $cookie, $template->output;
805 # Return an array containing all preferences defined in current Koha instance
806 # .pref files.
808 sub get_prefs_from_files {
809 my $context = C4::Context->new();
810 my $path_pref_en = $context->config('intrahtdocs') .
811 '/prog/en/modules/admin/preferences';
812 # Get all .pref file names
813 opendir ( my $fh, $path_pref_en );
814 my @pref_files = grep { /.pref/ } readdir($fh);
815 close $fh;
817 my @names = ();
818 my $append = sub {
819 my $prefs = shift;
820 for my $pref ( @$prefs ) {
821 for my $element ( @$pref ) {
822 if ( ref( $element) eq 'HASH' ) {
823 my $name = $element->{pref};
824 next unless $name;
825 push @names, $name;
826 next;
831 for my $file (@pref_files) {
832 my $pref = LoadFile( "$path_pref_en/$file" );
833 for my $tab ( keys %$pref ) {
834 my $content = $pref->{$tab};
835 if ( ref($content) eq 'ARRAY' ) {
836 $append->($content);
837 next;
839 for my $section ( keys %$content ) {
840 my $syspref = $content->{$section};
841 $append->($syspref);
845 return @names;
849 # Return an array containg all preferences defined in DB
851 sub get_prefs_from_db {
852 my $dbh = C4::Context->dbh;
853 my $sth = $dbh->prepare("SELECT variable FROM systempreferences");
854 $sth->execute;
855 my @names = ();
856 while ( (my $name) = $sth->fetchrow_array ) {
857 push @names, $name if $name;
859 return @names;
863 # Return an array containing all local preferences: those which are defined in
864 # DB and not defined in Koha .pref files.
866 sub get_local_prefs {
867 my @prefs_file = get_prefs_from_files();
868 my @prefs_db = get_prefs_from_db();
870 my %prefs_file = map { $_ => 1 } @prefs_file;
871 my @names = ();
872 foreach my $name (@prefs_db) {
873 push @names, $name unless $prefs_file{$name};
876 return @names;