Bug 5207 - Details on editing SAX Parser ini file.
[koha.git] / admin / systempreferences.pl
1 #!/usr/bin/perl
2
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)
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
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.
15 #
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.
19 #
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.
23
24 =head1 systempreferences.pl
25
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
40
41 =cut
42
43 use strict;
44 use warnings;
45
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 );
56
57
58 # use Smart::Comments;
59
60 # FIXME, shouldnt we store this stuff in the systempreferences table?
61
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 ...)];
66 #
67 #   Because some things *should* be on more than one tab.
68 #   And the tabname is the unique part (the key).
69
70 my %tabsysprefs;
71
72 # Acquisitions
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";
81
82 # Admin
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";
100
101 # This script is depricated so all of these prefs are lumped here to avoid their being displayed in the local use prefs tab
102
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";
133
134 # Authorities
135 $tabsysprefs{authoritysep}          = "Authorities";
136 $tabsysprefs{AuthDisplayHierarchy}  = "Authorities";
137 $tabsysprefs{dontmerge}             = "Authorities";
138 $tabsysprefs{BiblioAddsAuthorities} = "Authorities";
139
140 # Cataloguing
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";
164
165 # Circulation
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{RandomizeHoldsQueueWeight}      = "Circulation";
197 $tabsysprefs{StaticHoldsQueueWeight}         = "Circulation";
198 $tabsysprefs{AllowOnShelfHolds}              = "Circulation";
199 $tabsysprefs{AllowHoldsOnDamagedItems}       = "Circulation";
200 $tabsysprefs{UseBranchTransferLimits}        = "Circulation";
201 $tabsysprefs{AllowHoldPolicyOverride}        = "Circulation";
202 $tabsysprefs{BranchTransferLimitsType}       = "Circulation";
203 $tabsysprefs{AllowNotForLoanOverride}        = "Circulation";
204 $tabsysprefs{RenewalPeriodBase}              = "Circulation";
205 $tabsysprefs{FilterBeforeOverdueReport}      = "Circulation";
206 $tabsysprefs{AllowHoldDateInFuture}          = "Circulation";
207 $tabsysprefs{OPACFineNoRenewals}             = "Circulation";
208 $tabsysprefs{InProcessingToShelvingCart}     = "Circulation";
209 $tabsysprefs{NewItemsDefaultLocation}        = "Circulation";
210 $tabsysprefs{ReturnToShelvingCart}           = "Circulation";
211 $tabsysprefs{DisplayClearScreenButton}       = "Circulation";
212 $tabsysprefs{AllowAllMessageDeletion}        = "Circulation";
213 $tabsysprefs{OverdueNoticeBcc}               = "Circulation";
214 $tabsysprefs{OverduesBlockCirc}              = "Circulation";
215
216
217 # Staff Client
218 $tabsysprefs{TemplateEncoding}        = "StaffClient";
219 $tabsysprefs{template}                = "StaffClient";
220 $tabsysprefs{intranetstylesheet}      = "StaffClient";
221 $tabsysprefs{IntranetNav}             = "StaffClient";
222 $tabsysprefs{intranetcolorstylesheet} = "StaffClient";
223 $tabsysprefs{intranetuserjs}          = "StaffClient";
224 $tabsysprefs{yuipath}                 = "StaffClient";
225 $tabsysprefs{IntranetmainUserblock}   = "StaffClient";
226 $tabsysprefs{viewMARC}                = "StaffClient";
227 $tabsysprefs{viewLabeledMARC}         = "StaffClient";
228 $tabsysprefs{viewISBD}                = "StaffClient";
229
230 # Patrons
231 $tabsysprefs{autoMemberNum}                = "Patrons";
232 $tabsysprefs{checkdigit}                   = "Patrons";
233 $tabsysprefs{intranetreadinghistory}       = "Patrons";
234 $tabsysprefs{NotifyBorrowerDeparture}      = "Patrons";
235 $tabsysprefs{memberofinstitution}          = "Patrons";
236 $tabsysprefs{BorrowerMandatoryField}       = "Patrons";
237 $tabsysprefs{borrowerRelationship}         = "Patrons";
238 $tabsysprefs{BorrowersTitles}              = "Patrons";
239 $tabsysprefs{patronimages}                 = "Patrons";
240 $tabsysprefs{minPasswordLength}            = "Patrons";
241 $tabsysprefs{uppercasesurnames}            = "Patrons";
242 $tabsysprefs{MaxFine}                      = "Patrons";
243 $tabsysprefs{NotifyBorrowerDeparture}      = "Patrons";
244 $tabsysprefs{AddPatronLists}               = "Patrons";
245 $tabsysprefs{PatronsPerPage}               = "Patrons";
246 $tabsysprefs{ExtendedPatronAttributes}     = "Patrons";
247 $tabsysprefs{AutoEmailOpacUser}            = "Patrons";
248 $tabsysprefs{AutoEmailPrimaryAddress}      = "Patrons";
249 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
250 $tabsysprefs{'SMSSendDriver'}              = 'Patrons';
251 $tabsysprefs{HidePatronName}               = "Patrons";
252
253
254 # I18N/L10N
255 $tabsysprefs{dateformat}    = "I18N/L10N";
256 $tabsysprefs{opaclanguages} = "I18N/L10N";
257 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
258 $tabsysprefs{language}      = "I18N/L10N";
259
260 # Searching
261 $tabsysprefs{defaultSortField}        = "Searching";
262 $tabsysprefs{defaultSortOrder}        = "Searching";
263 $tabsysprefs{numSearchResults}        = "Searching";
264 $tabsysprefs{OPACdefaultSortField}    = "Searching";
265 $tabsysprefs{OPACdefaultSortOrder}    = "Searching";
266 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
267 $tabsysprefs{OPACnumSearchResults}    = "Searching";
268 $tabsysprefs{QueryFuzzy}              = "Searching";
269 $tabsysprefs{QueryStemming}           = "Searching";
270 $tabsysprefs{QueryWeightFields}       = "Searching";
271 $tabsysprefs{expandedSearchOption}    = "Searching";
272 $tabsysprefs{sortbynonfiling}         = "Searching";
273 $tabsysprefs{QueryAutoTruncate}       = "Searching";
274 $tabsysprefs{QueryRemoveStopwords}    = "Searching";
275 $tabsysprefs{AdvancedSearchTypes}     = "Searching";
276 $tabsysprefs{DisplayMultiPlaceHold}   = "Searching";
277
278 # EnhancedContent
279 $tabsysprefs{AmazonEnabled}          = "EnhancedContent";
280 $tabsysprefs{OPACAmazonEnabled}      = "EnhancedContent";
281 $tabsysprefs{AmazonCoverImages}      = "EnhancedContent";
282 $tabsysprefs{OPACAmazonCoverImages}  = "EnhancedContent";
283 $tabsysprefs{AWSAccessKeyID}         = "EnhancedContent";
284 $tabsysprefs{AWSPrivateKey}          = "EnhancedContent";
285 $tabsysprefs{AmazonLocale}           = "EnhancedContent";
286 $tabsysprefs{AmazonAssocTag}         = "EnhancedContent";
287 $tabsysprefs{AmazonSimilarItems}     = "EnhancedContent";
288 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
289 $tabsysprefs{AmazonReviews}          = "EnhancedContent";
290 $tabsysprefs{OPACAmazonReviews}      = "EnhancedContent";
291
292 # Babelthèque
293 $tabsysprefs{Babeltheque}            = "EnhancedContent";
294
295 # Baker & Taylor
296 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
297 $tabsysprefs{BakerTaylorEnabled}      = 'EnhancedContent';
298 $tabsysprefs{BakerTaylorPassword}     = 'EnhancedContent';
299 $tabsysprefs{BakerTaylorUsername}     = 'EnhancedContent';
300
301 # Library Thing for Libraries
302 $tabsysprefs{LibraryThingForLibrariesID} = "EnhancedContent";
303 $tabsysprefs{LibraryThingForLibrariesEnabled} = "EnhancedContent";
304 $tabsysprefs{LibraryThingForLibrariesTabbedView} = "EnhancedContent";
305
306 # Syndetics
307 $tabsysprefs{SyndeticsClientCode}     = 'EnhancedContent';
308 $tabsysprefs{SyndeticsEnabled}        = 'EnhancedContent';
309 $tabsysprefs{SyndeticsCoverImages}    = 'EnhancedContent';
310 $tabsysprefs{SyndeticsTOC}            = 'EnhancedContent';
311 $tabsysprefs{SyndeticsSummary}        = 'EnhancedContent';
312 $tabsysprefs{SyndeticsEditions}       = 'EnhancedContent';
313 $tabsysprefs{SyndeticsExcerpt}        = 'EnhancedContent';
314 $tabsysprefs{SyndeticsReviews}        = 'EnhancedContent';
315 $tabsysprefs{SyndeticsAuthorNotes}    = 'EnhancedContent';
316 $tabsysprefs{SyndeticsAwards}         = 'EnhancedContent';
317 $tabsysprefs{SyndeticsSeries}         = 'EnhancedContent';
318 $tabsysprefs{SyndeticsCoverImageSize} = 'EnhancedContent';
319
320
321 # FRBR
322 $tabsysprefs{FRBRizeEditions}     = "EnhancedContent";
323 $tabsysprefs{XISBN}               = "EnhancedContent";
324 $tabsysprefs{OCLCAffiliateID}     = "EnhancedContent";
325 $tabsysprefs{XISBNDailyLimit}     = "EnhancedContent";
326 $tabsysprefs{ThingISBN}           = "EnhancedContent";
327 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
328
329 # Tags
330 $tabsysprefs{TagsEnabled}            = 'EnhancedContent';
331 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
332 $tabsysprefs{TagsInputOnDetail}      = 'EnhancedContent';
333 $tabsysprefs{TagsInputOnList}        = 'EnhancedContent';
334 $tabsysprefs{TagsShowOnDetail}       = 'EnhancedContent';
335 $tabsysprefs{TagsShowOnList}         = 'EnhancedContent';
336 $tabsysprefs{TagsModeration}         = 'EnhancedContent';
337 $tabsysprefs{GoogleJackets}          = 'EnhancedContent';
338 $tabsysprefs{AuthorisedValueImages}  = "EnhancedContent";
339
340 # OPAC
341 $tabsysprefs{BiblioDefaultView}          = "OPAC";
342 $tabsysprefs{LibraryName}                = "OPAC";
343 $tabsysprefs{opaccolorstylesheet}        = "OPAC";
344 $tabsysprefs{opaccredits}                = "OPAC";
345 $tabsysprefs{opaclayoutstylesheet}       = "OPAC";
346 $tabsysprefs{OpacNav}                    = "OPAC";
347 $tabsysprefs{opacsmallimage}             = "OPAC";
348 $tabsysprefs{opacstylesheet}             = "OPAC";
349 $tabsysprefs{opacthemes}                 = "OPAC";
350 $tabsysprefs{opacuserjs}                 = "OPAC";
351 $tabsysprefs{opacheader}                 = "OPAC";
352 $tabsysprefs{hideBiblioNumber}           = "OPAC";
353 $tabsysprefs{OpacMainUserBlock}          = "OPAC";
354 $tabsysprefs{OPACURLOpenInNewWindow}     = "OPAC";
355 $tabsysprefs{OPACUserCSS}                = "OPAC";
356 $tabsysprefs{OPACHighlightedWords}       = "OPAC";
357 $tabsysprefs{OPACViewOthersSuggestions}  = "OPAC";
358 $tabsysprefs{URLLinkText}                = "OPAC";
359 $tabsysprefs{OPACSearchForTitleIn}       = "OPAC";
360 $tabsysprefs{OPACShelfBrowser}           = "OPAC";
361 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
362 $tabsysprefs{OPACAllowHoldDateInFuture}  = "OPAC";
363 $tabsysprefs{OPACPatronDetails}  = "OPAC";
364 $tabsysprefs{OPACFinesTab}  = "OPAC";
365 $tabsysprefs{DisplayOPACiconsXSLT}       = "OPAC";
366 $tabsysprefs{AutoSelfCheckAllowed}       = "OPAC";
367 $tabsysprefs{AutoSelfCheckID}            = "OPAC";
368 $tabsysprefs{AutoSelfCheckPass}          = "OPAC";
369
370 # OPAC
371 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
372 $tabsysprefs{hidelostitems}        = "OPAC";
373 $tabsysprefs{opacbookbag}          = "OPAC";
374 $tabsysprefs{OpacPasswordChange}   = "OPAC";
375 $tabsysprefs{opacreadinghistory}   = "OPAC";
376 $tabsysprefs{virtualshelves}       = "OPAC";
377 $tabsysprefs{RequestOnOpac}        = "OPAC";
378 $tabsysprefs{reviewson}            = "OPAC";
379 $tabsysprefs{OpacTopissues}        = "OPAC";
380 $tabsysprefs{OpacAuthorities}      = "OPAC";
381 $tabsysprefs{OpacCloud}            = "OPAC";
382 $tabsysprefs{opacuserlogin}        = "OPAC";
383 $tabsysprefs{AnonSuggestions}      = "OPAC";
384 $tabsysprefs{suggestion}           = "OPAC";
385 $tabsysprefs{OpacTopissue}         = "OPAC";
386 $tabsysprefs{OpacBrowser}          = "OPAC";
387 $tabsysprefs{kohaspsuggest}        = "OPAC";
388 $tabsysprefs{OpacRenewalAllowed}   = "OPAC";
389 $tabsysprefs{OPACItemHolds}        = "OPAC";
390 $tabsysprefs{OPACGroupResults}     = "OPAC";
391 $tabsysprefs{XSLTDetailsDisplay}   = "OPAC";
392 $tabsysprefs{XSLTResultsDisplay}   = "OPAC";
393 $tabsysprefs{OPACShowCheckoutName}   = "OPAC";
394
395 # Serials
396 $tabsysprefs{RoutingListAddReserves}       = "Serials";
397 $tabsysprefs{OPACSerialIssueDisplayCount}  = "Serials";
398 $tabsysprefs{StaffSerialIssueDisplayCount} = "Serials";
399 $tabsysprefs{OPACDisplayExtendedSubInfo}   = "Serials";
400 $tabsysprefs{OPACSubscriptionDisplay}      = "Serials";
401 $tabsysprefs{RenewSerialAddsSuggestion}    = "Serials";
402 $tabsysprefs{SubscriptionHistory}          = "Serials";
403
404 # LOGFeatures
405 $tabsysprefs{CataloguingLog}  = "Logs";
406 $tabsysprefs{BorrowersLog}    = "Logs";
407 $tabsysprefs{SubscriptionLog} = "Logs";
408 $tabsysprefs{IssueLog}        = "Logs";
409 $tabsysprefs{ReturnLog}       = "Logs";
410 $tabsysprefs{LetterLog}       = "Logs";
411 $tabsysprefs{FinesLog}        = "Logs";
412
413 # OAI-PMH variables
414 $tabsysprefs{'OAI-PMH'}           = "OAI-PMH";
415 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
416 $tabsysprefs{'OAI-PMH:MaxCount'}  = "OAI-PMH";
417 $tabsysprefs{'OAI-PMH:Set'}       = "OAI-PMH";
418 $tabsysprefs{'OAI-PMH:Subset'}    = "OAI-PMH";
419
420 # ILS-DI variables
421 $tabsysprefs{'ILS-DI'} = "ILS-DI";
422
423 # Creator variables
424
425 $tabsysprefs{'ImageLimit'} = "Creators";
426
427 sub StringSearch {
428     my ( $searchstring, $type ) = @_;
429     my $dbh = C4::Context->dbh;
430     $searchstring =~ s/\'/\\\'/g;
431     my @data = split( ' ', $searchstring );
432     my $count = @data;
433     my @results;
434     my $cnt = 0;
435     my $sth;
436
437     # used for doing a plain-old sys-pref search
438     if ( $type && $type ne 'all' ) {
439         foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
440             if ( $tabsysprefs{$syspref} eq $type ) {
441                 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
442                 $sth->execute($syspref);
443                 while ( my $data = $sth->fetchrow_hashref ) {
444                     $data->{shortvalue} = $data->{value};
445                     $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
446                     push( @results, $data );
447                     $cnt++;
448                 }
449                 $sth->finish;
450             }
451         }
452     } else {
453         my $sth;
454
455         if ( $type and $type eq 'all' ) {
456             $sth = $dbh->prepare( "
457             SELECT *
458               FROM systempreferences
459               WHERE variable LIKE ? OR explanation LIKE ?
460               ORDER BY VARIABLE" );
461             $sth->execute( "%$searchstring%", "%$searchstring%" );
462         } else {
463             my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable in (";
464             my $first = 1;
465             for my $name ( get_local_prefs() ) {
466                 $strsth .= ',' unless $first;
467                 $strsth .= "'$name'";
468                 $first = 0;
469             }
470             $strsth .= ") order by variable";
471             $sth = $dbh->prepare($strsth);
472             $sth->execute();
473         }
474
475         while ( my $data = $sth->fetchrow_hashref ) {
476             $data->{shortvalue} = $data->{value};
477             $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
478             push( @results, $data );
479             $cnt++;
480         }
481
482         $sth->finish;
483     }
484     return ( $cnt, \@results );
485 }
486
487 sub GetPrefParams {
488     my $data   = shift;
489     my $params = $data;
490     my @options;
491
492     if ( defined $data->{'options'} ) {
493         foreach my $option ( split( /\|/, $data->{'options'} ) ) {
494             my $selected = '0';
495             defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
496             push @options, { option => $option, selected => $selected };
497         }
498     }
499
500     $params->{'prefoptions'} = $data->{'options'};
501
502     if ( not defined( $data->{'type'} ) ) {
503         $params->{'type-free'} = 1;
504         $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
505     } elsif ( $data->{'type'} eq 'Upload' ) {
506         $params->{'type-upload'} = 1;
507     } elsif ( $data->{'type'} eq 'Choice' ) {
508         $params->{'type-choice'} = 1;
509     } elsif ( $data->{'type'} eq 'YesNo' ) {
510         $params->{'type-yesno'} = 1;
511         $data->{'value'}        = C4::Context->boolean_preference( $data->{'variable'} );
512         if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
513             $params->{'value-yes'} = 1;
514         } else {
515             $params->{'value-no'} = 1;
516         }
517     } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
518         $params->{'type-free'} = 1;
519         $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
520     } elsif ( $data->{'type'} eq 'Textarea' ) {
521         $params->{'type-textarea'} = 1;
522         $data->{options} =~ /(.*)\|(.*)/;
523         $params->{'cols'} = $1;
524         $params->{'rows'} = $2;
525     } elsif ( $data->{'type'} eq 'Themes' ) {
526         $params->{'type-choice'} = 1;
527         my $type = '';
528         ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
529         @options = ();
530         my $currently_selected_themes;
531         my $counter = 0;
532         foreach my $theme ( split /\s+/, $data->{'value'} ) {
533             push @options, { option => $theme, counter => $counter };
534             $currently_selected_themes->{$theme} = 1;
535             $counter++;
536         }
537         foreach my $theme ( getallthemes($type) ) {
538             my $selected = '0';
539             next if $currently_selected_themes->{$theme};
540             push @options, { option => $theme, counter => $counter };
541             $counter++;
542         }
543     } elsif ( $data->{'type'} eq 'ClassSources' ) {
544         $params->{'type-choice'} = 1;
545         my $type = '';
546         @options = ();
547         my $sources = GetClassSources();
548         my $counter = 0;
549         foreach my $cn_source ( sort keys %$sources ) {
550             if ( $cn_source eq $data->{'value'} ) {
551                 push @options, { option => $cn_source, counter => $counter, selected => 1 };
552             } else {
553                 push @options, { option => $cn_source, counter => $counter };
554             }
555             $counter++;
556         }
557     } elsif ( $data->{'type'} eq 'Languages' ) {
558         my $currently_selected_languages;
559         foreach my $language ( split /\s+/, $data->{'value'} ) {
560             $currently_selected_languages->{$language} = 1;
561         }
562
563         # current language
564         my $lang = $params->{'lang'};
565         my $theme;
566         my $interface;
567         if ( $data->{'variable'} =~ /opac/ ) {
568
569             # this is the OPAC
570             $interface = 'opac';
571             $theme     = C4::Context->preference('opacthemes');
572         } else {
573
574             # this is the staff client
575             $interface = 'intranet';
576             $theme     = C4::Context->preference('template');
577         }
578         my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
579
580         $params->{'languages_loop'}    = $languages_loop;
581         $params->{'type-langselector'} = 1;
582     } else {
583         $params->{'type-free'} = 1;
584         $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
585     }
586
587     if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
588         $params->{'oneline'} = 1;
589     }
590
591     $params->{'preftype'} = $data->{'type'};
592     $params->{'options'}  = \@options;
593
594     return $params;
595 }
596
597 my $input       = new CGI;
598 my $searchfield = $input->param('searchfield') || '';
599 my $Tvalue      = $input->param('Tvalue');
600 my $offset      = $input->param('offset') || 0;
601 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
602
603 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
604     {   template_name   => "admin/systempreferences.tmpl",
605         query           => $input,
606         type            => "intranet",
607         authnotrequired => 0,
608         flagsrequired   => { parameters => 1 },
609         debug           => 1,
610     }
611 );
612 my $pagesize = 100;
613 my $op = $input->param('op') || '';
614 $searchfield =~ s/\,//g;
615
616 if ($op) {
617     $template->param(
618         script_name => $script_name,
619         $op         => 1
620     );    # we show only the TMPL_VAR names $op
621 } else {
622     $template->param(
623         script_name => $script_name,
624         else        => 1
625     );    # we show only the TMPL_VAR names $op
626 }
627
628 if ( $op eq 'update_and_reedit' ) {
629     foreach ( $input->param ) {
630     }
631     my $value = '';
632     if ( my $currentorder = $input->param('currentorder') ) {
633         my @currentorder = split /\|/, $currentorder;
634         my $orderchanged = 0;
635         foreach my $param ( $input->param ) {
636             if ( $param =~ m#up-(\d+).x# ) {
637                 my $temp = $currentorder[$1];
638                 $currentorder[$1]       = $currentorder[ $1 - 1 ];
639                 $currentorder[ $1 - 1 ] = $temp;
640                 $orderchanged           = 1;
641                 last;
642             } elsif ( $param =~ m#down-(\d+).x# ) {
643                 my $temp = $currentorder[$1];
644                 $currentorder[$1]       = $currentorder[ $1 + 1 ];
645                 $currentorder[ $1 + 1 ] = $temp;
646                 $orderchanged           = 1;
647                 last;
648             }
649         }
650         $value = join ' ', @currentorder;
651         if ($orderchanged) {
652             $op = 'add_form';
653             $template->param(
654                 script_name => $script_name,
655                 $op         => 1
656             );    # we show only the TMPL_VAR names $op
657         } else {
658             $op          = '';
659             $searchfield = '';
660             $template->param(
661                 script_name => $script_name,
662                 else        => 1
663             );    # we show only the TMPL_VAR names $op
664         }
665     }
666     my $dbh   = C4::Context->dbh;
667     my $query = "select * from systempreferences where variable=?";
668     my $sth   = $dbh->prepare($query);
669     $sth->execute( $input->param('variable') );
670     if ( $sth->rows ) {
671         unless ( C4::Context->config('demo') ) {
672             my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
673             $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
674             $sth->finish;
675             logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
676         }
677     } else {
678         unless ( C4::Context->config('demo') ) {
679             my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
680             $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
681             $sth->finish;
682             logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
683         }
684     }
685     $sth->finish;
686
687 }
688
689 ################## ADD_FORM ##################################
690 # called by default. Used to create form to add or  modify a record
691
692 if ( $op eq 'add_form' ) {
693
694     #---- if primkey exists, it's a modify action, so read values to modify...
695     my $data;
696     if ($searchfield) {
697         my $dbh = C4::Context->dbh;
698         my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
699         $sth->execute($searchfield);
700         $data = $sth->fetchrow_hashref;
701         $sth->finish;
702         $template->param( modify => 1 );
703
704         # save tab to return to if user cancels edit
705         $template->param( return_tab => $tabsysprefs{$searchfield} );
706     }
707
708     $data->{'lang'} = $template->param('lang');
709
710     $template->param( GetPrefParams($data) );
711
712     $template->param( searchfield => $searchfield );
713
714 ################## ADD_VALIDATE ##################################
715     # called by add_form, used to insert/modify data in DB
716 } elsif ( $op eq 'add_validate' ) {
717     my $dbh = C4::Context->dbh;
718     my $sth = $dbh->prepare("select * from systempreferences where variable=?");
719     $sth->execute( $input->param('variable') );
720
721     # to handle multiple values
722     my $value;
723
724     # handle multiple value strings (separated by ',')
725     my $params = $input->Vars;
726     if ( defined $params->{'value'} ) {
727         my @values = ();
728         @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
729         if (@values) {
730             $value = "";
731             for my $vl (@values) {
732                 $value .= "$vl,";
733             }
734             $value =~ s/,$//;
735         } else {
736             $value = $params->{'value'};
737         }
738     }
739
740     if ( $input->param('preftype') eq 'Upload' ) {
741         my $lgtfh = $input->upload('value');
742         $value = join '', <$lgtfh>;
743         $value = encode_base64($value);
744     }
745
746     if ( $sth->rows ) {
747         unless ( C4::Context->config('demo') ) {
748             my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
749             $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
750             $sth->finish;
751             logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
752         }
753     } else {
754         unless ( C4::Context->config('demo') ) {
755             my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
756             $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
757             $sth->finish;
758             logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
759         }
760     }
761     $sth->finish;
762     print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
763     exit;
764 ################## DELETE_CONFIRM ##################################
765     # called by default form, used to confirm deletion of data in DB
766 } elsif ( $op eq 'delete_confirm' ) {
767     my $dbh = C4::Context->dbh;
768     my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
769     $sth->execute($searchfield);
770     my $data = $sth->fetchrow_hashref;
771     $sth->finish;
772     $template->param(
773         searchfield => $searchfield,
774         Tvalue      => $data->{'value'},
775     );
776
777     # END $OP eq DELETE_CONFIRM
778 ################## DELETE_CONFIRMED ##################################
779     # called by delete_confirm, used to effectively confirm deletion of data in DB
780 } elsif ( $op eq 'delete_confirmed' ) {
781     my $dbh = C4::Context->dbh;
782     my $sth = $dbh->prepare("delete from systempreferences where variable=?");
783     $sth->execute($searchfield);
784     my $logstring = $searchfield . " | " . $Tvalue;
785     logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
786     $sth->finish;
787
788     # END $OP eq DELETE_CONFIRMED
789 ################## DEFAULT ##################################
790 } else {    # DEFAULT
791             #Adding tab management for system preferences
792     my $tab = $input->param('tab');
793     $template->param( $tab => 1 );
794     my ( $count, $results ) = StringSearch( $searchfield, $tab );
795     my @loop_data = ();
796     for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
797         my $row_data = $results->[$i];
798         $row_data->{'lang'} = $template->param('lang');
799         $row_data           = GetPrefParams($row_data);                                                         # get a fresh hash for the row data
800         $row_data->{edit}   = "$script_name?op=add_form&amp;searchfield=" . $results->[$i]{'variable'};
801         $row_data->{delete} = "$script_name?op=delete_confirm&amp;searchfield=" . $results->[$i]{'variable'};
802         push( @loop_data, $row_data );
803     }
804     $tab = ( $tab ? $tab : "local-use" );
805     $template->param( loop => \@loop_data, $tab => 1 );
806     if ( $offset > 0 ) {
807         my $prevpage = $offset - $pagesize;
808         $template->param( "<a href=$script_name?offset=" . $prevpage . '&lt;&lt; Prev</a>' );
809     }
810     if ( $offset + $pagesize < $count ) {
811         my $nextpage = $offset + $pagesize;
812         $template->param( "a href=$script_name?offset=" . $nextpage . 'Next &gt;&gt;</a>' );
813     }
814     $template->param( tab => $tab, );
815 }    #---- END $OP eq DEFAULT
816 output_html_with_http_headers $input, $cookie, $template->output;
817
818
819 # Return an array containing all preferences defined in current Koha instance
820 # .pref files.
821
822 sub get_prefs_from_files {
823     my $context       = C4::Context->new();
824     my $path_pref_en  = $context->config('intrahtdocs') .
825                         '/prog/en/modules/admin/preferences';
826     # Get all .pref file names
827     opendir ( my $fh, $path_pref_en );
828     my @pref_files = grep { /.pref/ } readdir($fh);
829     close $fh;
830
831     my @names = ();
832     my $append = sub {
833         my $prefs = shift;
834         for my $pref ( @$prefs ) {
835             for my $element ( @$pref ) {
836                 if ( ref( $element) eq 'HASH' ) {
837                     my $name = $element->{pref};
838                     next unless $name;
839                     push @names, $name;
840                     next;
841                 }
842             }
843         }
844     };
845     for my $file (@pref_files) {
846         my $pref = LoadFile( "$path_pref_en/$file" );
847         for my $tab ( keys %$pref ) {
848             my $content = $pref->{$tab};
849             if ( ref($content) eq 'ARRAY' ) {
850                 $append->($content);
851                 next;
852             }
853             for my $section ( keys %$content ) {
854                 my $syspref = $content->{$section};
855                 $append->($syspref);
856             }
857         }
858     }
859     return @names;
860 }
861
862
863 # Return an array containg all preferences defined in DB
864
865 sub get_prefs_from_db {
866     my $dbh = C4::Context->dbh;
867     my $sth = $dbh->prepare("SELECT variable FROM systempreferences");
868     $sth->execute;
869     my @names = ();
870     while ( (my $name) = $sth->fetchrow_array ) {
871         push @names, $name if $name;
872     }
873     return @names;
874 }
875
876
877 # Return an array containing all local preferences: those which are defined in
878 # DB and not defined in Koha .pref files.
879
880 sub get_local_prefs {
881     my @prefs_file = get_prefs_from_files();
882     my @prefs_db = get_prefs_from_db();
883
884     my %prefs_file = map { $_ => 1 } @prefs_file;
885     my @names = ();
886     foreach my $name (@prefs_db) {
887         push @names, $name  unless $prefs_file{$name};
888     }
889
890     return @names;
891 }
892