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";
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{HomeOrHoldingBranchReturn} = "Circulation";
154 $tabsysprefs{RandomizeHoldsQueueWeight} = "Circulation";
155 $tabsysprefs{StaticHoldsQueueWeight} = "Circulation";
156 $tabsysprefs{AllowOnShelfHolds} = "Circulation";
157 $tabsysprefs{AllowHoldsOnDamagedItems} = "Circulation";
160 $tabsysprefs{TemplateEncoding} = "StaffClient";
161 $tabsysprefs{template} = "StaffClient";
162 $tabsysprefs{intranetstylesheet} = "StaffClient";
163 $tabsysprefs{IntranetNav} = "StaffClient";
164 $tabsysprefs{intranetcolorstylesheet} = "StaffClient";
165 $tabsysprefs{intranetuserjs} = "StaffClient";
166 $tabsysprefs{yuipath} = "StaffClient";
167 $tabsysprefs{IntranetmainUserblock} = "StaffClient";
170 $tabsysprefs{autoMemberNum} = "Patrons";
171 $tabsysprefs{checkdigit} = "Patrons";
172 $tabsysprefs{intranetreadinghistory} = "Patrons";
173 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
174 $tabsysprefs{memberofinstitution} = "Patrons";
175 #$tabsysprefs{ReadingHistory} = "Patrons";
176 $tabsysprefs{BorrowerMandatoryField} = "Patrons";
177 $tabsysprefs{borrowerRelationship} = "Patrons";
178 $tabsysprefs{BorrowersTitles} = "Patrons";
179 $tabsysprefs{patronimages} = "Patrons";
180 $tabsysprefs{minPasswordLength} = "Patrons";
181 $tabsysprefs{uppercasesurnames} = "Patrons";
182 $tabsysprefs{MaxFine} = "Patrons";
183 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
184 $tabsysprefs{AddPatronLists} = "Patrons";
185 $tabsysprefs{PatronsPerPage} = "Patrons";
186 $tabsysprefs{ExtendedPatronAttributes} = "Patrons";
187 $tabsysprefs{AutoEmailOpacUser} = "Patrons";
188 $tabsysprefs{AutoEmailPrimaryAddress} = "Patrons";
189 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
190 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
193 $tabsysprefs{dateformat} = "I18N/L10N";
194 $tabsysprefs{opaclanguages} = "I18N/L10N";
195 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
196 $tabsysprefs{language} = "I18N/L10N";
199 $tabsysprefs{defaultSortField} = "Searching";
200 $tabsysprefs{defaultSortOrder} = "Searching";
201 $tabsysprefs{numSearchResults} = "Searching";
202 $tabsysprefs{OPACdefaultSortField} = "Searching";
203 $tabsysprefs{OPACdefaultSortOrder} = "Searching";
204 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
205 $tabsysprefs{OPACnumSearchResults} = "Searching";
206 $tabsysprefs{QueryFuzzy} = "Searching";
207 $tabsysprefs{QueryStemming} = "Searching";
208 $tabsysprefs{QueryWeightFields} = "Searching";
209 $tabsysprefs{expandedSearchOption} = "Searching";
210 $tabsysprefs{sortbynonfiling} = "Searching";
211 $tabsysprefs{QueryAutoTruncate} = "Searching";
212 $tabsysprefs{QueryRemoveStopwords} = "Searching";
213 $tabsysprefs{AdvancedSearchTypes} = "Searching";
216 $tabsysprefs{AmazonContent} = "EnhancedContent";
217 $tabsysprefs{AWSAccessKeyID} = "EnhancedContent";
218 $tabsysprefs{AWSPrivateKey} = "EnhancedContent";
219 $tabsysprefs{AmazonLocale} = "EnhancedContent";
220 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
221 $tabsysprefs{AmazonSimilarItems} = "EnhancedContent";
222 $tabsysprefs{OPACAmazonCoverImages} = "EnhancedContent";
223 $tabsysprefs{OPACAmazonContent} = "EnhancedContent";
224 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
227 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
228 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
229 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
230 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
233 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
234 $tabsysprefs{XISBN} = "EnhancedContent";
235 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
236 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
237 $tabsysprefs{PINESISBN} = "EnhancedContent";
238 $tabsysprefs{ThingISBN} = "EnhancedContent";
239 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
242 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
243 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
244 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
245 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
246 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
247 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
248 $tabsysprefs{TagsModeration} = 'EnhancedContent';
249 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
250 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
253 $tabsysprefs{BiblioDefaultView} = "OPAC";
254 $tabsysprefs{LibraryName} = "OPAC";
255 $tabsysprefs{opaccolorstylesheet} = "OPAC";
256 $tabsysprefs{opaccredits} = "OPAC";
257 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
258 $tabsysprefs{OpacNav} = "OPAC";
259 $tabsysprefs{opacsmallimage} = "OPAC";
260 $tabsysprefs{opacstylesheet} = "OPAC";
261 $tabsysprefs{opacthemes} = "OPAC";
262 $tabsysprefs{opacuserjs} = "OPAC";
263 $tabsysprefs{opacheader} = "OPAC";
264 $tabsysprefs{hideBiblioNumber} = "OPAC";
265 $tabsysprefs{OpacMainUserBlock} = "OPAC";
266 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
267 $tabsysprefs{OPACUserCSS} = "OPAC";
268 $tabsysprefs{OPACHighlightedWords} = "OPAC";
269 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
270 $tabsysprefs{URLLinkText} = "OPAC";
271 $tabsysprefs{OPACShelfBrowser} = "OPAC";
272 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
275 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
276 $tabsysprefs{hidelostitems} = "OPAC";
277 $tabsysprefs{opacbookbag} = "OPAC";
278 $tabsysprefs{OpacPasswordChange} = "OPAC";
279 $tabsysprefs{opacreadinghistory} = "OPAC";
280 $tabsysprefs{virtualshelves} = "OPAC";
281 $tabsysprefs{RequestOnOpac} = "OPAC";
282 $tabsysprefs{reviewson} = "OPAC";
283 $tabsysprefs{OpacTopissues} = "OPAC";
284 $tabsysprefs{OpacAuthorities} = "OPAC";
285 $tabsysprefs{OpacCloud} = "OPAC";
286 $tabsysprefs{opacuserlogin} = "OPAC";
287 $tabsysprefs{AnonSuggestions} = "OPAC";
288 $tabsysprefs{suggestion} = "OPAC";
289 $tabsysprefs{OpacTopissue} = "OPAC";
290 $tabsysprefs{OpacBrowser} = "OPAC";
291 $tabsysprefs{OpacRecentAcquisitions} = "OPAC";
292 $tabsysprefs{kohaspsuggest} = "OPAC";
293 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
294 $tabsysprefs{OPACItemHolds} = "OPAC";
295 $tabsysprefs{OPACGroupResults} = "OPAC";
296 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
297 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
300 $tabsysprefs{OPACSerialIssueDisplayCount} = "Serials";
301 $tabsysprefs{StaffSerialIssueDisplayCount} = "Serials";
302 $tabsysprefs{OPACDisplayExtendedSubInfo} = "Serials";
303 $tabsysprefs{OPACSubscriptionDisplay} = "Serials";
304 $tabsysprefs{RenewSerialAddsSuggestion} = "Serials";
305 $tabsysprefs{SubscriptionHistory} = "Serials";
308 $tabsysprefs{CataloguingLog} = "Logs";
309 $tabsysprefs{BorrowersLog} = "Logs";
310 $tabsysprefs{SubscriptionLog} = "Logs";
311 $tabsysprefs{IssueLog} = "Logs";
312 $tabsysprefs{ReturnLog} = "Logs";
313 $tabsysprefs{LetterLog} = "Logs";
314 $tabsysprefs{FinesLog} = "Logs";
317 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
318 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
319 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
320 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
321 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
324 my ( $searchstring, $type ) = @_;
325 my $dbh = C4::Context->dbh;
326 $searchstring =~ s/\'/\\\'/g;
327 my @data = split( ' ', $searchstring );
333 # used for doing a plain-old sys-pref search
334 if ( $type && $type ne 'all' ) {
335 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
336 if ( $tabsysprefs{$syspref} eq $type ) {
337 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
338 $sth->execute($syspref);
339 while ( my $data = $sth->fetchrow_hashref ) {
340 $data->{shortvalue} = $data->{value};
341 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
342 push( @results, $data );
351 if ( $type and $type eq 'all' ) {
352 $sth = $dbh->prepare( "
354 FROM systempreferences
355 WHERE variable LIKE ? OR explanation LIKE ?
356 ORDER BY VARIABLE" );
357 $sth->execute( "%$searchstring%", "%$searchstring%" );
359 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable not in (";
360 foreach my $syspref ( keys %tabsysprefs ) {
361 $strsth .= $dbh->quote($syspref) . ",";
364 $strsth .= " order by variable";
365 $sth = $dbh->prepare($strsth);
369 while ( my $data = $sth->fetchrow_hashref ) {
370 $data->{shortvalue} = $data->{value};
371 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
372 push( @results, $data );
378 return ( $cnt, \@results );
386 if ( defined $data->{'options'} ) {
387 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
389 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
390 push @options, { option => $option, selected => $selected };
394 $params->{'prefoptions'} = $data->{'options'};
396 if ( not defined( $data->{'type'} ) ) {
397 $params->{'type-free'} = 1;
398 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
399 } elsif ( $data->{'type'} eq 'Choice' ) {
400 $params->{'type-choice'} = 1;
401 } elsif ( $data->{'type'} eq 'YesNo' ) {
402 $params->{'type-yesno'} = 1;
403 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
404 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
405 $params->{'value-yes'} = 1;
407 $params->{'value-no'} = 1;
409 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
410 $params->{'type-free'} = 1;
411 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
412 } elsif ( $data->{'type'} eq 'Textarea' ) {
413 $params->{'type-textarea'} = 1;
414 $data->{options} =~ /(.*)\|(.*)/;
415 $params->{'cols'} = $1;
416 $params->{'rows'} = $2;
417 } elsif ( $data->{'type'} eq 'Themes' ) {
418 $params->{'type-choice'} = 1;
420 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
422 my $currently_selected_themes;
424 foreach my $theme ( split /\s+/, $data->{'value'} ) {
425 push @options, { option => $theme, counter => $counter };
426 $currently_selected_themes->{$theme} = 1;
429 foreach my $theme ( getallthemes($type) ) {
431 next if $currently_selected_themes->{$theme};
432 push @options, { option => $theme, counter => $counter };
435 } elsif ( $data->{'type'} eq 'ClassSources' ) {
436 $params->{'type-choice'} = 1;
439 my $sources = GetClassSources();
441 foreach my $cn_source ( sort keys %$sources ) {
442 if ( $cn_source eq $data->{'value'} ) {
443 push @options, { option => $cn_source, counter => $counter, selected => 1 };
445 push @options, { option => $cn_source, counter => $counter };
449 } elsif ( $data->{'type'} eq 'Languages' ) {
450 my $currently_selected_languages;
451 foreach my $language ( split /\s+/, $data->{'value'} ) {
452 $currently_selected_languages->{$language} = 1;
456 my $lang = $params->{'lang'};
459 if ( $data->{'variable'} =~ /opac/ ) {
463 $theme = C4::Context->preference('opacthemes');
466 # this is the staff client
467 $interface = 'intranet';
468 $theme = C4::Context->preference('template');
470 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
472 $params->{'languages_loop'} = $languages_loop;
473 $params->{'type-langselector'} = 1;
475 $params->{'type-free'} = 1;
476 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
479 if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
480 $params->{'oneline'} = 1;
483 $params->{'preftype'} = $data->{'type'};
484 $params->{'options'} = \@options;
490 my $searchfield = $input->param('searchfield') || '';
491 my $Tvalue = $input->param('Tvalue');
492 my $offset = $input->param('offset') || 0;
493 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
495 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
496 { template_name => "admin/systempreferences.tmpl",
499 authnotrequired => 0,
500 flagsrequired => { parameters => 1 },
505 my $op = $input->param('op') || '';
506 $searchfield =~ s/\,//g;
510 script_name => $script_name,
512 ); # we show only the TMPL_VAR names $op
515 script_name => $script_name,
517 ); # we show only the TMPL_VAR names $op
520 if ( $op eq 'update_and_reedit' ) {
521 foreach ( $input->param ) {
524 if ( my $currentorder = $input->param('currentorder') ) {
525 my @currentorder = split /\|/, $currentorder;
526 my $orderchanged = 0;
527 foreach my $param ( $input->param ) {
528 if ( $param =~ m#up-(\d+).x# ) {
529 my $temp = $currentorder[$1];
530 $currentorder[$1] = $currentorder[ $1 - 1 ];
531 $currentorder[ $1 - 1 ] = $temp;
534 } elsif ( $param =~ m#down-(\d+).x# ) {
535 my $temp = $currentorder[$1];
536 $currentorder[$1] = $currentorder[ $1 + 1 ];
537 $currentorder[ $1 + 1 ] = $temp;
542 $value = join ' ', @currentorder;
546 script_name => $script_name,
548 ); # we show only the TMPL_VAR names $op
553 script_name => $script_name,
555 ); # we show only the TMPL_VAR names $op
558 my $dbh = C4::Context->dbh;
559 my $query = "select * from systempreferences where variable=?";
560 my $sth = $dbh->prepare($query);
561 $sth->execute( $input->param('variable') );
563 unless ( C4::Context->config('demo') ) {
564 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
565 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
567 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
570 unless ( C4::Context->config('demo') ) {
571 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
572 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
574 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
581 ################## ADD_FORM ##################################
582 # called by default. Used to create form to add or modify a record
584 if ( $op eq 'add_form' ) {
586 #---- if primkey exists, it's a modify action, so read values to modify...
589 my $dbh = C4::Context->dbh;
590 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
591 $sth->execute($searchfield);
592 $data = $sth->fetchrow_hashref;
594 $template->param( modify => 1 );
596 # save tab to return to if user cancels edit
597 $template->param( return_tab => $tabsysprefs{$searchfield} );
600 $data->{'lang'} = $template->param('lang');
602 $template->param( GetPrefParams($data) );
604 $template->param( searchfield => $searchfield );
606 ################## ADD_VALIDATE ##################################
607 # called by add_form, used to insert/modify data in DB
608 } elsif ( $op eq 'add_validate' ) {
609 my $dbh = C4::Context->dbh;
610 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
611 $sth->execute( $input->param('variable') );
613 # to handle multiple values
616 # handle multiple value strings (separated by ',')
617 my $params = $input->Vars;
618 if ( defined $params->{'value'} ) {
620 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
623 for my $vl (@values) {
628 $value = $params->{'value'};
632 unless ( C4::Context->config('demo') ) {
633 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
634 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
636 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
639 unless ( C4::Context->config('demo') ) {
640 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
641 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
643 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
647 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
649 ################## DELETE_CONFIRM ##################################
650 # called by default form, used to confirm deletion of data in DB
651 } elsif ( $op eq 'delete_confirm' ) {
652 my $dbh = C4::Context->dbh;
653 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
654 $sth->execute($searchfield);
655 my $data = $sth->fetchrow_hashref;
658 searchfield => $searchfield,
659 Tvalue => $data->{'value'},
662 # END $OP eq DELETE_CONFIRM
663 ################## DELETE_CONFIRMED ##################################
664 # called by delete_confirm, used to effectively confirm deletion of data in DB
665 } elsif ( $op eq 'delete_confirmed' ) {
666 my $dbh = C4::Context->dbh;
667 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
668 $sth->execute($searchfield);
669 my $logstring = $searchfield . " | " . $Tvalue;
670 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
673 # END $OP eq DELETE_CONFIRMED
674 ################## DEFAULT ##################################
676 #Adding tab management for system preferences
677 my $tab = $input->param('tab');
678 $template->param( $tab => 1 );
679 my ( $count, $results ) = StringSearch( $searchfield, $tab );
681 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
682 my $row_data = $results->[$i];
683 $row_data->{'lang'} = $template->param('lang');
684 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
685 $row_data->{edit} = "$script_name?op=add_form&searchfield=" . $results->[$i]{'variable'};
686 $row_data->{delete} = "$script_name?op=delete_confirm&searchfield=" . $results->[$i]{'variable'};
687 push( @loop_data, $row_data );
689 $tab = ( $tab ? $tab : "Local Use" );
690 $template->param( loop => \@loop_data, $tab => 1 );
692 my $prevpage = $offset - $pagesize;
693 $template->param( "<a href=$script_name?offset=" . $prevpage . '<< Prev</a>' );
695 if ( $offset + $pagesize < $count ) {
696 my $nextpage = $offset + $pagesize;
697 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next >></a>' );
699 $template->param( tab => $tab, );
700 } #---- END $OP eq DEFAULT
701 output_html_with_http_headers $input, $cookie, $template->output;