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