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
48 use C4::Languages qw(getTranslatedLanguages);
53 # use Smart::Comments;
56 # FIXME, shouldnt we store this stuff in the systempreferences table?
58 # FIXME: This uses hash in a backwards way. What we really want is:
59 # $tabsysprefs{key} = $array_ref;
61 # $tabsysprefs{Cataloguing} = [qw(autoBarcode ISBD marc ...)];
63 # Because some things *should* be on more than one tab.
64 # And the tabname is the unique part (the key).
68 $tabsysprefs{acquisitions}="Acquisitions";
69 $tabsysprefs{gist}="Acquisitions";
70 $tabsysprefs{emailPurchaseSuggestions}="Acquisitions";
71 $tabsysprefs{RenewSerialAddsSuggestion}="Acquisitions";
72 $tabsysprefs{serialsadditems}="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";
102 $tabsysprefs{advancedMARCEditor}="Cataloguing";
103 $tabsysprefs{autoBarcode}="Cataloguing";
104 $tabsysprefs{hide_marc}="Cataloguing";
105 $tabsysprefs{IntranetBiblioDefaultView} = "Cataloguing";
106 $tabsysprefs{ISBD}="Cataloguing";
107 $tabsysprefs{itemcallnumber}="Cataloguing";
108 $tabsysprefs{LabelMARCView}="Cataloguing";
109 $tabsysprefs{marc}="Cataloguing";
110 $tabsysprefs{marcflavour}="Cataloguing";
111 $tabsysprefs{MARCOrgCode}="Cataloguing";
112 $tabsysprefs{z3950AuthorAuthFields}="Cataloguing";
113 $tabsysprefs{z3950NormalizeAuthor}="Cataloguing";
114 $tabsysprefs{Stemming}="Cataloguing";
115 $tabsysprefs{WeightFields}="Cataloguing";
116 $tabsysprefs{NoZebra}="Cataloguing";
117 $tabsysprefs{NoZebraIndexes}="Cataloguing";
118 $tabsysprefs{ReceiveBackIssues}="Cataloguing";
119 $tabsysprefs{DefaultClassificationSource}="Cataloguing";
120 $tabsysprefs{RoutingSerials}="Cataloguing";
121 $tabsysprefs{'item-level_itypes'}="Cataloguing";
124 $tabsysprefs{maxoutstanding}="Circulation";
125 $tabsysprefs{maxreserves}="Circulation";
126 $tabsysprefs{noissuescharge}="Circulation";
127 $tabsysprefs{IssuingInProcess}="Circulation";
128 $tabsysprefs{patronimages}="Circulation";
129 $tabsysprefs{printcirculationslips}="Circulation";
130 $tabsysprefs{ReturnBeforeExpiry}="Circulation";
131 $tabsysprefs{SpecifyDueDate}="Circulation";
132 $tabsysprefs{AutomaticItemReturn}="Circulation";
133 $tabsysprefs{ReservesMaxPickUpDelay}="Circulation";
134 $tabsysprefs{TransfersMaxDaysWarning}="Circulation";
135 $tabsysprefs{useDaysMode}="Circulation";
136 $tabsysprefs{ReservesNeedReturns}="Circulation";
137 $tabsysprefs{CircAutocompl}="Circulation";
138 $tabsysprefs{canreservefromotherbranches}="Circulation";
139 $tabsysprefs{finesMode}="Circulation";
140 $tabsysprefs{emailLibrarianWhenHoldIsPlaced}="Circulation";
141 $tabsysprefs{globalDueDate}="Circulation";
142 $tabsysprefs{holdCancelLength}="Circulation";
143 $tabsysprefs{itemBarcodeInputFilter}="Circulation";
144 $tabsysprefs{noOPACHolds}="Circulation";
145 $tabsysprefs{WebBasedSelfCheck}="Circulation";
146 $tabsysprefs{CircControl}="Circulation";
147 $tabsysprefs{finesCalendar}="Circulation";
148 $tabsysprefs{previousIssuesDefaultSortOrder}="Circulation";
149 $tabsysprefs{todaysIssuesDefaultSortOrder}="Circulation";
150 $tabsysprefs{HomeOrHoldingBranch}="Circulation";
151 $tabsysprefs{RandomizeHoldsQueueWeight}="Circulation";
152 $tabsysprefs{StaticHoldsQueueWeight}="Circulation";
153 $tabsysprefs{AllowOnShelfHolds}="Circulation";
154 $tabsysprefs{AllowHoldsOnDamagedItems}="Circulation";
157 $tabsysprefs{TemplateEncoding}="StaffClient";
158 $tabsysprefs{template}="StaffClient";
159 $tabsysprefs{intranetstylesheet}="StaffClient";
160 $tabsysprefs{IntranetNav}="StaffClient";
161 $tabsysprefs{intranetcolorstylesheet}="StaffClient";
162 $tabsysprefs{intranetuserjs}="StaffClient";
163 $tabsysprefs{yuipath}="StaffClient";
164 $tabsysprefs{IntranetmainUserblock}="StaffClient";
167 $tabsysprefs{autoMemberNum}="Patrons";
168 $tabsysprefs{checkdigit}="Patrons";
169 $tabsysprefs{intranetreadinghistory}="Patrons";
170 $tabsysprefs{NotifyBorrowerDeparture}="Patrons";
171 $tabsysprefs{memberofinstitution}="Patrons";
172 $tabsysprefs{ReadingHistory}="Patrons";
173 $tabsysprefs{BorrowerMandatoryField}="Patrons";
174 $tabsysprefs{borrowerRelationship}="Patrons";
175 $tabsysprefs{BorrowersTitles}="Patrons";
176 $tabsysprefs{patronimages}="Patrons";
177 $tabsysprefs{MinPasswordLength}="Patrons";
178 $tabsysprefs{uppercasesurnames}="Patrons";
179 $tabsysprefs{NoReturnSetLost}="Patrons";
180 $tabsysprefs{MaxFine}="Patrons";
181 $tabsysprefs{NotifyBorrowerDeparture}="Patrons";
182 $tabsysprefs{AddPatronLists}="Patrons";
183 $tabsysprefs{PatronsPerPage}="Patrons";
184 $tabsysprefs{ExtendedPatronAttributes}="Patrons";
185 $tabsysprefs{AutoEmailOpacUser}="Patrons";
186 $tabsysprefs{AutoEmailPrimaryAddress}="Patrons";
187 $tabsysprefs{EnhancedMessagingPreferences}="Patrons";
190 $tabsysprefs{dateformat}="I18N/L10N";
191 $tabsysprefs{opaclanguages}="I18N/L10N";
192 $tabsysprefs{opacthemes}="I18N/L10N";
193 $tabsysprefs{language}="I18N/L10N";
196 $tabsysprefs{defaultSortField}="Searching";
197 $tabsysprefs{defaultSortOrder}="Searching";
198 $tabsysprefs{maxItemsInSearchResults}="Searching";
199 $tabsysprefs{numSearchResults}="Searching";
200 $tabsysprefs{OPACdefaultSortField}="Searching";
201 $tabsysprefs{OPACdefaultSortOrder}="Searching";
202 $tabsysprefs{OPACItemsResultsDisplay}="Searching";
203 $tabsysprefs{OPACnumSearchResults}="Searching";
204 $tabsysprefs{QueryFuzzy}="Searching";
205 $tabsysprefs{QueryStemming}="Searching";
206 $tabsysprefs{QueryWeightFields}="Searching";
207 $tabsysprefs{expandedSearchOption}="Searching";
208 $tabsysprefs{sortbynonfiling}="Searching";
209 $tabsysprefs{QueryAutoTruncate}="Searching";
210 $tabsysprefs{QueryRemoveStopwords}="Searching";
211 $tabsysprefs{AdvancedSearchTypes}="Searching";
214 $tabsysprefs{AmazonContent}="EnhancedContent";
215 $tabsysprefs{AWSAccessKeyID}="EnhancedContent";
216 $tabsysprefs{AmazonLocale}="EnhancedContent";
217 $tabsysprefs{AmazonAssocTag}="EnhancedContent";
218 $tabsysprefs{AmazonSimilarItems}="EnhancedContent";
219 $tabsysprefs{OPACAmazonContent}="EnhancedContent";
220 $tabsysprefs{OPACAmazonSimilarItems}="EnhancedContent";
223 $tabsysprefs{BakerTaylorBookstoreURL} = 'EnhancedContent';
224 $tabsysprefs{BakerTaylorEnabled} = 'EnhancedContent';
225 $tabsysprefs{BakerTaylorPassword} = 'EnhancedContent';
226 $tabsysprefs{BakerTaylorUsername} = 'EnhancedContent';
228 $tabsysprefs{FRBRizeEditions}="EnhancedContent";
229 $tabsysprefs{XISBN}="EnhancedContent";
230 $tabsysprefs{OCLCAffiliateID}="EnhancedContent";
231 $tabsysprefs{XISBNDailyLimit}="EnhancedContent";
232 $tabsysprefs{PINESISBN}="EnhancedContent";
233 $tabsysprefs{ThingISBN}="EnhancedContent";
234 $tabsysprefs{OPACFRBRizeEditions}="EnhancedContent";
236 $tabsysprefs{TagsEnabled} = 'EnhancedContent';
237 $tabsysprefs{TagsExternalDictionary} = 'EnhancedContent';
238 $tabsysprefs{TagsInputOnDetail} = 'EnhancedContent';
239 $tabsysprefs{TagsInputOnList} = 'EnhancedContent';
240 $tabsysprefs{TagsShowOnDetail} = 'EnhancedContent';
241 $tabsysprefs{TagsShowOnList} = 'EnhancedContent';
242 $tabsysprefs{TagsModeration} = 'EnhancedContent';
243 $tabsysprefs{GoogleJackets} = 'EnhancedContent';
244 $tabsysprefs{AuthorisedValueImages} = "EnhancedContent";
247 $tabsysprefs{BiblioDefaultView}="OPAC";
248 $tabsysprefs{LibraryName}="OPAC";
249 $tabsysprefs{opaccolorstylesheet}="OPAC";
250 $tabsysprefs{opaccredits}="OPAC";
251 $tabsysprefs{opaclargeimage}="OPAC";
252 $tabsysprefs{opaclayoutstylesheet}="OPAC";
253 $tabsysprefs{OpacNav}="OPAC";
254 $tabsysprefs{opacsmallimage}="OPAC";
255 $tabsysprefs{opacstylesheet}="OPAC";
256 $tabsysprefs{opacthemes}="OPAC";
257 $tabsysprefs{opacuserjs}="OPAC";
258 $tabsysprefs{SubscriptionHistory}="OPAC";
259 $tabsysprefs{opacheader}="OPAC";
260 $tabsysprefs{noOPACUserLogin}="OPAC";
261 $tabsysprefs{hideBiblioNumber}="OPAC";
262 $tabsysprefs{OPACDisplayExtendedSubInfo}="OPAC";
263 $tabsysprefs{OpacMainUserBlock}="OPAC";
264 $tabsysprefs{OPACSubscriptionDisplay}="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";
273 $tabsysprefs{SearchMyLibraryFirst}="OPAC";
274 $tabsysprefs{Disable_Dictionary}="OPAC";
275 $tabsysprefs{hidelostitems}="OPAC";
276 $tabsysprefs{opacbookbag}="OPAC";
277 $tabsysprefs{opaclanguagesdisplay}="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{kohaspsuggest} = "OPAC";
292 $tabsysprefs{OpacRenewalAllowed} = "OPAC";
293 $tabsysprefs{OPACItemHolds} = "OPAC";
294 $tabsysprefs{OPACGroupResults}="OPAC";
295 $tabsysprefs{XSLTDetailsDisplay}="OPAC";
296 $tabsysprefs{XSLTResultsDisplay}="OPAC";
299 $tabsysprefs{CataloguingLog} = "Logs";
300 $tabsysprefs{BorrowersLog} = "Logs";
301 $tabsysprefs{SubscriptionLog} = "Logs";
302 $tabsysprefs{IssueLog} = "Logs";
303 $tabsysprefs{ReturnLog} = "Logs";
304 $tabsysprefs{LetterLog} = "Logs";
305 $tabsysprefs{FinesLog} = "Logs";
308 $tabsysprefs{'OAI-PMH'} = "OAI-PMH";
309 $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
310 $tabsysprefs{'OAI-PMH:MaxCount'} = "OAI-PMH";
311 $tabsysprefs{'OAI-PMH:Set'} = "OAI-PMH";
312 $tabsysprefs{'OAI-PMH:Subset'} = "OAI-PMH";
315 my ($searchstring,$type)=@_;
316 my $dbh = C4::Context->dbh;
317 $searchstring=~ s/\'/\\\'/g;
318 my @data=split(' ',$searchstring);
323 # used for doing a plain-old sys-pref search
324 if ($type eq 'all' ){
325 my $sth=$dbh->prepare("SELECT * FROM systempreferences
326 WHERE variable LIKE ? OR explanation LIKE ?
328 $sth->execute("%$searchstring%", "%$searchstring%");
329 while (my $data=$sth->fetchrow_hashref){
330 $data->{value} =~ s/</</g;
331 $data->{value} =~ s/>/>/g;
332 $data->{value}=substr($data->{value},0,60)."..." if length($data->{value}) >60;
333 push(@results,$data);
339 foreach my $syspref (sort { lc $a cmp lc $b } keys %tabsysprefs){
340 if ($tabsysprefs{$syspref} eq $type){
341 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
342 $sth->execute($syspref);
343 while (my $data=$sth->fetchrow_hashref){
344 $data->{value} =~ s/</</g;
345 $data->{value} =~ s/>/>/g;
346 $data->{value}=substr($data->{value},0,60)."..." if length($data->{value}) >60;
347 push(@results,$data);
354 my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
355 foreach my $syspref (keys %tabsysprefs){
356 $strsth .= $dbh->quote($syspref).",";
359 $strsth .= " order by variable";
360 my $sth=$dbh->prepare($strsth);
362 while (my $data=$sth->fetchrow_hashref){
363 $data->{value}=substr($data->{value},0,60);
364 push(@results,$data);
369 return ($cnt,\@results);
373 my $searchfield = $input->param('searchfield');
374 my $Tvalue = $input->param('Tvalue');
375 my $offset = $input->param('offset');
376 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
378 my ($template, $borrowernumber, $cookie)
379 = get_template_and_user({template_name => "admin/systempreferences.tmpl",
382 authnotrequired => 0,
383 flagsrequired => {parameters => 1},
387 my $op = $input->param('op');
388 $searchfield=~ s/\,//g;
391 $template->param(script_name => $script_name,
392 $op => 1); # we show only the TMPL_VAR names $op
394 $template->param(script_name => $script_name,
395 else => 1); # we show only the TMPL_VAR names $op
398 if ($op eq 'update_and_reedit') {
399 foreach ($input->param) {
402 if (my $currentorder=$input->param('currentorder')) {
403 my @currentorder=split /\|/, $currentorder;
405 foreach my $param ($input->param) {
406 if ($param=~m#up-(\d+).x#) {
407 my $temp=$currentorder[$1];
408 $currentorder[$1]=$currentorder[$1-1];
409 $currentorder[$1-1]=$temp;
412 } elsif ($param=~m#down-(\d+).x#) {
413 my $temp=$currentorder[$1];
414 $currentorder[$1]=$currentorder[$1+1];
415 $currentorder[$1+1]=$temp;
420 $value=join ' ', @currentorder;
423 $template->param(script_name => $script_name,
424 $op => 1); # we show only the TMPL_VAR names $op
428 $template->param(script_name => $script_name,
429 else => 1); # we show only the TMPL_VAR names $op
432 my $dbh = C4::Context->dbh;
433 my $query="select * from systempreferences where variable=?";
434 my $sth=$dbh->prepare($query);
435 $sth->execute($input->param('variable'));
437 unless (C4::Context->config('demo') eq 1) {
438 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
439 $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
441 warn "logaction !! mod ";
442 logaction('SYSTEMPREFERENCE','MODIFY',undef, $input->param('variable') . " | " . $value );
445 unless (C4::Context->config('demo') eq 1) {
446 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
447 $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
449 warn "logaction !! add ";
450 logaction('SYSTEMPREFERENCE','ADD',undef, $input->param('variable') . " | " . $input->param('value') );
457 ################## ADD_FORM ##################################
458 # called by default. Used to create form to add or modify a record
460 if ($op eq 'add_form') {
461 #---- if primkey exists, it's a modify action, so read values to modify...
464 my $dbh = C4::Context->dbh;
465 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
466 $sth->execute($searchfield);
467 $data=$sth->fetchrow_hashref;
469 $template->param(modify => 1);
470 # save tab to return to if user cancels edit
471 $template->param(return_tab => $tabsysprefs{$searchfield});
475 foreach my $option (split(/\|/, $data->{'options'})) {
477 $option eq $data->{'value'} and $selected=1;
478 push @options, { option => $option, selected => $selected };
480 if ($data->{'type'} eq 'Choice') {
481 $template->param('type-choice' => 1);
482 } elsif ($data->{'type'} eq 'YesNo') {
483 $template->param('type-yesno' => 1);
484 $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
485 ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
486 } elsif ($data->{'type'} eq 'Integer') {
487 $template->param('type-free' => 1);
488 $template->param('fieldlength' => $data->{'options'});
489 } elsif ($data->{'type'} eq 'Textarea') {
490 $template->param('type-textarea' => 1);
491 $data->{options} =~ /(.*)\|(.*)/;
492 $template->param('cols' => $1, 'rows' => $2);;
493 } elsif ($data->{'type'} eq 'Float') {
494 $template->param('type-free' => 1);
495 $template->param('fieldlength' => $data->{'options'});
496 } elsif ($data->{'type'} eq 'Themes') {
497 $template->param('type-choice' => 1);
499 ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
501 my $currently_selected_themes;
503 foreach my $theme (split /\s+/, $data->{'value'}) {
504 push @options, { option => $theme, counter => $counter };
505 $currently_selected_themes->{$theme}=1;
508 foreach my $theme (getallthemes($type)) {
510 next if $currently_selected_themes->{$theme};
511 push @options, { option => $theme, counter => $counter };
514 } elsif ($data->{'type'} eq 'ClassSources') {
515 $template->param('type-choice' => 1);
518 my $sources = GetClassSources();
520 foreach my $cn_source (sort keys %$sources) {
521 if ($cn_source eq $data->{'value'}) {
522 push @options, { option => $cn_source, counter => $counter, selected => 1 };
524 push @options, { option => $cn_source, counter => $counter };
528 } elsif ($data->{'type'} eq 'Languages') {
529 my $currently_selected_languages;
530 foreach my $language (split /\s+/, $data->{'value'}) {
531 $currently_selected_languages->{$language}=1;
534 my $lang = $template->param('lang');
537 if ($data->{'variable'} =~ /opac/) {
540 $theme = C4::Context->preference('opacthemes');
543 # this is the staff client
544 $interface = 'intranet';
545 $theme = C4::Context->preference('template');
547 my $languages_loop = getTranslatedLanguages($interface,$theme,$lang,$currently_selected_languages);
549 $template->param('languages_loop' => $languages_loop);
550 $template->param('type-langselector' => 1);
552 $template->param('type-free' => 1);
553 $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
555 $template->param(explanation => $data->{'explanation'},
556 value => $data->{'value'},
557 type => $data->{'type'},
558 options => \@options,
559 preftype => $data->{'type'},
560 prefoptions => $data->{'options'},
561 searchfield => $searchfield);
563 ################## ADD_VALIDATE ##################################
564 # called by add_form, used to insert/modify data in DB
565 } elsif ($op eq 'add_validate') {
566 my $dbh = C4::Context->dbh;
567 my $sth=$dbh->prepare("select * from systempreferences where variable=?");
568 $sth->execute($input->param('variable'));
569 # to handle multiple values
571 # handle multiple value strings (separated by ',')
572 my $params = $input->Vars;
573 my @values = split("\0",$params->{'value'}) if $params->{'value'};
574 for my $vl (@values) {
579 unless (C4::Context->config('demo') eq 1) {
580 my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
581 $sth->execute($value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
583 logaction('SYSTEMPREFERENCE','MODIFY',undef, $input->param('variable') . " | " . $value );
586 unless (C4::Context->config('demo') eq 1) {
587 my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
588 $sth->execute($input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
590 logaction('SYSTEMPREFERENCE','ADD',undef, $input->param('variable') . " | " . $value );
594 print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
596 ################## DELETE_CONFIRM ##################################
597 # called by default form, used to confirm deletion of data in DB
598 } elsif ($op eq 'delete_confirm') {
599 my $dbh = C4::Context->dbh;
600 my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
601 $sth->execute($searchfield);
602 my $data=$sth->fetchrow_hashref;
604 $template->param(searchfield => $searchfield,
605 Tvalue => $data->{'value'},
608 # END $OP eq DELETE_CONFIRM
609 ################## DELETE_CONFIRMED ##################################
610 # called by delete_confirm, used to effectively confirm deletion of data in DB
611 } elsif ($op eq 'delete_confirmed') {
612 my $dbh = C4::Context->dbh;
613 my $sth=$dbh->prepare("delete from systempreferences where variable=?");
614 $sth->execute($searchfield);
615 my $logstring = $searchfield . " | " . $Tvalue ;
616 logaction('SYSTEMPREFERENCE','DELETE',undef,$logstring);
619 # END $OP eq DELETE_CONFIRMED
620 ################## DEFAULT ##################################
622 #Adding tab management for system preferences
623 my $tab=$input->param('tab');
624 $template->param($tab => 1);
625 my ($count,$results)=StringSearch($searchfield,$tab);
628 for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
634 my %row_data; # get a fresh hash for the row data
635 $row_data{variable} = $results->[$i]{'variable'};
636 $row_data{value} = $results->[$i]{'value'};
637 $row_data{yes} = 1 if ($results->[$i]{'value'} == 1);
638 $row_data{yesno} = 1 if ($results->[$i]{'type'} eq 'YesNo');
639 $row_data{explanation} = $results->[$i]{'explanation'};
640 $row_data{toggle} = $toggle;
641 $row_data{edit} = "$script_name?op=add_form&searchfield=".$results->[$i]{'variable'};
642 $row_data{delete} = "$script_name?op=delete_confirm&searchfield=".$results->[$i]{'variable'};
643 push(@loop_data, \%row_data);
645 $tab=($tab?$tab:"Local Use");
646 $template->param(loop => \@loop_data, $tab => 1);
648 my $prevpage = $offset-$pagesize;
649 $template->param("<a href=$script_name?offset=".$prevpage.'<< Prev</a>');
651 if ($offset+$pagesize<$count) {
652 my $nextpage =$offset+$pagesize;
653 $template->param("a href=$script_name?offset=".$nextpage.'Next >></a>');
655 $template->param( tab => $tab,
657 } #---- END $OP eq DEFAULT
658 output_html_with_http_headers $input, $cookie, $template->output;