OAI-PMH second try
[koha.git] / admin / systempreferences.pl
1 #!/usr/bin/perl
2
3 # script to administer the systempref table
4 # written 20/02/2002 by paul.poulain@free.fr
5 # This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
6
7 # Copyright 2000-2002 Katipo Communications
8 #
9 # This file is part of Koha.
10 #
11 # Koha is free software; you can redistribute it and/or modify it under the
12 # terms of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 #
16 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License along with
21 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
22 # Suite 330, Boston, MA  02111-1307 USA
23
24 =head1 systempreferences.pl
25
26 ALGO :
27  this script use an $op to know what to do.
28  if $op is empty or none of the above values,
29     - the default screen is build (with all records, or filtered datas).
30     - the   user can clic on add, modify or delete record.
31  if $op=add_form
32     - if primkey exists, this is a modification,so we read the $primkey record
33     - builds the add/modify form
34  if $op=add_validate
35     - the user has just send datas, so we create/modify the record
36  if $op=delete_form
37     - we show the record having primkey=$primkey and ask for deletion validation form
38  if $op=delete_confirm
39     - we delete the record having primkey=$primkey
40
41 =cut
42
43 use strict;
44 use CGI;
45 use C4::Auth;
46 use C4::Context;
47 use C4::Koha;
48 use C4::Languages qw(getTranslatedLanguages);
49 use C4::ClassSource;
50 use C4::Output;
51 use C4::Context;
52
53 # use Smart::Comments;
54
55
56 # FIXME, shouldnt we store this stuff in the systempreferences table? 
57
58 my %tabsysprefs;
59 # Acquisitions
60     $tabsysprefs{acquisitions}="Acquisitions";
61     $tabsysprefs{gist}="Acquisitions";
62     $tabsysprefs{emailPurchaseSuggestions}="Acquisitions";
63
64 # Admin
65     $tabsysprefs{singleBranchMode}="Admin";
66     $tabsysprefs{staffClientBaseURL}="Admin";
67     $tabsysprefs{Version}="Admin";
68     $tabsysprefs{OpacMaintenance}="Admin";
69     $tabsysprefs{FrameworksLoaded}="Admin";
70     $tabsysprefs{libraryAddress}="Admin";
71     $tabsysprefs{delimiter}="Admin";
72     $tabsysprefs{IndependantBranches}="Admin";
73     $tabsysprefs{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
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     $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 # OPAC
203     $tabsysprefs{AmazonAssocTag}="OPAC";
204     $tabsysprefs{AmazonSimilarItems}="OPAC";
205     $tabsysprefs{AmazonContent}="OPAC";
206     $tabsysprefs{OPACAmazonContent}="OPAC";
207     $tabsysprefs{AmazonDevKey}="OPAC";
208     $tabsysprefs{BiblioDefaultView}="OPAC";
209     $tabsysprefs{LibraryName}="OPAC";
210     $tabsysprefs{opaccolorstylesheet}="OPAC";
211     $tabsysprefs{opaccredits}="OPAC";
212     $tabsysprefs{opaclargeimage}="OPAC";
213     $tabsysprefs{opaclayoutstylesheet}="OPAC";
214     $tabsysprefs{OpacNav}="OPAC";
215     $tabsysprefs{opacsmallimage}="OPAC";
216     $tabsysprefs{opacstylesheet}="OPAC";
217     $tabsysprefs{opacthemes}="OPAC";
218     $tabsysprefs{opacuserjs}="OPAC";
219     $tabsysprefs{SubscriptionHistory}="OPAC";
220     $tabsysprefs{opacheader}="OPAC";
221     $tabsysprefs{OPACAmazonSimilarItems}="OPAC";
222     $tabsysprefs{OPACXISBNAmazonSimilarItems}="OPAC";
223
224     $tabsysprefs{hideBiblioNumber}="OPAC";
225     $tabsysprefs{noOPACUserLogin}="OPAC";
226     $tabsysprefs{OPACDisplayExtendedSubInfo}="OPAC";
227     $tabsysprefs{OpacMainUserBlock}="OPAC";
228     $tabsysprefs{OPACSubscriptionDisplay}="OPAC";
229     $tabsysprefs{OPACURLOpenInNewWindow}="OPAC";
230     $tabsysprefs{OPACUserCSS}="OPAC";
231     $tabsysprefs{OPACHighlightedWords}="OPAC";
232     $tabsysprefs{OPACViewOthersSuggestions}="OPAC";
233     $tabsysprefs{URLLinkText}="OPAC";
234
235 # OPACFeatures
236     $tabsysprefs{SearchMyLibraryFirst}="OPACFeatures";
237     $tabsysprefs{Disable_Dictionary}="OPACFeatures";
238     $tabsysprefs{hidelostitems}="OPACFeatures";
239     $tabsysprefs{opacbookbag}="OPACFeatures";
240     $tabsysprefs{opaclanguagesdisplay}="OPACFeatures";
241     $tabsysprefs{OpacPasswordChange}="OPACFeatures";
242     $tabsysprefs{opacreadinghistory}="OPACFeatures";
243     $tabsysprefs{virtualshelves}="OPACFeatures";
244     $tabsysprefs{RequestOnOpac}="OPACFeatures";
245     $tabsysprefs{reviewson}="OPACFeatures";
246     $tabsysprefs{OpacTopissues}="OPACFeatures";
247     $tabsysprefs{OpacAuthorities}="OPACFeatures";
248     $tabsysprefs{OpacCloud}="OPACFeatures";
249     $tabsysprefs{opacuserlogin}="OPACFeatures";
250     $tabsysprefs{AnonSuggestions}="OPACFeatures";
251     $tabsysprefs{suggestion}="OPACFeatures";
252     $tabsysprefs{OpacTopissue}="OPACFeatures";
253     $tabsysprefs{OpacBrowser}="OPACFeatures";
254     $tabsysprefs{kohaspsuggest} = "OPACFeatures";
255     $tabsysprefs{OpacRenewalAllowed} = "OPACFeatures";
256
257 # LOGFeatures
258     $tabsysprefs{CataloguingLog}  = "LOGFeatures";
259     $tabsysprefs{BorrowersLog}    = "LOGFeatures";
260     $tabsysprefs{SubscriptionLog} = "LOGFeatures";
261     $tabsysprefs{IssueLog}        = "LOGFeatures";
262     $tabsysprefs{ReturnLog}       = "LOGFeatures";
263     $tabsysprefs{LetterLog}       = "LOGFeatures";
264     $tabsysprefs{FinesLog}        = "LOGFeatures";
265     
266 # OAI-PMH variables
267    $tabsysprefs{'OAI-PMH'}           = "OAI-PMH";
268    $tabsysprefs{'OAI-PMH:archiveID'} = "OAI-PMH";
269    $tabsysprefs{'OAI-PMH:MaxCount'}  = "OAI-PMH";
270    $tabsysprefs{'OAI-PMH:Set'}       = "OAI-PMH";
271    $tabsysprefs{'OAI-PMH:Subset'}    = "OAI-PMH";
272
273
274 sub StringSearch  {
275     my ($searchstring,$type)=@_;
276     my $dbh = C4::Context->dbh;
277     $searchstring=~ s/\'/\\\'/g;
278     my @data=split(' ',$searchstring);
279     my $count=@data;
280     my @results;
281     my $cnt=0;
282
283     # used for doing a plain-old sys-pref search
284     if ($type eq 'all' ){
285         my $sth=$dbh->prepare("SELECT * FROM systempreferences 
286                 WHERE variable LIKE ? OR explanation LIKE ? 
287                 ORDER BY VARIABLE");
288         $sth->execute("%$searchstring%", "%$searchstring%");
289         while (my $data=$sth->fetchrow_hashref){
290             $data->{value} =~ s/</&lt;/g;
291             $data->{value} =~ s/>/&gt;/g;
292             $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
293             push(@results,$data);
294             $cnt++;
295         }
296         $sth->finish;
297
298     }  elsif ($type){
299         foreach my $syspref (sort { lc $a cmp lc $b } keys %tabsysprefs){
300             if ($tabsysprefs{$syspref} eq $type){
301                 my $sth=$dbh->prepare("Select variable,value,explanation,type,options from systempreferences where (variable like ?) order by variable");
302                 $sth->execute($syspref);
303                 while (my $data=$sth->fetchrow_hashref){
304                     $data->{value} =~ s/</&lt;/g;
305                     $data->{value} =~ s/>/&gt;/g;
306                     $data->{value}=substr($data->{value},0,100)."..." if length($data->{value}) >100;
307                     push(@results,$data);
308                     $cnt++;
309                 }
310                 $sth->finish;
311             }
312         }
313     } else {
314         my $strsth ="Select variable,value,explanation,type,options from systempreferences where variable not in (";
315         foreach my $syspref (keys %tabsysprefs){
316             $strsth .= $dbh->quote($syspref).",";
317         }
318         $strsth =~ s/,$/) /;
319         $strsth .= " order by variable";
320         my $sth=$dbh->prepare($strsth);
321         $sth->execute();
322         while (my $data=$sth->fetchrow_hashref){
323             $data->{value}=substr($data->{value},0,100);
324             push(@results,$data);
325             $cnt++;
326         }
327         $sth->finish;
328     }
329     return ($cnt,\@results);
330 }
331
332 my $input = new CGI;
333 my $searchfield=$input->param('searchfield');
334 my $offset=$input->param('offset');
335 my $script_name="/cgi-bin/koha/admin/systempreferences.pl";
336
337 my ($template, $borrowernumber, $cookie)
338     = get_template_and_user({template_name => "admin/systempreferences.tmpl",
339                  query => $input,
340                  type => "intranet",
341                  authnotrequired => 0,
342                  flagsrequired => {parameters => 1},
343                  debug => 1,
344                  });
345 my $pagesize=100;
346 my $op = $input->param('op');
347 $searchfield=~ s/\,//g;
348
349 if ($op) {
350 $template->param(script_name => $script_name,
351                         $op              => 1); # we show only the TMPL_VAR names $op
352 } else {
353 $template->param(script_name => $script_name,
354                         else              => 1); # we show only the TMPL_VAR names $op
355 }
356
357 if ($op eq 'update_and_reedit') {
358     foreach ($input->param) {
359     }
360     my $value='';
361     if (my $currentorder=$input->param('currentorder')) {
362         my @currentorder=split /\|/, $currentorder;
363         my $orderchanged=0;
364         foreach my $param ($input->param) {
365             if ($param=~m#up-(\d+).x#) {
366                 my $temp=$currentorder[$1];
367                 $currentorder[$1]=$currentorder[$1-1];
368                 $currentorder[$1-1]=$temp;
369                 $orderchanged=1;
370                 last;
371             } elsif ($param=~m#down-(\d+).x#) {
372                 my $temp=$currentorder[$1];
373                 $currentorder[$1]=$currentorder[$1+1];
374                 $currentorder[$1+1]=$temp;
375                 $orderchanged=1;
376                 last;
377             }
378         }
379         $value=join ' ', @currentorder;
380         if ($orderchanged) {
381             $op='add_form';
382             $template->param(script_name => $script_name,
383                             $op              => 1); # we show only the TMPL_VAR names $op
384         } else {
385             $op='';
386             $searchfield='';
387             $template->param(script_name => $script_name,
388                             else              => 1); # we show only the TMPL_VAR names $op
389         }
390     }
391     my $dbh = C4::Context->dbh;
392     my $query="select * from systempreferences where variable=?";
393     my $sth=$dbh->prepare($query);
394     $sth->execute($input->param('variable'));
395     if ($sth->rows) {
396         unless (C4::Context->config('demo') eq 1) {
397             my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
398             $sth->execute($value, $input->param('explanation'), $input->param('variable'), $input->param('preftype'), $input->param('prefoptions'));
399             $sth->finish;
400         }
401     } else {
402         unless (C4::Context->config('demo') eq 1) {
403             my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation) values (?,?,?,?,?)");
404             $sth->execute($input->param('variable'), $input->param('value'), $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
405             $sth->finish;
406         }
407     }
408     $sth->finish;
409
410 }
411
412 ################## ADD_FORM ##################################
413 # called by default. Used to create form to add or  modify a record
414
415 if ($op eq 'add_form') {
416     #---- if primkey exists, it's a modify action, so read values to modify...
417     my $data;
418     if ($searchfield) {
419         my $dbh = C4::Context->dbh;
420         my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
421         $sth->execute($searchfield);
422         $data=$sth->fetchrow_hashref;
423         $sth->finish;
424         $template->param(modify => 1);
425         # save tab to return to if user cancels edit
426         $template->param(return_tab => $tabsysprefs{$searchfield});
427     }
428
429     my @options;
430     foreach my $option (split(/\|/, $data->{'options'})) {
431         my $selected='0';
432         $option eq $data->{'value'} and $selected=1;
433         push @options, { option => $option, selected => $selected };
434     }
435     if ($data->{'type'} eq 'Choice') {
436         $template->param('type-choice' => 1);
437     } elsif ($data->{'type'} eq 'YesNo') {
438         $template->param('type-yesno' => 1);
439         $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
440         ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
441     } elsif ($data->{'type'} eq 'Integer') {
442         $template->param('type-free' => 1);
443         $template->param('fieldlength' => $data->{'options'});
444     } elsif ($data->{'type'} eq 'Textarea') {
445         $template->param('type-textarea' => 1);
446         $data->{options} =~ /(.*)\|(.*)/;
447         $template->param('cols' => $1, 'rows' => $2);;
448     } elsif ($data->{'type'} eq 'Float') {
449         $template->param('type-free' => 1);
450         $template->param('fieldlength' => $data->{'options'});
451     } elsif ($data->{'type'} eq 'Themes') {
452         $template->param('type-choice' => 1);
453         my $type='';
454         ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
455         @options=();
456         my $currently_selected_themes;
457         my $counter=0;
458         foreach my $theme (split /\s+/, $data->{'value'}) {
459             push @options, { option => $theme, counter => $counter };
460             $currently_selected_themes->{$theme}=1;
461             $counter++;
462         }
463         foreach my $theme (getallthemes($type)) {
464             my $selected='0';
465             next if $currently_selected_themes->{$theme};
466             push @options, { option => $theme, counter => $counter };
467             $counter++;
468         }
469     } elsif ($data->{'type'} eq 'ClassSources') {
470         $template->param('type-choice' => 1);
471         my $type='';
472         @options=();
473         my $sources = GetClassSources();
474         my $counter=0;
475         foreach my $cn_source (sort keys %$sources) {
476             if ($cn_source eq $data->{'value'}) {
477                 push @options, { option => $cn_source, counter => $counter, selected => 1 };
478             } else {
479                 push @options, { option => $cn_source, counter => $counter };
480             }
481             $counter++; 
482         }
483     } elsif ($data->{'type'} eq 'Languages') {
484         my $currently_selected_languages;
485         foreach my $language (split /\s+/, $data->{'value'}) {
486             $currently_selected_languages->{$language}=1;
487         }
488         # current language
489         my $lang = $template->param('lang');
490         my $theme;
491         my $interface;
492         if ($data->{'variable'} =~ /opac/) {
493                 # this is the OPAC
494                 $interface = 'opac';
495                 $theme = C4::Context->preference('opacthemes');
496         }
497         else {
498                 # this is the staff client      
499                 $interface = 'intranet';
500                 $theme = C4::Context->preference('template');
501         }
502         my $languages_loop = getTranslatedLanguages($interface,$theme,$lang,$currently_selected_languages);
503
504         $template->param('languages_loop' => $languages_loop);
505         $template->param('type-langselector' => 1);
506     } else {
507         $template->param('type-free' => 1);
508         $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
509     }
510     $template->param(explanation => $data->{'explanation'},
511              value => $data->{'value'},
512              type => $data->{'type'},
513              options => \@options,
514              preftype => $data->{'type'},
515              prefoptions => $data->{'options'},
516              searchfield => $searchfield);
517
518 ################## ADD_VALIDATE ##################################
519 # called by add_form, used to insert/modify data in DB
520 } elsif ($op eq 'add_validate') {
521     my $dbh = C4::Context->dbh;
522     my $sth=$dbh->prepare("select * from systempreferences where variable=?");
523     $sth->execute($input->param('variable'));
524     # to handle multiple values
525     my $value;
526     # handle multiple value strings (separated by ',')
527     my $params = $input->Vars;
528     my @values = split("\0",$params->{'value'}) if $params->{'value'};
529     for my $vl (@values) {
530         $value .= "$vl,";
531     }
532     $value =~ s/,$//;
533     if ($sth->rows) {
534         unless (C4::Context->config('demo') eq 1) {
535             my $sth=$dbh->prepare("update systempreferences set value=?,explanation=?,type=?,options=? where variable=?");
536             $sth->execute($value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'), $input->param('variable'));
537             $sth->finish;
538         }
539     } else {
540         unless (C4::Context->config('demo') eq 1) {
541             my $sth=$dbh->prepare("insert into systempreferences (variable,value,explanation,type,options) values (?,?,?,?,?)");
542             $sth->execute($input->param('variable'), $value, $input->param('explanation'), $input->param('preftype'), $input->param('prefoptions'));
543             $sth->finish;
544         }
545     }
546     $sth->finish;
547     print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=systempreferences.pl?tab=".$tabsysprefs{$input->param('variable')}."\"></html>";
548     exit;
549 ################## DELETE_CONFIRM ##################################
550 # called by default form, used to confirm deletion of data in DB
551 } elsif ($op eq 'delete_confirm') {
552     my $dbh = C4::Context->dbh;
553     my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
554     $sth->execute($searchfield);
555     my $data=$sth->fetchrow_hashref;
556     $sth->finish;
557     $template->param(searchfield => $searchfield,
558                             Tvalue => $data->{'value'},
559                             );
560
561                                                     # END $OP eq DELETE_CONFIRM
562 ################## DELETE_CONFIRMED ##################################
563 # called by delete_confirm, used to effectively confirm deletion of data in DB
564 } elsif ($op eq 'delete_confirmed') {
565     my $dbh = C4::Context->dbh;
566     my $sth=$dbh->prepare("delete from systempreferences where variable=?");
567     $sth->execute($searchfield);
568     $sth->finish;
569
570                                                     # END $OP eq DELETE_CONFIRMED
571 ################## DEFAULT ##################################
572 } else { # DEFAULT
573     #Adding tab management for system preferences
574     my $tab=$input->param('tab');
575     $template->param($tab => 1);
576     my ($count,$results)=StringSearch($searchfield,$tab);
577     my $toggle=0;
578     my @loop_data = ();
579     for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
580           if ($toggle eq 0){
581             $toggle=1;
582           } else {
583             $toggle=0;
584           }
585         my %row_data;  # get a fresh hash for the row data
586         $row_data{variable} = $results->[$i]{'variable'};
587         $row_data{value} = $results->[$i]{'value'};
588         $row_data{yes} = 1 if ($results->[$i]{'value'} == 1);
589         $row_data{yesno} = 1 if ($results->[$i]{'type'} eq 'YesNo');
590         $row_data{explanation} = $results->[$i]{'explanation'};
591         $row_data{toggle} = $toggle;
592         $row_data{edit} = "$script_name?op=add_form&amp;searchfield=".$results->[$i]{'variable'};
593         $row_data{delete} = "$script_name?op=delete_confirm&amp;searchfield=".$results->[$i]{'variable'};
594         push(@loop_data, \%row_data);
595     }
596     $tab=($tab?$tab:"Local Use");
597     $template->param(loop => \@loop_data, $tab => 1);
598     if ($offset>0) {
599         my $prevpage = $offset-$pagesize;
600         $template->param("<a href=$script_name?offset=".$prevpage.'&lt;&lt; Prev</a>');
601     }
602     if ($offset+$pagesize<$count) {
603         my $nextpage =$offset+$pagesize;
604         $template->param("a href=$script_name?offset=".$nextpage.'Next &gt;&gt;</a>');
605     }
606     $template->param(        tab => $tab,
607             );
608 } #---- END $OP eq DEFAULT
609 output_html_with_http_headers $input, $cookie, $template->output;