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} = "Cataloguing";
104 $tabsysprefs{autoBarcode} = "Cataloguing";
105 $tabsysprefs{hide_marc} = "Cataloguing";
106 $tabsysprefs{IntranetBiblioDefaultView} = "Cataloguing";
107 $tabsysprefs{ISBD} = "Cataloguing";
108 $tabsysprefs{itemcallnumber} = "Cataloguing";
109 $tabsysprefs{LabelMARCView} = "Cataloguing";
110 $tabsysprefs{marc} = "Cataloguing";
111 $tabsysprefs{marcflavour} = "Cataloguing";
112 $tabsysprefs{MARCOrgCode} = "Cataloguing";
113 $tabsysprefs{z3950AuthorAuthFields} = "Cataloguing";
114 $tabsysprefs{z3950NormalizeAuthor} = "Cataloguing";
115 $tabsysprefs{Stemming} = "Cataloguing";
116 $tabsysprefs{WeightFields} = "Cataloguing";
117 $tabsysprefs{NoZebra} = "Cataloguing";
118 $tabsysprefs{NoZebraIndexes} = "Cataloguing";
119 $tabsysprefs{ReceiveBackIssues} = "Cataloguing";
120 $tabsysprefs{DefaultClassificationSource} = "Cataloguing";
121 $tabsysprefs{RoutingSerials} = "Cataloguing";
122 $tabsysprefs{'item-level_itypes'} = "Cataloguing";
123 $tabsysprefs{OpacSuppression} = "Cataloguing";
126 $tabsysprefs{maxoutstanding} = "Circulation";
127 $tabsysprefs{maxreserves} = "Circulation";
128 $tabsysprefs{noissuescharge} = "Circulation";
129 $tabsysprefs{IssuingInProcess} = "Circulation";
130 $tabsysprefs{patronimages} = "Circulation";
131 $tabsysprefs{printcirculationslips} = "Circulation";
132 $tabsysprefs{ReturnBeforeExpiry} = "Circulation";
133 $tabsysprefs{SpecifyDueDate} = "Circulation";
134 $tabsysprefs{AutomaticItemReturn} = "Circulation";
135 $tabsysprefs{ReservesMaxPickUpDelay} = "Circulation";
136 $tabsysprefs{TransfersMaxDaysWarning} = "Circulation";
137 $tabsysprefs{useDaysMode} = "Circulation";
138 $tabsysprefs{ReservesNeedReturns} = "Circulation";
139 $tabsysprefs{CircAutocompl} = "Circulation";
140 $tabsysprefs{AllowRenewalLimitOverride} = "Circulation";
141 $tabsysprefs{canreservefromotherbranches} = "Circulation";
142 $tabsysprefs{finesMode} = "Circulation";
143 $tabsysprefs{emailLibrarianWhenHoldIsPlaced} = "Circulation";
144 $tabsysprefs{globalDueDate} = "Circulation";
145 $tabsysprefs{holdCancelLength} = "Circulation";
146 $tabsysprefs{itemBarcodeInputFilter} = "Circulation";
147 $tabsysprefs{WebBasedSelfCheck} = "Circulation";
148 $tabsysprefs{CircControl} = "Circulation";
149 $tabsysprefs{finesCalendar} = "Circulation";
150 $tabsysprefs{previousIssuesDefaultSortOrder} = "Circulation";
151 $tabsysprefs{todaysIssuesDefaultSortOrder} = "Circulation";
152 $tabsysprefs{HomeOrHoldingBranch} = "Circulation";
153 $tabsysprefs{RandomizeHoldsQueueWeight} = "Circulation";
154 $tabsysprefs{StaticHoldsQueueWeight} = "Circulation";
155 $tabsysprefs{AllowOnShelfHolds} = "Circulation";
156 $tabsysprefs{AllowHoldsOnDamagedItems} = "Circulation";
159 $tabsysprefs{TemplateEncoding} = "StaffClient";
160 $tabsysprefs{template} = "StaffClient";
161 $tabsysprefs{intranetstylesheet} = "StaffClient";
162 $tabsysprefs{IntranetNav} = "StaffClient";
163 $tabsysprefs{intranetcolorstylesheet} = "StaffClient";
164 $tabsysprefs{intranetuserjs} = "StaffClient";
165 $tabsysprefs{yuipath} = "StaffClient";
166 $tabsysprefs{IntranetmainUserblock} = "StaffClient";
169 $tabsysprefs{autoMemberNum} = "Patrons";
170 $tabsysprefs{checkdigit} = "Patrons";
171 $tabsysprefs{intranetreadinghistory} = "Patrons";
172 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
173 $tabsysprefs{memberofinstitution} = "Patrons";
174 $tabsysprefs{ReadingHistory} = "Patrons";
175 $tabsysprefs{BorrowerMandatoryField} = "Patrons";
176 $tabsysprefs{borrowerRelationship} = "Patrons";
177 $tabsysprefs{BorrowersTitles} = "Patrons";
178 $tabsysprefs{patronimages} = "Patrons";
179 $tabsysprefs{MinPasswordLength} = "Patrons";
180 $tabsysprefs{uppercasesurnames} = "Patrons";
181 $tabsysprefs{MaxFine} = "Patrons";
182 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
183 $tabsysprefs{AddPatronLists} = "Patrons";
184 $tabsysprefs{PatronsPerPage} = "Patrons";
185 $tabsysprefs{ExtendedPatronAttributes} = "Patrons";
186 $tabsysprefs{AutoEmailOpacUser} = "Patrons";
187 $tabsysprefs{AutoEmailPrimaryAddress} = "Patrons";
188 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
189 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
192 $tabsysprefs{dateformat} = "I18N/L10N";
193 $tabsysprefs{opaclanguages} = "I18N/L10N";
194 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
195 $tabsysprefs{language} = "I18N/L10N";
198 $tabsysprefs{defaultSortField} = "Searching";
199 $tabsysprefs{defaultSortOrder} = "Searching";
200 $tabsysprefs{numSearchResults} = "Searching";
201 $tabsysprefs{OPACdefaultSortField} = "Searching";
202 $tabsysprefs{OPACdefaultSortOrder} = "Searching";
203 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
204 $tabsysprefs{OPACnumSearchResults} = "Searching";
205 $tabsysprefs{QueryFuzzy} = "Searching";
206 $tabsysprefs{QueryStemming} = "Searching";
207 $tabsysprefs{QueryWeightFields} = "Searching";
208 $tabsysprefs{expandedSearchOption} = "Searching";
209 $tabsysprefs{sortbynonfiling} = "Searching";
210 $tabsysprefs{QueryAutoTruncate} = "Searching";
211 $tabsysprefs{QueryRemoveStopwords} = "Searching";
212 $tabsysprefs{AdvancedSearchTypes} = "Searching";
215 $tabsysprefs{AmazonContent} = "EnhancedContent";
216 $tabsysprefs{AWSAccessKeyID} = "EnhancedContent";
217 $tabsysprefs{AmazonLocale} = "EnhancedContent";
218 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
219 $tabsysprefs{AmazonSimilarItems} = "EnhancedContent";
220 $tabsysprefs{OPACAmazonContent} = "EnhancedContent";
221 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
224 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
225 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
226 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
227 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
230 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
231 $tabsysprefs{XISBN} = "EnhancedContent";
232 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
233 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
234 $tabsysprefs{PINESISBN} = "EnhancedContent";
235 $tabsysprefs{ThingISBN} = "EnhancedContent";
236 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
239 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
240 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
241 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
242 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
243 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
244 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
245 $tabsysprefs{TagsModeration} = 'EnhancedContent';
246 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
247 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
250 $tabsysprefs{BiblioDefaultView} = "OPAC";
251 $tabsysprefs{LibraryName} = "OPAC";
252 $tabsysprefs{opaccolorstylesheet} = "OPAC";
253 $tabsysprefs{opaccredits} = "OPAC";
254 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
255 $tabsysprefs{OpacNav} = "OPAC";
256 $tabsysprefs{opacsmallimage} = "OPAC";
257 $tabsysprefs{opacstylesheet} = "OPAC";
258 $tabsysprefs{opacthemes} = "OPAC";
259 $tabsysprefs{opacuserjs} = "OPAC";
260 $tabsysprefs{opacheader} = "OPAC";
261 $tabsysprefs{noOPACUserLogin} = "OPAC";
262 $tabsysprefs{hideBiblioNumber} = "OPAC";
263 $tabsysprefs{OpacMainUserBlock} = "OPAC";
264 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
265 $tabsysprefs{OPACUserCSS} = "OPAC";
266 $tabsysprefs{OPACHighlightedWords} = "OPAC";
267 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
268 $tabsysprefs{URLLinkText} = "OPAC";
269 $tabsysprefs{OPACShelfBrowser} = "OPAC";
270 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
273 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
274 $tabsysprefs{hidelostitems} = "OPAC";
275 $tabsysprefs{opacbookbag} = "OPAC";
276 $tabsysprefs{OpacPasswordChange} = "OPAC";
277 $tabsysprefs{opacreadinghistory} = "OPAC";
278 $tabsysprefs{virtualshelves} = "OPAC";
279 $tabsysprefs{RequestOnOpac} = "OPAC";
280 $tabsysprefs{reviewson} = "OPAC";
281 $tabsysprefs{OpacTopissues} = "OPAC";
282 $tabsysprefs{OpacAuthorities} = "OPAC";
283 $tabsysprefs{OpacCloud} = "OPAC";
284 $tabsysprefs{opacuserlogin} = "OPAC";
285 $tabsysprefs{AnonSuggestions} = "OPAC";
286 $tabsysprefs{suggestion} = "OPAC";
287 $tabsysprefs{OpacTopissue} = "OPAC";
288 $tabsysprefs{OpacBrowser} = "OPAC";
289 $tabsysprefs{kohaspsuggest} = "OPAC";
290 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
291 $tabsysprefs{OPACItemHolds} = "OPAC";
292 $tabsysprefs{OPACGroupResults} = "OPAC";
293 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
294 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
297 $tabsysprefs{OPACSerialIssueDisplayCount} = "Serials";
298 $tabsysprefs{StaffSerialIssueDisplayCount} = "Serials";
299 $tabsysprefs{OPACDisplayExtendedSubInfo} = "Serials";
300 $tabsysprefs{OPACSubscriptionDisplay} = "Serials";
301 $tabsysprefs{RenewSerialAddsSuggestion} = "Serials";
302 $tabsysprefs{SubscriptionHistory} = "Serials";
305 $tabsysprefs{CataloguingLog} = "Logs";
306 $tabsysprefs{BorrowersLog} = "Logs";
307 $tabsysprefs{SubscriptionLog} = "Logs";
308 $tabsysprefs{IssueLog} = "Logs";
309 $tabsysprefs{ReturnLog} = "Logs";
310 $tabsysprefs{LetterLog} = "Logs";
311 $tabsysprefs{FinesLog} = "Logs";
314 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
315 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
316 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
317 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
318 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
321 my ( $searchstring, $type ) = @_;
322 my $dbh = C4::Context->dbh;
323 $searchstring =~ s/\'/\\\'/g;
324 my @data = split( ' ', $searchstring );
330 # used for doing a plain-old sys-pref search
331 if ( $type && $type ne 'all' ) {
332 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
333 if ( $tabsysprefs{$syspref} eq $type ) {
334 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
335 $sth->execute($syspref);
336 while ( my $data = $sth->fetchrow_hashref ) {
337 $data->{shortvalue} = $data->{value};
338 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
339 push( @results, $data );
348 if ( $type and $type eq 'all' ) {
349 $sth = $dbh->prepare( "
351 FROM systempreferences
352 WHERE variable LIKE ? OR explanation LIKE ?
353 ORDER BY VARIABLE" );
354 $sth->execute( "%$searchstring%", "%$searchstring%" );
356 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable not in (";
357 foreach my $syspref ( keys %tabsysprefs ) {
358 $strsth .= $dbh->quote($syspref) . ",";
361 $strsth .= " order by variable";
362 $sth = $dbh->prepare($strsth);
366 while ( my $data = $sth->fetchrow_hashref ) {
367 $data->{shortvalue} = $data->{value};
368 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
369 push( @results, $data );
375 return ( $cnt, \@results );
383 if ( defined $data->{'options'} ) {
384 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
386 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
387 push @options, { option => $option, selected => $selected };
391 $params->{'prefoptions'} = $data->{'options'};
393 if ( not defined( $data->{'type'} ) ) {
394 $params->{'type-free'} = 1;
395 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
396 } elsif ( $data->{'type'} eq 'Choice' ) {
397 $params->{'type-choice'} = 1;
398 } elsif ( $data->{'type'} eq 'YesNo' ) {
399 $params->{'type-yesno'} = 1;
400 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
401 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
402 $params->{'value-yes'} = 1;
404 $params->{'value-no'} = 1;
406 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
407 $params->{'type-free'} = 1;
408 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
409 } elsif ( $data->{'type'} eq 'Textarea' ) {
410 $params->{'type-textarea'} = 1;
411 $data->{options} =~ /(.*)\|(.*)/;
412 $params->{'cols'} = $1;
413 $params->{'rows'} = $2;
414 } elsif ( $data->{'type'} eq 'Themes' ) {
415 $params->{'type-choice'} = 1;
417 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
419 my $currently_selected_themes;
421 foreach my $theme ( split /\s+/, $data->{'value'} ) {
422 push @options, { option => $theme, counter => $counter };
423 $currently_selected_themes->{$theme} = 1;
426 foreach my $theme ( getallthemes($type) ) {
428 next if $currently_selected_themes->{$theme};
429 push @options, { option => $theme, counter => $counter };
432 } elsif ( $data->{'type'} eq 'ClassSources' ) {
433 $params->{'type-choice'} = 1;
436 my $sources = GetClassSources();
438 foreach my $cn_source ( sort keys %$sources ) {
439 if ( $cn_source eq $data->{'value'} ) {
440 push @options, { option => $cn_source, counter => $counter, selected => 1 };
442 push @options, { option => $cn_source, counter => $counter };
446 } elsif ( $data->{'type'} eq 'Languages' ) {
447 my $currently_selected_languages;
448 foreach my $language ( split /\s+/, $data->{'value'} ) {
449 $currently_selected_languages->{$language} = 1;
453 my $lang = $params->{'lang'};
456 if ( $data->{'variable'} =~ /opac/ ) {
460 $theme = C4::Context->preference('opacthemes');
463 # this is the staff client
464 $interface = 'intranet';
465 $theme = C4::Context->preference('template');
467 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
469 $params->{'languages_loop'} = $languages_loop;
470 $params->{'type-langselector'} = 1;
472 $params->{'type-free'} = 1;
473 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
476 if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
477 $params->{'oneline'} = 1;
480 $params->{'preftype'} = $data->{'type'};
481 $params->{'options'} = \@options;
487 my $searchfield = $input->param('searchfield') || '';
488 my $Tvalue = $input->param('Tvalue');
489 my $offset = $input->param('offset') || 0;
490 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
492 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
493 { template_name => "admin/systempreferences.tmpl",
496 authnotrequired => 0,
497 flagsrequired => { parameters => 1 },
502 my $op = $input->param('op') || '';
503 $searchfield =~ s/\,//g;
507 script_name => $script_name,
509 ); # we show only the TMPL_VAR names $op
512 script_name => $script_name,
514 ); # we show only the TMPL_VAR names $op
517 if ( $op eq 'update_and_reedit' ) {
518 foreach ( $input->param ) {
521 if ( my $currentorder = $input->param('currentorder') ) {
522 my @currentorder = split /\|/, $currentorder;
523 my $orderchanged = 0;
524 foreach my $param ( $input->param ) {
525 if ( $param =~ m#up-(\d+).x# ) {
526 my $temp = $currentorder[$1];
527 $currentorder[$1] = $currentorder[ $1 - 1 ];
528 $currentorder[ $1 - 1 ] = $temp;
531 } elsif ( $param =~ m#down-(\d+).x# ) {
532 my $temp = $currentorder[$1];
533 $currentorder[$1] = $currentorder[ $1 + 1 ];
534 $currentorder[ $1 + 1 ] = $temp;
539 $value = join ' ', @currentorder;
543 script_name => $script_name,
545 ); # we show only the TMPL_VAR names $op
550 script_name => $script_name,
552 ); # we show only the TMPL_VAR names $op
555 my $dbh = C4::Context->dbh;
556 my $query = "select * from systempreferences where variable=?";
557 my $sth = $dbh->prepare($query);
558 $sth->execute( $input->param('variable') );
560 unless ( C4::Context->config('demo') ) {
561 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
562 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
564 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
567 unless ( C4::Context->config('demo') ) {
568 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
569 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
571 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
578 ################## ADD_FORM ##################################
579 # called by default. Used to create form to add or modify a record
581 if ( $op eq 'add_form' ) {
583 #---- if primkey exists, it's a modify action, so read values to modify...
586 my $dbh = C4::Context->dbh;
587 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
588 $sth->execute($searchfield);
589 $data = $sth->fetchrow_hashref;
591 $template->param( modify => 1 );
593 # save tab to return to if user cancels edit
594 $template->param( return_tab => $tabsysprefs{$searchfield} );
597 $data->{'lang'} = $template->param('lang');
599 $template->param( GetPrefParams($data) );
601 $template->param( searchfield => $searchfield );
603 ################## ADD_VALIDATE ##################################
604 # called by add_form, used to insert/modify data in DB
605 } elsif ( $op eq 'add_validate' ) {
606 my $dbh = C4::Context->dbh;
607 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
608 $sth->execute( $input->param('variable') );
610 # to handle multiple values
613 # handle multiple value strings (separated by ',')
614 my $params = $input->Vars;
615 if ( defined $params->{'value'} ) {
617 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
620 for my $vl (@values) {
625 $value = $params->{'value'};
629 unless ( C4::Context->config('demo') ) {
630 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
631 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
633 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
636 unless ( C4::Context->config('demo') ) {
637 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
638 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
640 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
644 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
646 ################## DELETE_CONFIRM ##################################
647 # called by default form, used to confirm deletion of data in DB
648 } elsif ( $op eq 'delete_confirm' ) {
649 my $dbh = C4::Context->dbh;
650 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
651 $sth->execute($searchfield);
652 my $data = $sth->fetchrow_hashref;
655 searchfield => $searchfield,
656 Tvalue => $data->{'value'},
659 # END $OP eq DELETE_CONFIRM
660 ################## DELETE_CONFIRMED ##################################
661 # called by delete_confirm, used to effectively confirm deletion of data in DB
662 } elsif ( $op eq 'delete_confirmed' ) {
663 my $dbh = C4::Context->dbh;
664 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
665 $sth->execute($searchfield);
666 my $logstring = $searchfield . " | " . $Tvalue;
667 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
670 # END $OP eq DELETE_CONFIRMED
671 ################## DEFAULT ##################################
673 #Adding tab management for system preferences
674 my $tab = $input->param('tab');
675 $template->param( $tab => 1 );
676 my ( $count, $results ) = StringSearch( $searchfield, $tab );
679 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
680 if ( $toggle == 0 ) {
685 my $row_data = $results->[$i];
686 $row_data->{'lang'} = $template->param('lang');
687 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
688 $row_data->{toggle} = $toggle;
689 $row_data->{edit} = "$script_name?op=add_form&searchfield=" . $results->[$i]{'variable'};
690 $row_data->{delete} = "$script_name?op=delete_confirm&searchfield=" . $results->[$i]{'variable'};
691 push( @loop_data, $row_data );
693 $tab = ( $tab ? $tab : "Local Use" );
694 $template->param( loop => \@loop_data, $tab => 1 );
696 my $prevpage = $offset - $pagesize;
697 $template->param( "<a href=$script_name?offset=" . $prevpage . '<< Prev</a>' );
699 if ( $offset + $pagesize < $count ) {
700 my $nextpage = $offset + $pagesize;
701 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next >></a>' );
703 $template->param( tab => $tab, );
704 } #---- END $OP eq DEFAULT
705 output_html_with_http_headers $input, $cookie, $template->output;