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