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