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
50 use C4
::Languages
qw(getTranslatedLanguages);
55 # use Smart::Comments;
57 # FIXME, shouldnt we store this stuff in the systempreferences table?
59 # FIXME: This uses hash in a backwards way. What we really want is:
60 # $tabsysprefs{key} = $array_ref;
62 # $tabsysprefs{Cataloguing} = [qw(autoBarcode ISBD marc ...)];
64 # Because some things *should* be on more than one tab.
65 # And the tabname is the unique part (the key).
70 $tabsysprefs{acquisitions
}="Acquisitions";
71 $tabsysprefs{gist
}="Acquisitions";
72 $tabsysprefs{emailPurchaseSuggestions
}="Acquisitions";
73 $tabsysprefs{RenewSerialAddsSuggestion
}="Acquisitions";
74 $tabsysprefs{AcqCreateItem
}="Acquisitions";
75 $tabsysprefs{pdfformat
}="Acquisitions";
76 $tabsysprefs{CurrencyFormat
}="Acquisitions";
79 $tabsysprefs{singleBranchMode
} = "Admin";
80 $tabsysprefs{staffClientBaseURL
} = "Admin";
81 $tabsysprefs{Version
} = "Admin";
82 $tabsysprefs{OpacMaintenance
} = "Admin";
83 $tabsysprefs{FrameworksLoaded
} = "Admin";
84 $tabsysprefs{libraryAddress
} = "Admin";
85 $tabsysprefs{delimiter
} = "Admin";
86 $tabsysprefs{IndependantBranches
} = "Admin";
87 $tabsysprefs{insecure
} = "Admin";
88 $tabsysprefs{KohaAdmin
} = "Admin";
89 $tabsysprefs{KohaAdminEmailAddress
} = "Admin";
90 $tabsysprefs{MIME
} = "Admin";
91 $tabsysprefs{timeout
} = "Admin";
92 $tabsysprefs{Intranet_includes
} = "Admin";
93 $tabsysprefs{AutoLocation
} = "Admin";
94 $tabsysprefs{DebugLevel
} = "Admin";
95 $tabsysprefs{SessionStorage
} = "Admin";
96 $tabsysprefs{noItemTypeImages
} = "Admin";
97 $tabsysprefs{OPACBaseURL
} = "Admin";
98 $tabsysprefs{GranularPermissions
} = "Admin";
101 $tabsysprefs{authoritysep
} = "Authorities";
102 $tabsysprefs{AuthDisplayHierarchy
} = "Authorities";
103 $tabsysprefs{dontmerge
} = "Authorities";
104 $tabsysprefs{BiblioAddsAuthorities
} = "Authorities";
107 $tabsysprefs{advancedMARCeditor
} = "Cataloging";
108 $tabsysprefs{autoBarcode
} = "Cataloging";
109 $tabsysprefs{hide_marc
} = "Cataloging";
110 $tabsysprefs{IntranetBiblioDefaultView
} = "Cataloging";
111 $tabsysprefs{ISBD
} = "Cataloging";
112 $tabsysprefs{itemcallnumber
} = "Cataloging";
113 $tabsysprefs{LabelMARCView
} = "Cataloging";
114 $tabsysprefs{marc
} = "Cataloging";
115 $tabsysprefs{marcflavour
} = "Cataloging";
116 $tabsysprefs{MARCOrgCode
} = "Cataloging";
117 $tabsysprefs{z3950AuthorAuthFields
} = "Cataloging";
118 $tabsysprefs{z3950NormalizeAuthor
} = "Cataloging";
119 $tabsysprefs{Stemming
} = "Cataloging";
120 $tabsysprefs{WeightFields
} = "Cataloging";
121 $tabsysprefs{NoZebra
} = "Cataloging";
122 $tabsysprefs{NoZebraIndexes
} = "Cataloging";
123 $tabsysprefs{ReceiveBackIssues
} = "Cataloging";
124 $tabsysprefs{DefaultClassificationSource
} = "Cataloging";
125 $tabsysprefs{RoutingSerials
} = "Cataloging";
126 $tabsysprefs{'item-level_itypes'} = "Cataloging";
127 $tabsysprefs{OpacSuppression
} = "Cataloging";
128 $tabsysprefs{SpineLabelFormat
} = "Cataloging";
129 $tabsysprefs{SpineLabelAutoPrint
} = "Cataloging";
132 $tabsysprefs{maxoutstanding
} = "Circulation";
133 $tabsysprefs{maxreserves
} = "Circulation";
134 $tabsysprefs{noissuescharge
} = "Circulation";
135 $tabsysprefs{IssuingInProcess
} = "Circulation";
136 $tabsysprefs{patronimages
} = "Circulation";
137 $tabsysprefs{printcirculationslips
} = "Circulation";
138 $tabsysprefs{ReturnBeforeExpiry
} = "Circulation";
139 $tabsysprefs{ceilingDueDate
} = "Circulation";
140 $tabsysprefs{SpecifyDueDate
} = "Circulation";
141 $tabsysprefs{AutomaticItemReturn
} = "Circulation";
142 $tabsysprefs{ReservesMaxPickUpDelay
} = "Circulation";
143 $tabsysprefs{TransfersMaxDaysWarning
} = "Circulation";
144 $tabsysprefs{useDaysMode
} = "Circulation";
145 $tabsysprefs{ReservesNeedReturns
} = "Circulation";
146 $tabsysprefs{CircAutocompl
} = "Circulation";
147 $tabsysprefs{AllowRenewalLimitOverride
} = "Circulation";
148 $tabsysprefs{canreservefromotherbranches
} = "Circulation";
149 $tabsysprefs{finesMode
} = "Circulation";
150 $tabsysprefs{numReturnedItemsToShow
} = "Circulation";
151 $tabsysprefs{emailLibrarianWhenHoldIsPlaced
} = "Circulation";
152 $tabsysprefs{globalDueDate
} = "Circulation";
153 $tabsysprefs{holdCancelLength
} = "Circulation";
154 $tabsysprefs{itemBarcodeInputFilter
} = "Circulation";
155 $tabsysprefs{WebBasedSelfCheck
} = "Circulation";
156 $tabsysprefs{ShowPatronImageInWebBasedSelfCheck
} = "Circulation";
157 $tabsysprefs{CircControl
} = "Circulation";
158 $tabsysprefs{finesCalendar
} = "Circulation";
159 $tabsysprefs{previousIssuesDefaultSortOrder
} = "Circulation";
160 $tabsysprefs{todaysIssuesDefaultSortOrder
} = "Circulation";
161 $tabsysprefs{HomeOrHoldingBranch
} = "Circulation";
162 $tabsysprefs{RandomizeHoldsQueueWeight
} = "Circulation";
163 $tabsysprefs{StaticHoldsQueueWeight
} = "Circulation";
164 $tabsysprefs{AllowOnShelfHolds
} = "Circulation";
165 $tabsysprefs{AllowHoldsOnDamagedItems
} = "Circulation";
166 $tabsysprefs{UseBranchTransferLimits
} = "Circulation";
167 $tabsysprefs{AllowHoldPolicyOverride
} = "Circulation";
168 $tabsysprefs{BranchTransferLimitsType
} = "Circulation";
169 $tabsysprefs{AllowNotForLoanOverride
} = "Circulation";
170 $tabsysprefs{RenewalPeriodBase
} = "Circulation";
171 $tabsysprefs{FilterBeforeOverdueReport
} = "Circulation";
172 $tabsysprefs{AllowHoldDateInFuture
} = "Circulation";
173 $tabsysprefs{OPACFineNoRenewals
} = "Circulation";
174 $tabsysprefs{InProcessingToShelvingCart
} = "Circulation";
175 $tabsysprefs{NewItemsDefaultLocation
} = "Circulation";
176 $tabsysprefs{ReturnToShelvingCart
} = "Circulation";
177 $tabsysprefs{DisplayClearScreenButton
} = "Circulation";
178 $tabsysprefs{AllowAllMessageDeletion
} = "Circulation";
181 $tabsysprefs{TemplateEncoding
} = "StaffClient";
182 $tabsysprefs{template
} = "StaffClient";
183 $tabsysprefs{intranetstylesheet
} = "StaffClient";
184 $tabsysprefs{IntranetNav
} = "StaffClient";
185 $tabsysprefs{intranetcolorstylesheet
} = "StaffClient";
186 $tabsysprefs{intranetuserjs
} = "StaffClient";
187 $tabsysprefs{yuipath
} = "StaffClient";
188 $tabsysprefs{IntranetmainUserblock
} = "StaffClient";
189 $tabsysprefs{viewMARC
} = "StaffClient";
190 $tabsysprefs{viewLabeledMARC
} = "StaffClient";
191 $tabsysprefs{viewISBD
} = "StaffClient";
194 $tabsysprefs{autoMemberNum
} = "Patrons";
195 $tabsysprefs{checkdigit
} = "Patrons";
196 $tabsysprefs{intranetreadinghistory
} = "Patrons";
197 $tabsysprefs{NotifyBorrowerDeparture
} = "Patrons";
198 $tabsysprefs{memberofinstitution
} = "Patrons";
199 $tabsysprefs{ReadingHistory
} = "Patrons";
200 $tabsysprefs{BorrowerMandatoryField
} = "Patrons";
201 $tabsysprefs{borrowerRelationship
} = "Patrons";
202 $tabsysprefs{BorrowersTitles
} = "Patrons";
203 $tabsysprefs{patronimages
} = "Patrons";
204 $tabsysprefs{minPasswordLength
} = "Patrons";
205 $tabsysprefs{uppercasesurnames
} = "Patrons";
206 $tabsysprefs{MaxFine
} = "Patrons";
207 $tabsysprefs{NotifyBorrowerDeparture
} = "Patrons";
208 $tabsysprefs{AddPatronLists
} = "Patrons";
209 $tabsysprefs{PatronsPerPage
} = "Patrons";
210 $tabsysprefs{ExtendedPatronAttributes
} = "Patrons";
211 $tabsysprefs{AutoEmailOpacUser
} = "Patrons";
212 $tabsysprefs{AutoEmailPrimaryAddress
} = "Patrons";
213 $tabsysprefs{EnhancedMessagingPreferences
} = "Patrons";
214 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
215 $tabsysprefs{HidePatronName
} = "Patrons";
219 $tabsysprefs{dateformat
} = "I18N/L10N";
220 $tabsysprefs{opaclanguages
} = "I18N/L10N";
221 $tabsysprefs{opaclanguagesdisplay
} = "I18N/L10N";
222 $tabsysprefs{language
} = "I18N/L10N";
225 $tabsysprefs{defaultSortField
} = "Searching";
226 $tabsysprefs{defaultSortOrder
} = "Searching";
227 $tabsysprefs{numSearchResults
} = "Searching";
228 $tabsysprefs{OPACdefaultSortField
} = "Searching";
229 $tabsysprefs{OPACdefaultSortOrder
} = "Searching";
230 $tabsysprefs{OPACItemsResultsDisplay
} = "Searching";
231 $tabsysprefs{OPACnumSearchResults
} = "Searching";
232 $tabsysprefs{QueryFuzzy
} = "Searching";
233 $tabsysprefs{QueryStemming
} = "Searching";
234 $tabsysprefs{QueryWeightFields
} = "Searching";
235 $tabsysprefs{expandedSearchOption
} = "Searching";
236 $tabsysprefs{sortbynonfiling
} = "Searching";
237 $tabsysprefs{QueryAutoTruncate
} = "Searching";
238 $tabsysprefs{QueryRemoveStopwords
} = "Searching";
239 $tabsysprefs{AdvancedSearchTypes
} = "Searching";
242 $tabsysprefs{AmazonEnabled
} = "EnhancedContent";
243 $tabsysprefs{OPACAmazonEnabled
} = "EnhancedContent";
244 $tabsysprefs{AmazonCoverImages
} = "EnhancedContent";
245 $tabsysprefs{OPACAmazonCoverImages
} = "EnhancedContent";
246 $tabsysprefs{AWSAccessKeyID
} = "EnhancedContent";
247 $tabsysprefs{AWSPrivateKey
} = "EnhancedContent";
248 $tabsysprefs{AmazonLocale
} = "EnhancedContent";
249 $tabsysprefs{AmazonAssocTag
} = "EnhancedContent";
250 $tabsysprefs{AmazonSimilarItems
} = "EnhancedContent";
251 $tabsysprefs{OPACAmazonSimilarItems
} = "EnhancedContent";
252 $tabsysprefs{AmazonReviews
} = "EnhancedContent";
253 $tabsysprefs{OPACAmazonReviews
} = "EnhancedContent";
256 $tabsysprefs{Babeltheque
} = "EnhancedContent";
259 $tabsysprefs{BakerTaylorBookstoreURL
} = 'EnhancedContent';
260 $tabsysprefs{BakerTaylorEnabled
} = 'EnhancedContent';
261 $tabsysprefs{BakerTaylorPassword
} = 'EnhancedContent';
262 $tabsysprefs{BakerTaylorUsername
} = 'EnhancedContent';
264 # Library Thing for Libraries
265 $tabsysprefs{LibraryThingForLibrariesID
} = "EnhancedContent";
266 $tabsysprefs{LibraryThingForLibrariesEnabled
} = "EnhancedContent";
267 $tabsysprefs{LibraryThingForLibrariesTabbedView
} = "EnhancedContent";
270 $tabsysprefs{SyndeticsClientCode
} = 'EnhancedContent';
271 $tabsysprefs{SyndeticsEnabled
} = 'EnhancedContent';
272 $tabsysprefs{SyndeticsCoverImages
} = 'EnhancedContent';
273 $tabsysprefs{SyndeticsTOC
} = 'EnhancedContent';
274 $tabsysprefs{SyndeticsSummary
} = 'EnhancedContent';
275 $tabsysprefs{SyndeticsEditions
} = 'EnhancedContent';
276 $tabsysprefs{SyndeticsExcerpt
} = 'EnhancedContent';
277 $tabsysprefs{SyndeticsReviews
} = 'EnhancedContent';
278 $tabsysprefs{SyndeticsAuthorNotes
} = 'EnhancedContent';
279 $tabsysprefs{SyndeticsAwards
} = 'EnhancedContent';
280 $tabsysprefs{SyndeticsSeries
} = 'EnhancedContent';
281 $tabsysprefs{SyndeticsCoverImageSize
} = 'EnhancedContent';
285 $tabsysprefs{FRBRizeEditions
} = "EnhancedContent";
286 $tabsysprefs{XISBN
} = "EnhancedContent";
287 $tabsysprefs{OCLCAffiliateID
} = "EnhancedContent";
288 $tabsysprefs{XISBNDailyLimit
} = "EnhancedContent";
289 $tabsysprefs{PINESISBN
} = "EnhancedContent";
290 $tabsysprefs{ThingISBN
} = "EnhancedContent";
291 $tabsysprefs{OPACFRBRizeEditions
} = "EnhancedContent";
294 $tabsysprefs{TagsEnabled
} = 'EnhancedContent';
295 $tabsysprefs{TagsExternalDictionary
} = 'EnhancedContent';
296 $tabsysprefs{TagsInputOnDetail
} = 'EnhancedContent';
297 $tabsysprefs{TagsInputOnList
} = 'EnhancedContent';
298 $tabsysprefs{TagsShowOnDetail
} = 'EnhancedContent';
299 $tabsysprefs{TagsShowOnList
} = 'EnhancedContent';
300 $tabsysprefs{TagsModeration
} = 'EnhancedContent';
301 $tabsysprefs{GoogleJackets
} = 'EnhancedContent';
302 $tabsysprefs{AuthorisedValueImages
} = "EnhancedContent";
305 $tabsysprefs{BiblioDefaultView
} = "OPAC";
306 $tabsysprefs{LibraryName
} = "OPAC";
307 $tabsysprefs{opaccolorstylesheet
} = "OPAC";
308 $tabsysprefs{opaccredits
} = "OPAC";
309 $tabsysprefs{opaclayoutstylesheet
} = "OPAC";
310 $tabsysprefs{OpacNav
} = "OPAC";
311 $tabsysprefs{opacsmallimage
} = "OPAC";
312 $tabsysprefs{opacstylesheet
} = "OPAC";
313 $tabsysprefs{opacthemes
} = "OPAC";
314 $tabsysprefs{opacuserjs
} = "OPAC";
315 $tabsysprefs{opacheader
} = "OPAC";
316 $tabsysprefs{hideBiblioNumber
} = "OPAC";
317 $tabsysprefs{OpacMainUserBlock
} = "OPAC";
318 $tabsysprefs{OPACURLOpenInNewWindow
} = "OPAC";
319 $tabsysprefs{OPACUserCSS
} = "OPAC";
320 $tabsysprefs{OPACHighlightedWords
} = "OPAC";
321 $tabsysprefs{OPACViewOthersSuggestions
} = "OPAC";
322 $tabsysprefs{URLLinkText
} = "OPAC";
323 $tabsysprefs{OPACSearchForTitleIn
} = "OPAC";
324 $tabsysprefs{OPACShelfBrowser
} = "OPAC";
325 $tabsysprefs{OPACDisplayRequestPriority
} = "OPAC";
326 $tabsysprefs{OPACAllowHoldDateInFuture
} = "OPAC";
327 $tabsysprefs{OPACPatronDetails
} = "OPAC";
328 $tabsysprefs{OPACFinesTab
} = "OPAC";
329 $tabsysprefs{DisplayOPACiconsXSLT
} = "OPAC";
332 $tabsysprefs{SearchMyLibraryFirst
} = "OPAC";
333 $tabsysprefs{hidelostitems
} = "OPAC";
334 $tabsysprefs{opacbookbag
} = "OPAC";
335 $tabsysprefs{OpacPasswordChange
} = "OPAC";
336 $tabsysprefs{opacreadinghistory
} = "OPAC";
337 $tabsysprefs{virtualshelves
} = "OPAC";
338 $tabsysprefs{RequestOnOpac
} = "OPAC";
339 $tabsysprefs{reviewson
} = "OPAC";
340 $tabsysprefs{OpacTopissues
} = "OPAC";
341 $tabsysprefs{OpacAuthorities
} = "OPAC";
342 $tabsysprefs{OpacCloud
} = "OPAC";
343 $tabsysprefs{opacuserlogin
} = "OPAC";
344 $tabsysprefs{AnonSuggestions
} = "OPAC";
345 $tabsysprefs{suggestion
} = "OPAC";
346 $tabsysprefs{OpacTopissue
} = "OPAC";
347 $tabsysprefs{OpacBrowser
} = "OPAC";
348 $tabsysprefs{kohaspsuggest
} = "OPAC";
349 $tabsysprefs{OpacRenewalAllowed
} = "OPAC";
350 $tabsysprefs{OPACItemHolds
} = "OPAC";
351 $tabsysprefs{OPACGroupResults
} = "OPAC";
352 $tabsysprefs{XSLTDetailsDisplay
} = "OPAC";
353 $tabsysprefs{XSLTResultsDisplay
} = "OPAC";
354 $tabsysprefs{OPACShowCheckoutName
} = "OPAC";
357 $tabsysprefs{OPACSerialIssueDisplayCount
} = "Serials";
358 $tabsysprefs{StaffSerialIssueDisplayCount
} = "Serials";
359 $tabsysprefs{OPACDisplayExtendedSubInfo
} = "Serials";
360 $tabsysprefs{OPACSubscriptionDisplay
} = "Serials";
361 $tabsysprefs{RenewSerialAddsSuggestion
} = "Serials";
362 $tabsysprefs{SubscriptionHistory
} = "Serials";
365 $tabsysprefs{CataloguingLog
} = "Logs";
366 $tabsysprefs{BorrowersLog
} = "Logs";
367 $tabsysprefs{SubscriptionLog
} = "Logs";
368 $tabsysprefs{IssueLog
} = "Logs";
369 $tabsysprefs{ReturnLog
} = "Logs";
370 $tabsysprefs{LetterLog
} = "Logs";
371 $tabsysprefs{FinesLog
} = "Logs";
374 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
375 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
376 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
377 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
378 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
381 $tabsysprefs{'ILS-DI'} = "ILS-DI";
383 my ( $searchstring, $type ) = @_;
384 my $dbh = C4
::Context
->dbh;
385 $searchstring =~ s/\'/\\\'/g;
386 my @data = split( ' ', $searchstring );
392 # used for doing a plain-old sys-pref search
393 if ( $type && $type ne 'all' ) {
394 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
395 if ( $tabsysprefs{$syspref} eq $type ) {
396 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
397 $sth->execute($syspref);
398 while ( my $data = $sth->fetchrow_hashref ) {
399 $data->{shortvalue
} = $data->{value
};
400 $data->{shortvalue
} = substr( $data->{value
}, 0, 60 ) . "..." if defined( $data->{value
} ) and length( $data->{value
} ) > 60;
401 push( @results, $data );
410 if ( $type and $type eq 'all' ) {
411 $sth = $dbh->prepare( "
413 FROM systempreferences
414 WHERE variable LIKE ? OR explanation LIKE ?
415 ORDER BY VARIABLE" );
416 $sth->execute( "%$searchstring%", "%$searchstring%" );
418 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable not in (";
419 foreach my $syspref ( keys %tabsysprefs ) {
420 $strsth .= $dbh->quote($syspref) . ",";
423 $strsth .= " order by variable";
424 $sth = $dbh->prepare($strsth);
428 while ( my $data = $sth->fetchrow_hashref ) {
429 $data->{shortvalue
} = $data->{value
};
430 $data->{shortvalue
} = substr( $data->{value
}, 0, 60 ) . "..." if length( $data->{value
} ) > 60;
431 push( @results, $data );
437 return ( $cnt, \
@results );
445 if ( defined $data->{'options'} ) {
446 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
448 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
449 push @options, { option
=> $option, selected
=> $selected };
453 $params->{'prefoptions'} = $data->{'options'};
455 if ( not defined( $data->{'type'} ) ) {
456 $params->{'type-free'} = 1;
457 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
458 } elsif ( $data->{'type'} eq 'Choice' ) {
459 $params->{'type-choice'} = 1;
460 } elsif ( $data->{'type'} eq 'YesNo' ) {
461 $params->{'type-yesno'} = 1;
462 $data->{'value'} = C4
::Context
->boolean_preference( $data->{'variable'} );
463 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
464 $params->{'value-yes'} = 1;
466 $params->{'value-no'} = 1;
468 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
469 $params->{'type-free'} = 1;
470 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ?
$data->{'options'} : 10;
471 } elsif ( $data->{'type'} eq 'Textarea' ) {
472 $params->{'type-textarea'} = 1;
473 $data->{options
} =~ /(.*)\|(.*)/;
474 $params->{'cols'} = $1;
475 $params->{'rows'} = $2;
476 } elsif ( $data->{'type'} eq 'Themes' ) {
477 $params->{'type-choice'} = 1;
479 ( $data->{'variable'} =~ m
#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
481 my $currently_selected_themes;
483 foreach my $theme ( split /\s+/, $data->{'value'} ) {
484 push @options, { option
=> $theme, counter
=> $counter };
485 $currently_selected_themes->{$theme} = 1;
488 foreach my $theme ( getallthemes
($type) ) {
490 next if $currently_selected_themes->{$theme};
491 push @options, { option
=> $theme, counter
=> $counter };
494 } elsif ( $data->{'type'} eq 'ClassSources' ) {
495 $params->{'type-choice'} = 1;
498 my $sources = GetClassSources
();
500 foreach my $cn_source ( sort keys %$sources ) {
501 if ( $cn_source eq $data->{'value'} ) {
502 push @options, { option
=> $cn_source, counter
=> $counter, selected
=> 1 };
504 push @options, { option
=> $cn_source, counter
=> $counter };
508 } elsif ( $data->{'type'} eq 'Languages' ) {
509 my $currently_selected_languages;
510 foreach my $language ( split /\s+/, $data->{'value'} ) {
511 $currently_selected_languages->{$language} = 1;
515 my $lang = $params->{'lang'};
518 if ( $data->{'variable'} =~ /opac/ ) {
522 $theme = C4
::Context
->preference('opacthemes');
525 # this is the staff client
526 $interface = 'intranet';
527 $theme = C4
::Context
->preference('template');
529 my $languages_loop = getTranslatedLanguages
( $interface, $theme, $lang, $currently_selected_languages );
531 $params->{'languages_loop'} = $languages_loop;
532 $params->{'type-langselector'} = 1;
534 $params->{'type-free'} = 1;
535 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ?
$data->{'options'} : 30;
538 if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
539 $params->{'oneline'} = 1;
542 $params->{'preftype'} = $data->{'type'};
543 $params->{'options'} = \
@options;
549 my $searchfield = $input->param('searchfield') || '';
550 my $Tvalue = $input->param('Tvalue');
551 my $offset = $input->param('offset') || 0;
552 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
554 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
555 { template_name
=> "admin/systempreferences.tmpl",
558 authnotrequired
=> 0,
559 flagsrequired
=> { parameters
=> 1 },
564 my $op = $input->param('op') || '';
565 $searchfield =~ s/\,//g;
569 script_name
=> $script_name,
571 ); # we show only the TMPL_VAR names $op
574 script_name
=> $script_name,
576 ); # we show only the TMPL_VAR names $op
579 if ( $op eq 'update_and_reedit' ) {
580 foreach ( $input->param ) {
583 if ( my $currentorder = $input->param('currentorder') ) {
584 my @currentorder = split /\|/, $currentorder;
585 my $orderchanged = 0;
586 foreach my $param ( $input->param ) {
587 if ( $param =~ m
#up-(\d+).x# ) {
588 my $temp = $currentorder[$1];
589 $currentorder[$1] = $currentorder[ $1 - 1 ];
590 $currentorder[ $1 - 1 ] = $temp;
593 } elsif ( $param =~ m
#down-(\d+).x# ) {
594 my $temp = $currentorder[$1];
595 $currentorder[$1] = $currentorder[ $1 + 1 ];
596 $currentorder[ $1 + 1 ] = $temp;
601 $value = join ' ', @currentorder;
605 script_name
=> $script_name,
607 ); # we show only the TMPL_VAR names $op
612 script_name
=> $script_name,
614 ); # we show only the TMPL_VAR names $op
617 my $dbh = C4
::Context
->dbh;
618 my $query = "select * from systempreferences where variable=?";
619 my $sth = $dbh->prepare($query);
620 $sth->execute( $input->param('variable') );
622 unless ( C4
::Context
->config('demo') ) {
623 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
624 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
626 logaction
( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
629 unless ( C4
::Context
->config('demo') ) {
630 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
631 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
633 logaction
( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
640 ################## ADD_FORM ##################################
641 # called by default. Used to create form to add or modify a record
643 if ( $op eq 'add_form' ) {
645 #---- if primkey exists, it's a modify action, so read values to modify...
648 my $dbh = C4
::Context
->dbh;
649 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
650 $sth->execute($searchfield);
651 $data = $sth->fetchrow_hashref;
653 $template->param( modify
=> 1 );
655 # save tab to return to if user cancels edit
656 $template->param( return_tab
=> $tabsysprefs{$searchfield} );
659 $data->{'lang'} = $template->param('lang');
661 $template->param( GetPrefParams
($data) );
663 $template->param( searchfield
=> $searchfield );
665 ################## ADD_VALIDATE ##################################
666 # called by add_form, used to insert/modify data in DB
667 } elsif ( $op eq 'add_validate' ) {
668 my $dbh = C4
::Context
->dbh;
669 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
670 $sth->execute( $input->param('variable') );
672 # to handle multiple values
675 # handle multiple value strings (separated by ',')
676 my $params = $input->Vars;
677 if ( defined $params->{'value'} ) {
679 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
682 for my $vl (@values) {
687 $value = $params->{'value'};
691 unless ( C4
::Context
->config('demo') ) {
692 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
693 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
695 logaction
( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
698 unless ( C4
::Context
->config('demo') ) {
699 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
700 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
702 logaction
( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
706 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
708 ################## DELETE_CONFIRM ##################################
709 # called by default form, used to confirm deletion of data in DB
710 } elsif ( $op eq 'delete_confirm' ) {
711 my $dbh = C4
::Context
->dbh;
712 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
713 $sth->execute($searchfield);
714 my $data = $sth->fetchrow_hashref;
717 searchfield
=> $searchfield,
718 Tvalue
=> $data->{'value'},
721 # END $OP eq DELETE_CONFIRM
722 ################## DELETE_CONFIRMED ##################################
723 # called by delete_confirm, used to effectively confirm deletion of data in DB
724 } elsif ( $op eq 'delete_confirmed' ) {
725 my $dbh = C4
::Context
->dbh;
726 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
727 $sth->execute($searchfield);
728 my $logstring = $searchfield . " | " . $Tvalue;
729 logaction
( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
732 # END $OP eq DELETE_CONFIRMED
733 ################## DEFAULT ##################################
735 #Adding tab management for system preferences
736 my $tab = $input->param('tab');
737 $template->param( $tab => 1 );
738 my ( $count, $results ) = StringSearch
( $searchfield, $tab );
740 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ?
$offset + $pagesize : $count ) ; $i++ ) {
741 my $row_data = $results->[$i];
742 $row_data->{'lang'} = $template->param('lang');
743 $row_data = GetPrefParams
($row_data); # get a fresh hash for the row data
744 $row_data->{edit
} = "$script_name?op=add_form&searchfield=" . $results->[$i]{'variable'};
745 $row_data->{delete} = "$script_name?op=delete_confirm&searchfield=" . $results->[$i]{'variable'};
746 push( @loop_data, $row_data );
748 $tab = ( $tab ?
$tab : "Local Use" );
749 $template->param( loop => \
@loop_data, $tab => 1 );
751 my $prevpage = $offset - $pagesize;
752 $template->param( "<a href=$script_name?offset=" . $prevpage . '<< Prev</a>' );
754 if ( $offset + $pagesize < $count ) {
755 my $nextpage = $offset + $pagesize;
756 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next >></a>' );
758 $template->param( tab
=> $tab, );
759 } #---- END $OP eq DEFAULT
760 output_html_with_http_headers
$input, $cookie, $template->output;