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