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