Bug 6024 : Show "Run report" link after sql update as wel
[koha.git] / admin / systempreferences.pl
blob87ecac452157c31930439d5c68538914a6700607
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";
80 # Admin
81 $tabsysprefs{singleBranchMode} = "Admin";
82 $tabsysprefs{staffClientBaseURL} = "Admin";
83 $tabsysprefs{Version} = "Admin";
84 $tabsysprefs{OpacMaintenance} = "Admin";
85 $tabsysprefs{FrameworksLoaded} = "Admin";
86 $tabsysprefs{delimiter} = "Admin";
87 $tabsysprefs{IndependantBranches} = "Admin";
88 $tabsysprefs{insecure} = "Admin";
89 $tabsysprefs{KohaAdmin} = "Admin";
90 $tabsysprefs{KohaAdminEmailAddress} = "Admin";
91 $tabsysprefs{timeout} = "Admin";
92 $tabsysprefs{Intranet_includes} = "Admin";
93 $tabsysprefs{AutoLocation} = "Admin";
94 $tabsysprefs{DebugLevel} = "Admin";
95 $tabsysprefs{SessionStorage} = "Admin";
97 # This script is depricated so all of these prefs are lumped here to avoid their being displayed in the local use prefs tab
99 $tabsysprefs{noItemTypeImages} = "Admin";
100 $tabsysprefs{OPACBaseURL} = "Admin";
101 $tabsysprefs{AnonymousPatron} = "Admin";
102 $tabsysprefs{casAuthentication} = "Admin";
103 $tabsysprefs{casLogout} = "Admin";
104 $tabsysprefs{casServerUrl} = "Admin";
105 $tabsysprefs{Disable_Dictionary} = "Admin";
106 $tabsysprefs{EnableOpacSearchHistory} = "Admin";
107 $tabsysprefs{Intranetbookbag} = "Admin";
108 $tabsysprefs{maxitemsinSearchResults} = "Admin";
109 $tabsysprefs{noOPACUserLogin} = "Admin";
110 $tabsysprefs{'OAI-PMH:ConfFile'} = "Admin";
111 $tabsysprefs{OpacAddMastheadLibraryPulldown} = "Admin";
112 $tabsysprefs{opaclargeimage} = "Admin";
113 $tabsysprefs{OPACXSLTDetailsDisplay} = "Admin";
114 $tabsysprefs{OPACXSLTResultsDisplay} = "Admin";
115 $tabsysprefs{PDFFontType} = "Admin";
116 $tabsysprefs{PrintNoticesMaxLines} = "Admin";
117 $tabsysprefs{ReservesControlBranch} = "Admin";
118 $tabsysprefs{ResultsDisplay} = "Admin";
119 $tabsysprefs{NoReturnSetLost} = "Admin";
120 $tabsysprefs{SearchURL} = "Admin";
121 $tabsysprefs{ShowPictures} = "Admin";
122 $tabsysprefs{soundon} = "Admin";
123 $tabsysprefs{SpineLabelShowPrintOnBibDetails} = "Admin";
124 $tabsysprefs{WebBasedSelfCheckHeader} = "Admin";
125 $tabsysprefs{WebBasedSelfCheckTimeout} = "Admin";
127 # Authorities
128 $tabsysprefs{authoritysep} = "Authorities";
129 $tabsysprefs{AuthDisplayHierarchy} = "Authorities";
130 $tabsysprefs{dontmerge} = "Authorities";
131 $tabsysprefs{BiblioAddsAuthorities} = "Authorities";
133 # Cataloguing
134 $tabsysprefs{advancedMARCeditor} = "Cataloging";
135 $tabsysprefs{autoBarcode} = "Cataloging";
136 $tabsysprefs{hide_marc} = "Cataloging";
137 $tabsysprefs{IntranetBiblioDefaultView} = "Cataloging";
138 $tabsysprefs{ISBD} = "Cataloging";
139 $tabsysprefs{itemcallnumber} = "Cataloging";
140 $tabsysprefs{LabelMARCView} = "Cataloging";
141 $tabsysprefs{marcflavour} = "Cataloging";
142 $tabsysprefs{MARCOrgCode} = "Cataloging";
143 $tabsysprefs{z3950AuthorAuthFields} = "Cataloging";
144 $tabsysprefs{z3950NormalizeAuthor} = "Cataloging";
145 $tabsysprefs{Stemming} = "Cataloging";
146 $tabsysprefs{WeightFields} = "Cataloging";
147 $tabsysprefs{NoZebra} = "Cataloging";
148 $tabsysprefs{NoZebraIndexes} = "Cataloging";
149 $tabsysprefs{ReceiveBackIssues} = "Cataloging";
150 $tabsysprefs{DefaultClassificationSource} = "Cataloging";
151 $tabsysprefs{RoutingSerials} = "Cataloging";
152 $tabsysprefs{'item-level_itypes'} = "Cataloging";
153 $tabsysprefs{OpacSuppression} = "Cataloging";
154 $tabsysprefs{SpineLabelFormat} = "Cataloging";
155 $tabsysprefs{SpineLabelAutoPrint} = "Cataloging";
157 # Circulation
158 $tabsysprefs{maxoutstanding} = "Circulation";
159 $tabsysprefs{maxreserves} = "Circulation";
160 $tabsysprefs{noissuescharge} = "Circulation";
161 $tabsysprefs{IssuingInProcess} = "Circulation";
162 $tabsysprefs{patronimages} = "Circulation";
163 $tabsysprefs{printcirculationslips} = "Circulation";
164 $tabsysprefs{ReturnBeforeExpiry} = "Circulation";
165 $tabsysprefs{SpecifyDueDate} = "Circulation";
166 $tabsysprefs{AutomaticItemReturn} = "Circulation";
167 $tabsysprefs{ReservesMaxPickUpDelay} = "Circulation";
168 $tabsysprefs{TransfersMaxDaysWarning} = "Circulation";
169 $tabsysprefs{useDaysMode} = "Circulation";
170 $tabsysprefs{ReservesNeedReturns} = "Circulation";
171 $tabsysprefs{CircAutocompl} = "Circulation";
172 $tabsysprefs{AllowRenewalLimitOverride} = "Circulation";
173 $tabsysprefs{canreservefromotherbranches} = "Circulation";
174 $tabsysprefs{finesMode} = "Circulation";
175 $tabsysprefs{numReturnedItemsToShow} = "Circulation";
176 $tabsysprefs{emailLibrarianWhenHoldIsPlaced} = "Circulation";
177 $tabsysprefs{itemBarcodeInputFilter} = "Circulation";
178 $tabsysprefs{WebBasedSelfCheck} = "Circulation";
179 $tabsysprefs{ShowPatronImageInWebBasedSelfCheck} = "Circulation";
180 $tabsysprefs{CircControl} = "Circulation";
181 $tabsysprefs{finesCalendar} = "Circulation";
182 $tabsysprefs{previousIssuesDefaultSortOrder} = "Circulation";
183 $tabsysprefs{todaysIssuesDefaultSortOrder} = "Circulation";
184 $tabsysprefs{HomeOrHoldingBranch} = "Circulation";
185 $tabsysprefs{HomeOrHoldingBranchReturn} = "Circulation";
186 $tabsysprefs{RandomizeHoldsQueueWeight} = "Circulation";
187 $tabsysprefs{StaticHoldsQueueWeight} = "Circulation";
188 $tabsysprefs{AllowOnShelfHolds} = "Circulation";
189 $tabsysprefs{AllowHoldsOnDamagedItems} = "Circulation";
190 $tabsysprefs{UseBranchTransferLimits} = "Circulation";
191 $tabsysprefs{AllowHoldPolicyOverride} = "Circulation";
192 $tabsysprefs{BranchTransferLimitsType} = "Circulation";
193 $tabsysprefs{AllowNotForLoanOverride} = "Circulation";
194 $tabsysprefs{RenewalPeriodBase} = "Circulation";
195 $tabsysprefs{FilterBeforeOverdueReport} = "Circulation";
196 $tabsysprefs{AllowHoldDateInFuture} = "Circulation";
197 $tabsysprefs{OPACFineNoRenewals} = "Circulation";
198 $tabsysprefs{InProcessingToShelvingCart} = "Circulation";
199 $tabsysprefs{NewItemsDefaultLocation} = "Circulation";
200 $tabsysprefs{ReturnToShelvingCart} = "Circulation";
201 $tabsysprefs{DisplayClearScreenButton} = "Circulation";
202 $tabsysprefs{AllowAllMessageDeletion} = "Circulation";
203 $tabsysprefs{OverdueNoticeBcc} = "Circulation";
204 $tabsysprefs{OverduesBlockCirc} = "Circulation";
207 # Staff Client
208 $tabsysprefs{template} = "StaffClient";
209 $tabsysprefs{intranetstylesheet} = "StaffClient";
210 $tabsysprefs{IntranetNav} = "StaffClient";
211 $tabsysprefs{intranetcolorstylesheet} = "StaffClient";
212 $tabsysprefs{intranetuserjs} = "StaffClient";
213 $tabsysprefs{yuipath} = "StaffClient";
214 $tabsysprefs{IntranetmainUserblock} = "StaffClient";
215 $tabsysprefs{viewMARC} = "StaffClient";
216 $tabsysprefs{viewLabeledMARC} = "StaffClient";
217 $tabsysprefs{viewISBD} = "StaffClient";
219 # Patrons
220 $tabsysprefs{autoMemberNum} = "Patrons";
221 $tabsysprefs{checkdigit} = "Patrons";
222 $tabsysprefs{intranetreadinghistory} = "Patrons";
223 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
224 $tabsysprefs{memberofinstitution} = "Patrons";
225 $tabsysprefs{BorrowerMandatoryField} = "Patrons";
226 $tabsysprefs{borrowerRelationship} = "Patrons";
227 $tabsysprefs{BorrowersTitles} = "Patrons";
228 $tabsysprefs{patronimages} = "Patrons";
229 $tabsysprefs{minPasswordLength} = "Patrons";
230 $tabsysprefs{uppercasesurnames} = "Patrons";
231 $tabsysprefs{MaxFine} = "Patrons";
232 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
233 $tabsysprefs{AddPatronLists} = "Patrons";
234 $tabsysprefs{PatronsPerPage} = "Patrons";
235 $tabsysprefs{ExtendedPatronAttributes} = "Patrons";
236 $tabsysprefs{AutoEmailOpacUser} = "Patrons";
237 $tabsysprefs{AutoEmailPrimaryAddress} = "Patrons";
238 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
239 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
240 $tabsysprefs{HidePatronName} = "Patrons";
243 # I18N/L10N
244 $tabsysprefs{dateformat} = "I18N/L10N";
245 $tabsysprefs{opaclanguages} = "I18N/L10N";
246 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
247 $tabsysprefs{language} = "I18N/L10N";
249 # Searching
250 $tabsysprefs{defaultSortField} = "Searching";
251 $tabsysprefs{defaultSortOrder} = "Searching";
252 $tabsysprefs{numSearchResults} = "Searching";
253 $tabsysprefs{OPACdefaultSortField} = "Searching";
254 $tabsysprefs{OPACdefaultSortOrder} = "Searching";
255 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
256 $tabsysprefs{OPACnumSearchResults} = "Searching";
257 $tabsysprefs{QueryFuzzy} = "Searching";
258 $tabsysprefs{QueryStemming} = "Searching";
259 $tabsysprefs{QueryWeightFields} = "Searching";
260 $tabsysprefs{expandedSearchOption} = "Searching";
261 $tabsysprefs{QueryAutoTruncate} = "Searching";
262 $tabsysprefs{QueryRemoveStopwords} = "Searching";
263 $tabsysprefs{AdvancedSearchTypes} = "Searching";
264 $tabsysprefs{DisplayMultiPlaceHold} = "Searching";
266 # EnhancedContent
267 $tabsysprefs{AmazonEnabled} = "EnhancedContent";
268 $tabsysprefs{OPACAmazonEnabled} = "EnhancedContent";
269 $tabsysprefs{AmazonCoverImages} = "EnhancedContent";
270 $tabsysprefs{OPACAmazonCoverImages} = "EnhancedContent";
271 $tabsysprefs{AWSAccessKeyID} = "EnhancedContent";
272 $tabsysprefs{AWSPrivateKey} = "EnhancedContent";
273 $tabsysprefs{AmazonLocale} = "EnhancedContent";
274 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
275 $tabsysprefs{AmazonSimilarItems} = "EnhancedContent";
276 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
277 $tabsysprefs{AmazonReviews} = "EnhancedContent";
278 $tabsysprefs{OPACAmazonReviews} = "EnhancedContent";
280 # Babelthèque
281 $tabsysprefs{Babeltheque} = "EnhancedContent";
283 # Baker & Taylor
284 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
285 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
286 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
287 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
289 # Library Thing for Libraries
290 $tabsysprefs{LibraryThingForLibrariesID} = "EnhancedContent";
291 $tabsysprefs{LibraryThingForLibrariesEnabled} = "EnhancedContent";
292 $tabsysprefs{LibraryThingForLibrariesTabbedView} = "EnhancedContent";
294 # Syndetics
295 $tabsysprefs{SyndeticsClientCode} = 'EnhancedContent';
296 $tabsysprefs{SyndeticsEnabled} = 'EnhancedContent';
297 $tabsysprefs{SyndeticsCoverImages} = 'EnhancedContent';
298 $tabsysprefs{SyndeticsTOC} = 'EnhancedContent';
299 $tabsysprefs{SyndeticsSummary} = 'EnhancedContent';
300 $tabsysprefs{SyndeticsEditions} = 'EnhancedContent';
301 $tabsysprefs{SyndeticsExcerpt} = 'EnhancedContent';
302 $tabsysprefs{SyndeticsReviews} = 'EnhancedContent';
303 $tabsysprefs{SyndeticsAuthorNotes} = 'EnhancedContent';
304 $tabsysprefs{SyndeticsAwards} = 'EnhancedContent';
305 $tabsysprefs{SyndeticsSeries} = 'EnhancedContent';
306 $tabsysprefs{SyndeticsCoverImageSize} = 'EnhancedContent';
309 # FRBR
310 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
311 $tabsysprefs{XISBN} = "EnhancedContent";
312 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
313 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
314 $tabsysprefs{ThingISBN} = "EnhancedContent";
315 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
317 # Tags
318 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
319 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
320 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
321 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
322 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
323 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
324 $tabsysprefs{TagsModeration} = 'EnhancedContent';
325 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
326 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
328 # OPAC
329 $tabsysprefs{BiblioDefaultView} = "OPAC";
330 $tabsysprefs{LibraryName} = "OPAC";
331 $tabsysprefs{opaccolorstylesheet} = "OPAC";
332 $tabsysprefs{opaccredits} = "OPAC";
333 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
334 $tabsysprefs{OpacNav} = "OPAC";
335 $tabsysprefs{opacsmallimage} = "OPAC";
336 $tabsysprefs{opacstylesheet} = "OPAC";
337 $tabsysprefs{opacthemes} = "OPAC";
338 $tabsysprefs{opacuserjs} = "OPAC";
339 $tabsysprefs{opacheader} = "OPAC";
340 $tabsysprefs{hideBiblioNumber} = "OPAC";
341 $tabsysprefs{OpacMainUserBlock} = "OPAC";
342 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
343 $tabsysprefs{OPACUserCSS} = "OPAC";
344 $tabsysprefs{OPACHighlightedWords} = "OPAC";
345 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
346 $tabsysprefs{URLLinkText} = "OPAC";
347 $tabsysprefs{OPACSearchForTitleIn} = "OPAC";
348 $tabsysprefs{OPACShelfBrowser} = "OPAC";
349 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
350 $tabsysprefs{OPACAllowHoldDateInFuture} = "OPAC";
351 $tabsysprefs{OPACPatronDetails} = "OPAC";
352 $tabsysprefs{OPACFinesTab} = "OPAC";
353 $tabsysprefs{DisplayOPACiconsXSLT} = "OPAC";
354 $tabsysprefs{AutoSelfCheckAllowed} = "OPAC";
355 $tabsysprefs{AutoSelfCheckID} = "OPAC";
356 $tabsysprefs{AutoSelfCheckPass} = "OPAC";
358 # OPAC
359 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
360 $tabsysprefs{hidelostitems} = "OPAC";
361 $tabsysprefs{opacbookbag} = "OPAC";
362 $tabsysprefs{OpacPasswordChange} = "OPAC";
363 $tabsysprefs{opacreadinghistory} = "OPAC";
364 $tabsysprefs{virtualshelves} = "OPAC";
365 $tabsysprefs{RequestOnOpac} = "OPAC";
366 $tabsysprefs{reviewson} = "OPAC";
367 $tabsysprefs{OpacTopissues} = "OPAC";
368 $tabsysprefs{OpacAuthorities} = "OPAC";
369 $tabsysprefs{OpacCloud} = "OPAC";
370 $tabsysprefs{opacuserlogin} = "OPAC";
371 $tabsysprefs{AnonSuggestions} = "OPAC";
372 $tabsysprefs{suggestion} = "OPAC";
373 $tabsysprefs{OpacTopissue} = "OPAC";
374 $tabsysprefs{OpacBrowser} = "OPAC";
375 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
376 $tabsysprefs{OPACItemHolds} = "OPAC";
377 $tabsysprefs{OPACGroupResults} = "OPAC";
378 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
379 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
380 $tabsysprefs{OPACShowCheckoutName} = "OPAC";
381 $tabsysprefs{AllowPurchaseSuggestionBranchChoice} = "OPAC";
383 # Serials
384 $tabsysprefs{RoutingListAddReserves} = "Serials";
385 $tabsysprefs{OPACSerialIssueDisplayCount} = "Serials";
386 $tabsysprefs{StaffSerialIssueDisplayCount} = "Serials";
387 $tabsysprefs{RenewSerialAddsSuggestion} = "Serials";
388 $tabsysprefs{SubscriptionHistory} = "Serials";
390 # LOGFeatures
391 $tabsysprefs{CataloguingLog} = "Logs";
392 $tabsysprefs{BorrowersLog} = "Logs";
393 $tabsysprefs{SubscriptionLog} = "Logs";
394 $tabsysprefs{IssueLog} = "Logs";
395 $tabsysprefs{ReturnLog} = "Logs";
396 $tabsysprefs{LetterLog} = "Logs";
397 $tabsysprefs{FinesLog} = "Logs";
399 # OAI-PMH variables
400 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
401 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
402 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
404 # ILS-DI variables
405 $tabsysprefs{'ILS-DI'} = "ILS-DI";
406 $tabsysprefs{'ILS-DI:AuthorizedIPs'} = "Admin";
408 # Creator variables
410 $tabsysprefs{'ImageLimit'} = "Creators";
412 sub StringSearch {
413 my ( $searchstring, $type ) = @_;
414 my $dbh = C4::Context->dbh;
415 $searchstring =~ s/\'/\\\'/g;
416 my @data = split( ' ', $searchstring );
417 my $count = @data;
418 my @results;
419 my $cnt = 0;
420 my $sth;
422 # used for doing a plain-old sys-pref search
423 if ( $type && $type ne 'all' ) {
424 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
425 if ( $tabsysprefs{$syspref} eq $type ) {
426 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
427 $sth->execute($syspref);
428 while ( my $data = $sth->fetchrow_hashref ) {
429 $data->{shortvalue} = $data->{value};
430 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
431 push( @results, $data );
432 $cnt++;
434 $sth->finish;
437 } else {
438 my $sth;
440 if ( $type and $type eq 'all' ) {
441 $sth = $dbh->prepare( "
442 SELECT *
443 FROM systempreferences
444 WHERE variable LIKE ? OR explanation LIKE ?
445 ORDER BY VARIABLE" );
446 $sth->execute( "%$searchstring%", "%$searchstring%" );
447 } else {
448 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable in (";
449 my $first = 1;
450 for my $name ( get_local_prefs() ) {
451 $strsth .= ',' unless $first;
452 $strsth .= "'$name'";
453 $first = 0;
455 $strsth .= ") order by variable";
456 $sth = $dbh->prepare($strsth);
457 $sth->execute();
460 while ( my $data = $sth->fetchrow_hashref ) {
461 $data->{shortvalue} = $data->{value};
462 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
463 push( @results, $data );
464 $cnt++;
467 $sth->finish;
469 return ( $cnt, \@results );
472 sub GetPrefParams {
473 my $data = shift;
474 my $params = $data;
475 my @options;
477 if ( defined $data->{'options'} ) {
478 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
479 my $selected = '0';
480 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
481 push @options, { option => $option, selected => $selected };
485 $params->{'prefoptions'} = $data->{'options'};
487 if ( not defined( $data->{'type'} ) ) {
488 $params->{'type_free'} = 1;
489 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
490 } elsif ( $data->{'type'} eq 'Upload' ) {
491 $params->{'type_upload'} = 1;
492 } elsif ( $data->{'type'} eq 'Choice' ) {
493 $params->{'type_choice'} = 1;
494 } elsif ( $data->{'type'} eq 'YesNo' ) {
495 $params->{'type_yesno'} = 1;
496 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
497 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
498 $params->{'value_yes'} = 1;
499 } else {
500 $params->{'value_no'} = 1;
502 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
503 $params->{'type_free'} = 1;
504 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
505 } elsif ( $data->{'type'} eq 'Textarea' ) {
506 $params->{'type_textarea'} = 1;
507 $data->{options} =~ /(.*)\|(.*)/;
508 $params->{'cols'} = $1;
509 $params->{'rows'} = $2;
510 } elsif ( $data->{'type'} eq 'Themes' ) {
511 $params->{'type_choice'} = 1;
512 my $type = '';
513 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
514 @options = ();
515 my $currently_selected_themes;
516 my $counter = 0;
517 foreach my $theme ( split /\s+/, $data->{'value'} ) {
518 push @options, { option => $theme, counter => $counter };
519 $currently_selected_themes->{$theme} = 1;
520 $counter++;
522 foreach my $theme ( getallthemes($type) ) {
523 my $selected = '0';
524 next if $currently_selected_themes->{$theme};
525 push @options, { option => $theme, counter => $counter };
526 $counter++;
528 } elsif ( $data->{'type'} eq 'ClassSources' ) {
529 $params->{'type_choice'} = 1;
530 my $type = '';
531 @options = ();
532 my $sources = GetClassSources();
533 my $counter = 0;
534 foreach my $cn_source ( sort keys %$sources ) {
535 if ( $cn_source eq $data->{'value'} ) {
536 push @options, { option => $cn_source, counter => $counter, selected => 1 };
537 } else {
538 push @options, { option => $cn_source, counter => $counter };
540 $counter++;
542 } elsif ( $data->{'type'} eq 'Languages' ) {
543 my $currently_selected_languages;
544 foreach my $language ( split /\s+/, $data->{'value'} ) {
545 $currently_selected_languages->{$language} = 1;
548 # current language
549 my $lang = $params->{'lang'};
550 my $theme;
551 my $interface;
552 if ( $data->{'variable'} =~ /opac/ ) {
554 # this is the OPAC
555 $interface = 'opac';
556 $theme = C4::Context->preference('opacthemes');
557 } else {
559 # this is the staff client
560 $interface = 'intranet';
561 $theme = C4::Context->preference('template');
563 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
565 $params->{'languages_loop'} = $languages_loop;
566 $params->{'type_langselector'} = 1;
567 } else {
568 $params->{'type_free'} = 1;
569 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
572 if ( $params->{'type_choice'} || $params->{'type_free'} || $params->{'type_yesno'} ) {
573 $params->{'oneline'} = 1;
576 $params->{'preftype'} = $data->{'type'};
577 $params->{'options'} = \@options;
579 return $params;
582 my $input = new CGI;
583 my $searchfield = $input->param('searchfield') || '';
584 my $Tvalue = $input->param('Tvalue');
585 my $offset = $input->param('offset') || 0;
586 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
588 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
589 { template_name => "admin/systempreferences.tmpl",
590 query => $input,
591 type => "intranet",
592 authnotrequired => 0,
593 flagsrequired => { parameters => 1 },
594 debug => 1,
597 my $pagesize = 100;
598 my $op = $input->param('op') || '';
599 $searchfield =~ s/\,//g;
601 if ($op) {
602 $template->param(
603 script_name => $script_name,
604 $op => 1
605 ); # we show only the TMPL_VAR names $op
606 } else {
607 $template->param(
608 script_name => $script_name,
609 else => 1
610 ); # we show only the TMPL_VAR names $op
613 if ( $op eq 'update_and_reedit' ) {
614 foreach ( $input->param ) {
616 my $value = '';
617 if ( my $currentorder = $input->param('currentorder') ) {
618 my @currentorder = split /\|/, $currentorder;
619 my $orderchanged = 0;
620 foreach my $param ( $input->param ) {
621 if ( $param =~ m#up-(\d+).x# ) {
622 my $temp = $currentorder[$1];
623 $currentorder[$1] = $currentorder[ $1 - 1 ];
624 $currentorder[ $1 - 1 ] = $temp;
625 $orderchanged = 1;
626 last;
627 } elsif ( $param =~ m#down-(\d+).x# ) {
628 my $temp = $currentorder[$1];
629 $currentorder[$1] = $currentorder[ $1 + 1 ];
630 $currentorder[ $1 + 1 ] = $temp;
631 $orderchanged = 1;
632 last;
635 $value = join ' ', @currentorder;
636 if ($orderchanged) {
637 $op = 'add_form';
638 $template->param(
639 script_name => $script_name,
640 $op => 1
641 ); # we show only the TMPL_VAR names $op
642 } else {
643 $op = '';
644 $searchfield = '';
645 $template->param(
646 script_name => $script_name,
647 else => 1
648 ); # we show only the TMPL_VAR names $op
651 my $dbh = C4::Context->dbh;
652 my $query = "select * from systempreferences where variable=?";
653 my $sth = $dbh->prepare($query);
654 $sth->execute( $input->param('variable') );
655 if ( $sth->rows ) {
656 unless ( C4::Context->config('demo') ) {
657 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
658 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
659 $sth->finish;
660 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
662 } else {
663 unless ( C4::Context->config('demo') ) {
664 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
665 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
666 $sth->finish;
667 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
670 $sth->finish;
674 ################## ADD_FORM ##################################
675 # called by default. Used to create form to add or modify a record
677 if ( $op eq 'add_form' ) {
679 #---- if primkey exists, it's a modify action, so read values to modify...
680 my $data;
681 if ($searchfield) {
682 my $dbh = C4::Context->dbh;
683 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
684 $sth->execute($searchfield);
685 $data = $sth->fetchrow_hashref;
686 $sth->finish;
687 $template->param( modify => 1 );
689 # save tab to return to if user cancels edit
690 $template->param( return_tab => $tabsysprefs{$searchfield} );
693 $data->{'lang'} = $template->param('lang');
695 $template->param( GetPrefParams($data) );
697 $template->param( searchfield => $searchfield );
699 ################## ADD_VALIDATE ##################################
700 # called by add_form, used to insert/modify data in DB
701 } elsif ( $op eq 'add_validate' ) {
702 my $dbh = C4::Context->dbh;
703 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
704 $sth->execute( $input->param('variable') );
706 # to handle multiple values
707 my $value;
709 # handle multiple value strings (separated by ',')
710 my $params = $input->Vars;
711 if ( defined $params->{'value'} ) {
712 my @values = ();
713 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
714 if (@values) {
715 $value = "";
716 for my $vl (@values) {
717 $value .= "$vl,";
719 $value =~ s/,$//;
720 } else {
721 $value = $params->{'value'};
725 if ( $input->param('preftype') eq 'Upload' ) {
726 my $lgtfh = $input->upload('value');
727 $value = join '', <$lgtfh>;
728 $value = encode_base64($value);
731 if ( $sth->rows ) {
732 unless ( C4::Context->config('demo') ) {
733 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
734 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
735 $sth->finish;
736 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
738 } else {
739 unless ( C4::Context->config('demo') ) {
740 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
741 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
742 $sth->finish;
743 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
746 $sth->finish;
747 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
748 exit;
749 ################## DELETE_CONFIRM ##################################
750 # called by default form, used to confirm deletion of data in DB
751 } elsif ( $op eq 'delete_confirm' ) {
752 my $dbh = C4::Context->dbh;
753 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
754 $sth->execute($searchfield);
755 my $data = $sth->fetchrow_hashref;
756 $sth->finish;
757 $template->param(
758 searchfield => $searchfield,
759 Tvalue => $data->{'value'},
762 # END $OP eq DELETE_CONFIRM
763 ################## DELETE_CONFIRMED ##################################
764 # called by delete_confirm, used to effectively confirm deletion of data in DB
765 } elsif ( $op eq 'delete_confirmed' ) {
766 my $dbh = C4::Context->dbh;
767 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
768 $sth->execute($searchfield);
769 my $logstring = $searchfield . " | " . $Tvalue;
770 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
771 $sth->finish;
773 # END $OP eq DELETE_CONFIRMED
774 ################## DEFAULT ##################################
775 } else { # DEFAULT
776 #Adding tab management for system preferences
777 my $tab = $input->param('tab');
778 $template->param( $tab => 1 );
779 my ( $count, $results ) = StringSearch( $searchfield, $tab );
780 my @loop_data = ();
781 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
782 my $row_data = $results->[$i];
783 $row_data->{'lang'} = $template->param('lang');
784 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
785 $row_data->{edit} = "$script_name?op=add_form&amp;searchfield=" . $results->[$i]{'variable'};
786 $row_data->{delete} = "$script_name?op=delete_confirm&amp;searchfield=" . $results->[$i]{'variable'};
787 push( @loop_data, $row_data );
789 $tab = ( $tab ? $tab : "local_use" );
790 $template->param( loop => \@loop_data, $tab => 1 );
791 if ( $offset > 0 ) {
792 my $prevpage = $offset - $pagesize;
793 $template->param( "<a href=$script_name?offset=" . $prevpage . '&lt;&lt; Prev</a>' );
795 if ( $offset + $pagesize < $count ) {
796 my $nextpage = $offset + $pagesize;
797 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next &gt;&gt;</a>' );
799 $template->param( tab => $tab, );
800 } #---- END $OP eq DEFAULT
801 output_html_with_http_headers $input, $cookie, $template->output;
804 # Return an array containing all preferences defined in current Koha instance
805 # .pref files.
807 sub get_prefs_from_files {
808 my $context = C4::Context->new();
809 my $path_pref_en = $context->config('intrahtdocs') .
810 '/prog/en/modules/admin/preferences';
811 # Get all .pref file names
812 opendir ( my $fh, $path_pref_en );
813 my @pref_files = grep { /.pref/ } readdir($fh);
814 close $fh;
816 my @names = ();
817 my $append = sub {
818 my $prefs = shift;
819 for my $pref ( @$prefs ) {
820 for my $element ( @$pref ) {
821 if ( ref( $element) eq 'HASH' ) {
822 my $name = $element->{pref};
823 next unless $name;
824 push @names, $name;
825 next;
830 for my $file (@pref_files) {
831 my $pref = LoadFile( "$path_pref_en/$file" );
832 for my $tab ( keys %$pref ) {
833 my $content = $pref->{$tab};
834 if ( ref($content) eq 'ARRAY' ) {
835 $append->($content);
836 next;
838 for my $section ( keys %$content ) {
839 my $syspref = $content->{$section};
840 $append->($syspref);
844 return @names;
848 # Return an array containg all preferences defined in DB
850 sub get_prefs_from_db {
851 my $dbh = C4::Context->dbh;
852 my $sth = $dbh->prepare("SELECT variable FROM systempreferences");
853 $sth->execute;
854 my @names = ();
855 while ( (my $name) = $sth->fetchrow_array ) {
856 push @names, $name if $name;
858 return @names;
862 # Return an array containing all local preferences: those which are defined in
863 # DB and not defined in Koha .pref files.
865 sub get_local_prefs {
866 my @prefs_file = get_prefs_from_files();
867 my @prefs_db = get_prefs_from_db();
869 my %prefs_file = map { $_ => 1 } @prefs_file;
870 my @names = ();
871 foreach my $name (@prefs_db) {
872 push @names, $name unless $prefs_file{$name};
875 return @names;