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{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{AWSPrivateKey} = "EnhancedContent";
218 $tabsysprefs{AmazonLocale} = "EnhancedContent";
219 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
220 $tabsysprefs{AmazonSimilarItems} = "EnhancedContent";
221 $tabsysprefs{OPACAmazonCoverImages} = "EnhancedContent";
222 $tabsysprefs{OPACAmazonContent} = "EnhancedContent";
223 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
226 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
227 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
228 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
229 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
232 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
233 $tabsysprefs{XISBN} = "EnhancedContent";
234 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
235 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
236 $tabsysprefs{PINESISBN} = "EnhancedContent";
237 $tabsysprefs{ThingISBN} = "EnhancedContent";
238 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
241 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
242 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
243 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
244 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
245 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
246 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
247 $tabsysprefs{TagsModeration} = 'EnhancedContent';
248 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
249 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
252 $tabsysprefs{BiblioDefaultView} = "OPAC";
253 $tabsysprefs{LibraryName} = "OPAC";
254 $tabsysprefs{opaccolorstylesheet} = "OPAC";
255 $tabsysprefs{opaccredits} = "OPAC";
256 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
257 $tabsysprefs{OpacNav} = "OPAC";
258 $tabsysprefs{opacsmallimage} = "OPAC";
259 $tabsysprefs{opacstylesheet} = "OPAC";
260 $tabsysprefs{opacthemes} = "OPAC";
261 $tabsysprefs{opacuserjs} = "OPAC";
262 $tabsysprefs{opacheader} = "OPAC";
263 $tabsysprefs{hideBiblioNumber} = "OPAC";
264 $tabsysprefs{OpacMainUserBlock} = "OPAC";
265 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
266 $tabsysprefs{OPACUserCSS} = "OPAC";
267 $tabsysprefs{OPACHighlightedWords} = "OPAC";
268 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
269 $tabsysprefs{URLLinkText} = "OPAC";
270 $tabsysprefs{OPACShelfBrowser} = "OPAC";
271 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
274 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
275 $tabsysprefs{hidelostitems} = "OPAC";
276 $tabsysprefs{opacbookbag} = "OPAC";
277 $tabsysprefs{OpacPasswordChange} = "OPAC";
278 $tabsysprefs{opacreadinghistory} = "OPAC";
279 $tabsysprefs{virtualshelves} = "OPAC";
280 $tabsysprefs{RequestOnOpac} = "OPAC";
281 $tabsysprefs{reviewson} = "OPAC";
282 $tabsysprefs{OpacTopissues} = "OPAC";
283 $tabsysprefs{OpacAuthorities} = "OPAC";
284 $tabsysprefs{OpacCloud} = "OPAC";
285 $tabsysprefs{opacuserlogin} = "OPAC";
286 $tabsysprefs{AnonSuggestions} = "OPAC";
287 $tabsysprefs{suggestion} = "OPAC";
288 $tabsysprefs{OpacTopissue} = "OPAC";
289 $tabsysprefs{OpacBrowser} = "OPAC";
290 $tabsysprefs{OpacRecentAcquisitions} = "OPAC";
291 $tabsysprefs{kohaspsuggest} = "OPAC";
292 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
293 $tabsysprefs{OPACItemHolds} = "OPAC";
294 $tabsysprefs{OPACGroupResults} = "OPAC";
295 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
296 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
299 $tabsysprefs{OPACSerialIssueDisplayCount} = "Serials";
300 $tabsysprefs{StaffSerialIssueDisplayCount} = "Serials";
301 $tabsysprefs{OPACDisplayExtendedSubInfo} = "Serials";
302 $tabsysprefs{OPACSubscriptionDisplay} = "Serials";
303 $tabsysprefs{RenewSerialAddsSuggestion} = "Serials";
304 $tabsysprefs{SubscriptionHistory} = "Serials";
307 $tabsysprefs{CataloguingLog} = "Logs";
308 $tabsysprefs{BorrowersLog} = "Logs";
309 $tabsysprefs{SubscriptionLog} = "Logs";
310 $tabsysprefs{IssueLog} = "Logs";
311 $tabsysprefs{ReturnLog} = "Logs";
312 $tabsysprefs{LetterLog} = "Logs";
313 $tabsysprefs{FinesLog} = "Logs";
316 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
317 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
318 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
319 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
320 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
323 my ( $searchstring, $type ) = @_;
324 my $dbh = C4::Context->dbh;
325 $searchstring =~ s/\'/\\\'/g;
326 my @data = split( ' ', $searchstring );
332 # used for doing a plain-old sys-pref search
333 if ( $type && $type ne 'all' ) {
334 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
335 if ( $tabsysprefs{$syspref} eq $type ) {
336 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
337 $sth->execute($syspref);
338 while ( my $data = $sth->fetchrow_hashref ) {
339 $data->{shortvalue} = $data->{value};
340 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
341 push( @results, $data );
350 if ( $type and $type eq 'all' ) {
351 $sth = $dbh->prepare( "
353 FROM systempreferences
354 WHERE variable LIKE ? OR explanation LIKE ?
355 ORDER BY VARIABLE" );
356 $sth->execute( "%$searchstring%", "%$searchstring%" );
358 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable not in (";
359 foreach my $syspref ( keys %tabsysprefs ) {
360 $strsth .= $dbh->quote($syspref) . ",";
363 $strsth .= " order by variable";
364 $sth = $dbh->prepare($strsth);
368 while ( my $data = $sth->fetchrow_hashref ) {
369 $data->{shortvalue} = $data->{value};
370 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
371 push( @results, $data );
377 return ( $cnt, \@results );
385 if ( defined $data->{'options'} ) {
386 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
388 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
389 push @options, { option => $option, selected => $selected };
393 $params->{'prefoptions'} = $data->{'options'};
395 if ( not defined( $data->{'type'} ) ) {
396 $params->{'type-free'} = 1;
397 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
398 } elsif ( $data->{'type'} eq 'Choice' ) {
399 $params->{'type-choice'} = 1;
400 } elsif ( $data->{'type'} eq 'YesNo' ) {
401 $params->{'type-yesno'} = 1;
402 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
403 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
404 $params->{'value-yes'} = 1;
406 $params->{'value-no'} = 1;
408 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
409 $params->{'type-free'} = 1;
410 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
411 } elsif ( $data->{'type'} eq 'Textarea' ) {
412 $params->{'type-textarea'} = 1;
413 $data->{options} =~ /(.*)\|(.*)/;
414 $params->{'cols'} = $1;
415 $params->{'rows'} = $2;
416 } elsif ( $data->{'type'} eq 'Themes' ) {
417 $params->{'type-choice'} = 1;
419 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
421 my $currently_selected_themes;
423 foreach my $theme ( split /\s+/, $data->{'value'} ) {
424 push @options, { option => $theme, counter => $counter };
425 $currently_selected_themes->{$theme} = 1;
428 foreach my $theme ( getallthemes($type) ) {
430 next if $currently_selected_themes->{$theme};
431 push @options, { option => $theme, counter => $counter };
434 } elsif ( $data->{'type'} eq 'ClassSources' ) {
435 $params->{'type-choice'} = 1;
438 my $sources = GetClassSources();
440 foreach my $cn_source ( sort keys %$sources ) {
441 if ( $cn_source eq $data->{'value'} ) {
442 push @options, { option => $cn_source, counter => $counter, selected => 1 };
444 push @options, { option => $cn_source, counter => $counter };
448 } elsif ( $data->{'type'} eq 'Languages' ) {
449 my $currently_selected_languages;
450 foreach my $language ( split /\s+/, $data->{'value'} ) {
451 $currently_selected_languages->{$language} = 1;
455 my $lang = $params->{'lang'};
458 if ( $data->{'variable'} =~ /opac/ ) {
462 $theme = C4::Context->preference('opacthemes');
465 # this is the staff client
466 $interface = 'intranet';
467 $theme = C4::Context->preference('template');
469 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
471 $params->{'languages_loop'} = $languages_loop;
472 $params->{'type-langselector'} = 1;
474 $params->{'type-free'} = 1;
475 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
478 if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
479 $params->{'oneline'} = 1;
482 $params->{'preftype'} = $data->{'type'};
483 $params->{'options'} = \@options;
489 my $searchfield = $input->param('searchfield') || '';
490 my $Tvalue = $input->param('Tvalue');
491 my $offset = $input->param('offset') || 0;
492 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
494 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
495 { template_name => "admin/systempreferences.tmpl",
498 authnotrequired => 0,
499 flagsrequired => { parameters => 1 },
504 my $op = $input->param('op') || '';
505 $searchfield =~ s/\,//g;
509 script_name => $script_name,
511 ); # we show only the TMPL_VAR names $op
514 script_name => $script_name,
516 ); # we show only the TMPL_VAR names $op
519 if ( $op eq 'update_and_reedit' ) {
520 foreach ( $input->param ) {
523 if ( my $currentorder = $input->param('currentorder') ) {
524 my @currentorder = split /\|/, $currentorder;
525 my $orderchanged = 0;
526 foreach my $param ( $input->param ) {
527 if ( $param =~ m#up-(\d+).x# ) {
528 my $temp = $currentorder[$1];
529 $currentorder[$1] = $currentorder[ $1 - 1 ];
530 $currentorder[ $1 - 1 ] = $temp;
533 } elsif ( $param =~ m#down-(\d+).x# ) {
534 my $temp = $currentorder[$1];
535 $currentorder[$1] = $currentorder[ $1 + 1 ];
536 $currentorder[ $1 + 1 ] = $temp;
541 $value = join ' ', @currentorder;
545 script_name => $script_name,
547 ); # we show only the TMPL_VAR names $op
552 script_name => $script_name,
554 ); # we show only the TMPL_VAR names $op
557 my $dbh = C4::Context->dbh;
558 my $query = "select * from systempreferences where variable=?";
559 my $sth = $dbh->prepare($query);
560 $sth->execute( $input->param('variable') );
562 unless ( C4::Context->config('demo') ) {
563 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
564 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
566 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
569 unless ( C4::Context->config('demo') ) {
570 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
571 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
573 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
580 ################## ADD_FORM ##################################
581 # called by default. Used to create form to add or modify a record
583 if ( $op eq 'add_form' ) {
585 #---- if primkey exists, it's a modify action, so read values to modify...
588 my $dbh = C4::Context->dbh;
589 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
590 $sth->execute($searchfield);
591 $data = $sth->fetchrow_hashref;
593 $template->param( modify => 1 );
595 # save tab to return to if user cancels edit
596 $template->param( return_tab => $tabsysprefs{$searchfield} );
599 $data->{'lang'} = $template->param('lang');
601 $template->param( GetPrefParams($data) );
603 $template->param( searchfield => $searchfield );
605 ################## ADD_VALIDATE ##################################
606 # called by add_form, used to insert/modify data in DB
607 } elsif ( $op eq 'add_validate' ) {
608 my $dbh = C4::Context->dbh;
609 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
610 $sth->execute( $input->param('variable') );
612 # to handle multiple values
615 # handle multiple value strings (separated by ',')
616 my $params = $input->Vars;
617 if ( defined $params->{'value'} ) {
619 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
622 for my $vl (@values) {
627 $value = $params->{'value'};
631 unless ( C4::Context->config('demo') ) {
632 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
633 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
635 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
638 unless ( C4::Context->config('demo') ) {
639 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
640 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
642 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
646 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
648 ################## DELETE_CONFIRM ##################################
649 # called by default form, used to confirm deletion of data in DB
650 } elsif ( $op eq 'delete_confirm' ) {
651 my $dbh = C4::Context->dbh;
652 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
653 $sth->execute($searchfield);
654 my $data = $sth->fetchrow_hashref;
657 searchfield => $searchfield,
658 Tvalue => $data->{'value'},
661 # END $OP eq DELETE_CONFIRM
662 ################## DELETE_CONFIRMED ##################################
663 # called by delete_confirm, used to effectively confirm deletion of data in DB
664 } elsif ( $op eq 'delete_confirmed' ) {
665 my $dbh = C4::Context->dbh;
666 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
667 $sth->execute($searchfield);
668 my $logstring = $searchfield . " | " . $Tvalue;
669 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
672 # END $OP eq DELETE_CONFIRMED
673 ################## DEFAULT ##################################
675 #Adding tab management for system preferences
676 my $tab = $input->param('tab');
677 $template->param( $tab => 1 );
678 my ( $count, $results ) = StringSearch( $searchfield, $tab );
680 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
681 my $row_data = $results->[$i];
682 $row_data->{'lang'} = $template->param('lang');
683 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
684 $row_data->{edit} = "$script_name?op=add_form&searchfield=" . $results->[$i]{'variable'};
685 $row_data->{delete} = "$script_name?op=delete_confirm&searchfield=" . $results->[$i]{'variable'};
686 push( @loop_data, $row_data );
688 $tab = ( $tab ? $tab : "Local Use" );
689 $template->param( loop => \@loop_data, $tab => 1 );
691 my $prevpage = $offset - $pagesize;
692 $template->param( "<a href=$script_name?offset=" . $prevpage . '<< Prev</a>' );
694 if ( $offset + $pagesize < $count ) {
695 my $nextpage = $offset + $pagesize;
696 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next >></a>' );
698 $template->param( tab => $tab, );
699 } #---- END $OP eq DEFAULT
700 output_html_with_http_headers $input, $cookie, $template->output;