BUG 4499: Javascript error messages not translatable
[koha.git] / admin / systempreferences.pl
blobecdfa053027d6f9dd35da88034a3c5e55474fd03
1 #!/usr/bin/perl
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)
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
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.
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.
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.
24 =head1 systempreferences.pl
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
41 =cut
43 use strict;
44 use warnings;
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;
56 # use Smart::Comments;
58 # FIXME, shouldnt we store this stuff in the systempreferences table?
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 ...)];
65 # Because some things *should* be on more than one tab.
66 # And the tabname is the unique part (the key).
68 my %tabsysprefs;
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";
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";
102 # Authorities
103 $tabsysprefs{authoritysep} = "Authorities";
104 $tabsysprefs{AuthDisplayHierarchy} = "Authorities";
105 $tabsysprefs{dontmerge} = "Authorities";
106 $tabsysprefs{BiblioAddsAuthorities} = "Authorities";
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";
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";
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";
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";
222 # I18N/L10N
223 $tabsysprefs{dateformat} = "I18N/L10N";
224 $tabsysprefs{opaclanguages} = "I18N/L10N";
225 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
226 $tabsysprefs{language} = "I18N/L10N";
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 $tabsysprefs{DisplayMultiPlaceHold} = "Searching";
246 # EnhancedContent
247 $tabsysprefs{AmazonEnabled} = "EnhancedContent";
248 $tabsysprefs{OPACAmazonEnabled} = "EnhancedContent";
249 $tabsysprefs{AmazonCoverImages} = "EnhancedContent";
250 $tabsysprefs{OPACAmazonCoverImages} = "EnhancedContent";
251 $tabsysprefs{AWSAccessKeyID} = "EnhancedContent";
252 $tabsysprefs{AWSPrivateKey} = "EnhancedContent";
253 $tabsysprefs{AmazonLocale} = "EnhancedContent";
254 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
255 $tabsysprefs{AmazonSimilarItems} = "EnhancedContent";
256 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
257 $tabsysprefs{AmazonReviews} = "EnhancedContent";
258 $tabsysprefs{OPACAmazonReviews} = "EnhancedContent";
260 # Babelthèque
261 $tabsysprefs{Babeltheque} = "EnhancedContent";
263 # Baker & Taylor
264 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
265 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
266 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
267 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
269 # Library Thing for Libraries
270 $tabsysprefs{LibraryThingForLibrariesID} = "EnhancedContent";
271 $tabsysprefs{LibraryThingForLibrariesEnabled} = "EnhancedContent";
272 $tabsysprefs{LibraryThingForLibrariesTabbedView} = "EnhancedContent";
274 # Syndetics
275 $tabsysprefs{SyndeticsClientCode} = 'EnhancedContent';
276 $tabsysprefs{SyndeticsEnabled} = 'EnhancedContent';
277 $tabsysprefs{SyndeticsCoverImages} = 'EnhancedContent';
278 $tabsysprefs{SyndeticsTOC} = 'EnhancedContent';
279 $tabsysprefs{SyndeticsSummary} = 'EnhancedContent';
280 $tabsysprefs{SyndeticsEditions} = 'EnhancedContent';
281 $tabsysprefs{SyndeticsExcerpt} = 'EnhancedContent';
282 $tabsysprefs{SyndeticsReviews} = 'EnhancedContent';
283 $tabsysprefs{SyndeticsAuthorNotes} = 'EnhancedContent';
284 $tabsysprefs{SyndeticsAwards} = 'EnhancedContent';
285 $tabsysprefs{SyndeticsSeries} = 'EnhancedContent';
286 $tabsysprefs{SyndeticsCoverImageSize} = 'EnhancedContent';
289 # FRBR
290 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
291 $tabsysprefs{XISBN} = "EnhancedContent";
292 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
293 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
294 $tabsysprefs{PINESISBN} = "EnhancedContent";
295 $tabsysprefs{ThingISBN} = "EnhancedContent";
296 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
298 # Tags
299 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
300 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
301 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
302 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
303 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
304 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
305 $tabsysprefs{TagsModeration} = 'EnhancedContent';
306 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
307 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
309 # OPAC
310 $tabsysprefs{BiblioDefaultView} = "OPAC";
311 $tabsysprefs{LibraryName} = "OPAC";
312 $tabsysprefs{opaccolorstylesheet} = "OPAC";
313 $tabsysprefs{opaccredits} = "OPAC";
314 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
315 $tabsysprefs{OpacNav} = "OPAC";
316 $tabsysprefs{opacsmallimage} = "OPAC";
317 $tabsysprefs{opacstylesheet} = "OPAC";
318 $tabsysprefs{opacthemes} = "OPAC";
319 $tabsysprefs{opacuserjs} = "OPAC";
320 $tabsysprefs{opacheader} = "OPAC";
321 $tabsysprefs{hideBiblioNumber} = "OPAC";
322 $tabsysprefs{OpacMainUserBlock} = "OPAC";
323 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
324 $tabsysprefs{OPACUserCSS} = "OPAC";
325 $tabsysprefs{OPACHighlightedWords} = "OPAC";
326 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
327 $tabsysprefs{URLLinkText} = "OPAC";
328 $tabsysprefs{OPACSearchForTitleIn} = "OPAC";
329 $tabsysprefs{OPACShelfBrowser} = "OPAC";
330 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
331 $tabsysprefs{OPACAllowHoldDateInFuture} = "OPAC";
332 $tabsysprefs{OPACPatronDetails} = "OPAC";
333 $tabsysprefs{OPACFinesTab} = "OPAC";
334 $tabsysprefs{DisplayOPACiconsXSLT} = "OPAC";
335 $tabsysprefs{AutoSelfCheckAllowed} = "OPAC";
336 $tabsysprefs{AutoSelfCheckID} = "OPAC";
337 $tabsysprefs{AutoSelfCheckPass} = "OPAC";
339 # OPAC
340 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
341 $tabsysprefs{hidelostitems} = "OPAC";
342 $tabsysprefs{opacbookbag} = "OPAC";
343 $tabsysprefs{OpacPasswordChange} = "OPAC";
344 $tabsysprefs{opacreadinghistory} = "OPAC";
345 $tabsysprefs{virtualshelves} = "OPAC";
346 $tabsysprefs{RequestOnOpac} = "OPAC";
347 $tabsysprefs{reviewson} = "OPAC";
348 $tabsysprefs{OpacTopissues} = "OPAC";
349 $tabsysprefs{OpacAuthorities} = "OPAC";
350 $tabsysprefs{OpacCloud} = "OPAC";
351 $tabsysprefs{opacuserlogin} = "OPAC";
352 $tabsysprefs{AnonSuggestions} = "OPAC";
353 $tabsysprefs{suggestion} = "OPAC";
354 $tabsysprefs{OpacTopissue} = "OPAC";
355 $tabsysprefs{OpacBrowser} = "OPAC";
356 $tabsysprefs{kohaspsuggest} = "OPAC";
357 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
358 $tabsysprefs{OPACItemHolds} = "OPAC";
359 $tabsysprefs{OPACGroupResults} = "OPAC";
360 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
361 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
362 $tabsysprefs{OPACShowCheckoutName} = "OPAC";
364 # Serials
365 $tabsysprefs{RoutingListAddReserves} = "Serials";
366 $tabsysprefs{OPACSerialIssueDisplayCount} = "Serials";
367 $tabsysprefs{StaffSerialIssueDisplayCount} = "Serials";
368 $tabsysprefs{OPACDisplayExtendedSubInfo} = "Serials";
369 $tabsysprefs{OPACSubscriptionDisplay} = "Serials";
370 $tabsysprefs{RenewSerialAddsSuggestion} = "Serials";
371 $tabsysprefs{SubscriptionHistory} = "Serials";
373 # LOGFeatures
374 $tabsysprefs{CataloguingLog} = "Logs";
375 $tabsysprefs{BorrowersLog} = "Logs";
376 $tabsysprefs{SubscriptionLog} = "Logs";
377 $tabsysprefs{IssueLog} = "Logs";
378 $tabsysprefs{ReturnLog} = "Logs";
379 $tabsysprefs{LetterLog} = "Logs";
380 $tabsysprefs{FinesLog} = "Logs";
382 # OAI-PMH variables
383 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
384 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
385 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
386 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
387 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
389 # ILS-DI variables
390 $tabsysprefs{'ILS-DI'} = "ILS-DI";
392 # Creator variables
394 $tabsysprefs{'ImageLimit'} = "Creators";
396 sub StringSearch {
397 my ( $searchstring, $type ) = @_;
398 my $dbh = C4::Context->dbh;
399 $searchstring =~ s/\'/\\\'/g;
400 my @data = split( ' ', $searchstring );
401 my $count = @data;
402 my @results;
403 my $cnt = 0;
404 my $sth;
406 # used for doing a plain-old sys-pref search
407 if ( $type && $type ne 'all' ) {
408 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
409 if ( $tabsysprefs{$syspref} eq $type ) {
410 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
411 $sth->execute($syspref);
412 while ( my $data = $sth->fetchrow_hashref ) {
413 $data->{shortvalue} = $data->{value};
414 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
415 push( @results, $data );
416 $cnt++;
418 $sth->finish;
421 } else {
422 my $sth;
424 if ( $type and $type eq 'all' ) {
425 $sth = $dbh->prepare( "
426 SELECT *
427 FROM systempreferences
428 WHERE variable LIKE ? OR explanation LIKE ?
429 ORDER BY VARIABLE" );
430 $sth->execute( "%$searchstring%", "%$searchstring%" );
431 } else {
432 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable not in (";
433 foreach my $syspref ( keys %tabsysprefs ) {
434 $strsth .= $dbh->quote($syspref) . ",";
436 $strsth =~ s/,$/) /;
437 $strsth .= " order by variable";
438 $sth = $dbh->prepare($strsth);
439 $sth->execute();
442 while ( my $data = $sth->fetchrow_hashref ) {
443 $data->{shortvalue} = $data->{value};
444 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
445 push( @results, $data );
446 $cnt++;
449 $sth->finish;
451 return ( $cnt, \@results );
454 sub GetPrefParams {
455 my $data = shift;
456 my $params = $data;
457 my @options;
459 if ( defined $data->{'options'} ) {
460 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
461 my $selected = '0';
462 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
463 push @options, { option => $option, selected => $selected };
467 $params->{'prefoptions'} = $data->{'options'};
469 if ( not defined( $data->{'type'} ) ) {
470 $params->{'type-free'} = 1;
471 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
472 } elsif ( $data->{'type'} eq 'Upload' ) {
473 $params->{'type-upload'} = 1;
474 } elsif ( $data->{'type'} eq 'Choice' ) {
475 $params->{'type-choice'} = 1;
476 } elsif ( $data->{'type'} eq 'YesNo' ) {
477 $params->{'type-yesno'} = 1;
478 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
479 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
480 $params->{'value-yes'} = 1;
481 } else {
482 $params->{'value-no'} = 1;
484 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
485 $params->{'type-free'} = 1;
486 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
487 } elsif ( $data->{'type'} eq 'Textarea' ) {
488 $params->{'type-textarea'} = 1;
489 $data->{options} =~ /(.*)\|(.*)/;
490 $params->{'cols'} = $1;
491 $params->{'rows'} = $2;
492 } elsif ( $data->{'type'} eq 'Themes' ) {
493 $params->{'type-choice'} = 1;
494 my $type = '';
495 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
496 @options = ();
497 my $currently_selected_themes;
498 my $counter = 0;
499 foreach my $theme ( split /\s+/, $data->{'value'} ) {
500 push @options, { option => $theme, counter => $counter };
501 $currently_selected_themes->{$theme} = 1;
502 $counter++;
504 foreach my $theme ( getallthemes($type) ) {
505 my $selected = '0';
506 next if $currently_selected_themes->{$theme};
507 push @options, { option => $theme, counter => $counter };
508 $counter++;
510 } elsif ( $data->{'type'} eq 'ClassSources' ) {
511 $params->{'type-choice'} = 1;
512 my $type = '';
513 @options = ();
514 my $sources = GetClassSources();
515 my $counter = 0;
516 foreach my $cn_source ( sort keys %$sources ) {
517 if ( $cn_source eq $data->{'value'} ) {
518 push @options, { option => $cn_source, counter => $counter, selected => 1 };
519 } else {
520 push @options, { option => $cn_source, counter => $counter };
522 $counter++;
524 } elsif ( $data->{'type'} eq 'Languages' ) {
525 my $currently_selected_languages;
526 foreach my $language ( split /\s+/, $data->{'value'} ) {
527 $currently_selected_languages->{$language} = 1;
530 # current language
531 my $lang = $params->{'lang'};
532 my $theme;
533 my $interface;
534 if ( $data->{'variable'} =~ /opac/ ) {
536 # this is the OPAC
537 $interface = 'opac';
538 $theme = C4::Context->preference('opacthemes');
539 } else {
541 # this is the staff client
542 $interface = 'intranet';
543 $theme = C4::Context->preference('template');
545 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
547 $params->{'languages_loop'} = $languages_loop;
548 $params->{'type-langselector'} = 1;
549 } else {
550 $params->{'type-free'} = 1;
551 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
554 if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
555 $params->{'oneline'} = 1;
558 $params->{'preftype'} = $data->{'type'};
559 $params->{'options'} = \@options;
561 return $params;
564 my $input = new CGI;
565 my $searchfield = $input->param('searchfield') || '';
566 my $Tvalue = $input->param('Tvalue');
567 my $offset = $input->param('offset') || 0;
568 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
570 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
571 { template_name => "admin/systempreferences.tmpl",
572 query => $input,
573 type => "intranet",
574 authnotrequired => 0,
575 flagsrequired => { parameters => 1 },
576 debug => 1,
579 my $pagesize = 100;
580 my $op = $input->param('op') || '';
581 $searchfield =~ s/\,//g;
583 if ($op) {
584 $template->param(
585 script_name => $script_name,
586 $op => 1
587 ); # we show only the TMPL_VAR names $op
588 } else {
589 $template->param(
590 script_name => $script_name,
591 else => 1
592 ); # we show only the TMPL_VAR names $op
595 if ( $op eq 'update_and_reedit' ) {
596 foreach ( $input->param ) {
598 my $value = '';
599 if ( my $currentorder = $input->param('currentorder') ) {
600 my @currentorder = split /\|/, $currentorder;
601 my $orderchanged = 0;
602 foreach my $param ( $input->param ) {
603 if ( $param =~ m#up-(\d+).x# ) {
604 my $temp = $currentorder[$1];
605 $currentorder[$1] = $currentorder[ $1 - 1 ];
606 $currentorder[ $1 - 1 ] = $temp;
607 $orderchanged = 1;
608 last;
609 } elsif ( $param =~ m#down-(\d+).x# ) {
610 my $temp = $currentorder[$1];
611 $currentorder[$1] = $currentorder[ $1 + 1 ];
612 $currentorder[ $1 + 1 ] = $temp;
613 $orderchanged = 1;
614 last;
617 $value = join ' ', @currentorder;
618 if ($orderchanged) {
619 $op = 'add_form';
620 $template->param(
621 script_name => $script_name,
622 $op => 1
623 ); # we show only the TMPL_VAR names $op
624 } else {
625 $op = '';
626 $searchfield = '';
627 $template->param(
628 script_name => $script_name,
629 else => 1
630 ); # we show only the TMPL_VAR names $op
633 my $dbh = C4::Context->dbh;
634 my $query = "select * from systempreferences where variable=?";
635 my $sth = $dbh->prepare($query);
636 $sth->execute( $input->param('variable') );
637 if ( $sth->rows ) {
638 unless ( C4::Context->config('demo') ) {
639 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
640 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
641 $sth->finish;
642 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
644 } else {
645 unless ( C4::Context->config('demo') ) {
646 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
647 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
648 $sth->finish;
649 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
652 $sth->finish;
656 ################## ADD_FORM ##################################
657 # called by default. Used to create form to add or modify a record
659 if ( $op eq 'add_form' ) {
661 #---- if primkey exists, it's a modify action, so read values to modify...
662 my $data;
663 if ($searchfield) {
664 my $dbh = C4::Context->dbh;
665 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
666 $sth->execute($searchfield);
667 $data = $sth->fetchrow_hashref;
668 $sth->finish;
669 $template->param( modify => 1 );
671 # save tab to return to if user cancels edit
672 $template->param( return_tab => $tabsysprefs{$searchfield} );
675 $data->{'lang'} = $template->param('lang');
677 $template->param( GetPrefParams($data) );
679 $template->param( searchfield => $searchfield );
681 ################## ADD_VALIDATE ##################################
682 # called by add_form, used to insert/modify data in DB
683 } elsif ( $op eq 'add_validate' ) {
684 my $dbh = C4::Context->dbh;
685 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
686 $sth->execute( $input->param('variable') );
688 # to handle multiple values
689 my $value;
691 # handle multiple value strings (separated by ',')
692 my $params = $input->Vars;
693 if ( defined $params->{'value'} ) {
694 my @values = ();
695 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
696 if (@values) {
697 $value = "";
698 for my $vl (@values) {
699 $value .= "$vl,";
701 $value =~ s/,$//;
702 } else {
703 $value = $params->{'value'};
707 if ( $input->param('preftype') eq 'Upload' ) {
708 my $lgtfh = $input->upload('value');
709 $value = join '', <$lgtfh>;
710 $value = encode_base64($value);
713 if ( $sth->rows ) {
714 unless ( C4::Context->config('demo') ) {
715 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
716 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
717 $sth->finish;
718 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
720 } else {
721 unless ( C4::Context->config('demo') ) {
722 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
723 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
724 $sth->finish;
725 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
728 $sth->finish;
729 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
730 exit;
731 ################## DELETE_CONFIRM ##################################
732 # called by default form, used to confirm deletion of data in DB
733 } elsif ( $op eq 'delete_confirm' ) {
734 my $dbh = C4::Context->dbh;
735 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
736 $sth->execute($searchfield);
737 my $data = $sth->fetchrow_hashref;
738 $sth->finish;
739 $template->param(
740 searchfield => $searchfield,
741 Tvalue => $data->{'value'},
744 # END $OP eq DELETE_CONFIRM
745 ################## DELETE_CONFIRMED ##################################
746 # called by delete_confirm, used to effectively confirm deletion of data in DB
747 } elsif ( $op eq 'delete_confirmed' ) {
748 my $dbh = C4::Context->dbh;
749 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
750 $sth->execute($searchfield);
751 my $logstring = $searchfield . " | " . $Tvalue;
752 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
753 $sth->finish;
755 # END $OP eq DELETE_CONFIRMED
756 ################## DEFAULT ##################################
757 } else { # DEFAULT
758 #Adding tab management for system preferences
759 my $tab = $input->param('tab');
760 $template->param( $tab => 1 );
761 my ( $count, $results ) = StringSearch( $searchfield, $tab );
762 my @loop_data = ();
763 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
764 my $row_data = $results->[$i];
765 $row_data->{'lang'} = $template->param('lang');
766 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
767 $row_data->{edit} = "$script_name?op=add_form&amp;searchfield=" . $results->[$i]{'variable'};
768 $row_data->{delete} = "$script_name?op=delete_confirm&amp;searchfield=" . $results->[$i]{'variable'};
769 push( @loop_data, $row_data );
771 $tab = ( $tab ? $tab : "Local Use" );
772 $template->param( loop => \@loop_data, $tab => 1 );
773 if ( $offset > 0 ) {
774 my $prevpage = $offset - $pagesize;
775 $template->param( "<a href=$script_name?offset=" . $prevpage . '&lt;&lt; Prev</a>' );
777 if ( $offset + $pagesize < $count ) {
778 my $nextpage = $offset + $pagesize;
779 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next &gt;&gt;</a>' );
781 $template->param( tab => $tab, );
782 } #---- END $OP eq DEFAULT
783 output_html_with_http_headers $input, $cookie, $template->output;