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