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";
158 $tabsysprefs{UseBranchTransferLimits} = "Circulation";
159 $tabsysprefs{AllowHoldPolicyOverride} = "Circulation";
160 $tabsysprefs{BranchTransferLimitsType} = "Circulation";
163 $tabsysprefs{TemplateEncoding} = "StaffClient";
164 $tabsysprefs{template} = "StaffClient";
165 $tabsysprefs{intranetstylesheet} = "StaffClient";
166 $tabsysprefs{IntranetNav} = "StaffClient";
167 $tabsysprefs{intranetcolorstylesheet} = "StaffClient";
168 $tabsysprefs{intranetuserjs} = "StaffClient";
169 $tabsysprefs{yuipath} = "StaffClient";
170 $tabsysprefs{IntranetmainUserblock} = "StaffClient";
173 $tabsysprefs{autoMemberNum} = "Patrons";
174 $tabsysprefs{checkdigit} = "Patrons";
175 $tabsysprefs{intranetreadinghistory} = "Patrons";
176 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
177 $tabsysprefs{memberofinstitution} = "Patrons";
178 $tabsysprefs{ReadingHistory} = "Patrons";
179 $tabsysprefs{BorrowerMandatoryField} = "Patrons";
180 $tabsysprefs{borrowerRelationship} = "Patrons";
181 $tabsysprefs{BorrowersTitles} = "Patrons";
182 $tabsysprefs{patronimages} = "Patrons";
183 $tabsysprefs{MinPasswordLength} = "Patrons";
184 $tabsysprefs{uppercasesurnames} = "Patrons";
185 $tabsysprefs{NoReturnSetLost} = "Patrons";
186 $tabsysprefs{MaxFine} = "Patrons";
187 $tabsysprefs{NotifyBorrowerDeparture} = "Patrons";
188 $tabsysprefs{AddPatronLists} = "Patrons";
189 $tabsysprefs{PatronsPerPage} = "Patrons";
190 $tabsysprefs{ExtendedPatronAttributes} = "Patrons";
191 $tabsysprefs{AutoEmailOpacUser} = "Patrons";
192 $tabsysprefs{AutoEmailPrimaryAddress} = "Patrons";
193 $tabsysprefs{EnhancedMessagingPreferences} = "Patrons";
194 $tabsysprefs{'SMSSendDriver'} = 'Patrons';
197 $tabsysprefs{dateformat} = "I18N/L10N";
198 $tabsysprefs{opaclanguages} = "I18N/L10N";
199 $tabsysprefs{opaclanguagesdisplay} = "I18N/L10N";
200 $tabsysprefs{language} = "I18N/L10N";
203 $tabsysprefs{defaultSortField} = "Searching";
204 $tabsysprefs{defaultSortOrder} = "Searching";
205 $tabsysprefs{numSearchResults} = "Searching";
206 $tabsysprefs{OPACdefaultSortField} = "Searching";
207 $tabsysprefs{OPACdefaultSortOrder} = "Searching";
208 $tabsysprefs{OPACItemsResultsDisplay} = "Searching";
209 $tabsysprefs{OPACnumSearchResults} = "Searching";
210 $tabsysprefs{QueryFuzzy} = "Searching";
211 $tabsysprefs{QueryStemming} = "Searching";
212 $tabsysprefs{QueryWeightFields} = "Searching";
213 $tabsysprefs{expandedSearchOption} = "Searching";
214 $tabsysprefs{sortbynonfiling} = "Searching";
215 $tabsysprefs{QueryAutoTruncate} = "Searching";
216 $tabsysprefs{QueryRemoveStopwords} = "Searching";
217 $tabsysprefs{AdvancedSearchTypes} = "Searching";
220 $tabsysprefs{AmazonContent} = "EnhancedContent";
221 $tabsysprefs{AWSAccessKeyID} = "EnhancedContent";
222 $tabsysprefs{AmazonLocale} = "EnhancedContent";
223 $tabsysprefs{AmazonAssocTag} = "EnhancedContent";
224 $tabsysprefs{AmazonSimilarItems} = "EnhancedContent";
225 $tabsysprefs{OPACAmazonContent} = "EnhancedContent";
226 $tabsysprefs{OPACAmazonSimilarItems} = "EnhancedContent";
229 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
230 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
231 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
232 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
235 $tabsysprefs{SyndeticsClientCode} = 'EnhancedContent';
236 $tabsysprefs{SyndeticsEnabled} = 'EnhancedContent';
237 $tabsysprefs{SyndeticsCoverImages} = 'EnhancedContent';
238 $tabsysprefs{SyndeticsTOC} = 'EnhancedContent';
239 $tabsysprefs{SyndeticsSummary} = 'EnhancedContent';
240 $tabsysprefs{SyndeticsEditions} = 'EnhancedContent';
241 $tabsysprefs{SyndeticsExcerpt} = 'EnhancedContent';
244 $tabsysprefs{FRBRizeEditions} = "EnhancedContent";
245 $tabsysprefs{XISBN} = "EnhancedContent";
246 $tabsysprefs{OCLCAffiliateID} = "EnhancedContent";
247 $tabsysprefs{XISBNDailyLimit} = "EnhancedContent";
248 $tabsysprefs{PINESISBN} = "EnhancedContent";
249 $tabsysprefs{ThingISBN} = "EnhancedContent";
250 $tabsysprefs{OPACFRBRizeEditions} = "EnhancedContent";
253 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
254 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
255 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
256 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
257 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
258 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
259 $tabsysprefs{TagsModeration} = 'EnhancedContent';
260 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
261 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
264 $tabsysprefs{BiblioDefaultView} = "OPAC";
265 $tabsysprefs{LibraryName} = "OPAC";
266 $tabsysprefs{opaccolorstylesheet} = "OPAC";
267 $tabsysprefs{opaccredits} = "OPAC";
268 $tabsysprefs{opaclayoutstylesheet} = "OPAC";
269 $tabsysprefs{OpacNav} = "OPAC";
270 $tabsysprefs{opacsmallimage} = "OPAC";
271 $tabsysprefs{opacstylesheet} = "OPAC";
272 $tabsysprefs{opacthemes} = "OPAC";
273 $tabsysprefs{opacuserjs} = "OPAC";
274 $tabsysprefs{SubscriptionHistory} = "OPAC";
275 $tabsysprefs{opacheader} = "OPAC";
276 $tabsysprefs{noOPACUserLogin} = "OPAC";
277 $tabsysprefs{hideBiblioNumber} = "OPAC";
278 $tabsysprefs{OPACDisplayExtendedSubInfo} = "OPAC";
279 $tabsysprefs{OpacMainUserBlock} = "OPAC";
280 $tabsysprefs{OPACSubscriptionDisplay} = "OPAC";
281 $tabsysprefs{OPACURLOpenInNewWindow} = "OPAC";
282 $tabsysprefs{OPACUserCSS} = "OPAC";
283 $tabsysprefs{OPACHighlightedWords} = "OPAC";
284 $tabsysprefs{OPACViewOthersSuggestions} = "OPAC";
285 $tabsysprefs{URLLinkText} = "OPAC";
286 $tabsysprefs{OPACShelfBrowser} = "OPAC";
287 $tabsysprefs{OPACDisplayRequestPriority} = "OPAC";
290 $tabsysprefs{SearchMyLibraryFirst} = "OPAC";
291 $tabsysprefs{hidelostitems} = "OPAC";
292 $tabsysprefs{opacbookbag} = "OPAC";
293 $tabsysprefs{OpacPasswordChange} = "OPAC";
294 $tabsysprefs{opacreadinghistory} = "OPAC";
295 $tabsysprefs{virtualshelves} = "OPAC";
296 $tabsysprefs{RequestOnOpac} = "OPAC";
297 $tabsysprefs{reviewson} = "OPAC";
298 $tabsysprefs{OpacTopissues} = "OPAC";
299 $tabsysprefs{OpacAuthorities} = "OPAC";
300 $tabsysprefs{OpacCloud} = "OPAC";
301 $tabsysprefs{opacuserlogin} = "OPAC";
302 $tabsysprefs{AnonSuggestions} = "OPAC";
303 $tabsysprefs{suggestion} = "OPAC";
304 $tabsysprefs{OpacTopissue} = "OPAC";
305 $tabsysprefs{OpacBrowser} = "OPAC";
306 $tabsysprefs{kohaspsuggest} = "OPAC";
307 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
308 $tabsysprefs{OPACItemHolds} = "OPAC";
309 $tabsysprefs{OPACGroupResults} = "OPAC";
310 $tabsysprefs{XSLTDetailsDisplay} = "OPAC";
311 $tabsysprefs{XSLTResultsDisplay} = "OPAC";
314 $tabsysprefs{CataloguingLog} = "Logs";
315 $tabsysprefs{BorrowersLog} = "Logs";
316 $tabsysprefs{SubscriptionLog} = "Logs";
317 $tabsysprefs{IssueLog} = "Logs";
318 $tabsysprefs{ReturnLog} = "Logs";
319 $tabsysprefs{LetterLog} = "Logs";
320 $tabsysprefs{FinesLog} = "Logs";
323 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
324 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
325 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
326 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
327 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
330 my ( $searchstring, $type ) = @_;
331 my $dbh = C4::Context->dbh;
332 $searchstring =~ s/\'/\\\'/g;
333 my @data = split( ' ', $searchstring );
339 # used for doing a plain-old sys-pref search
340 if ( $type && $type ne 'all' ) {
341 foreach my $syspref ( sort { lc $a cmp lc $b } keys %tabsysprefs ) {
342 if ( $tabsysprefs{$syspref} eq $type ) {
343 my $sth = $dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
344 $sth->execute($syspref);
345 while ( my $data = $sth->fetchrow_hashref ) {
346 $data->{shortvalue} = $data->{value};
347 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if defined( $data->{value} ) and length( $data->{value} ) > 60;
348 push( @results, $data );
357 if ( $type and $type eq 'all' ) {
358 $sth = $dbh->prepare( "
360 FROM systempreferences
361 WHERE variable LIKE ? OR explanation LIKE ?
362 ORDER BY VARIABLE" );
363 $sth->execute( "%$searchstring%", "%$searchstring%" );
365 my $strsth = "Select variable,value,explanation,type,options from systempreferences where variable not in (";
366 foreach my $syspref ( keys %tabsysprefs ) {
367 $strsth .= $dbh->quote($syspref) . ",";
370 $strsth .= " order by variable";
371 $sth = $dbh->prepare($strsth);
375 while ( my $data = $sth->fetchrow_hashref ) {
376 $data->{shortvalue} = $data->{value};
377 $data->{shortvalue} = substr( $data->{value}, 0, 60 ) . "..." if length( $data->{value} ) > 60;
378 push( @results, $data );
384 return ( $cnt, \@results );
392 if ( defined $data->{'options'} ) {
393 foreach my $option ( split( /\|/, $data->{'options'} ) ) {
395 defined( $data->{'value'} ) and $option eq $data->{'value'} and $selected = 1;
396 push @options, { option => $option, selected => $selected };
400 $params->{'prefoptions'} = $data->{'options'};
402 if ( not defined( $data->{'type'} ) ) {
403 $params->{'type-free'} = 1;
404 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 );
405 } elsif ( $data->{'type'} eq 'Choice' ) {
406 $params->{'type-choice'} = 1;
407 } elsif ( $data->{'type'} eq 'YesNo' ) {
408 $params->{'type-yesno'} = 1;
409 $data->{'value'} = C4::Context->boolean_preference( $data->{'variable'} );
410 if ( defined( $data->{'value'} ) and $data->{'value'} eq '1' ) {
411 $params->{'value-yes'} = 1;
413 $params->{'value-no'} = 1;
415 } elsif ( $data->{'type'} eq 'Integer' || $data->{'type'} eq 'Float' ) {
416 $params->{'type-free'} = 1;
417 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 10;
418 } elsif ( $data->{'type'} eq 'Textarea' ) {
419 $params->{'type-textarea'} = 1;
420 $data->{options} =~ /(.*)\|(.*)/;
421 $params->{'cols'} = $1;
422 $params->{'rows'} = $2;
423 } elsif ( $data->{'type'} eq 'Themes' ) {
424 $params->{'type-choice'} = 1;
426 ( $data->{'variable'} =~ m#opac#i ) ? ( $type = 'opac' ) : ( $type = 'intranet' );
428 my $currently_selected_themes;
430 foreach my $theme ( split /\s+/, $data->{'value'} ) {
431 push @options, { option => $theme, counter => $counter };
432 $currently_selected_themes->{$theme} = 1;
435 foreach my $theme ( getallthemes($type) ) {
437 next if $currently_selected_themes->{$theme};
438 push @options, { option => $theme, counter => $counter };
441 } elsif ( $data->{'type'} eq 'ClassSources' ) {
442 $params->{'type-choice'} = 1;
445 my $sources = GetClassSources();
447 foreach my $cn_source ( sort keys %$sources ) {
448 if ( $cn_source eq $data->{'value'} ) {
449 push @options, { option => $cn_source, counter => $counter, selected => 1 };
451 push @options, { option => $cn_source, counter => $counter };
455 } elsif ( $data->{'type'} eq 'Languages' ) {
456 my $currently_selected_languages;
457 foreach my $language ( split /\s+/, $data->{'value'} ) {
458 $currently_selected_languages->{$language} = 1;
462 my $lang = $params->{'lang'};
465 if ( $data->{'variable'} =~ /opac/ ) {
469 $theme = C4::Context->preference('opacthemes');
472 # this is the staff client
473 $interface = 'intranet';
474 $theme = C4::Context->preference('template');
476 my $languages_loop = getTranslatedLanguages( $interface, $theme, $lang, $currently_selected_languages );
478 $params->{'languages_loop'} = $languages_loop;
479 $params->{'type-langselector'} = 1;
481 $params->{'type-free'} = 1;
482 $params->{'fieldlength'} = ( defined( $data->{'options'} ) and $data->{'options'} and $data->{'options'} > 0 ) ? $data->{'options'} : 30;
485 if ( $params->{'type-choice'} || $params->{'type-free'} || $params->{'type-yesno'} ) {
486 $params->{'oneline'} = 1;
489 $params->{'preftype'} = $data->{'type'};
490 $params->{'options'} = \@options;
496 my $searchfield = $input->param('searchfield') || '';
497 my $Tvalue = $input->param('Tvalue');
498 my $offset = $input->param('offset') || 0;
499 my $script_name = "/cgi-bin/koha/admin/systempreferences.pl";
501 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
502 { template_name => "admin/systempreferences.tmpl",
505 authnotrequired => 0,
506 flagsrequired => { parameters => 1 },
511 my $op = $input->param('op') || '';
512 $searchfield =~ s/\,//g;
516 script_name => $script_name,
518 ); # we show only the TMPL_VAR names $op
521 script_name => $script_name,
523 ); # we show only the TMPL_VAR names $op
526 if ( $op eq 'update_and_reedit' ) {
527 foreach ( $input->param ) {
530 if ( my $currentorder = $input->param('currentorder') ) {
531 my @currentorder = split /\|/, $currentorder;
532 my $orderchanged = 0;
533 foreach my $param ( $input->param ) {
534 if ( $param =~ m#up-(\d+).x# ) {
535 my $temp = $currentorder[$1];
536 $currentorder[$1] = $currentorder[ $1 - 1 ];
537 $currentorder[ $1 - 1 ] = $temp;
540 } elsif ( $param =~ m#down-(\d+).x# ) {
541 my $temp = $currentorder[$1];
542 $currentorder[$1] = $currentorder[ $1 + 1 ];
543 $currentorder[ $1 + 1 ] = $temp;
548 $value = join ' ', @currentorder;
552 script_name => $script_name,
554 ); # we show only the TMPL_VAR names $op
559 script_name => $script_name,
561 ); # we show only the TMPL_VAR names $op
564 my $dbh = C4::Context->dbh;
565 my $query = "select * from systempreferences where variable=?";
566 my $sth = $dbh->prepare($query);
567 $sth->execute( $input->param('variable') );
569 unless ( C4::Context->config('demo') ) {
570 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
571 $sth->execute( $value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions') );
573 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
576 unless ( C4::Context->config('demo') ) {
577 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
578 $sth->execute( $input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
580 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $input->param('value') );
587 ################## ADD_FORM ##################################
588 # called by default. Used to create form to add or modify a record
590 if ( $op eq 'add_form' ) {
592 #---- if primkey exists, it's a modify action, so read values to modify...
595 my $dbh = C4::Context->dbh;
596 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
597 $sth->execute($searchfield);
598 $data = $sth->fetchrow_hashref;
600 $template->param( modify => 1 );
602 # save tab to return to if user cancels edit
603 $template->param( return_tab => $tabsysprefs{$searchfield} );
606 $data->{'lang'} = $template->param('lang');
608 $template->param( GetPrefParams($data) );
610 $template->param( searchfield => $searchfield );
612 ################## ADD_VALIDATE ##################################
613 # called by add_form, used to insert/modify data in DB
614 } elsif ( $op eq 'add_validate' ) {
615 my $dbh = C4::Context->dbh;
616 my $sth = $dbh->prepare("select * from systempreferences where variable=?");
617 $sth->execute( $input->param('variable') );
619 # to handle multiple values
622 # handle multiple value strings (separated by ',')
623 my $params = $input->Vars;
624 if ( defined $params->{'value'} ) {
626 @values = split( "\0", $params->{'value'} ) if defined( $params->{'value'} );
629 for my $vl (@values) {
634 $value = $params->{'value'};
638 unless ( C4::Context->config('demo') ) {
639 my $sth = $dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
640 $sth->execute( $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable') );
642 logaction( 'SYSTEMPREFERENCE', 'MODIFY', undef, $input->param('variable') . " | " . $value );
645 unless ( C4::Context->config('demo') ) {
646 my $sth = $dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
647 $sth->execute( $input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions') );
649 logaction( 'SYSTEMPREFERENCE', 'ADD', undef, $input->param('variable') . " | " . $value );
653 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=" . $tabsysprefs{ $input->param('variable') } . "\"></html>";
655 ################## DELETE_CONFIRM ##################################
656 # called by default form, used to confirm deletion of data in DB
657 } elsif ( $op eq 'delete_confirm' ) {
658 my $dbh = C4::Context->dbh;
659 my $sth = $dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
660 $sth->execute($searchfield);
661 my $data = $sth->fetchrow_hashref;
664 searchfield => $searchfield,
665 Tvalue => $data->{'value'},
668 # END $OP eq DELETE_CONFIRM
669 ################## DELETE_CONFIRMED ##################################
670 # called by delete_confirm, used to effectively confirm deletion of data in DB
671 } elsif ( $op eq 'delete_confirmed' ) {
672 my $dbh = C4::Context->dbh;
673 my $sth = $dbh->prepare("delete from systempreferences where variable=?");
674 $sth->execute($searchfield);
675 my $logstring = $searchfield . " | " . $Tvalue;
676 logaction( 'SYSTEMPREFERENCE', 'DELETE', undef, $logstring );
679 # END $OP eq DELETE_CONFIRMED
680 ################## DEFAULT ##################################
682 #Adding tab management for system preferences
683 my $tab = $input->param('tab');
684 $template->param( $tab => 1 );
685 my ( $count, $results ) = StringSearch( $searchfield, $tab );
687 for ( my $i = $offset ; $i < ( $offset + $pagesize < $count ? $offset + $pagesize : $count ) ; $i++ ) {
688 my $row_data = $results->[$i];
689 $row_data->{'lang'} = $template->param('lang');
690 $row_data = GetPrefParams($row_data); # get a fresh hash for the row data
691 $row_data->{edit} = "$script_name?op=add_form&searchfield=" . $results->[$i]{'variable'};
692 $row_data->{delete} = "$script_name?op=delete_confirm&searchfield=" . $results->[$i]{'variable'};
693 push( @loop_data, $row_data );
695 $tab = ( $tab ? $tab : "Local Use" );
696 $template->param( loop => \@loop_data, $tab => 1 );
698 my $prevpage = $offset - $pagesize;
699 $template->param( "<a href=$script_name?offset=" . $prevpage . '<< Prev</a>' );
701 if ( $offset + $pagesize < $count ) {
702 my $nextpage = $offset + $pagesize;
703 $template->param( "a href=$script_name?offset=" . $nextpage . 'Next >></a>' );
705 $template->param( tab => $tab, );
706 } #---- END $OP eq DEFAULT
707 output_html_with_http_headers $input, $cookie, $template->output;