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