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
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 with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
24 =head1 systempreferences.pl
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.
32 - if primkey exists, this is a modification,so we read the $primkey record
33 - builds the add/modify form
35 - the user has just send datas, so we create/modify the record
37 - we show the record having primkey=$primkey and ask for deletion validation form
39 - we delete the record having primkey=$primkey
51 use C4::Languages qw(getTranslatedLanguages);
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;
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).
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";
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";
103 $tabsysprefs{authoritysep} = "Authorities";
104 $tabsysprefs{AuthDisplayHierarchy} = "Authorities";
105 $tabsysprefs{dontmerge} = "Authorities";
106 $tabsysprefs{BiblioAddsAuthorities} = "Authorities";
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";
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";
184 $tabsysprefs{TemplateEncoding} = "StaffClient";
185 $tabsysprefs{template} = "StaffClient";
186 $tabsysprefs{intranetstylesheet} = "StaffClient";
187 $tabsysprefs{IntranetNav} = "StaffClient";
188 $tabsysprefs{intranetcolorstylesheet} = "StaffClient";
189 $tabsysprefs{intranetuserjs} = "StaffClient";
190 $tabsysprefs{yuipath} = "StaffClient";
191 $tabsysprefs{IntranetmainUserblock} = "StaffClient";
192 $tabsysprefs{viewMARC} = "StaffClient";
193 $tabsysprefs{viewLabeledMARC} = "StaffClient";
194 $tabsysprefs{viewISBD} = "StaffClient";
197 $tabsysprefs{autoMemberNum} = "Patrons";
198 $tabsysprefs{checkdigit} = "Patrons";
199 $tabsysprefs{intranetreadinghistory} = "Patrons";
200 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
201 $tabsysprefs{memberofinstitution} = "Patrons";
202 $tabsysprefs{ReadingHistory} = "Patrons";
203 $tabsysprefs{BorrowerMandatoryField} = "Patrons";
204 $tabsysprefs{borrowerRelationship} = "Patrons";
205 $tabsysprefs{BorrowersTitles} = "Patrons";
206 $tabsysprefs{patronimages} = "Patrons";
207 $tabsysprefs{minPasswordLength} = "Patrons";
208 $tabsysprefs{uppercasesurnames} = "Patrons";
209 $tabsysprefs{MaxFine} = "Patrons";
210 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
211 $tabsysprefs{AddPatronLists} = "Patrons";
212 $tabsysprefs{PatronsPerPage} = "Patrons";
213 $tabsysprefs{ExtendedPatronAttributes} = "Patrons";
214 $tabsysprefs{AutoEmailOpacUser} = "Patrons";
215 $tabsysprefs{AutoEmailPrimaryAddress} = "Patrons";
216 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
217 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
218 $tabsysprefs{HidePatronName} = "Patrons";
222 $tabsysprefs{dateformat} = "I18N/L10N";
223 $tabsysprefs{opaclanguages} = "I18N/L10N";
224 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
225 $tabsysprefs{language} = "I18N/L10N";
228 $tabsysprefs{defaultSortField} = "Searching";
229 $tabsysprefs{defaultSortOrder} = "Searching";
230 $tabsysprefs{numSearchResults} = "Searching";
231 $tabsysprefs{OPACdefaultSortField} = "Searching";
232 $tabsysprefs{OPACdefaultSortOrder} = "Searching";
233 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
234 $tabsysprefs{OPACnumSearchResults} = "Searching";
235 $tabsysprefs{QueryFuzzy} = "Searching";
236 $tabsysprefs{QueryStemming} = "Searching";
237 $tabsysprefs{QueryWeightFields} = "Searching";
238 $tabsysprefs{expandedSearchOption} = "Searching";
239 $tabsysprefs{sortbynonfiling} = "Searching";
240 $tabsysprefs{QueryAutoTruncate} = "Searching";
241 $tabsysprefs{QueryRemoveStopwords} = "Searching";
242 $tabsysprefs{AdvancedSearchTypes} = "Searching";
245 $tabsysprefs{AmazonEnabled} = "EnhancedContent";
246 $tabsysprefs{OPACAmazonEnabled} = "EnhancedContent";
247 $tabsysprefs{AmazonCoverImages} = "EnhancedContent";
248 $tabsysprefs{OPACAmazonCoverImages} = "EnhancedContent";
249 $tabsysprefs{AWSAccessKeyID} = "EnhancedContent";
250 $tabsysprefs{AWSPrivateKey} = "EnhancedContent";
251 $tabsysprefs{AmazonLocale} = "EnhancedContent";
252 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
253 $tabsysprefs{AmazonSimilarItems} = "EnhancedContent";
254 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
255 $tabsysprefs{AmazonReviews} = "EnhancedContent";
256 $tabsysprefs{OPACAmazonReviews} = "EnhancedContent";
259 $tabsysprefs{Babeltheque} = "EnhancedContent";
262 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
263 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
264 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
265 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
267 # Library Thing for Libraries
268 $tabsysprefs{LibraryThingForLibrariesID} = "EnhancedContent";
269 $tabsysprefs{LibraryThingForLibrariesEnabled} = "EnhancedContent";
270 $tabsysprefs{LibraryThingForLibrariesTabbedView} = "EnhancedContent";
273 $tabsysprefs{SyndeticsClientCode} = 'EnhancedContent';
274 $tabsysprefs{SyndeticsEnabled} = 'EnhancedContent';
275 $tabsysprefs{SyndeticsCoverImages} = 'EnhancedContent';
276 $tabsysprefs{SyndeticsTOC} = 'EnhancedContent';
277 $tabsysprefs{SyndeticsSummary} = 'EnhancedContent';
278 $tabsysprefs{SyndeticsEditions} = 'EnhancedContent';
279 $tabsysprefs{SyndeticsExcerpt} = 'EnhancedContent';
280 $tabsysprefs{SyndeticsReviews} = 'EnhancedContent';
281 $tabsysprefs{SyndeticsAuthorNotes} = 'EnhancedContent';
282 $tabsysprefs{SyndeticsAwards} = 'EnhancedContent';
283 $tabsysprefs{SyndeticsSeries} = 'EnhancedContent';
284 $tabsysprefs{SyndeticsCoverImageSize} = 'EnhancedContent';
288 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
289 $tabsysprefs{XISBN} = "EnhancedContent";
290 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
291 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
292 $tabsysprefs{PINESISBN} = "EnhancedContent";
293 $tabsysprefs{ThingISBN} = "EnhancedContent";
294 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
297 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
298 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
299 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
300 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
301 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
302 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
303 $tabsysprefs{TagsModeration} = 'EnhancedContent';
304 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
305 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
308 $tabsysprefs{BiblioDefaultView} = "OPAC";
309 $tabsysprefs{LibraryName} = "OPAC";
310 $tabsysprefs{opaccolorstylesheet} = "OPAC";
311 $tabsysprefs{opaccredits} = "OPAC";
312 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
313 $tabsysprefs{OpacNav} = "OPAC";
314 $tabsysprefs{opacsmallimage} = "OPAC";
315 $tabsysprefs{opacstylesheet} = "OPAC";
316 $tabsysprefs{opacthemes} = "OPAC";
317 $tabsysprefs{opacuserjs} = "OPAC";
318 $tabsysprefs{opacheader} = "OPAC";
319 $tabsysprefs{hideBiblioNumber} = "OPAC";
320 $tabsysprefs{OpacMainUserBlock} = "OPAC";
321 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
322 $tabsysprefs{OPACUserCSS} = "OPAC";
323 $tabsysprefs{OPACHighlightedWords} = "OPAC";
324 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
325 $tabsysprefs{URLLinkText} = "OPAC";
326 $tabsysprefs{OPACSearchForTitleIn} = "OPAC";
327 $tabsysprefs{OPACShelfBrowser} = "OPAC";
328 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
329 $tabsysprefs{OPACAllowHoldDateInFuture} = "OPAC";
330 $tabsysprefs{OPACPatronDetails} = "OPAC";
331 $tabsysprefs{OPACFinesTab} = "OPAC";
332 $tabsysprefs{DisplayOPACiconsXSLT} = "OPAC";
335 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
336 $tabsysprefs{hidelostitems} = "OPAC";
337 $tabsysprefs{opacbookbag} = "OPAC";
338 $tabsysprefs{OpacPasswordChange} = "OPAC";
339 $tabsysprefs{opacreadinghistory} = "OPAC";
340 $tabsysprefs{virtualshelves} = "OPAC";
341 $tabsysprefs{RequestOnOpac} = "OPAC";
342 $tabsysprefs{reviewson} = "OPAC";
343 $tabsysprefs{OpacTopissues} = "OPAC";
344 $tabsysprefs{OpacAuthorities} = "OPAC";
345 $tabsysprefs{OpacCloud} = "OPAC";
346 $tabsysprefs{opacuserlogin} = "OPAC";
347 $tabsysprefs{AnonSuggestions} = "OPAC";
348 $tabsysprefs{suggestion} = "OPAC";
349 $tabsysprefs{OpacTopissue} = "OPAC";
350 $tabsysprefs{OpacBrowser} = "OPAC";
351 $tabsysprefs{kohaspsuggest} = "OPAC";
352 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
353 $tabsysprefs{OPACItemHolds} = "OPAC";
354 $tabsysprefs{OPACGroupResults} = "OPAC";
355 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
356 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
357 $tabsysprefs{OPACShowCheckoutName} = "OPAC";
360 $tabsysprefs{RoutingListAddReserves} = "Serials";
361 $tabsysprefs{OPACSerialIssueDisplayCount} = "Serials";
362 $tabsysprefs{StaffSerialIssueDisplayCount} = "Serials";
363 $tabsysprefs{OPACDisplayExtendedSubInfo} = "Serials";
364 $tabsysprefs{OPACSubscriptionDisplay} = "Serials";
365 $tabsysprefs{RenewSerialAddsSuggestion} = "Serials";
366 $tabsysprefs{SubscriptionHistory} = "Serials";
369 $tabsysprefs{CataloguingLog} = "Logs";
370 $tabsysprefs{BorrowersLog} = "Logs";
371 $tabsysprefs{SubscriptionLog} = "Logs";
372 $tabsysprefs{IssueLog} = "Logs";
373 $tabsysprefs{ReturnLog} = "Logs";
374 $tabsysprefs{LetterLog} = "Logs";
375 $tabsysprefs{FinesLog} = "Logs";
378 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
379 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
380 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
381 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
382 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
385 $tabsysprefs{'ILS-DI'} = "ILS-DI";
389 $tabsysprefs{'ImageLimit'} = "Creators";
392 my ( $searchstring, $type ) = @_;
393 my $dbh = C4::Context->dbh;
394 $searchstring =~ s/\'/\\\'/g;
395 my @data = split( ' ', $searchstring );
401 # used for doing a plain-old sys-pref search
402 if ( $type && $type ne 'all' ) {
403 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
404 if ( $tabsysprefs{$syspref} eq $type ) {
405 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
406 $sth->execute($syspref);
407 while ( my $data = $sth->fetchrow_hashref ) {
408 $data->{shortvalue} = $data->{value};
409 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
410 push( @results, $data );
419 if ( $type and $type eq 'all' ) {
420 $sth = $dbh->prepare( "
422 FROM systempreferences
423 WHERE variable LIKE ? OR explanation LIKE ?
424 ORDER BY VARIABLE" );
425 $sth->execute( "%$searchstring%", "%$searchstring%" );
427 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable not in (";
428 foreach my $syspref ( keys %tabsysprefs ) {
429 $strsth .= $dbh->quote($syspref) . ",";
432 $strsth .= " order by variable";
433 $sth = $dbh->prepare($strsth);
437 while ( my $data = $sth->fetchrow_hashref ) {
438 $data->{shortvalue} = $data->{value};
439 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
440 push( @results, $data );
446 return ( $cnt, \@results );
454 if ( defined $data->{'options'} ) {
455 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
457 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
458 push @options, { option => $option, selected => $selected };
462 $params->{'prefoptions'} = $data->{'options'};
464 if ( not defined( $data->{'type'} ) ) {
465 $params->{'type-free'} = 1;
466 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
467 } elsif ( $data->{'type'} eq 'Upload' ) {
468 $params->{'type-upload'} = 1;
469 } elsif ( $data->{'type'} eq 'Choice' ) {
470 $params->{'type-choice'} = 1;
471 } elsif ( $data->{'type'} eq 'YesNo' ) {
472 $params->{'type-yesno'} = 1;
473 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
474 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
475 $params->{'value-yes'} = 1;
477 $params->{'value-no'} = 1;
479 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
480 $params->{'type-free'} = 1;
481 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
482 } elsif ( $data->{'type'} eq 'Textarea' ) {
483 $params->{'type-textarea'} = 1;
484 $data->{options} =~ /(.*)\|(.*)/;
485 $params->{'cols'} = $1;
486 $params->{'rows'} = $2;
487 } elsif ( $data->{'type'} eq 'Themes' ) {
488 $params->{'type-choice'} = 1;
490 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
492 my $currently_selected_themes;
494 foreach my $theme ( split /\s+/, $data->{'value'} ) {
495 push @options, { option => $theme, counter => $counter };
496 $currently_selected_themes->{$theme} = 1;
499 foreach my $theme ( getallthemes($type) ) {
501 next if $currently_selected_themes->{$theme};
502 push @options, { option => $theme, counter => $counter };
505 } elsif ( $data->{'type'} eq 'ClassSources' ) {
506 $params->{'type-choice'} = 1;
509 my $sources = GetClassSources();
511 foreach my $cn_source ( sort keys %$sources ) {
512 if ( $cn_source eq $data->{'value'} ) {
513 push @options, { option => $cn_source, counter => $counter, selected => 1 };
515 push @options, { option => $cn_source, counter => $counter };
519 } elsif ( $data->{'type'} eq 'Languages' ) {
520 my $currently_selected_languages;
521 foreach my $language ( split /\s+/, $data->{'value'} ) {
522 $currently_selected_languages->{$language} = 1;
526 my $lang = $params->{'lang'};
529 if ( $data->{'variable'} =~ /opac/ ) {
533 $theme = C4::Context->preference('opacthemes');
536 # this is the staff client
537 $interface = 'intranet';
538 $theme = C4::Context->preference('template');
540 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
542 $params->{'languages_loop'} = $languages_loop;
543 $params->{'type-langselector'} = 1;
545 $params->{'type-free'} = 1;
546 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
549 if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
550 $params->{'oneline'} = 1;
553 $params->{'preftype'} = $data->{'type'};
554 $params->{'options'} = \@options;
560 my $searchfield = $input->param('searchfield') || '';
561 my $Tvalue = $input->param('Tvalue');
562 my $offset = $input->param('offset') || 0;
563 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
565 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
566 { template_name => "admin/systempreferences.tmpl",
569 authnotrequired => 0,
570 flagsrequired => { parameters => 1 },
575 my $op = $input->param('op') || '';
576 $searchfield =~ s/\,//g;
580 script_name => $script_name,
582 ); # we show only the TMPL_VAR names $op
585 script_name => $script_name,
587 ); # we show only the TMPL_VAR names $op
590 if ( $op eq 'update_and_reedit' ) {
591 foreach ( $input->param ) {
594 if ( my $currentorder = $input->param('currentorder') ) {
595 my @currentorder = split /\|/, $currentorder;
596 my $orderchanged = 0;
597 foreach my $param ( $input->param ) {
598 if ( $param =~ m#up-(\d+).x# ) {
599 my $temp = $currentorder[$1];
600 $currentorder[$1] = $currentorder[ $1 - 1 ];
601 $currentorder[ $1 - 1 ] = $temp;
604 } elsif ( $param =~ m#down-(\d+).x# ) {
605 my $temp = $currentorder[$1];
606 $currentorder[$1] = $currentorder[ $1 + 1 ];
607 $currentorder[ $1 + 1 ] = $temp;
612 $value = join ' ', @currentorder;
616 script_name => $script_name,
618 ); # we show only the TMPL_VAR names $op
623 script_name => $script_name,
625 ); # we show only the TMPL_VAR names $op
628 my $dbh = C4::Context->dbh;
629 my $query = "select * from systempreferences where variable=?";
630 my $sth = $dbh->prepare($query);
631 $sth->execute( $input->param('variable') );
633 unless ( C4::Context->config('demo') ) {
634 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
635 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
637 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
640 unless ( C4::Context->config('demo') ) {
641 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
642 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
644 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
651 ################## ADD_FORM ##################################
652 # called by default. Used to create form to add or modify a record
654 if ( $op eq 'add_form' ) {
656 #---- if primkey exists, it's a modify action, so read values to modify...
659 my $dbh = C4::Context->dbh;
660 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
661 $sth->execute($searchfield);
662 $data = $sth->fetchrow_hashref;
664 $template->param( modify => 1 );
666 # save tab to return to if user cancels edit
667 $template->param( return_tab => $tabsysprefs{$searchfield} );
670 $data->{'lang'} = $template->param('lang');
672 $template->param( GetPrefParams($data) );
674 $template->param( searchfield => $searchfield );
676 ################## ADD_VALIDATE ##################################
677 # called by add_form, used to insert/modify data in DB
678 } elsif ( $op eq 'add_validate' ) {
679 my $dbh = C4::Context->dbh;
680 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
681 $sth->execute( $input->param('variable') );
683 # to handle multiple values
686 # handle multiple value strings (separated by ',')
687 my $params = $input->Vars;
688 if ( defined $params->{'value'} ) {
690 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
693 for my $vl (@values) {
698 $value = $params->{'value'};
702 if ( $input->param('preftype') eq 'Upload' ) {
703 my $lgtfh = $input->upload('value');
704 $value = join '', <$lgtfh>;
705 $value = encode_base64($value);
709 unless ( C4::Context->config('demo') ) {
710 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
711 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
713 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
716 unless ( C4::Context->config('demo') ) {
717 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
718 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
720 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
724 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
726 ################## DELETE_CONFIRM ##################################
727 # called by default form, used to confirm deletion of data in DB
728 } elsif ( $op eq 'delete_confirm' ) {
729 my $dbh = C4::Context->dbh;
730 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
731 $sth->execute($searchfield);
732 my $data = $sth->fetchrow_hashref;
735 searchfield => $searchfield,
736 Tvalue => $data->{'value'},
739 # END $OP eq DELETE_CONFIRM
740 ################## DELETE_CONFIRMED ##################################
741 # called by delete_confirm, used to effectively confirm deletion of data in DB
742 } elsif ( $op eq 'delete_confirmed' ) {
743 my $dbh = C4::Context->dbh;
744 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
745 $sth->execute($searchfield);
746 my $logstring = $searchfield . " | " . $Tvalue;
747 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
750 # END $OP eq DELETE_CONFIRMED
751 ################## DEFAULT ##################################
753 #Adding tab management for system preferences
754 my $tab = $input->param('tab');
755 $template->param( $tab => 1 );
756 my ( $count, $results ) = StringSearch( $searchfield, $tab );
758 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
759 my $row_data = $results->[$i];
760 $row_data->{'lang'} = $template->param('lang');
761 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
762 $row_data->{edit} = "$script_name?op=add_form&searchfield=" . $results->[$i]{'variable'};
763 $row_data->{delete} = "$script_name?op=delete_confirm&searchfield=" . $results->[$i]{'variable'};
764 push( @loop_data, $row_data );
766 $tab = ( $tab ? $tab : "Local Use" );
767 $template->param( loop => \@loop_data, $tab => 1 );
769 my $prevpage = $offset - $pagesize;
770 $template->param( "<a href=$script_name?offset=" . $prevpage . '<< Prev</a>' );
772 if ( $offset + $pagesize < $count ) {
773 my $nextpage = $offset + $pagesize;
774 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next >></a>' );
776 $template->param( tab => $tab, );
777 } #---- END $OP eq DEFAULT
778 output_html_with_http_headers $input, $cookie, $template->output;