619a473cf908463d089603c8a4a5654f07493109
[koha_gimpoz] / 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{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";
216
217
218 # Staff Client
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";
230
231 # Patrons
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";
253
254
255 # I18N/L10N
256 $tabsysprefs{dateformat}    = "I18N/L10N";
257 $tabsysprefs{opaclanguages} = "I18N/L10N";
258 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
259 $tabsysprefs{language}      = "I18N/L10N";
260
261 # Searching
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";
278
279 # EnhancedContent
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";
292
293 # Babelthèque
294 $tabsysprefs{Babeltheque}            = "EnhancedContent";
295
296 # Baker & Taylor
297 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
298 $tabsysprefs{BakerTaylorEnabled}      = 'EnhancedContent';
299 $tabsysprefs{BakerTaylorPassword}     = 'EnhancedContent';
300 $tabsysprefs{BakerTaylorUsername}     = 'EnhancedContent';
301
302 # Library Thing for Libraries
303 $tabsysprefs{LibraryThingForLibrariesID} = "EnhancedContent";
304 $tabsysprefs{LibraryThingForLibrariesEnabled} = "EnhancedContent";
305 $tabsysprefs{LibraryThingForLibrariesTabbedView} = "EnhancedContent";
306
307 # Syndetics
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';
320
321
322 # FRBR
323 $tabsysprefs{FRBRizeEditions}     = "EnhancedContent";
324 $tabsysprefs{XISBN}               = "EnhancedContent";
325 $tabsysprefs{OCLCAffiliateID}     = "EnhancedContent";
326 $tabsysprefs{XISBNDailyLimit}     = "EnhancedContent";
327 $tabsysprefs{ThingISBN}           = "EnhancedContent";
328 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
329
330 # Tags
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";
340
341 # OPAC
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";
370
371 # 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";
395
396 # Serials
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";
404
405 # LOGFeatures
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";
413
414 # OAI-PMH variables
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";
420
421 # ILS-DI variables
422 $tabsysprefs{'ILS-DI'} = "ILS-DI";
423
424 # Creator variables
425
426 $tabsysprefs{'ImageLimit'} = "Creators";
427
428 sub StringSearch {
429     my ( $searchstring, $type ) = @_;
430     my $dbh = C4::Context->dbh;
431     $searchstring =~ s/\'/\\\'/g;
432     my @data = split( ' ', $searchstring );
433     my $count = @data;
434     my @results;
435     my $cnt = 0;
436     my $sth;
437
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 );
448                     $cnt++;
449                 }
450                 $sth->finish;
451             }
452         }
453     } else {
454         my $sth;
455
456         if ( $type and $type eq 'all' ) {
457             $sth = $dbh->prepare( "
458             SELECT *
459               FROM systempreferences
460               WHERE variable LIKE ? OR explanation LIKE ?
461               ORDER BY VARIABLE" );
462             $sth->execute( "%$searchstring%", "%$searchstring%" );
463         } else {
464             my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable in (";
465             my $first = 1;
466             for my $name ( get_local_prefs() ) {
467                 $strsth .= ',' unless $first;
468                 $strsth .= "'$name'";
469                 $first = 0;
470             }
471             $strsth .= ") order by variable";
472             $sth = $dbh->prepare($strsth);
473             $sth->execute();
474         }
475
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 );
480             $cnt++;
481         }
482
483         $sth->finish;
484     }
485     return ( $cnt, \@results );
486 }
487
488 sub GetPrefParams {
489     my $data   = shift;
490     my $params = $data;
491     my @options;
492
493     if ( defined $data->{'options'} ) {
494         foreach my $option ( split( /\|/, $data->{'options'} ) ) {
495             my $selected = '0';
496             defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
497             push @options, { option => $option, selected => $selected };
498         }
499     }
500
501     $params->{'prefoptions'} = $data->{'options'};
502
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;
515         } else {
516             $params->{'value-no'} = 1;
517         }
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;
528         my $type = '';
529         ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
530         @options = ();
531         my $currently_selected_themes;
532         my $counter = 0;
533         foreach my $theme ( split /\s+/, $data->{'value'} ) {
534             push @options, { option => $theme, counter => $counter };
535             $currently_selected_themes->{$theme} = 1;
536             $counter++;
537         }
538         foreach my $theme ( getallthemes($type) ) {
539             my $selected = '0';
540             next if $currently_selected_themes->{$theme};
541             push @options, { option => $theme, counter => $counter };
542             $counter++;
543         }
544     } elsif ( $data->{'type'} eq 'ClassSources' ) {
545         $params->{'type-choice'} = 1;
546         my $type = '';
547         @options = ();
548         my $sources = GetClassSources();
549         my $counter = 0;
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 };
553             } else {
554                 push @options, { option => $cn_source, counter => $counter };
555             }
556             $counter++;
557         }
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;
562         }
563
564         # current language
565         my $lang = $params->{'lang'};
566         my $theme;
567         my $interface;
568         if ( $data->{'variable'} =~ /opac/ ) {
569
570             # this is the OPAC
571             $interface = 'opac';
572             $theme     = C4::Context->preference('opacthemes');
573         } else {
574
575             # this is the staff client
576             $interface = 'intranet';
577             $theme     = C4::Context->preference('template');
578         }
579         my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
580
581         $params->{'languages_loop'}    = $languages_loop;
582         $params->{'type-langselector'} = 1;
583     } else {
584         $params->{'type-free'} = 1;
585         $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
586     }
587
588     if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
589         $params->{'oneline'} = 1;
590     }
591
592     $params->{'preftype'} = $data->{'type'};
593     $params->{'options'}  = \@options;
594
595     return $params;
596 }
597
598 my $input       = new CGI;
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";
603
604 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
605     {   template_name   => "admin/systempreferences.tmpl",
606         query           => $input,
607         type            => "intranet",
608         authnotrequired => 0,
609         flagsrequired   => { parameters => 1 },
610         debug           => 1,
611     }
612 );
613 my $pagesize = 100;
614 my $op = $input->param('op') || '';
615 $searchfield =~ s/\,//g;
616
617 if ($op) {
618     $template->param(
619         script_name => $script_name,
620         $op         => 1
621     );    # we show only the TMPL_VAR names $op
622 } else {
623     $template->param(
624         script_name => $script_name,
625         else        => 1
626     );    # we show only the TMPL_VAR names $op
627 }
628
629 if ( $op eq 'update_and_reedit' ) {
630     foreach ( $input->param ) {
631     }
632     my $value = '';
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;
641                 $orderchanged           = 1;
642                 last;
643             } elsif ( $param =~ m#down-(\d+).x# ) {
644                 my $temp = $currentorder[$1];
645                 $currentorder[$1]       = $currentorder[ $1 + 1 ];
646                 $currentorder[ $1 + 1 ] = $temp;
647                 $orderchanged           = 1;
648                 last;
649             }
650         }
651         $value = join ' ', @currentorder;
652         if ($orderchanged) {
653             $op = 'add_form';
654             $template->param(
655                 script_name => $script_name,
656                 $op         => 1
657             );    # we show only the TMPL_VAR names $op
658         } else {
659             $op          = '';
660             $searchfield = '';
661             $template->param(
662                 script_name => $script_name,
663                 else        => 1
664             );    # we show only the TMPL_VAR names $op
665         }
666     }
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') );
671     if ( $sth->rows ) {
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') );
675             $sth->finish;
676             logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
677         }
678     } else {
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') );
682             $sth->finish;
683             logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
684         }
685     }
686     $sth->finish;
687
688 }
689
690 ################## ADD_FORM ##################################
691 # called by default. Used to create form to add or  modify a record
692
693 if ( $op eq 'add_form' ) {
694
695     #---- if primkey exists, it's a modify action, so read values to modify...
696     my $data;
697     if ($searchfield) {
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;
702         $sth->finish;
703         $template->param( modify => 1 );
704
705         # save tab to return to if user cancels edit
706         $template->param( return_tab => $tabsysprefs{$searchfield} );
707     }
708
709     $data->{'lang'} = $template->param('lang');
710
711     $template->param( GetPrefParams($data) );
712
713     $template->param( searchfield => $searchfield );
714
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') );
721
722     # to handle multiple values
723     my $value;
724
725     # handle multiple value strings (separated by ',')
726     my $params = $input->Vars;
727     if ( defined $params->{'value'} ) {
728         my @values = ();
729         @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
730         if (@values) {
731             $value = "";
732             for my $vl (@values) {
733                 $value .= "$vl,";
734             }
735             $value =~ s/,$//;
736         } else {
737             $value = $params->{'value'};
738         }
739     }
740
741     if ( $input->param('preftype') eq 'Upload' ) {
742         my $lgtfh = $input->upload('value');
743         $value = join '', <$lgtfh>;
744         $value = encode_base64($value);
745     }
746
747     if ( $sth->rows ) {
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') );
751             $sth->finish;
752             logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
753         }
754     } else {
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') );
758             $sth->finish;
759             logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
760         }
761     }
762     $sth->finish;
763     print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
764     exit;
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;
772     $sth->finish;
773     $template->param(
774         searchfield => $searchfield,
775         Tvalue      => $data->{'value'},
776     );
777
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 );
787     $sth->finish;
788
789     # END $OP eq DELETE_CONFIRMED
790 ################## DEFAULT ##################################
791 } else {    # 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 );
796     my @loop_data = ();
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&amp;searchfield=" . $results->[$i]{'variable'};
802         $row_data->{delete} = "$script_name?op=delete_confirm&amp;searchfield=" . $results->[$i]{'variable'};
803         push( @loop_data, $row_data );
804     }
805     $tab = ( $tab ? $tab : "local-use" );
806     $template->param( loop => \@loop_data, $tab => 1 );
807     if ( $offset > 0 ) {
808         my $prevpage = $offset - $pagesize;
809         $template->param( "<a href=$script_name?offset=" . $prevpage . '&lt;&lt; Prev</a>' );
810     }
811     if ( $offset + $pagesize < $count ) {
812         my $nextpage = $offset + $pagesize;
813         $template->param( "a href=$script_name?offset=" . $nextpage . 'Next &gt;&gt;</a>' );
814     }
815     $template->param( tab => $tab, );
816 }    #---- END $OP eq DEFAULT
817 output_html_with_http_headers $input, $cookie, $template->output;
818
819
820 # Return an array containing all preferences defined in current Koha instance
821 # .pref files.
822
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);
830     close $fh;
831
832     my @names = ();
833     my $append = sub {
834         my $prefs = shift;
835         for my $pref ( @$prefs ) {
836             for my $element ( @$pref ) {
837                 if ( ref( $element) eq 'HASH' ) {
838                     my $name = $element->{pref};
839                     next unless $name;
840                     push @names, $name;
841                     next;
842                 }
843             }
844         }
845     };
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' ) {
851                 $append->($content);
852                 next;
853             }
854             for my $section ( keys %$content ) {
855                 my $syspref = $content->{$section};
856                 $append->($syspref);
857             }
858         }
859     }
860     return @names;
861 }
862
863
864 # Return an array containg all preferences defined in DB
865
866 sub get_prefs_from_db {
867     my $dbh = C4::Context->dbh;
868     my $sth = $dbh->prepare("SELECT variable FROM systempreferences");
869     $sth->execute;
870     my @names = ();
871     while ( (my $name) = $sth->fetchrow_array ) {
872         push @names, $name if $name;
873     }
874     return @names;
875 }
876
877
878 # Return an array containing all local preferences: those which are defined in
879 # DB and not defined in Koha .pref files.
880
881 sub get_local_prefs {
882     my @prefs_file = get_prefs_from_files();
883     my @prefs_db = get_prefs_from_db();
884
885     my %prefs_file = map { $_ => 1 } @prefs_file;
886     my @names = ();
887     foreach my $name (@prefs_db) {
888         push @names, $name  unless $prefs_file{$name};
889     }
890
891     return @names;
892 }
893