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