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