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