- #---- if primkey exists, it's a modify action, so read values to modify...
- my $data;
- if ($searchfield) {
- my $dbh = C4::Context->dbh;
- my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
- $sth->execute($searchfield);
- $data=$sth->fetchrow_hashref;
- $sth->finish;
- $template->param(modify => 1);
- }
-
- my @options;
- foreach my $option (split(/\|/, $data->{'options'})) {
- my $selected='0';
- $option eq $data->{'value'} and $selected=1;
- push @options, { option => $option, selected => $selected };
- }
- if ($data->{'type'} eq 'Choice') {
- $template->param('type-choice' => 1);
- } elsif ($data->{'type'} eq 'YesNo') {
- $template->param('type-yesno' => 1);
- $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
- ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
- } elsif ($data->{'type'} eq 'Integer') {
- $template->param('type-free' => 1);
- $template->param('fieldlength' => $data->{'options'});
- } elsif ($data->{'type'} eq 'Textarea') {
- $template->param('type-textarea' => 1);
- $data->{options} =~ /(.*)\|(.*)/;
- $template->param('cols' => $1, 'rows' => $2);;
- } elsif ($data->{'type'} eq 'Float') {
- $template->param('type-free' => 1);
- $template->param('fieldlength' => $data->{'options'});
- } elsif ($data->{'type'} eq 'Themes') {
- $template->param('type-choice' => 1);
- my $type='';
- ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
- @options=();
- my $currently_selected_themes;
- my $counter=0;
- foreach my $theme (split /\s+/, $data->{'value'}) {
- push @options, { option => $theme, counter => $counter };
- $currently_selected_themes->{$theme}=1;
- $counter++;
- }
- foreach my $theme (getallthemes($type)) {
- my $selected='0';
- next if $currently_selected_themes->{$theme};
- push @options, { option => $theme, counter => $counter };
- $counter++;
- }
- } elsif ($data->{'type'} eq 'Languages') {
- $template->param('type-choice' => 1);
- my $type='';
- @options=();
- my $currently_selected_languages;
- my $counter=0;
- foreach my $language (split /\s+/, $data->{'value'}) {
- next if $language eq 'images';
- push @options, { option => $language, counter => $counter };
- $currently_selected_languages->{$language}=1;
- $counter++;
- }
- foreach my $language (getalllanguages()) {
- next if $language eq 'images';
- my $selected='0';
- next if $currently_selected_languages->{$language};
- push @options, { option => $language, counter => $counter };
- $counter++;
- }
- } else {
- $template->param('type-free' => 1);
- $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
- }
- $template->param(explanation => $data->{'explanation'},
- value => $data->{'value'},
- type => $data->{'type'},
- options => \@options,
- preftype => $data->{'type'},
- prefoptions => $data->{'options'},
- searchfield => $searchfield);
+ #---- if primkey exists, it's a modify action, so read values to modify...
+ my $data;
+ if ($searchfield) {
+ my $dbh = C4::Context->dbh;
+ my $sth=$dbh->prepare("select variable,value,explanation,type,options from systempreferences where variable=?");
+ $sth->execute($searchfield);
+ $data=$sth->fetchrow_hashref;
+ $sth->finish;
+ $template->param(modify => 1);
+ # save tab to return to if user cancels edit
+ $template->param(return_tab => $tabsysprefs{$searchfield});
+ }
+
+ my @options;
+ foreach my $option (split(/\|/, $data->{'options'})) {
+ my $selected='0';
+ $option eq $data->{'value'} and $selected=1;
+ push @options, { option => $option, selected => $selected };
+ }
+ if ($data->{'type'} eq 'Choice') {
+ $template->param('type-choice' => 1);
+ } elsif ($data->{'type'} eq 'YesNo') {
+ $template->param('type-yesno' => 1);
+ $data->{'value'}=C4::Context->boolean_preference($data->{'variable'});
+ ($data->{'value'} eq '1') ? ($template->param('value-yes'=>1)) : ($template->param('value-no'=>1));
+ } elsif ($data->{'type'} eq 'Integer') {
+ $template->param('type-free' => 1);
+ $template->param('fieldlength' => $data->{'options'});
+ } elsif ($data->{'type'} eq 'Textarea') {
+ $template->param('type-textarea' => 1);
+ $data->{options} =~ /(.*)\|(.*)/;
+ $template->param('cols' => $1, 'rows' => $2);;
+ } elsif ($data->{'type'} eq 'Float') {
+ $template->param('type-free' => 1);
+ $template->param('fieldlength' => $data->{'options'});
+ } elsif ($data->{'type'} eq 'Themes') {
+ $template->param('type-choice' => 1);
+ my $type='';
+ ($data->{'variable'}=~m#opac#i) ? ($type='opac') : ($type='intranet');
+ @options=();
+ my $currently_selected_themes;
+ my $counter=0;
+ foreach my $theme (split /\s+/, $data->{'value'}) {
+ push @options, { option => $theme, counter => $counter };
+ $currently_selected_themes->{$theme}=1;
+ $counter++;
+ }
+ foreach my $theme (getallthemes($type)) {
+ my $selected='0';
+ next if $currently_selected_themes->{$theme};
+ push @options, { option => $theme, counter => $counter };
+ $counter++;
+ }
+ } elsif ($data->{'type'} eq 'ClassSources') {
+ $template->param('type-choice' => 1);
+ my $type='';
+ @options=();
+ my $sources = GetClassSources();
+ my $counter=0;
+ foreach my $cn_source (sort keys %$sources) {
+ if ($cn_source eq $data->{'value'}) {
+ push @options, { option => $cn_source, counter => $counter, selected => 1 };
+ } else {
+ push @options, { option => $cn_source, counter => $counter };
+ }
+ $counter++;
+ }
+ } elsif ($data->{'type'} eq 'Languages') {
+ $template->param('type-choice' => 1);
+ my $type='';
+ @options=();
+ my $currently_selected_languages;
+ my $counter=0;
+ foreach my $language (split /\s+/, $data->{'value'}) {
+ next if $language eq 'images';
+ push @options, { option => $language, counter => $counter };
+ $currently_selected_languages->{$language}=1;
+ $counter++;
+ }
+ my $langavail = getTranslatedLanguages();
+ foreach my $language (@$langavail) {
+ my $selected='0';
+ next if $currently_selected_languages->{$language->{'language_code'}};
+ #FIXME: could add language_name and language_locale_name for better display
+ push @options, { option => $language->{'language_code'}, counter => $counter };
+ $counter++;
+ }
+ } else {
+ $template->param('type-free' => 1);
+ $template->param('fieldlength' => $data->{'options'}>0?$data->{'options'}:60);
+ }
+ $template->param(explanation => $data->{'explanation'},
+ value => $data->{'value'},
+ type => $data->{'type'},
+ options => \@options,
+ preftype => $data->{'type'},
+ prefoptions => $data->{'options'},
+ searchfield => $searchfield);