3 # script to administer the systempref table
4 # written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
7 # Copyright 2000-2002 Katipo Communications
9 # This file is part of Koha.
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA 02111-1307 USA
24 =head1 systempreferences.pl
27 this script use an $op to know what to do.
28 if $op is empty or none of the above values,
29 - the default screen is build (with all records, or filtered datas).
30 - the user can clic on add, modify or delete record.
32 - if primkey exists, this is a modification,so we read the $primkey record
33 - builds the add/modify form
35 - the user has just send datas, so we create/modify the record
37 - we show the record having primkey=$primkey and ask for deletion validation form
39 - we delete the record having primkey=$primkey
50 use C4::Languages qw(getTranslatedLanguages);
55 # use Smart::Comments;
57 # FIXME, shouldnt we store this stuff in the systempreferences table?
59 # FIXME: This uses hash in a backwards way. What we really want is:
60 # $tabsysprefs{key} = $array_ref;
62 # $tabsysprefs{Cataloguing} = [qw(autoBarcode ISBD marc ...)];
64 # Because some things *should* be on more than one tab.
65 # And the tabname is the unique part (the key).
70 $tabsysprefs{acquisitions} = "Acquisitions";
71 $tabsysprefs{gist} = "Acquisitions";
72 $tabsysprefs{emailPurchaseSuggestions} = "Acquisitions";
73 $tabsysprefs{RenewSerialAddsSuggestion} = "Acquisitions";
76 $tabsysprefs{singleBranchMode} = "Admin";
77 $tabsysprefs{staffClientBaseURL} = "Admin";
78 $tabsysprefs{Version} = "Admin";
79 $tabsysprefs{OpacMaintenance} = "Admin";
80 $tabsysprefs{FrameworksLoaded} = "Admin";
81 $tabsysprefs{libraryAddress} = "Admin";
82 $tabsysprefs{delimiter} = "Admin";
83 $tabsysprefs{IndependantBranches} = "Admin";
84 $tabsysprefs{insecure} = "Admin";
85 $tabsysprefs{KohaAdmin} = "Admin";
86 $tabsysprefs{KohaAdminEmailAddress} = "Admin";
87 $tabsysprefs{MIME} = "Admin";
88 $tabsysprefs{timeout} = "Admin";
89 $tabsysprefs{Intranet_includes} = "Admin";
90 $tabsysprefs{AutoLocation} = "Admin";
91 $tabsysprefs{DebugLevel} = "Admin";
92 $tabsysprefs{SessionStorage} = "Admin";
93 $tabsysprefs{noItemTypeImages} = "Admin";
94 $tabsysprefs{OPACBaseURL} = "Admin";
95 $tabsysprefs{GranularPermissions} = "Admin";
98 $tabsysprefs{authoritysep} = "Authorities";
99 $tabsysprefs{AuthDisplayHierarchy} = "Authorities";
100 $tabsysprefs{dontmerge} = "Authorities";
101 $tabsysprefs{BiblioAddsAuthorities} = "Authorities";
104 $tabsysprefs{advancedMARCEditor} = "Cataloguing";
105 $tabsysprefs{autoBarcode} = "Cataloguing";
106 $tabsysprefs{hide_marc} = "Cataloguing";
107 $tabsysprefs{IntranetBiblioDefaultView} = "Cataloguing";
108 $tabsysprefs{ISBD} = "Cataloguing";
109 $tabsysprefs{itemcallnumber} = "Cataloguing";
110 $tabsysprefs{LabelMARCView} = "Cataloguing";
111 $tabsysprefs{marc} = "Cataloguing";
112 $tabsysprefs{marcflavour} = "Cataloguing";
113 $tabsysprefs{MARCOrgCode} = "Cataloguing";
114 $tabsysprefs{z3950AuthorAuthFields} = "Cataloguing";
115 $tabsysprefs{z3950NormalizeAuthor} = "Cataloguing";
116 $tabsysprefs{Stemming} = "Cataloguing";
117 $tabsysprefs{WeightFields} = "Cataloguing";
118 $tabsysprefs{NoZebra} = "Cataloguing";
119 $tabsysprefs{NoZebraIndexes} = "Cataloguing";
120 $tabsysprefs{ReceiveBackIssues} = "Cataloguing";
121 $tabsysprefs{DefaultClassificationSource} = "Cataloguing";
122 $tabsysprefs{RoutingSerials} = "Cataloguing";
123 $tabsysprefs{'item-level_itypes'} = "Cataloguing";
124 $tabsysprefs{OpacSuppression} = "Cataloguing";
127 $tabsysprefs{maxoutstanding} = "Circulation";
128 $tabsysprefs{maxreserves} = "Circulation";
129 $tabsysprefs{noissuescharge} = "Circulation";
130 $tabsysprefs{IssuingInProcess} = "Circulation";
131 $tabsysprefs{patronimages} = "Circulation";
132 $tabsysprefs{printcirculationslips} = "Circulation";
133 $tabsysprefs{ReturnBeforeExpiry} = "Circulation";
134 $tabsysprefs{SpecifyDueDate} = "Circulation";
135 $tabsysprefs{AutomaticItemReturn} = "Circulation";
136 $tabsysprefs{ReservesMaxPickUpDelay} = "Circulation";
137 $tabsysprefs{TransfersMaxDaysWarning} = "Circulation";
138 $tabsysprefs{useDaysMode} = "Circulation";
139 $tabsysprefs{ReservesNeedReturns} = "Circulation";
140 $tabsysprefs{CircAutocompl} = "Circulation";
141 $tabsysprefs{AllowRenewalLimitOverride} = "Circulation";
142 $tabsysprefs{canreservefromotherbranches} = "Circulation";
143 $tabsysprefs{finesMode} = "Circulation";
144 $tabsysprefs{emailLibrarianWhenHoldIsPlaced} = "Circulation";
145 $tabsysprefs{globalDueDate} = "Circulation";
146 $tabsysprefs{holdCancelLength} = "Circulation";
147 $tabsysprefs{itemBarcodeInputFilter} = "Circulation";
148 $tabsysprefs{WebBasedSelfCheck} = "Circulation";
149 $tabsysprefs{CircControl} = "Circulation";
150 $tabsysprefs{finesCalendar} = "Circulation";
151 $tabsysprefs{previousIssuesDefaultSortOrder} = "Circulation";
152 $tabsysprefs{todaysIssuesDefaultSortOrder} = "Circulation";
153 $tabsysprefs{HomeOrHoldingBranch} = "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{NoReturnSetLost} = "Patrons";
183 $tabsysprefs{MaxFine} = "Patrons";
184 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
185 $tabsysprefs{AddPatronLists} = "Patrons";
186 $tabsysprefs{PatronsPerPage} = "Patrons";
187 $tabsysprefs{ExtendedPatronAttributes} = "Patrons";
188 $tabsysprefs{AutoEmailOpacUser} = "Patrons";
189 $tabsysprefs{AutoEmailPrimaryAddress} = "Patrons";
190 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
191 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
194 $tabsysprefs{dateformat} = "I18N/L10N";
195 $tabsysprefs{opaclanguages} = "I18N/L10N";
196 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
197 $tabsysprefs{language} = "I18N/L10N";
200 $tabsysprefs{defaultSortField} = "Searching";
201 $tabsysprefs{defaultSortOrder} = "Searching";
202 $tabsysprefs{numSearchResults} = "Searching";
203 $tabsysprefs{OPACdefaultSortField} = "Searching";
204 $tabsysprefs{OPACdefaultSortOrder} = "Searching";
205 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
206 $tabsysprefs{OPACnumSearchResults} = "Searching";
207 $tabsysprefs{QueryFuzzy} = "Searching";
208 $tabsysprefs{QueryStemming} = "Searching";
209 $tabsysprefs{QueryWeightFields} = "Searching";
210 $tabsysprefs{expandedSearchOption} = "Searching";
211 $tabsysprefs{sortbynonfiling} = "Searching";
212 $tabsysprefs{QueryAutoTruncate} = "Searching";
213 $tabsysprefs{QueryRemoveStopwords} = "Searching";
214 $tabsysprefs{AdvancedSearchTypes} = "Searching";
217 $tabsysprefs{AmazonContent} = "EnhancedContent";
218 $tabsysprefs{AWSAccessKeyID} = "EnhancedContent";
219 $tabsysprefs{AmazonLocale} = "EnhancedContent";
220 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
221 $tabsysprefs{AmazonSimilarItems} = "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{SubscriptionHistory} = "OPAC";
263 $tabsysprefs{opacheader} = "OPAC";
264 $tabsysprefs{noOPACUserLogin} = "OPAC";
265 $tabsysprefs{hideBiblioNumber} = "OPAC";
266 $tabsysprefs{OPACDisplayExtendedSubInfo} = "OPAC";
267 $tabsysprefs{OpacMainUserBlock} = "OPAC";
268 $tabsysprefs{OPACSubscriptionDisplay} = "OPAC";
269 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
270 $tabsysprefs{OPACUserCSS} = "OPAC";
271 $tabsysprefs{OPACHighlightedWords} = "OPAC";
272 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
273 $tabsysprefs{URLLinkText} = "OPAC";
274 $tabsysprefs{OPACShelfBrowser} = "OPAC";
275 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
278 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
279 $tabsysprefs{hidelostitems} = "OPAC";
280 $tabsysprefs{opacbookbag} = "OPAC";
281 $tabsysprefs{OpacPasswordChange} = "OPAC";
282 $tabsysprefs{opacreadinghistory} = "OPAC";
283 $tabsysprefs{virtualshelves} = "OPAC";
284 $tabsysprefs{RequestOnOpac} = "OPAC";
285 $tabsysprefs{reviewson} = "OPAC";
286 $tabsysprefs{OpacTopissues} = "OPAC";
287 $tabsysprefs{OpacAuthorities} = "OPAC";
288 $tabsysprefs{OpacCloud} = "OPAC";
289 $tabsysprefs{opacuserlogin} = "OPAC";
290 $tabsysprefs{AnonSuggestions} = "OPAC";
291 $tabsysprefs{suggestion} = "OPAC";
292 $tabsysprefs{OpacTopissue} = "OPAC";
293 $tabsysprefs{OpacBrowser} = "OPAC";
294 $tabsysprefs{kohaspsuggest} = "OPAC";
295 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
296 $tabsysprefs{OPACItemHolds} = "OPAC";
297 $tabsysprefs{OPACGroupResults} = "OPAC";
298 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
299 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
302 $tabsysprefs{CataloguingLog} = "Logs";
303 $tabsysprefs{BorrowersLog} = "Logs";
304 $tabsysprefs{SubscriptionLog} = "Logs";
305 $tabsysprefs{IssueLog} = "Logs";
306 $tabsysprefs{ReturnLog} = "Logs";
307 $tabsysprefs{LetterLog} = "Logs";
308 $tabsysprefs{FinesLog} = "Logs";
311 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
312 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
313 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
314 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
315 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
318 my ( $searchstring, $type ) = @_;
319 my $dbh = C4::Context->dbh;
320 $searchstring =~ s/\'/\\\'/g;
321 my @data = split( ' ', $searchstring );
327 # used for doing a plain-old sys-pref search
328 if ( $type && $type ne 'all' ) {
329 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
330 if ( $tabsysprefs{$syspref} eq $type ) {
331 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
332 $sth->execute($syspref);
333 while ( my $data = $sth->fetchrow_hashref ) {
334 $data->{shortvalue} = $data->{value};
335 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
336 push( @results, $data );
345 if ( $type and $type eq 'all' ) {
346 $sth = $dbh->prepare( "
348 FROM systempreferences
349 WHERE variable LIKE ? OR explanation LIKE ?
350 ORDER BY VARIABLE" );
351 $sth->execute( "%$searchstring%", "%$searchstring%" );
353 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable not in (";
354 foreach my $syspref ( keys %tabsysprefs ) {
355 $strsth .= $dbh->quote($syspref) . ",";
358 $strsth .= " order by variable";
359 $sth = $dbh->prepare($strsth);
363 while ( my $data = $sth->fetchrow_hashref ) {
364 $data->{shortvalue} = $data->{value};
365 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
366 push( @results, $data );
372 return ( $cnt, \@results );
380 if ( defined $data->{'options'} ) {
381 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
383 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
384 push @options, { option => $option, selected => $selected };
388 $params->{'prefoptions'} = $data->{'options'};
390 if ( not defined( $data->{'type'} ) ) {
391 $params->{'type-free'} = 1;
392 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
393 } elsif ( $data->{'type'} eq 'Choice' ) {
394 $params->{'type-choice'} = 1;
395 } elsif ( $data->{'type'} eq 'YesNo' ) {
396 $params->{'type-yesno'} = 1;
397 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
398 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
399 $params->{'value-yes'} = 1;
401 $params->{'value-no'} = 1;
403 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
404 $params->{'type-free'} = 1;
405 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
406 } elsif ( $data->{'type'} eq 'Textarea' ) {
407 $params->{'type-textarea'} = 1;
408 $data->{options} =~ /(.*)\|(.*)/;
409 $params->{'cols'} = $1;
410 $params->{'rows'} = $2;
411 } elsif ( $data->{'type'} eq 'Themes' ) {
412 $params->{'type-choice'} = 1;
414 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
416 my $currently_selected_themes;
418 foreach my $theme ( split /\s+/, $data->{'value'} ) {
419 push @options, { option => $theme, counter => $counter };
420 $currently_selected_themes->{$theme} = 1;
423 foreach my $theme ( getallthemes($type) ) {
425 next if $currently_selected_themes->{$theme};
426 push @options, { option => $theme, counter => $counter };
429 } elsif ( $data->{'type'} eq 'ClassSources' ) {
430 $params->{'type-choice'} = 1;
433 my $sources = GetClassSources();
435 foreach my $cn_source ( sort keys %$sources ) {
436 if ( $cn_source eq $data->{'value'} ) {
437 push @options, { option => $cn_source, counter => $counter, selected => 1 };
439 push @options, { option => $cn_source, counter => $counter };
443 } elsif ( $data->{'type'} eq 'Languages' ) {
444 my $currently_selected_languages;
445 foreach my $language ( split /\s+/, $data->{'value'} ) {
446 $currently_selected_languages->{$language} = 1;
450 my $lang = $params->{'lang'};
453 if ( $data->{'variable'} =~ /opac/ ) {
457 $theme = C4::Context->preference('opacthemes');
460 # this is the staff client
461 $interface = 'intranet';
462 $theme = C4::Context->preference('template');
464 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
466 $params->{'languages_loop'} = $languages_loop;
467 $params->{'type-langselector'} = 1;
469 $params->{'type-free'} = 1;
470 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
473 if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
474 $params->{'oneline'} = 1;
477 $params->{'preftype'} = $data->{'type'};
478 $params->{'options'} = \@options;
484 my $searchfield = $input->param('searchfield') || '';
485 my $Tvalue = $input->param('Tvalue');
486 my $offset = $input->param('offset') || 0;
487 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
489 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
490 { template_name => "admin/systempreferences.tmpl",
493 authnotrequired => 0,
494 flagsrequired => { parameters => 1 },
499 my $op = $input->param('op') || '';
500 $searchfield =~ s/\,//g;
504 script_name => $script_name,
506 ); # we show only the TMPL_VAR names $op
509 script_name => $script_name,
511 ); # we show only the TMPL_VAR names $op
514 if ( $op eq 'update_and_reedit' ) {
515 foreach ( $input->param ) {
518 if ( my $currentorder = $input->param('currentorder') ) {
519 my @currentorder = split /\|/, $currentorder;
520 my $orderchanged = 0;
521 foreach my $param ( $input->param ) {
522 if ( $param =~ m#up-(\d+).x# ) {
523 my $temp = $currentorder[$1];
524 $currentorder[$1] = $currentorder[ $1 - 1 ];
525 $currentorder[ $1 - 1 ] = $temp;
528 } elsif ( $param =~ m#down-(\d+).x# ) {
529 my $temp = $currentorder[$1];
530 $currentorder[$1] = $currentorder[ $1 + 1 ];
531 $currentorder[ $1 + 1 ] = $temp;
536 $value = join ' ', @currentorder;
540 script_name => $script_name,
542 ); # we show only the TMPL_VAR names $op
547 script_name => $script_name,
549 ); # we show only the TMPL_VAR names $op
552 my $dbh = C4::Context->dbh;
553 my $query = "select * from systempreferences where variable=?";
554 my $sth = $dbh->prepare($query);
555 $sth->execute( $input->param('variable') );
557 unless ( C4::Context->config('demo') ) {
558 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
559 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
561 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
564 unless ( C4::Context->config('demo') ) {
565 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
566 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
568 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
575 ################## ADD_FORM ##################################
576 # called by default. Used to create form to add or modify a record
578 if ( $op eq 'add_form' ) {
580 #---- if primkey exists, it's a modify action, so read values to modify...
583 my $dbh = C4::Context->dbh;
584 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
585 $sth->execute($searchfield);
586 $data = $sth->fetchrow_hashref;
588 $template->param( modify => 1 );
590 # save tab to return to if user cancels edit
591 $template->param( return_tab => $tabsysprefs{$searchfield} );
594 $data->{'lang'} = $template->param('lang');
596 $template->param( GetPrefParams($data) );
598 $template->param( searchfield => $searchfield );
600 ################## ADD_VALIDATE ##################################
601 # called by add_form, used to insert/modify data in DB
602 } elsif ( $op eq 'add_validate' ) {
603 my $dbh = C4::Context->dbh;
604 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
605 $sth->execute( $input->param('variable') );
607 # to handle multiple values
610 # handle multiple value strings (separated by ',')
611 my $params = $input->Vars;
612 if ( defined $params->{'value'} ) {
614 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
617 for my $vl (@values) {
622 $value = $params->{'value'};
626 unless ( C4::Context->config('demo') ) {
627 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
628 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
630 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
633 unless ( C4::Context->config('demo') ) {
634 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
635 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
637 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
641 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
643 ################## DELETE_CONFIRM ##################################
644 # called by default form, used to confirm deletion of data in DB
645 } elsif ( $op eq 'delete_confirm' ) {
646 my $dbh = C4::Context->dbh;
647 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
648 $sth->execute($searchfield);
649 my $data = $sth->fetchrow_hashref;
652 searchfield => $searchfield,
653 Tvalue => $data->{'value'},
656 # END $OP eq DELETE_CONFIRM
657 ################## DELETE_CONFIRMED ##################################
658 # called by delete_confirm, used to effectively confirm deletion of data in DB
659 } elsif ( $op eq 'delete_confirmed' ) {
660 my $dbh = C4::Context->dbh;
661 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
662 $sth->execute($searchfield);
663 my $logstring = $searchfield . " | " . $Tvalue;
664 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
667 # END $OP eq DELETE_CONFIRMED
668 ################## DEFAULT ##################################
670 #Adding tab management for system preferences
671 my $tab = $input->param('tab');
672 $template->param( $tab => 1 );
673 my ( $count, $results ) = StringSearch( $searchfield, $tab );
676 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
677 if ( $toggle == 0 ) {
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->{toggle} = $toggle;
686 $row_data->{edit} = "$script_name?op=add_form&searchfield=" . $results->[$i]{'variable'};
687 $row_data->{delete} = "$script_name?op=delete_confirm&searchfield=" . $results->[$i]{'variable'};
688 push( @loop_data, $row_data );
690 $tab = ( $tab ? $tab : "Local Use" );
691 $template->param( loop => \@loop_data, $tab => 1 );
693 my $prevpage = $offset - $pagesize;
694 $template->param( "<a href=$script_name?offset=" . $prevpage . '<< Prev</a>' );
696 if ( $offset + $pagesize < $count ) {
697 my $nextpage = $offset + $pagesize;
698 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next >></a>' );
700 $template->param( tab => $tab, );
701 } #---- END $OP eq DEFAULT
702 output_html_with_http_headers $input, $cookie, $template->output;