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";
75 $tabsysprefs{singleBranchMode} = "Admin";
76 $tabsysprefs{staffClientBaseURL} = "Admin";
77 $tabsysprefs{Version} = "Admin";
78 $tabsysprefs{OpacMaintenance} = "Admin";
79 $tabsysprefs{FrameworksLoaded} = "Admin";
80 $tabsysprefs{libraryAddress} = "Admin";
81 $tabsysprefs{delimiter} = "Admin";
82 $tabsysprefs{IndependantBranches} = "Admin";
83 $tabsysprefs{insecure} = "Admin";
84 $tabsysprefs{KohaAdmin} = "Admin";
85 $tabsysprefs{KohaAdminEmailAddress} = "Admin";
86 $tabsysprefs{MIME} = "Admin";
87 $tabsysprefs{timeout} = "Admin";
88 $tabsysprefs{Intranet_includes} = "Admin";
89 $tabsysprefs{AutoLocation} = "Admin";
90 $tabsysprefs{DebugLevel} = "Admin";
91 $tabsysprefs{SessionStorage} = "Admin";
92 $tabsysprefs{noItemTypeImages} = "Admin";
93 $tabsysprefs{OPACBaseURL} = "Admin";
94 $tabsysprefs{GranularPermissions} = "Admin";
97 $tabsysprefs{authoritysep} = "Authorities";
98 $tabsysprefs{AuthDisplayHierarchy} = "Authorities";
99 $tabsysprefs{dontmerge} = "Authorities";
100 $tabsysprefs{BiblioAddsAuthorities} = "Authorities";
103 $tabsysprefs{advancedMARCeditor} = "Cataloging";
104 $tabsysprefs{autoBarcode} = "Cataloging";
105 $tabsysprefs{hide_marc} = "Cataloging";
106 $tabsysprefs{IntranetBiblioDefaultView} = "Cataloging";
107 $tabsysprefs{ISBD} = "Cataloging";
108 $tabsysprefs{itemcallnumber} = "Cataloging";
109 $tabsysprefs{LabelMARCView} = "Cataloging";
110 $tabsysprefs{marc} = "Cataloging";
111 $tabsysprefs{marcflavour} = "Cataloging";
112 $tabsysprefs{MARCOrgCode} = "Cataloging";
113 $tabsysprefs{z3950AuthorAuthFields} = "Cataloging";
114 $tabsysprefs{z3950NormalizeAuthor} = "Cataloging";
115 $tabsysprefs{Stemming} = "Cataloging";
116 $tabsysprefs{WeightFields} = "Cataloging";
117 $tabsysprefs{NoZebra} = "Cataloging";
118 $tabsysprefs{NoZebraIndexes} = "Cataloging";
119 $tabsysprefs{ReceiveBackIssues} = "Cataloging";
120 $tabsysprefs{DefaultClassificationSource} = "Cataloging";
121 $tabsysprefs{RoutingSerials} = "Cataloging";
122 $tabsysprefs{'item-level_itypes'} = "Cataloging";
123 $tabsysprefs{OpacSuppression} = "Cataloging";
124 $tabsysprefs{SpineLabelFormat} = "Cataloging";
125 $tabsysprefs{SpineLabelAutoPrint} = "Cataloging";
128 $tabsysprefs{maxoutstanding} = "Circulation";
129 $tabsysprefs{maxreserves} = "Circulation";
130 $tabsysprefs{noissuescharge} = "Circulation";
131 $tabsysprefs{IssuingInProcess} = "Circulation";
132 $tabsysprefs{patronimages} = "Circulation";
133 $tabsysprefs{printcirculationslips} = "Circulation";
134 $tabsysprefs{ReturnBeforeExpiry} = "Circulation";
135 $tabsysprefs{ceilingDueDate} = "Circulation";
136 $tabsysprefs{SpecifyDueDate} = "Circulation";
137 $tabsysprefs{AutomaticItemReturn} = "Circulation";
138 $tabsysprefs{ReservesMaxPickUpDelay} = "Circulation";
139 $tabsysprefs{TransfersMaxDaysWarning} = "Circulation";
140 $tabsysprefs{useDaysMode} = "Circulation";
141 $tabsysprefs{ReservesNeedReturns} = "Circulation";
142 $tabsysprefs{CircAutocompl} = "Circulation";
143 $tabsysprefs{AllowRenewalLimitOverride} = "Circulation";
144 $tabsysprefs{canreservefromotherbranches} = "Circulation";
145 $tabsysprefs{finesMode} = "Circulation";
146 $tabsysprefs{numReturnedItemsToShow} = "Circulation";
147 $tabsysprefs{emailLibrarianWhenHoldIsPlaced} = "Circulation";
148 $tabsysprefs{globalDueDate} = "Circulation";
149 $tabsysprefs{holdCancelLength} = "Circulation";
150 $tabsysprefs{itemBarcodeInputFilter} = "Circulation";
151 $tabsysprefs{WebBasedSelfCheck} = "Circulation";
152 $tabsysprefs{CircControl} = "Circulation";
153 $tabsysprefs{finesCalendar} = "Circulation";
154 $tabsysprefs{previousIssuesDefaultSortOrder} = "Circulation";
155 $tabsysprefs{todaysIssuesDefaultSortOrder} = "Circulation";
156 $tabsysprefs{HomeOrHoldingBranch} = "Circulation";
157 $tabsysprefs{RandomizeHoldsQueueWeight} = "Circulation";
158 $tabsysprefs{StaticHoldsQueueWeight} = "Circulation";
159 $tabsysprefs{AllowOnShelfHolds} = "Circulation";
160 $tabsysprefs{AllowHoldsOnDamagedItems} = "Circulation";
161 $tabsysprefs{UseBranchTransferLimits} = "Circulation";
162 $tabsysprefs{AllowHoldPolicyOverride} = "Circulation";
163 $tabsysprefs{BranchTransferLimitsType} = "Circulation";
164 $tabsysprefs{AllowNotForLoanOverride} = "Circulation";
165 $tabsysprefs{RenewalPeriodBase} = "Circulation";
166 $tabsysprefs{FilterBeforeOverdueReport} = "Circulation";
167 $tabsysprefs{AllowHoldDateInFuture} = "Circulation";
168 $tabsysprefs{OPACFineNoRenewals} = "Circulation";
171 $tabsysprefs{TemplateEncoding} = "StaffClient";
172 $tabsysprefs{template} = "StaffClient";
173 $tabsysprefs{intranetstylesheet} = "StaffClient";
174 $tabsysprefs{IntranetNav} = "StaffClient";
175 $tabsysprefs{intranetcolorstylesheet} = "StaffClient";
176 $tabsysprefs{intranetuserjs} = "StaffClient";
177 $tabsysprefs{yuipath} = "StaffClient";
178 $tabsysprefs{IntranetmainUserblock} = "StaffClient";
179 $tabsysprefs{viewMARC} = "StaffClient";
180 $tabsysprefs{viewLabeledMARC} = "StaffClient";
181 $tabsysprefs{viewISBD} = "StaffClient";
184 $tabsysprefs{autoMemberNum} = "Patrons";
185 $tabsysprefs{checkdigit} = "Patrons";
186 $tabsysprefs{intranetreadinghistory} = "Patrons";
187 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
188 $tabsysprefs{memberofinstitution} = "Patrons";
189 $tabsysprefs{ReadingHistory} = "Patrons";
190 $tabsysprefs{BorrowerMandatoryField} = "Patrons";
191 $tabsysprefs{borrowerRelationship} = "Patrons";
192 $tabsysprefs{BorrowersTitles} = "Patrons";
193 $tabsysprefs{patronimages} = "Patrons";
194 $tabsysprefs{minPasswordLength} = "Patrons";
195 $tabsysprefs{uppercasesurnames} = "Patrons";
196 $tabsysprefs{MaxFine} = "Patrons";
197 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
198 $tabsysprefs{AddPatronLists} = "Patrons";
199 $tabsysprefs{PatronsPerPage} = "Patrons";
200 $tabsysprefs{ExtendedPatronAttributes} = "Patrons";
201 $tabsysprefs{AutoEmailOpacUser} = "Patrons";
202 $tabsysprefs{AutoEmailPrimaryAddress} = "Patrons";
203 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
204 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
207 $tabsysprefs{dateformat} = "I18N/L10N";
208 $tabsysprefs{opaclanguages} = "I18N/L10N";
209 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
210 $tabsysprefs{language} = "I18N/L10N";
213 $tabsysprefs{defaultSortField} = "Searching";
214 $tabsysprefs{defaultSortOrder} = "Searching";
215 $tabsysprefs{numSearchResults} = "Searching";
216 $tabsysprefs{OPACdefaultSortField} = "Searching";
217 $tabsysprefs{OPACdefaultSortOrder} = "Searching";
218 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
219 $tabsysprefs{OPACnumSearchResults} = "Searching";
220 $tabsysprefs{QueryFuzzy} = "Searching";
221 $tabsysprefs{QueryStemming} = "Searching";
222 $tabsysprefs{QueryWeightFields} = "Searching";
223 $tabsysprefs{expandedSearchOption} = "Searching";
224 $tabsysprefs{sortbynonfiling} = "Searching";
225 $tabsysprefs{QueryAutoTruncate} = "Searching";
226 $tabsysprefs{QueryRemoveStopwords} = "Searching";
227 $tabsysprefs{AdvancedSearchTypes} = "Searching";
230 $tabsysprefs{AmazonEnabled} = "EnhancedContent";
231 $tabsysprefs{OPACAmazonEnabled} = "EnhancedContent";
232 $tabsysprefs{AmazonCoverImages} = "EnhancedContent";
233 $tabsysprefs{OPACAmazonCoverImages} = "EnhancedContent";
234 $tabsysprefs{AWSAccessKeyID} = "EnhancedContent";
235 $tabsysprefs{AWSPrivateKey} = "EnhancedContent";
236 $tabsysprefs{AmazonLocale} = "EnhancedContent";
237 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
238 $tabsysprefs{AmazonSimilarItems} = "EnhancedContent";
239 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
240 $tabsysprefs{AmazonReviews} = "EnhancedContent";
241 $tabsysprefs{OPACAmazonReviews} = "EnhancedContent";
244 $tabsysprefs{Babeltheque} = "EnhancedContent";
247 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
248 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
249 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
250 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
252 # Library Thing for Libraries
253 $tabsysprefs{LibraryThingForLibrariesID} = "EnhancedContent";
254 $tabsysprefs{LibraryThingForLibrariesEnabled} = "EnhancedContent";
255 $tabsysprefs{LibraryThingForLibrariesTabbedView} = "EnhancedContent";
258 $tabsysprefs{SyndeticsClientCode} = 'EnhancedContent';
259 $tabsysprefs{SyndeticsEnabled} = 'EnhancedContent';
260 $tabsysprefs{SyndeticsCoverImages} = 'EnhancedContent';
261 $tabsysprefs{SyndeticsTOC} = 'EnhancedContent';
262 $tabsysprefs{SyndeticsSummary} = 'EnhancedContent';
263 $tabsysprefs{SyndeticsEditions} = 'EnhancedContent';
264 $tabsysprefs{SyndeticsExcerpt} = 'EnhancedContent';
265 $tabsysprefs{SyndeticsReviews} = 'EnhancedContent';
266 $tabsysprefs{SyndeticsAuthorNotes} = 'EnhancedContent';
267 $tabsysprefs{SyndeticsAwards} = 'EnhancedContent';
268 $tabsysprefs{SyndeticsSeries} = 'EnhancedContent';
269 $tabsysprefs{SyndeticsCoverImageSize} = 'EnhancedContent';
273 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
274 $tabsysprefs{XISBN} = "EnhancedContent";
275 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
276 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
277 $tabsysprefs{PINESISBN} = "EnhancedContent";
278 $tabsysprefs{ThingISBN} = "EnhancedContent";
279 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
282 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
283 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
284 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
285 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
286 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
287 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
288 $tabsysprefs{TagsModeration} = 'EnhancedContent';
289 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
290 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
293 $tabsysprefs{BiblioDefaultView} = "OPAC";
294 $tabsysprefs{LibraryName} = "OPAC";
295 $tabsysprefs{opaccolorstylesheet} = "OPAC";
296 $tabsysprefs{opaccredits} = "OPAC";
297 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
298 $tabsysprefs{OpacNav} = "OPAC";
299 $tabsysprefs{opacsmallimage} = "OPAC";
300 $tabsysprefs{opacstylesheet} = "OPAC";
301 $tabsysprefs{opacthemes} = "OPAC";
302 $tabsysprefs{opacuserjs} = "OPAC";
303 $tabsysprefs{opacheader} = "OPAC";
304 $tabsysprefs{hideBiblioNumber} = "OPAC";
305 $tabsysprefs{OpacMainUserBlock} = "OPAC";
306 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
307 $tabsysprefs{OPACUserCSS} = "OPAC";
308 $tabsysprefs{OPACHighlightedWords} = "OPAC";
309 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
310 $tabsysprefs{URLLinkText} = "OPAC";
311 $tabsysprefs{OPACShelfBrowser} = "OPAC";
312 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
313 $tabsysprefs{OPACAllowHoldDateInFuture} = "OPAC";
316 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
317 $tabsysprefs{hidelostitems} = "OPAC";
318 $tabsysprefs{opacbookbag} = "OPAC";
319 $tabsysprefs{OpacPasswordChange} = "OPAC";
320 $tabsysprefs{opacreadinghistory} = "OPAC";
321 $tabsysprefs{virtualshelves} = "OPAC";
322 $tabsysprefs{RequestOnOpac} = "OPAC";
323 $tabsysprefs{reviewson} = "OPAC";
324 $tabsysprefs{OpacTopissues} = "OPAC";
325 $tabsysprefs{OpacAuthorities} = "OPAC";
326 $tabsysprefs{OpacCloud} = "OPAC";
327 $tabsysprefs{opacuserlogin} = "OPAC";
328 $tabsysprefs{AnonSuggestions} = "OPAC";
329 $tabsysprefs{suggestion} = "OPAC";
330 $tabsysprefs{OpacTopissue} = "OPAC";
331 $tabsysprefs{OpacBrowser} = "OPAC";
332 $tabsysprefs{kohaspsuggest} = "OPAC";
333 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
334 $tabsysprefs{OPACItemHolds} = "OPAC";
335 $tabsysprefs{OPACGroupResults} = "OPAC";
336 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
337 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
338 $tabsysprefs{OPACShowCheckoutName} = "OPAC";
341 $tabsysprefs{OPACSerialIssueDisplayCount} = "Serials";
342 $tabsysprefs{StaffSerialIssueDisplayCount} = "Serials";
343 $tabsysprefs{OPACDisplayExtendedSubInfo} = "Serials";
344 $tabsysprefs{OPACSubscriptionDisplay} = "Serials";
345 $tabsysprefs{RenewSerialAddsSuggestion} = "Serials";
346 $tabsysprefs{SubscriptionHistory} = "Serials";
349 $tabsysprefs{CataloguingLog} = "Logs";
350 $tabsysprefs{BorrowersLog} = "Logs";
351 $tabsysprefs{SubscriptionLog} = "Logs";
352 $tabsysprefs{IssueLog} = "Logs";
353 $tabsysprefs{ReturnLog} = "Logs";
354 $tabsysprefs{LetterLog} = "Logs";
355 $tabsysprefs{FinesLog} = "Logs";
358 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
359 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
360 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
361 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
362 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
365 my ( $searchstring, $type ) = @_;
366 my $dbh = C4::Context->dbh;
367 $searchstring =~ s/\'/\\\'/g;
368 my @data = split( ' ', $searchstring );
374 # used for doing a plain-old sys-pref search
375 if ( $type && $type ne 'all' ) {
376 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
377 if ( $tabsysprefs{$syspref} eq $type ) {
378 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
379 $sth->execute($syspref);
380 while ( my $data = $sth->fetchrow_hashref ) {
381 $data->{shortvalue} = $data->{value};
382 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
383 push( @results, $data );
392 if ( $type and $type eq 'all' ) {
393 $sth = $dbh->prepare( "
395 FROM systempreferences
396 WHERE variable LIKE ? OR explanation LIKE ?
397 ORDER BY VARIABLE" );
398 $sth->execute( "%$searchstring%", "%$searchstring%" );
400 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable not in (";
401 foreach my $syspref ( keys %tabsysprefs ) {
402 $strsth .= $dbh->quote($syspref) . ",";
405 $strsth .= " order by variable";
406 $sth = $dbh->prepare($strsth);
410 while ( my $data = $sth->fetchrow_hashref ) {
411 $data->{shortvalue} = $data->{value};
412 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
413 push( @results, $data );
419 return ( $cnt, \@results );
427 if ( defined $data->{'options'} ) {
428 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
430 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
431 push @options, { option => $option, selected => $selected };
435 $params->{'prefoptions'} = $data->{'options'};
437 if ( not defined( $data->{'type'} ) ) {
438 $params->{'type-free'} = 1;
439 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
440 } elsif ( $data->{'type'} eq 'Choice' ) {
441 $params->{'type-choice'} = 1;
442 } elsif ( $data->{'type'} eq 'YesNo' ) {
443 $params->{'type-yesno'} = 1;
444 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
445 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
446 $params->{'value-yes'} = 1;
448 $params->{'value-no'} = 1;
450 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
451 $params->{'type-free'} = 1;
452 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
453 } elsif ( $data->{'type'} eq 'Textarea' ) {
454 $params->{'type-textarea'} = 1;
455 $data->{options} =~ /(.*)\|(.*)/;
456 $params->{'cols'} = $1;
457 $params->{'rows'} = $2;
458 } elsif ( $data->{'type'} eq 'Themes' ) {
459 $params->{'type-choice'} = 1;
461 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
463 my $currently_selected_themes;
465 foreach my $theme ( split /\s+/, $data->{'value'} ) {
466 push @options, { option => $theme, counter => $counter };
467 $currently_selected_themes->{$theme} = 1;
470 foreach my $theme ( getallthemes($type) ) {
472 next if $currently_selected_themes->{$theme};
473 push @options, { option => $theme, counter => $counter };
476 } elsif ( $data->{'type'} eq 'ClassSources' ) {
477 $params->{'type-choice'} = 1;
480 my $sources = GetClassSources();
482 foreach my $cn_source ( sort keys %$sources ) {
483 if ( $cn_source eq $data->{'value'} ) {
484 push @options, { option => $cn_source, counter => $counter, selected => 1 };
486 push @options, { option => $cn_source, counter => $counter };
490 } elsif ( $data->{'type'} eq 'Languages' ) {
491 my $currently_selected_languages;
492 foreach my $language ( split /\s+/, $data->{'value'} ) {
493 $currently_selected_languages->{$language} = 1;
497 my $lang = $params->{'lang'};
500 if ( $data->{'variable'} =~ /opac/ ) {
504 $theme = C4::Context->preference('opacthemes');
507 # this is the staff client
508 $interface = 'intranet';
509 $theme = C4::Context->preference('template');
511 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
513 $params->{'languages_loop'} = $languages_loop;
514 $params->{'type-langselector'} = 1;
516 $params->{'type-free'} = 1;
517 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
520 if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
521 $params->{'oneline'} = 1;
524 $params->{'preftype'} = $data->{'type'};
525 $params->{'options'} = \@options;
531 my $searchfield = $input->param('searchfield') || '';
532 my $Tvalue = $input->param('Tvalue');
533 my $offset = $input->param('offset') || 0;
534 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
536 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
537 { template_name => "admin/systempreferences.tmpl",
540 authnotrequired => 0,
541 flagsrequired => { parameters => 1 },
546 my $op = $input->param('op') || '';
547 $searchfield =~ s/\,//g;
551 script_name => $script_name,
553 ); # we show only the TMPL_VAR names $op
556 script_name => $script_name,
558 ); # we show only the TMPL_VAR names $op
561 if ( $op eq 'update_and_reedit' ) {
562 foreach ( $input->param ) {
565 if ( my $currentorder = $input->param('currentorder') ) {
566 my @currentorder = split /\|/, $currentorder;
567 my $orderchanged = 0;
568 foreach my $param ( $input->param ) {
569 if ( $param =~ m#up-(\d+).x# ) {
570 my $temp = $currentorder[$1];
571 $currentorder[$1] = $currentorder[ $1 - 1 ];
572 $currentorder[ $1 - 1 ] = $temp;
575 } elsif ( $param =~ m#down-(\d+).x# ) {
576 my $temp = $currentorder[$1];
577 $currentorder[$1] = $currentorder[ $1 + 1 ];
578 $currentorder[ $1 + 1 ] = $temp;
583 $value = join ' ', @currentorder;
587 script_name => $script_name,
589 ); # we show only the TMPL_VAR names $op
594 script_name => $script_name,
596 ); # we show only the TMPL_VAR names $op
599 my $dbh = C4::Context->dbh;
600 my $query = "select * from systempreferences where variable=?";
601 my $sth = $dbh->prepare($query);
602 $sth->execute( $input->param('variable') );
604 unless ( C4::Context->config('demo') ) {
605 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
606 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
608 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
611 unless ( C4::Context->config('demo') ) {
612 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
613 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
615 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
622 ################## ADD_FORM ##################################
623 # called by default. Used to create form to add or modify a record
625 if ( $op eq 'add_form' ) {
627 #---- if primkey exists, it's a modify action, so read values to modify...
630 my $dbh = C4::Context->dbh;
631 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
632 $sth->execute($searchfield);
633 $data = $sth->fetchrow_hashref;
635 $template->param( modify => 1 );
637 # save tab to return to if user cancels edit
638 $template->param( return_tab => $tabsysprefs{$searchfield} );
641 $data->{'lang'} = $template->param('lang');
643 $template->param( GetPrefParams($data) );
645 $template->param( searchfield => $searchfield );
647 ################## ADD_VALIDATE ##################################
648 # called by add_form, used to insert/modify data in DB
649 } elsif ( $op eq 'add_validate' ) {
650 my $dbh = C4::Context->dbh;
651 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
652 $sth->execute( $input->param('variable') );
654 # to handle multiple values
657 # handle multiple value strings (separated by ',')
658 my $params = $input->Vars;
659 if ( defined $params->{'value'} ) {
661 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
664 for my $vl (@values) {
669 $value = $params->{'value'};
673 unless ( C4::Context->config('demo') ) {
674 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
675 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
677 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
680 unless ( C4::Context->config('demo') ) {
681 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
682 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
684 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
688 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
690 ################## DELETE_CONFIRM ##################################
691 # called by default form, used to confirm deletion of data in DB
692 } elsif ( $op eq 'delete_confirm' ) {
693 my $dbh = C4::Context->dbh;
694 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
695 $sth->execute($searchfield);
696 my $data = $sth->fetchrow_hashref;
699 searchfield => $searchfield,
700 Tvalue => $data->{'value'},
703 # END $OP eq DELETE_CONFIRM
704 ################## DELETE_CONFIRMED ##################################
705 # called by delete_confirm, used to effectively confirm deletion of data in DB
706 } elsif ( $op eq 'delete_confirmed' ) {
707 my $dbh = C4::Context->dbh;
708 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
709 $sth->execute($searchfield);
710 my $logstring = $searchfield . " | " . $Tvalue;
711 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
714 # END $OP eq DELETE_CONFIRMED
715 ################## DEFAULT ##################################
717 #Adding tab management for system preferences
718 my $tab = $input->param('tab');
719 $template->param( $tab => 1 );
720 my ( $count, $results ) = StringSearch( $searchfield, $tab );
722 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
723 my $row_data = $results->[$i];
724 $row_data->{'lang'} = $template->param('lang');
725 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
726 $row_data->{edit} = "$script_name?op=add_form&searchfield=" . $results->[$i]{'variable'};
727 $row_data->{delete} = "$script_name?op=delete_confirm&searchfield=" . $results->[$i]{'variable'};
728 push( @loop_data, $row_data );
730 $tab = ( $tab ? $tab : "Local Use" );
731 $template->param( loop => \@loop_data, $tab => 1 );
733 my $prevpage = $offset - $pagesize;
734 $template->param( "<a href=$script_name?offset=" . $prevpage . '<< Prev</a>' );
736 if ( $offset + $pagesize < $count ) {
737 my $nextpage = $offset + $pagesize;
738 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next >></a>' );
740 $template->param( tab => $tab, );
741 } #---- END $OP eq DEFAULT
742 output_html_with_http_headers $input, $cookie, $template->output;