773fbfe064acd111dd262f24f5b93056881aa638
[koha.git] / admin / systempreferences.pl
1 #!/usr/bin/perl
2
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)
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
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
14 # version.
15 #
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.
19 #
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
23
24 =head1 systempreferences.pl
25
26 ALGO :
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.
31  if $op=add_form
32     - if primkey exists, this is a modification,so we read the $primkey record
33     - builds the add/modify form
34  if $op=add_validate
35     - the user has just send datas, so we create/modify the record
36  if $op=delete_form
37     - we show the record having primkey=$primkey and ask for deletion validation form
38  if $op=delete_confirm
39     - we delete the record having primkey=$primkey
40
41 =cut
42
43 use strict;
44 use CGI;
45 use C4::Auth;
46 use C4::Context;
47 use C4::Koha;
48 use C4::Languages qw(getTranslatedLanguages);
49 use C4::ClassSource;
50 use C4::Output;
51 use C4::Context;
52
53 # use Smart::Comments;
54
55
56 # FIXME, shouldnt we store this stuff in the systempreferences table? 
57
58 my %tabsysprefs;
59 # Acquisitions
60     $tabsysprefs{acquisitions}="Acquisitions";
61     $tabsysprefs{gist}="Acquisitions";
62     $tabsysprefs{emailPurchaseSuggestions}="Acquisitions";
63
64 # Admin
65     $tabsysprefs{singleBranchMode}="Admin";
66     $tabsysprefs{staffClientBaseURL}="Admin";
67     $tabsysprefs{Version}="Admin";
68     $tabsysprefs{OpacMaintenance}="Admin";
69     $tabsysprefs{FrameworksLoaded}="Admin";
70     $tabsysprefs{libraryAddress}="Admin";
71     $tabsysprefs{delimiter}="Admin";
72     $tabsysprefs{IndependantBranches}="Admin";
73     $tabsysprefs{HomeOrHoldingBranch}="Admin";
74     $tabsysprefs{insecure}="Admin";
75     $tabsysprefs{KohaAdmin}="Admin";
76     $tabsysprefs{KohaAdminEmailAddress}="Admin";
77     $tabsysprefs{MIME}="Admin";
78     $tabsysprefs{timeout}="Admin";
79     $tabsysprefs{Intranet_includes}="Admin";
80     $tabsysprefs{AutoLocation}="Admin";
81     $tabsysprefs{DebugLevel}="Admin";
82     $tabsysprefs{SessionStorage}="Admin";
83     $tabsysprefs{noItemTypeImages}="Admin";
84     $tabsysprefs{OPACBaseURL}="Admin";
85
86 # Authorities
87     $tabsysprefs{authoritysep}="Authorities";
88     $tabsysprefs{AuthDisplayHierarchy}="Authorities";
89     $tabsysprefs{dontmerge}="Authorities";
90     $tabsysprefs{BiblioAddsAuthorities}="Authorities";
91 # Cataloguing
92     $tabsysprefs{advancedMARCEditor}="Cataloguing";
93     $tabsysprefs{autoBarcode}="Cataloguing";
94     $tabsysprefs{hide_marc}="Cataloguing";
95     $tabsysprefs{IntranetBiblioDefaultView} = "Cataloguing";
96     $tabsysprefs{ISBD}="Cataloguing";
97     $tabsysprefs{itemcallnumber}="Cataloguing";
98     $tabsysprefs{LabelMARCView}="Cataloguing";
99     $tabsysprefs{marc}="Cataloguing";
100     $tabsysprefs{marcflavour}="Cataloguing";
101     $tabsysprefs{serialsadditems}="Cataloguing";
102     $tabsysprefs{MARCOrgCode}="Cataloguing";
103     $tabsysprefs{z3950AuthorAuthFields}="Cataloguing";
104     $tabsysprefs{z3950NormalizeAuthor}="Cataloguing";
105     $tabsysprefs{Stemming}="Cataloguing";
106     $tabsysprefs{WeightFields}="Cataloguing";
107     $tabsysprefs{NoZebra}="Cataloguing";
108     $tabsysprefs{NoZebraIndexes}="Cataloguing";
109     $tabsysprefs{ReceiveBackIssues}="Cataloguing";
110     $tabsysprefs{DefaultClassificationSource}="Cataloguing";
111     $tabsysprefs{RoutingSerials}="Cataloguing";
112     $tabsysprefs{'item-level_itypes'}="Cataloguing";
113
114 # Circulation
115     $tabsysprefs{maxoutstanding}="Circulation";
116     $tabsysprefs{maxreserves}="Circulation";
117     $tabsysprefs{noissuescharge}="Circulation";
118     $tabsysprefs{IssuingInProcess}="Circulation";
119     $tabsysprefs{patronimages}="Circulation";
120     $tabsysprefs{printcirculationslips}="Circulation";
121     $tabsysprefs{ReturnBeforeExpiry}="Circulation";
122     $tabsysprefs{SpecifyDueDate}="Circulation";
123     $tabsysprefs{AutomaticItemReturn}="Circulation";
124     $tabsysprefs{ReservesMaxPickUpDelay}="Circulation";
125     $tabsysprefs{TransfersMaxDaysWarning}="Circulation";
126     $tabsysprefs{useDaysMode}="Circulation";
127     $tabsysprefs{ReservesNeedReturns}="Circulation";
128     $tabsysprefs{CircAutocompl}="Circulation";
129     $tabsysprefs{canreservefromotherbranches}="Circulation";
130     $tabsysprefs{finesMode}="Circulation";
131     $tabsysprefs{emailLibrarianWhenHoldIsPlaced}="Circulation";
132     $tabsysprefs{globalDueDate}="Circulation";
133     $tabsysprefs{holdCancelLength}="Circulation";
134     $tabsysprefs{itemBarcodeInputFilter}="Circulation";
135     $tabsysprefs{noOPACHolds}="Circulation";
136     $tabsysprefs{WebBasedSelfCheck}="Circulation";
137     $tabsysprefs{CircControl}="Circulation";
138     $tabsysprefs{finesCalendar}="Circulation";
139     $tabsysprefs{previousIssuesDefaultSortOrder}="Circulation";
140     $tabsysprefs{todaysIssuesDefaultSortOrder}="Circulation";
141
142 # Staff Client
143     $tabsysprefs{TemplateEncoding}="StaffClient";
144     $tabsysprefs{template}="StaffClient";
145     $tabsysprefs{intranetstylesheet}="StaffClient";
146     $tabsysprefs{IntranetNav}="StaffClient";
147     $tabsysprefs{intranetcolorstylesheet}="StaffClient";
148     $tabsysprefs{intranetuserjs}="StaffClient";
149     $tabsysprefs{yuipath}="StaffClient";
150     $tabsysprefs{IntranetmainUserblock}="StaffClient";
151     
152 # Patrons
153     $tabsysprefs{automembernum}="Patrons";
154     $tabsysprefs{checkdigit}="Patrons";
155     $tabsysprefs{intranetreadinghistory}="Patrons";
156     $tabsysprefs{NotifyBorrowerDeparture}="Patrons";
157     $tabsysprefs{memberofinstitution}="Patrons";
158     $tabsysprefs{ReadingHistory}="Patrons";
159     $tabsysprefs{BorrowerMandatoryField}="Patrons";
160     $tabsysprefs{borrowerRelationship}="Patrons";
161     $tabsysprefs{BorrowersTitles}="Patrons";    
162     $tabsysprefs{patronimages}="Patrons";
163     $tabsysprefs{MinPasswordLength}="Patrons";
164     $tabsysprefs{uppercasesurnames}="Patrons";
165     $tabsysprefs{NoReturnSetLost}="Patrons";
166     $tabsysprefs{MaxFine}="Patrons";
167     $tabsysprefs{NotifyBorrowerDeparture}="Patrons";
168
169 # FRBR
170     $tabsysprefs{FRBRizeEditions}="FRBR";
171     $tabsysprefs{XISBN}="FRBR";
172     $tabsysprefs{OCLCAffiliateID}="FRBR";
173     $tabsysprefs{XISBNDailyLimit}="FRBR";
174     $tabsysprefs{PINESISBN}="FRBR";
175     $tabsysprefs{ThingISBN}="FRBR";
176     $tabsysprefs{OPACFRBRizeEditions}="FRBR";
177     $tabsysprefs{XISBNAmazonSimilarItems}="FRBR";
178
179 # I18N/L10N
180     $tabsysprefs{dateformat}="I18N/L10N";
181     $tabsysprefs{opaclanguages}="I18N/L10N";
182     $tabsysprefs{opacthemes}="I18N/L10N";
183     $tabsysprefs{language}="I18N/L10N";
184
185 # Searching
186     $tabsysprefs{defaultSortField}="Searching";
187     $tabsysprefs{defaultSortOrder}="Searching";
188     $tabsysprefs{maxItemsInSearchResults}="Searching";
189     $tabsysprefs{numSearchResults}="Searching";
190     $tabsysprefs{OPACdefaultSortField}="Searching";
191     $tabsysprefs{OPACdefaultSortOrder}="Searching";
192     $tabsysprefs{OPACItemsResultsDisplay}="Searching";
193     $tabsysprefs{OPACnumSearchResults}="Searching";
194     $tabsysprefs{QueryFuzzy}="Searching";
195     $tabsysprefs{QueryStemming}="Searching";
196     $tabsysprefs{QueryWeightFields}="Searching";
197     $tabsysprefs{expandedSearchOption}="Searching";
198     $tabsysprefs{sortbynonfiling}="Searching";
199     $tabsysprefs{QueryAutoTruncate}="Searching";
200     $tabsysprefs{QueryRemoveStopwords}="Searching";
201
202 # OPAC
203     $tabsysprefs{AmazonAssocTag}="OPAC";
204     $tabsysprefs{AmazonSimilarItems}="OPAC";
205     $tabsysprefs{AmazonContent}="OPAC";
206     $tabsysprefs{OPACAmazonContent}="OPAC";
207     $tabsysprefs{AmazonDevKey}="OPAC";
208     $tabsysprefs{BiblioDefaultView}="OPAC";
209     $tabsysprefs{LibraryName}="OPAC";
210     $tabsysprefs{opaccolorstylesheet}="OPAC";
211     $tabsysprefs{opaccredits}="OPAC";
212     $tabsysprefs{opaclargeimage}="OPAC";
213     $tabsysprefs{opaclayoutstylesheet}="OPAC";
214     $tabsysprefs{OpacNav}="OPAC";
215     $tabsysprefs{opacsmallimage}="OPAC";
216     $tabsysprefs{opacstylesheet}="OPAC";
217     $tabsysprefs{opacthemes}="OPAC";
218     $tabsysprefs{opacuserjs}="OPAC";
219     $tabsysprefs{SubscriptionHistory}="OPAC";
220     $tabsysprefs{opacheader}="OPAC";
221     $tabsysprefs{OPACAmazonSimilarItems}="OPAC";
222     $tabsysprefs{OPACXISBNAmazonSimilarItems}="OPAC";
223
224     $tabsysprefs{hideBiblioNumber}="OPAC";
225     $tabsysprefs{noOPACUserLogin}="OPAC";
226     $tabsysprefs{OPACDisplayExtendedSubInfo}="OPAC";
227     $tabsysprefs{OpacMainUserBlock}="OPAC";
228     $tabsysprefs{OPACSubscriptionDisplay}="OPAC";
229     $tabsysprefs{OPACURLOpenInNewWindow}="OPAC";
230     $tabsysprefs{OPACUserCSS}="OPAC";
231     $tabsysprefs{OPACViewOthersSuggestions}="OPAC";
232     $tabsysprefs{URLLinkText}="OPAC";
233
234 # OPACFeatures
235     $tabsysprefs{SearchMyLibraryFirst}="OPACFeatures";
236     $tabsysprefs{Disable_Dictionary}="OPACFeatures";
237     $tabsysprefs{hidelostitems}="OPACFeatures";
238     $tabsysprefs{opacbookbag}="OPACFeatures";
239     $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
240     $tabsysprefs{OpacPasswordChange}="OPACFeatures";
241     $tabsysprefs{opacreadinghistory}="OPACFeatures";
242     $tabsysprefs{virtualshelves}="OPACFeatures";
243     $tabsysprefs{RequestOnOpac}="OPACFeatures";
244     $tabsysprefs{reviewson}="OPACFeatures";
245     $tabsysprefs{OpacTopissues}="OPACFeatures";
246     $tabsysprefs{OpacAuthorities}="OPACFeatures";
247     $tabsysprefs{OpacCloud}="OPACFeatures";
248     $tabsysprefs{opacuserlogin}="OPACFeatures";
249     $tabsysprefs{AnonSuggestions}="OPACFeatures";
250     $tabsysprefs{suggestion}="OPACFeatures";
251     $tabsysprefs{OpacTopissue}="OPACFeatures";
252     $tabsysprefs{OpacBrowser}="OPACFeatures";
253     $tabsysprefs{kohaspsuggest} = "OPACFeatures";
254
255 # LOGFeatures
256     $tabsysprefs{CataloguingLog}  = "LOGFeatures";
257     $tabsysprefs{BorrowersLog}    = "LOGFeatures";
258     $tabsysprefs{SubscriptionLog} = "LOGFeatures";
259     $tabsysprefs{IssueLog}        = "LOGFeatures";
260     $tabsysprefs{ReturnLog}       = "LOGFeatures";
261     $tabsysprefs{LetterLog}       = "LOGFeatures";
262     $tabsysprefs{FinesLog}        = "LOGFeatures";
263     
264 sub StringSearch  {
265     my ($searchstring,$type)=@_;
266     my $dbh = C4::Context->dbh;
267     $searchstring=~ s/\'/\\\'/g;
268     my @data=split(' ',$searchstring);
269     my $count=@data;
270     my @results;
271     my $cnt=0;
272
273     # used for doing a plain-old sys-pref search
274     if ($type eq 'all' ){
275         my $sth=$dbh->prepare("SELECT * FROM systempreferences 
276                 WHERE variable LIKE ? OR explanation LIKE ? 
277                 ORDER BY VARIABLE");
278         $sth->execute("%$searchstring%", "%$searchstring%");
279         while (my $data=$sth->fetchrow_hashref){
280             $data->{value} =~ s/</&lt;/g;
281             $data->{value} =~ s/>/&gt;/g;
282             $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
283             push(@results,$data);
284             $cnt++;
285         }
286         $sth->finish;
287
288     }  elsif ($type){
289         foreach my $syspref (sort { lc $a cmp lc $b } keys %tabsysprefs){
290             if ($tabsysprefs{$syspref} eq $type){
291                 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
292                 $sth->execute($syspref);
293                 while (my $data=$sth->fetchrow_hashref){
294                     $data->{value} =~ s/</&lt;/g;
295                     $data->{value} =~ s/>/&gt;/g;
296                     $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
297                     push(@results,$data);
298                     $cnt++;
299                 }
300                 $sth->finish;
301             }
302         }
303     } else {
304         my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
305         foreach my $syspref (keys %tabsysprefs){
306             $strsth .= $dbh->quote($syspref).",";
307         }
308         $strsth =~ s/,$/) /;
309         $strsth .= " order by variable";
310         my $sth=$dbh->prepare($strsth);
311         $sth->execute();
312         while (my $data=$sth->fetchrow_hashref){
313             $data->{value}=substr($data->{value},0,100);
314             push(@results,$data);
315             $cnt++;
316         }
317         $sth->finish;
318     }
319     return ($cnt,\@results);
320 }
321
322 my $input = new CGI;
323 my $searchfield=$input->param('searchfield');
324 my $offset=$input->param('offset');
325 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
326
327 my ($template, $borrowernumber, $cookie)
328     = get_template_and_user({template_name => "admin/systempreferences.tmpl",
329                  query => $input,
330                  type => "intranet",
331                  authnotrequired => 0,
332                  flagsrequired => {parameters => 1},
333                  debug => 1,
334                  });
335 my $pagesize=100;
336 my $op = $input->param('op');
337 $searchfield=~ s/\,//g;
338
339 if ($op) {
340 $template->param(script_name => $script_name,
341                         $op              => 1); # we show only the TMPL_VAR names $op
342 } else {
343 $template->param(script_name => $script_name,
344                         else              => 1); # we show only the TMPL_VAR names $op
345 }
346
347 if ($op eq 'update_and_reedit') {
348     foreach ($input->param) {
349     }
350     my $value='';
351     if (my $currentorder=$input->param('currentorder')) {
352         my @currentorder=split /\|/, $currentorder;
353         my $orderchanged=0;
354         foreach my $param ($input->param) {
355             if ($param=~m#up-(\d+).x#) {
356                 my $temp=$currentorder[$1];
357                 $currentorder[$1]=$currentorder[$1-1];
358                 $currentorder[$1-1]=$temp;
359                 $orderchanged=1;
360                 last;
361             } elsif ($param=~m#down-(\d+).x#) {
362                 my $temp=$currentorder[$1];
363                 $currentorder[$1]=$currentorder[$1+1];
364                 $currentorder[$1+1]=$temp;
365                 $orderchanged=1;
366                 last;
367             }
368         }
369         $value=join ' ', @currentorder;
370         if ($orderchanged) {
371             $op='add_form';
372             $template->param(script_name => $script_name,
373                             $op              => 1); # we show only the TMPL_VAR names $op
374         } else {
375             $op='';
376             $searchfield='';
377             $template->param(script_name => $script_name,
378                             else              => 1); # we show only the TMPL_VAR names $op
379         }
380     }
381     my $dbh = C4::Context->dbh;
382     my $query="select * from systempreferences where variable=?";
383     my $sth=$dbh->prepare($query);
384     $sth->execute($input->param('variable'));
385     if ($sth->rows) {
386         unless (C4::Context->config('demo') eq 1) {
387             my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
388             $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
389             $sth->finish;
390         }
391     } else {
392         unless (C4::Context->config('demo') eq 1) {
393             my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
394             $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
395             $sth->finish;
396         }
397     }
398     $sth->finish;
399
400 }
401
402 ################## ADD_FORM ##################################
403 # called by default. Used to create form to add or  modify a record
404
405 if ($op eq 'add_form') {
406     #---- if primkey exists, it's a modify action, so read values to modify...
407     my $data;
408     if ($searchfield) {
409         my $dbh = C4::Context->dbh;
410         my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
411         $sth->execute($searchfield);
412         $data=$sth->fetchrow_hashref;
413         $sth->finish;
414         $template->param(modify => 1);
415         # save tab to return to if user cancels edit
416         $template->param(return_tab => $tabsysprefs{$searchfield});
417     }
418
419     my @options;
420     foreach my $option (split(/\|/, $data->{'options'})) {
421         my $selected='0';
422         $option eq $data->{'value'} and $selected=1;
423         push @options, { option => $option, selected => $selected };
424     }
425     if ($data->{'type'} eq 'Choice') {
426         $template->param('type-choice' => 1);
427     } elsif ($data->{'type'} eq 'YesNo') {
428         $template->param('type-yesno' => 1);
429         $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
430         ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
431     } elsif ($data->{'type'} eq 'Integer') {
432         $template->param('type-free' => 1);
433         $template->param('fieldlength' => $data->{'options'});
434     } elsif ($data->{'type'} eq 'Textarea') {
435         $template->param('type-textarea' => 1);
436         $data->{options} =~ /(.*)\|(.*)/;
437         $template->param('cols' => $1, 'rows' => $2);;
438     } elsif ($data->{'type'} eq 'Float') {
439         $template->param('type-free' => 1);
440         $template->param('fieldlength' => $data->{'options'});
441     } elsif ($data->{'type'} eq 'Themes') {
442         $template->param('type-choice' => 1);
443         my $type='';
444         ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
445         @options=();
446         my $currently_selected_themes;
447         my $counter=0;
448         foreach my $theme (split /\s+/, $data->{'value'}) {
449             push @options, { option => $theme, counter => $counter };
450             $currently_selected_themes->{$theme}=1;
451             $counter++;
452         }
453         foreach my $theme (getallthemes($type)) {
454             my $selected='0';
455             next if $currently_selected_themes->{$theme};
456             push @options, { option => $theme, counter => $counter };
457             $counter++;
458         }
459     } elsif ($data->{'type'} eq 'ClassSources') {
460         $template->param('type-choice' => 1);
461         my $type='';
462         @options=();
463         my $sources = GetClassSources();
464         my $counter=0;
465         foreach my $cn_source (sort keys %$sources) {
466             if ($cn_source eq $data->{'value'}) {
467                 push @options, { option => $cn_source, counter => $counter, selected => 1 };
468             } else {
469                 push @options, { option => $cn_source, counter => $counter };
470             }
471             $counter++; 
472         }
473     } elsif ($data->{'type'} eq 'Languages') {
474         $template->param('type-choice' => 1);
475         my $type='';
476         @options=();
477         my $currently_selected_languages;
478         my $counter=0;
479         foreach my $language (split /\s+/, $data->{'value'}) {
480             next if $language eq 'images';
481             push @options, { option => $language, counter => $counter };
482             $currently_selected_languages->{$language}=1;
483             $counter++;
484         }
485         my $langavail = getTranslatedLanguages();
486         foreach my $language (@$langavail) {
487             my $selected='0';
488             next if $currently_selected_languages->{$language->{'language_code'}};
489             #FIXME: could add language_name and language_locale_name for better display
490             push @options, { option => $language->{'language_code'}, counter => $counter };
491             $counter++;
492         }
493     } else {
494         $template->param('type-free' => 1);
495         $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
496     }
497     $template->param(explanation => $data->{'explanation'},
498              value => $data->{'value'},
499              type => $data->{'type'},
500              options => \@options,
501              preftype => $data->{'type'},
502              prefoptions => $data->{'options'},
503              searchfield => $searchfield);
504
505 ################## ADD_VALIDATE ##################################
506 # called by add_form, used to insert/modify data in DB
507 } elsif ($op eq 'add_validate') {
508     my $dbh = C4::Context->dbh;
509     my $sth=$dbh->prepare("select * from systempreferences where variable=?");
510     $sth->execute($input->param('variable'));
511     if ($sth->rows) {
512         unless (C4::Context->config('demo') eq 1) {
513             my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
514             $sth->execute($input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
515             $sth->finish;
516         }
517     } else {
518         unless (C4::Context->config('demo') eq 1) {
519             my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
520             $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
521             $sth->finish;
522         }
523     }
524     $sth->finish;
525     print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
526     exit;
527 ################## DELETE_CONFIRM ##################################
528 # called by default form, used to confirm deletion of data in DB
529 } elsif ($op eq 'delete_confirm') {
530     my $dbh = C4::Context->dbh;
531     my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
532     $sth->execute($searchfield);
533     my $data=$sth->fetchrow_hashref;
534     $sth->finish;
535     $template->param(searchfield => $searchfield,
536                             Tvalue => $data->{'value'},
537                             );
538
539                                                     # END $OP eq DELETE_CONFIRM
540 ################## DELETE_CONFIRMED ##################################
541 # called by delete_confirm, used to effectively confirm deletion of data in DB
542 } elsif ($op eq 'delete_confirmed') {
543     my $dbh = C4::Context->dbh;
544     my $sth=$dbh->prepare("delete from systempreferences where variable=?");
545     $sth->execute($searchfield);
546     $sth->finish;
547
548                                                     # END $OP eq DELETE_CONFIRMED
549 ################## DEFAULT ##################################
550 } else { # DEFAULT
551     #Adding tab management for system preferences
552     my $tab=$input->param('tab');
553     $template->param($tab => 1);
554     my ($count,$results)=StringSearch($searchfield,$tab);
555     my $toggle=0;
556     my @loop_data = ();
557     for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
558           if ($toggle eq 0){
559             $toggle=1;
560           } else {
561             $toggle=0;
562           }
563         my %row_data;  # get a fresh hash for the row data
564         $row_data{variable} = $results->[$i]{'variable'};
565         $row_data{value} = $results->[$i]{'value'};
566         $row_data{yes} = 1 if ($results->[$i]{'value'} == 1);
567         $row_data{yesno} = 1 if ($results->[$i]{'type'} eq 'YesNo');
568         $row_data{explanation} = $results->[$i]{'explanation'};
569         $row_data{toggle} = $toggle;
570         $row_data{edit} = "$script_name?op=add_form&amp;searchfield=".$results->[$i]{'variable'};
571         $row_data{delete} = "$script_name?op=delete_confirm&amp;searchfield=".$results->[$i]{'variable'};
572         push(@loop_data, \%row_data);
573     }
574     $tab=($tab?$tab:"Local Use");
575     $template->param(loop => \@loop_data, $tab => 1);
576     if ($offset>0) {
577         my $prevpage = $offset-$pagesize;
578         $template->param("<a href=$script_name?offset=".$prevpage.'&lt;&lt; Prev</a>');
579     }
580     if ($offset+$pagesize<$count) {
581         my $nextpage =$offset+$pagesize;
582         $template->param("a href=$script_name?offset=".$nextpage.'Next &gt;&gt;</a>');
583     }
584     $template->param(        tab => $tab,
585             );
586 } #---- END $OP eq DEFAULT
587 output_html_with_http_headers $input, $cookie, $template->output;