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{acquisitions}="Acquisitions";
74 $tabsysprefs{gist}="Acquisitions";
75 $tabsysprefs{emailPurchaseSuggestions}="Acquisitions";
76 $tabsysprefs{RenewSerialAddsSuggestion}="Acquisitions";
77 $tabsysprefs{AcqCreateItem}="Acquisitions";
78 $tabsysprefs{OrderPdfFormat}="Acquisitions";
79 $tabsysprefs{OrderPdfTemplate}="Acquisitions";
80 $tabsysprefs{CurrencyFormat}="Acquisitions";
83 $tabsysprefs{singleBranchMode} = "Admin";
84 $tabsysprefs{staffClientBaseURL} = "Admin";
85 $tabsysprefs{Version} = "Admin";
86 $tabsysprefs{OpacMaintenance} = "Admin";
87 $tabsysprefs{FrameworksLoaded} = "Admin";
88 $tabsysprefs{libraryAddress} = "Admin";
89 $tabsysprefs{delimiter} = "Admin";
90 $tabsysprefs{IndependantBranches} = "Admin";
91 $tabsysprefs{insecure} = "Admin";
92 $tabsysprefs{KohaAdmin} = "Admin";
93 $tabsysprefs{KohaAdminEmailAddress} = "Admin";
94 $tabsysprefs{MIME} = "Admin";
95 $tabsysprefs{timeout} = "Admin";
96 $tabsysprefs{Intranet_includes} = "Admin";
97 $tabsysprefs{AutoLocation} = "Admin";
98 $tabsysprefs{DebugLevel} = "Admin";
99 $tabsysprefs{SessionStorage} = "Admin";
101 # This script is depricated so all of these prefs are lumped here to avoid their being displayed in the local use prefs tab
103 $tabsysprefs{noItemTypeImages} = "Admin";
104 $tabsysprefs{OPACBaseURL} = "Admin";
105 $tabsysprefs{AnonymousPatron} = "Admin";
106 $tabsysprefs{casAuthentication} = "Admin";
107 $tabsysprefs{casLogout} = "Admin";
108 $tabsysprefs{casServerUrl} = "Admin";
109 $tabsysprefs{Disable_Dictionary} = "Admin";
110 $tabsysprefs{EnableOpacSearchHistory} = "Admin";
111 $tabsysprefs{'ILS-DI:AuthorizedIPs'} = "Admin";
112 $tabsysprefs{Intranetbookbag} = "Admin";
113 $tabsysprefs{maxitemsinSearchResults} = "Admin";
114 $tabsysprefs{noOPACUserLogin} = "Admin";
115 $tabsysprefs{'OAI-PMH:ConfFile'} = "Admin";
116 $tabsysprefs{OpacAddMastheadLibraryPulldown} = "Admin";
117 $tabsysprefs{opaclargeimage} = "Admin";
118 $tabsysprefs{OpacPrivacy} = "Admin";
119 $tabsysprefs{OPACXSLTDetailsDisplay} = "Admin";
120 $tabsysprefs{OPACXSLTResultsDisplay} = "Admin";
121 $tabsysprefs{PDFFontType} = "Admin";
122 $tabsysprefs{PINESISBN} = "Admin";
123 $tabsysprefs{PrintNoticesMaxLines} = "Admin";
124 $tabsysprefs{ReservesControlBranch} = "Admin";
125 $tabsysprefs{ResultsDisplay} = "Admin";
126 $tabsysprefs{NoReturnSetLost} = "Admin";
127 $tabsysprefs{SearchURL} = "Admin";
128 $tabsysprefs{ShowPictures} = "Admin";
129 $tabsysprefs{soundon} = "Admin";
130 $tabsysprefs{SpineLabelShowPrintOnBibDetails} = "Admin";
131 $tabsysprefs{WebBasedSelfCheckHeader} = "Admin";
132 $tabsysprefs{WebBasedSelfCheckTimeout} = "Admin";
135 $tabsysprefs{authoritysep} = "Authorities";
136 $tabsysprefs{AuthDisplayHierarchy} = "Authorities";
137 $tabsysprefs{dontmerge} = "Authorities";
138 $tabsysprefs{BiblioAddsAuthorities} = "Authorities";
141 $tabsysprefs{advancedMARCeditor} = "Cataloging";
142 $tabsysprefs{autoBarcode} = "Cataloging";
143 $tabsysprefs{hide_marc} = "Cataloging";
144 $tabsysprefs{IntranetBiblioDefaultView} = "Cataloging";
145 $tabsysprefs{ISBD} = "Cataloging";
146 $tabsysprefs{itemcallnumber} = "Cataloging";
147 $tabsysprefs{LabelMARCView} = "Cataloging";
148 $tabsysprefs{marc} = "Cataloging";
149 $tabsysprefs{marcflavour} = "Cataloging";
150 $tabsysprefs{MARCOrgCode} = "Cataloging";
151 $tabsysprefs{z3950AuthorAuthFields} = "Cataloging";
152 $tabsysprefs{z3950NormalizeAuthor} = "Cataloging";
153 $tabsysprefs{Stemming} = "Cataloging";
154 $tabsysprefs{WeightFields} = "Cataloging";
155 $tabsysprefs{NoZebra} = "Cataloging";
156 $tabsysprefs{NoZebraIndexes} = "Cataloging";
157 $tabsysprefs{ReceiveBackIssues} = "Cataloging";
158 $tabsysprefs{DefaultClassificationSource} = "Cataloging";
159 $tabsysprefs{RoutingSerials} = "Cataloging";
160 $tabsysprefs{'item-level_itypes'} = "Cataloging";
161 $tabsysprefs{OpacSuppression} = "Cataloging";
162 $tabsysprefs{SpineLabelFormat} = "Cataloging";
163 $tabsysprefs{SpineLabelAutoPrint} = "Cataloging";
166 $tabsysprefs{maxoutstanding} = "Circulation";
167 $tabsysprefs{maxreserves} = "Circulation";
168 $tabsysprefs{noissuescharge} = "Circulation";
169 $tabsysprefs{IssuingInProcess} = "Circulation";
170 $tabsysprefs{patronimages} = "Circulation";
171 $tabsysprefs{printcirculationslips} = "Circulation";
172 $tabsysprefs{ReturnBeforeExpiry} = "Circulation";
173 $tabsysprefs{ceilingDueDate} = "Circulation";
174 $tabsysprefs{SpecifyDueDate} = "Circulation";
175 $tabsysprefs{AutomaticItemReturn} = "Circulation";
176 $tabsysprefs{ReservesMaxPickUpDelay} = "Circulation";
177 $tabsysprefs{TransfersMaxDaysWarning} = "Circulation";
178 $tabsysprefs{useDaysMode} = "Circulation";
179 $tabsysprefs{ReservesNeedReturns} = "Circulation";
180 $tabsysprefs{CircAutocompl} = "Circulation";
181 $tabsysprefs{AllowRenewalLimitOverride} = "Circulation";
182 $tabsysprefs{canreservefromotherbranches} = "Circulation";
183 $tabsysprefs{finesMode} = "Circulation";
184 $tabsysprefs{numReturnedItemsToShow} = "Circulation";
185 $tabsysprefs{emailLibrarianWhenHoldIsPlaced} = "Circulation";
186 $tabsysprefs{globalDueDate} = "Circulation";
187 $tabsysprefs{holdCancelLength} = "Circulation";
188 $tabsysprefs{itemBarcodeInputFilter} = "Circulation";
189 $tabsysprefs{WebBasedSelfCheck} = "Circulation";
190 $tabsysprefs{ShowPatronImageInWebBasedSelfCheck} = "Circulation";
191 $tabsysprefs{CircControl} = "Circulation";
192 $tabsysprefs{finesCalendar} = "Circulation";
193 $tabsysprefs{previousIssuesDefaultSortOrder} = "Circulation";
194 $tabsysprefs{todaysIssuesDefaultSortOrder} = "Circulation";
195 $tabsysprefs{HomeOrHoldingBranch} = "Circulation";
196 $tabsysprefs{HomeOrHoldingBranchReturn} = "Circulation";
197 $tabsysprefs{RandomizeHoldsQueueWeight} = "Circulation";
198 $tabsysprefs{StaticHoldsQueueWeight} = "Circulation";
199 $tabsysprefs{AllowOnShelfHolds} = "Circulation";
200 $tabsysprefs{AllowHoldsOnDamagedItems} = "Circulation";
201 $tabsysprefs{UseBranchTransferLimits} = "Circulation";
202 $tabsysprefs{AllowHoldPolicyOverride} = "Circulation";
203 $tabsysprefs{BranchTransferLimitsType} = "Circulation";
204 $tabsysprefs{AllowNotForLoanOverride} = "Circulation";
205 $tabsysprefs{RenewalPeriodBase} = "Circulation";
206 $tabsysprefs{FilterBeforeOverdueReport} = "Circulation";
207 $tabsysprefs{AllowHoldDateInFuture} = "Circulation";
208 $tabsysprefs{OPACFineNoRenewals} = "Circulation";
209 $tabsysprefs{InProcessingToShelvingCart} = "Circulation";
210 $tabsysprefs{NewItemsDefaultLocation} = "Circulation";
211 $tabsysprefs{ReturnToShelvingCart} = "Circulation";
212 $tabsysprefs{DisplayClearScreenButton} = "Circulation";
213 $tabsysprefs{AllowAllMessageDeletion} = "Circulation";
214 $tabsysprefs{OverdueNoticeBcc} = "Circulation";
215 $tabsysprefs{OverduesBlockCirc} = "Circulation";
219 $tabsysprefs{TemplateEncoding} = "StaffClient";
220 $tabsysprefs{template} = "StaffClient";
221 $tabsysprefs{intranetstylesheet} = "StaffClient";
222 $tabsysprefs{IntranetNav} = "StaffClient";
223 $tabsysprefs{intranetcolorstylesheet} = "StaffClient";
224 $tabsysprefs{intranetuserjs} = "StaffClient";
225 $tabsysprefs{yuipath} = "StaffClient";
226 $tabsysprefs{IntranetmainUserblock} = "StaffClient";
227 $tabsysprefs{viewMARC} = "StaffClient";
228 $tabsysprefs{viewLabeledMARC} = "StaffClient";
229 $tabsysprefs{viewISBD} = "StaffClient";
232 $tabsysprefs{autoMemberNum} = "Patrons";
233 $tabsysprefs{checkdigit} = "Patrons";
234 $tabsysprefs{intranetreadinghistory} = "Patrons";
235 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
236 $tabsysprefs{memberofinstitution} = "Patrons";
237 $tabsysprefs{BorrowerMandatoryField} = "Patrons";
238 $tabsysprefs{borrowerRelationship} = "Patrons";
239 $tabsysprefs{BorrowersTitles} = "Patrons";
240 $tabsysprefs{patronimages} = "Patrons";
241 $tabsysprefs{minPasswordLength} = "Patrons";
242 $tabsysprefs{uppercasesurnames} = "Patrons";
243 $tabsysprefs{MaxFine} = "Patrons";
244 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
245 $tabsysprefs{AddPatronLists} = "Patrons";
246 $tabsysprefs{PatronsPerPage} = "Patrons";
247 $tabsysprefs{ExtendedPatronAttributes} = "Patrons";
248 $tabsysprefs{AutoEmailOpacUser} = "Patrons";
249 $tabsysprefs{AutoEmailPrimaryAddress} = "Patrons";
250 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
251 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
252 $tabsysprefs{HidePatronName} = "Patrons";
256 $tabsysprefs{dateformat} = "I18N/L10N";
257 $tabsysprefs{opaclanguages} = "I18N/L10N";
258 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
259 $tabsysprefs{language} = "I18N/L10N";
262 $tabsysprefs{defaultSortField} = "Searching";
263 $tabsysprefs{defaultSortOrder} = "Searching";
264 $tabsysprefs{numSearchResults} = "Searching";
265 $tabsysprefs{OPACdefaultSortField} = "Searching";
266 $tabsysprefs{OPACdefaultSortOrder} = "Searching";
267 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
268 $tabsysprefs{OPACnumSearchResults} = "Searching";
269 $tabsysprefs{QueryFuzzy} = "Searching";
270 $tabsysprefs{QueryStemming} = "Searching";
271 $tabsysprefs{QueryWeightFields} = "Searching";
272 $tabsysprefs{expandedSearchOption} = "Searching";
273 $tabsysprefs{sortbynonfiling} = "Searching";
274 $tabsysprefs{QueryAutoTruncate} = "Searching";
275 $tabsysprefs{QueryRemoveStopwords} = "Searching";
276 $tabsysprefs{AdvancedSearchTypes} = "Searching";
277 $tabsysprefs{DisplayMultiPlaceHold} = "Searching";
280 $tabsysprefs{AmazonEnabled} = "EnhancedContent";
281 $tabsysprefs{OPACAmazonEnabled} = "EnhancedContent";
282 $tabsysprefs{AmazonCoverImages} = "EnhancedContent";
283 $tabsysprefs{OPACAmazonCoverImages} = "EnhancedContent";
284 $tabsysprefs{AWSAccessKeyID} = "EnhancedContent";
285 $tabsysprefs{AWSPrivateKey} = "EnhancedContent";
286 $tabsysprefs{AmazonLocale} = "EnhancedContent";
287 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
288 $tabsysprefs{AmazonSimilarItems} = "EnhancedContent";
289 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
290 $tabsysprefs{AmazonReviews} = "EnhancedContent";
291 $tabsysprefs{OPACAmazonReviews} = "EnhancedContent";
294 $tabsysprefs{Babeltheque} = "EnhancedContent";
297 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
298 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
299 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
300 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
302 # Library Thing for Libraries
303 $tabsysprefs{LibraryThingForLibrariesID} = "EnhancedContent";
304 $tabsysprefs{LibraryThingForLibrariesEnabled} = "EnhancedContent";
305 $tabsysprefs{LibraryThingForLibrariesTabbedView} = "EnhancedContent";
308 $tabsysprefs{SyndeticsClientCode} = 'EnhancedContent';
309 $tabsysprefs{SyndeticsEnabled} = 'EnhancedContent';
310 $tabsysprefs{SyndeticsCoverImages} = 'EnhancedContent';
311 $tabsysprefs{SyndeticsTOC} = 'EnhancedContent';
312 $tabsysprefs{SyndeticsSummary} = 'EnhancedContent';
313 $tabsysprefs{SyndeticsEditions} = 'EnhancedContent';
314 $tabsysprefs{SyndeticsExcerpt} = 'EnhancedContent';
315 $tabsysprefs{SyndeticsReviews} = 'EnhancedContent';
316 $tabsysprefs{SyndeticsAuthorNotes} = 'EnhancedContent';
317 $tabsysprefs{SyndeticsAwards} = 'EnhancedContent';
318 $tabsysprefs{SyndeticsSeries} = 'EnhancedContent';
319 $tabsysprefs{SyndeticsCoverImageSize} = 'EnhancedContent';
323 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
324 $tabsysprefs{XISBN} = "EnhancedContent";
325 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
326 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
327 $tabsysprefs{ThingISBN} = "EnhancedContent";
328 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
331 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
332 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
333 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
334 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
335 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
336 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
337 $tabsysprefs{TagsModeration} = 'EnhancedContent';
338 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
339 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
342 $tabsysprefs{BiblioDefaultView} = "OPAC";
343 $tabsysprefs{LibraryName} = "OPAC";
344 $tabsysprefs{opaccolorstylesheet} = "OPAC";
345 $tabsysprefs{opaccredits} = "OPAC";
346 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
347 $tabsysprefs{OpacNav} = "OPAC";
348 $tabsysprefs{opacsmallimage} = "OPAC";
349 $tabsysprefs{opacstylesheet} = "OPAC";
350 $tabsysprefs{opacthemes} = "OPAC";
351 $tabsysprefs{opacuserjs} = "OPAC";
352 $tabsysprefs{opacheader} = "OPAC";
353 $tabsysprefs{hideBiblioNumber} = "OPAC";
354 $tabsysprefs{OpacMainUserBlock} = "OPAC";
355 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
356 $tabsysprefs{OPACUserCSS} = "OPAC";
357 $tabsysprefs{OPACHighlightedWords} = "OPAC";
358 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
359 $tabsysprefs{URLLinkText} = "OPAC";
360 $tabsysprefs{OPACSearchForTitleIn} = "OPAC";
361 $tabsysprefs{OPACShelfBrowser} = "OPAC";
362 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
363 $tabsysprefs{OPACAllowHoldDateInFuture} = "OPAC";
364 $tabsysprefs{OPACPatronDetails} = "OPAC";
365 $tabsysprefs{OPACFinesTab} = "OPAC";
366 $tabsysprefs{DisplayOPACiconsXSLT} = "OPAC";
367 $tabsysprefs{AutoSelfCheckAllowed} = "OPAC";
368 $tabsysprefs{AutoSelfCheckID} = "OPAC";
369 $tabsysprefs{AutoSelfCheckPass} = "OPAC";
372 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
373 $tabsysprefs{hidelostitems} = "OPAC";
374 $tabsysprefs{opacbookbag} = "OPAC";
375 $tabsysprefs{OpacPasswordChange} = "OPAC";
376 $tabsysprefs{opacreadinghistory} = "OPAC";
377 $tabsysprefs{virtualshelves} = "OPAC";
378 $tabsysprefs{RequestOnOpac} = "OPAC";
379 $tabsysprefs{reviewson} = "OPAC";
380 $tabsysprefs{OpacTopissues} = "OPAC";
381 $tabsysprefs{OpacAuthorities} = "OPAC";
382 $tabsysprefs{OpacCloud} = "OPAC";
383 $tabsysprefs{opacuserlogin} = "OPAC";
384 $tabsysprefs{AnonSuggestions} = "OPAC";
385 $tabsysprefs{suggestion} = "OPAC";
386 $tabsysprefs{OpacTopissue} = "OPAC";
387 $tabsysprefs{OpacBrowser} = "OPAC";
388 $tabsysprefs{kohaspsuggest} = "OPAC";
389 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
390 $tabsysprefs{OPACItemHolds} = "OPAC";
391 $tabsysprefs{OPACGroupResults} = "OPAC";
392 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
393 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
394 $tabsysprefs{OPACShowCheckoutName} = "OPAC";
397 $tabsysprefs{RoutingListAddReserves} = "Serials";
398 $tabsysprefs{OPACSerialIssueDisplayCount} = "Serials";
399 $tabsysprefs{StaffSerialIssueDisplayCount} = "Serials";
400 $tabsysprefs{OPACDisplayExtendedSubInfo} = "Serials";
401 $tabsysprefs{OPACSubscriptionDisplay} = "Serials";
402 $tabsysprefs{RenewSerialAddsSuggestion} = "Serials";
403 $tabsysprefs{SubscriptionHistory} = "Serials";
406 $tabsysprefs{CataloguingLog} = "Logs";
407 $tabsysprefs{BorrowersLog} = "Logs";
408 $tabsysprefs{SubscriptionLog} = "Logs";
409 $tabsysprefs{IssueLog} = "Logs";
410 $tabsysprefs{ReturnLog} = "Logs";
411 $tabsysprefs{LetterLog} = "Logs";
412 $tabsysprefs{FinesLog} = "Logs";
415 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
416 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
417 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
418 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
419 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
422 $tabsysprefs{'ILS-DI'} = "ILS-DI";
426 $tabsysprefs{'ImageLimit'} = "Creators";
429 my ( $searchstring, $type ) = @_;
430 my $dbh = C4::Context->dbh;
431 $searchstring =~ s/\'/\\\'/g;
432 my @data = split( ' ', $searchstring );
438 # used for doing a plain-old sys-pref search
439 if ( $type && $type ne 'all' ) {
440 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
441 if ( $tabsysprefs{$syspref} eq $type ) {
442 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
443 $sth->execute($syspref);
444 while ( my $data = $sth->fetchrow_hashref ) {
445 $data->{shortvalue} = $data->{value};
446 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
447 push( @results, $data );
456 if ( $type and $type eq 'all' ) {
457 $sth = $dbh->prepare( "
459 FROM systempreferences
460 WHERE variable LIKE ? OR explanation LIKE ?
461 ORDER BY VARIABLE" );
462 $sth->execute( "%$searchstring%", "%$searchstring%" );
464 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable in (";
466 for my $name ( get_local_prefs() ) {
467 $strsth .= ',' unless $first;
468 $strsth .= "'$name'";
471 $strsth .= ") order by variable";
472 $sth = $dbh->prepare($strsth);
476 while ( my $data = $sth->fetchrow_hashref ) {
477 $data->{shortvalue} = $data->{value};
478 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
479 push( @results, $data );
485 return ( $cnt, \@results );
493 if ( defined $data->{'options'} ) {
494 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
496 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
497 push @options, { option => $option, selected => $selected };
501 $params->{'prefoptions'} = $data->{'options'};
503 if ( not defined( $data->{'type'} ) ) {
504 $params->{'type-free'} = 1;
505 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
506 } elsif ( $data->{'type'} eq 'Upload' ) {
507 $params->{'type-upload'} = 1;
508 } elsif ( $data->{'type'} eq 'Choice' ) {
509 $params->{'type-choice'} = 1;
510 } elsif ( $data->{'type'} eq 'YesNo' ) {
511 $params->{'type-yesno'} = 1;
512 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
513 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
514 $params->{'value-yes'} = 1;
516 $params->{'value-no'} = 1;
518 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
519 $params->{'type-free'} = 1;
520 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
521 } elsif ( $data->{'type'} eq 'Textarea' ) {
522 $params->{'type-textarea'} = 1;
523 $data->{options} =~ /(.*)\|(.*)/;
524 $params->{'cols'} = $1;
525 $params->{'rows'} = $2;
526 } elsif ( $data->{'type'} eq 'Themes' ) {
527 $params->{'type-choice'} = 1;
529 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
531 my $currently_selected_themes;
533 foreach my $theme ( split /\s+/, $data->{'value'} ) {
534 push @options, { option => $theme, counter => $counter };
535 $currently_selected_themes->{$theme} = 1;
538 foreach my $theme ( getallthemes($type) ) {
540 next if $currently_selected_themes->{$theme};
541 push @options, { option => $theme, counter => $counter };
544 } elsif ( $data->{'type'} eq 'ClassSources' ) {
545 $params->{'type-choice'} = 1;
548 my $sources = GetClassSources();
550 foreach my $cn_source ( sort keys %$sources ) {
551 if ( $cn_source eq $data->{'value'} ) {
552 push @options, { option => $cn_source, counter => $counter, selected => 1 };
554 push @options, { option => $cn_source, counter => $counter };
558 } elsif ( $data->{'type'} eq 'Languages' ) {
559 my $currently_selected_languages;
560 foreach my $language ( split /\s+/, $data->{'value'} ) {
561 $currently_selected_languages->{$language} = 1;
565 my $lang = $params->{'lang'};
568 if ( $data->{'variable'} =~ /opac/ ) {
572 $theme = C4::Context->preference('opacthemes');
575 # this is the staff client
576 $interface = 'intranet';
577 $theme = C4::Context->preference('template');
579 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
581 $params->{'languages_loop'} = $languages_loop;
582 $params->{'type-langselector'} = 1;
584 $params->{'type-free'} = 1;
585 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
588 if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
589 $params->{'oneline'} = 1;
592 $params->{'preftype'} = $data->{'type'};
593 $params->{'options'} = \@options;
599 my $searchfield = $input->param('searchfield') || '';
600 my $Tvalue = $input->param('Tvalue');
601 my $offset = $input->param('offset') || 0;
602 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
604 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
605 { template_name => "admin/systempreferences.tmpl",
608 authnotrequired => 0,
609 flagsrequired => { parameters => 1 },
614 my $op = $input->param('op') || '';
615 $searchfield =~ s/\,//g;
619 script_name => $script_name,
621 ); # we show only the TMPL_VAR names $op
624 script_name => $script_name,
626 ); # we show only the TMPL_VAR names $op
629 if ( $op eq 'update_and_reedit' ) {
630 foreach ( $input->param ) {
633 if ( my $currentorder = $input->param('currentorder') ) {
634 my @currentorder = split /\|/, $currentorder;
635 my $orderchanged = 0;
636 foreach my $param ( $input->param ) {
637 if ( $param =~ m#up-(\d+).x# ) {
638 my $temp = $currentorder[$1];
639 $currentorder[$1] = $currentorder[ $1 - 1 ];
640 $currentorder[ $1 - 1 ] = $temp;
643 } elsif ( $param =~ m#down-(\d+).x# ) {
644 my $temp = $currentorder[$1];
645 $currentorder[$1] = $currentorder[ $1 + 1 ];
646 $currentorder[ $1 + 1 ] = $temp;
651 $value = join ' ', @currentorder;
655 script_name => $script_name,
657 ); # we show only the TMPL_VAR names $op
662 script_name => $script_name,
664 ); # we show only the TMPL_VAR names $op
667 my $dbh = C4::Context->dbh;
668 my $query = "select * from systempreferences where variable=?";
669 my $sth = $dbh->prepare($query);
670 $sth->execute( $input->param('variable') );
672 unless ( C4::Context->config('demo') ) {
673 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
674 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
676 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
679 unless ( C4::Context->config('demo') ) {
680 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
681 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
683 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
690 ################## ADD_FORM ##################################
691 # called by default. Used to create form to add or modify a record
693 if ( $op eq 'add_form' ) {
695 #---- if primkey exists, it's a modify action, so read values to modify...
698 my $dbh = C4::Context->dbh;
699 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
700 $sth->execute($searchfield);
701 $data = $sth->fetchrow_hashref;
703 $template->param( modify => 1 );
705 # save tab to return to if user cancels edit
706 $template->param( return_tab => $tabsysprefs{$searchfield} );
709 $data->{'lang'} = $template->param('lang');
711 $template->param( GetPrefParams($data) );
713 $template->param( searchfield => $searchfield );
715 ################## ADD_VALIDATE ##################################
716 # called by add_form, used to insert/modify data in DB
717 } elsif ( $op eq 'add_validate' ) {
718 my $dbh = C4::Context->dbh;
719 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
720 $sth->execute( $input->param('variable') );
722 # to handle multiple values
725 # handle multiple value strings (separated by ',')
726 my $params = $input->Vars;
727 if ( defined $params->{'value'} ) {
729 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
732 for my $vl (@values) {
737 $value = $params->{'value'};
741 if ( $input->param('preftype') eq 'Upload' ) {
742 my $lgtfh = $input->upload('value');
743 $value = join '', <$lgtfh>;
744 $value = encode_base64($value);
748 unless ( C4::Context->config('demo') ) {
749 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
750 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
752 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
755 unless ( C4::Context->config('demo') ) {
756 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
757 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
759 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
763 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
765 ################## DELETE_CONFIRM ##################################
766 # called by default form, used to confirm deletion of data in DB
767 } elsif ( $op eq 'delete_confirm' ) {
768 my $dbh = C4::Context->dbh;
769 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
770 $sth->execute($searchfield);
771 my $data = $sth->fetchrow_hashref;
774 searchfield => $searchfield,
775 Tvalue => $data->{'value'},
778 # END $OP eq DELETE_CONFIRM
779 ################## DELETE_CONFIRMED ##################################
780 # called by delete_confirm, used to effectively confirm deletion of data in DB
781 } elsif ( $op eq 'delete_confirmed' ) {
782 my $dbh = C4::Context->dbh;
783 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
784 $sth->execute($searchfield);
785 my $logstring = $searchfield . " | " . $Tvalue;
786 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
789 # END $OP eq DELETE_CONFIRMED
790 ################## DEFAULT ##################################
792 #Adding tab management for system preferences
793 my $tab = $input->param('tab');
794 $template->param( $tab => 1 );
795 my ( $count, $results ) = StringSearch( $searchfield, $tab );
797 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
798 my $row_data = $results->[$i];
799 $row_data->{'lang'} = $template->param('lang');
800 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
801 $row_data->{edit} = "$script_name?op=add_form&searchfield=" . $results->[$i]{'variable'};
802 $row_data->{delete} = "$script_name?op=delete_confirm&searchfield=" . $results->[$i]{'variable'};
803 push( @loop_data, $row_data );
805 $tab = ( $tab ? $tab : "local-use" );
806 $template->param( loop => \@loop_data, $tab => 1 );
808 my $prevpage = $offset - $pagesize;
809 $template->param( "<a href=$script_name?offset=" . $prevpage . '<< Prev</a>' );
811 if ( $offset + $pagesize < $count ) {
812 my $nextpage = $offset + $pagesize;
813 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next >></a>' );
815 $template->param( tab => $tab, );
816 } #---- END $OP eq DEFAULT
817 output_html_with_http_headers $input, $cookie, $template->output;
820 # Return an array containing all preferences defined in current Koha instance
823 sub get_prefs_from_files {
824 my $context = C4::Context->new();
825 my $path_pref_en = $context->config('intrahtdocs') .
826 '/prog/en/modules/admin/preferences';
827 # Get all .pref file names
828 opendir ( my $fh, $path_pref_en );
829 my @pref_files = grep { /.pref/ } readdir($fh);
835 for my $pref ( @$prefs ) {
836 for my $element ( @$pref ) {
837 if ( ref( $element) eq 'HASH' ) {
838 my $name = $element->{pref};
846 for my $file (@pref_files) {
847 my $pref = LoadFile( "$path_pref_en/$file" );
848 for my $tab ( keys %$pref ) {
849 my $content = $pref->{$tab};
850 if ( ref($content) eq 'ARRAY' ) {
854 for my $section ( keys %$content ) {
855 my $syspref = $content->{$section};
864 # Return an array containg all preferences defined in DB
866 sub get_prefs_from_db {
867 my $dbh = C4::Context->dbh;
868 my $sth = $dbh->prepare("SELECT variable FROM systempreferences");
871 while ( (my $name) = $sth->fetchrow_array ) {
872 push @names, $name if $name;
878 # Return an array containing all local preferences: those which are defined in
879 # DB and not defined in Koha .pref files.
881 sub get_local_prefs {
882 my @prefs_file = get_prefs_from_files();
883 my @prefs_db = get_prefs_from_db();
885 my %prefs_file = map { $_ => 1 } @prefs_file;
887 foreach my $name (@prefs_db) {
888 push @names, $name unless $prefs_file{$name};