--- loncom/interface/lonpreferences.pm 2022/09/19 19:49:26 1.196.4.28.2.1
+++ loncom/interface/lonpreferences.pm 2024/03/01 14:23:23 1.196.4.28.2.3
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Preferences
#
-# $Id: lonpreferences.pm,v 1.196.4.28.2.1 2022/09/19 19:49:26 raeburn Exp $
+# $Id: lonpreferences.pm,v 1.196.4.28.2.3 2024/03/01 14:23:23 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2043,9 +2043,98 @@ sub author_space_settings {
my $domain = $env{'user.domain'};
my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
if (keys(%author_roles) > 0) {
- $r->print(Apache::loncommon::start_page('Authoring Space Settings'));
- $r->print(Apache::lonhtmlcommon::breadcrumbs('Authoring Space Settings'));
- my %userenv = &Apache::lonnet::get('environment',['nocodemirror']);
+ my ($showdomdefs,$js,$args,@items);
+ my $returnurl = &HTML::Entities::encode($env{'form.returnurl'},'"<>&\'');
+ my $reqdmajor = 2;
+ my $reqdminor = 12;
+ my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'user.domain'},$env{'user.home'});
+ my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
+ unless (($major eq '' && $minor eq '') ||
+ ($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor))) {
+ @items = ('nocodemirror','copyright','sourceavail');
+ $showdomdefs = 1;
+ $js = &toggle_options_js();
+ my $onload;
+ foreach my $item (@items) {
+ $onload .= "javascript:toggleOptions(document.prefs,'$item','user_$item');"
+ }
+ $args = { 'add_entries' => { 'onload' => $onload } };
+ }
+ $r->print(Apache::loncommon::start_page('Authoring Space Settings',$js,$args));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Authoring Space Settings'));
+ if ($showdomdefs) {
+ my %userenv = &Apache::lonnet::get('environment',\@items);
+ my %domdefs = &Apache::lonnet::get_domain_defaults($domain);
+ my %staticdefaults = (
+ 'nocodemirror' => '0',
+ 'copyright' => 'default',
+ 'sourceavail' => 'closed',
+ );
+ my %lt = &authoring_settings_text();
+ my %titles = &authoring_settings_titles();
+ $r->print("
$lt{'auss'}
\n".
+ ''."\n");
+ } else {
my $constchecked='';
if ($env{'environment.nocodemirror'}) {
$constchecked=' checked="checked"';
@@ -2053,7 +2142,6 @@ sub author_space_settings {
my $text=&mt('By default, CodeMirror an editor with advanced functionality for editing code is activated for authors.');
my $cmoff=&mt('Deactivate CodeMirror. This can improve performance on slow computers and accessibility.');
my $change=&mt('Save');
- my $returnurl = &HTML::Entities::encode($env{'form.returnurl'},'"<>&\'');
$r->print(<
@@ -2063,6 +2151,7 @@ sub author_space_settings {
ENDSCREEN
+ }
}
}
@@ -2072,6 +2161,8 @@ sub change_authoring_settings {
my $domain = $env{'user.domain'};
my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
if (keys(%author_roles) > 0) {
+ my $message;
+ if (0) {
my %ausettings=('environment.nocodemirror' => '');
if ($env{'form.cmoff'}) { $ausettings{'environment.nocodemirror'}='yes'; }
&Apache::lonnet::put('environment',\%ausettings);
@@ -2082,16 +2173,138 @@ sub change_authoring_settings {
} else {
$status=&mt('off');
}
- my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]',''.&mt('Deactivate CodeMirror in Authoring Space').'',''.$status.''));
+ $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]',''.&mt('Deactivate CodeMirror in Authoring Space').'',''.$status.''));
$message=&Apache::loncommon::confirmwrapper($message);
- if ($env{'form.returnurl'}) {
- &do_redirect($r,$env{'form.returnurl'},$message);
- } else {
- &print_main_menu($r,$message);
+ } else {
+ my @items = ('nocodemirror','copyright','sourceavail');
+ my %oldsettings = &Apache::lonnet::get('environment',\@items);
+ my %domdefs = &Apache::lonnet::get_domain_defaults($domain);
+ my %lt = &authoring_settings_text();
+ my %titles = &authoring_settings_titles();
+ my ($result,%newsettings,%changes,@delete,@unchanged,@delerrors,@adderrors);
+ foreach my $item (@items) {
+ if ($env{'form.'.$item} eq 'dom') {
+ if ($oldsettings{$item} eq '') {
+ push(@unchanged,$item);
+ } else {
+ push(@delete,$item);
+ }
+ } elsif ($env{'form.'.$item} eq 'user') {
+ my $newval = $env{'form.userchoice_'.$item};
+ my @possibles;
+ if ($item eq 'nocodemirror') {
+ if ($newval =~ /^yes|no$/) {
+ $newsettings{$item} = $newval;
+ }
+ } elsif ($item eq 'copyright') {
+ @possibles = (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids));
+ if (grep(/^\Q$newval\E$/,@possibles)) {
+ $newsettings{$item} = $newval;
+ }
+ } elsif ($item eq 'sourceavail') {
+ @possibles = (&Apache::loncommon::source_copyrightids);
+ if (grep(/^\Q$newval\E$/,@possibles)) {
+ $newsettings{$item} = $newval;
+ }
+ }
+ if ($oldsettings{$item} eq $newsettings{$item}) {
+ push(@unchanged,$item);
+ } else {
+ $changes{$item} = $newsettings{$item};
+ }
+ }
+ }
+ if (@delete) {
+ if (&Apache::lonnet::del('environment',\@delete) eq 'ok') {
+ foreach my $key (@delete) {
+ &Apache::lonnet::delenv('environment.'.$key);
+ }
+ } else {
+ @delerrors = @delete;
+ }
+ }
+ if (keys(%changes)) {
+ if (&Apache::lonnet::put('environment',\%changes) eq 'ok') {
+ my %newenvhash;
+ map {$newenvhash{'environment.'.$_} = $changes{$_}; } (keys(%changes));
+ &Apache::lonnet::appenv(\%newenvhash);
+ } else {
+ foreach my $item (@items) {
+ if (exists($changes{$item})) {
+ push(@adderrors,$item);
+ }
+ }
+ }
+ }
+ if (@adderrors) {
+ $result = &mt('An error occurred when saving user-specific settings for').': '.
+ join(', ', map { $titles{$_} } @adderrors);
+ $message = &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result,1));
+ } elsif (keys(%changes)) {
+ $result = &mt('User-specific settings saved:').'';
+ foreach my $item (@items) {
+ next unless (exists($changes{$item}));
+ my $value = $changes{$item};
+ if ($item eq 'nocodemirror') {
+ $value = $lt{$changes{$item}};
+ } elsif ($item eq 'copyright') {
+ $value = &Apache::loncommon::copyrightdescription($changes{$item});
+ } elsif ($item eq 'sourceavail') {
+ $value = &Apache::loncommon::source_copyrightdescription($changes{$item});
+ }
+ $result .= '- '.
+ &mt('[_1] set to [_2]',
+ $titles{$item},
+ ''.$value.'').
+ '
';
+ }
+ $result .= '
';
+ $message = &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result));
+ }
+ if (@delerrors) {
+ $result = &mt('An error occurred when deleting user-specific settings for').':- '.
+ join('
- ', map { $titles{$_} } @delerrors).'
';
+ $message .= &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result,1));
+ } elsif (@delete) {
+ $result = &mt('Set use of domain default for').':- '.
+ join('
- ', map { $titles{$_} } @delete).'
';
+ $message .= &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result));
+ }
+ if (@unchanged) {
+ $result = &mt('No changes made for').':- '.
+ join('
- ', map { $titles{$_} } @unchanged).'
';
+ $message .= &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result));
}
+ }
+ if ($env{'form.returnurl'}) {
+ &do_redirect($r,$env{'form.returnurl'},$message);
+ } else {
+ &print_main_menu($r,$message);
+ }
}
}
+sub authoring_settings_text {
+ return &Apache::lonlocal::texthash(
+ 'auss' => 'Authoring Space Settings',
+ 'used' => 'Use domain default',
+ 'usyo' => 'Use your own user-specific setting',
+ 'curd' => 'Current domain default is',
+ 'ousv' => 'Own user-specific value',
+ 'save' => 'Save',
+ 'yes' => 'Deactivated',
+ 'no' => 'Activated',
+ );
+}
+
+sub authoring_settings_titles {
+ return &Apache::lonlocal::texthash(
+ 'nocodemirror' => 'CodeMirror for EditXML editor',
+ 'copyright' => 'Default Copyright/Distribution in new metadata file',
+ 'sourceavail' => 'Default Source Available in new metadata file',
+ );
+}
+
sub lockednameschanger {
my $r = shift;
my %userenv = &Apache::lonnet::get('environment',['lockedname']);
@@ -2188,39 +2401,9 @@ sub timezonechanger {
my $uname = $env{'user.name'};
my $udom = $env{'user.domain'};
if (&Apache::lonnet::usertools_access($uname,$udom,'timezone')) {
- my $js = <<"ENDSCRIPT";
-
-ENDSCRIPT
+ my $js = &toggle_options_js();
my %loaditems = (
- onload => 'javascript:toggleTZdisplay(document.prefs);',
+ onload => "javascript:toggleOptions(document.prefs,'settimezone','LC_timezone_selector');",
);
my $args = { 'add_entries' => \%loaditems };
&Apache::lonhtmlcommon::add_breadcrumb(
@@ -2243,7 +2426,7 @@ ENDSCRIPT
$checked{'lctz'} = ' checked="checked"';
$tzsty = 'none';
}
- my $onclick = ' onclick="javascript:toggleTZdisplay(this.form);"';
+ my $onclick = ' onclick="javascript:toggleOptions(this.form,'."'settimezone','LC_timezone_selector'".');"';
my $selector = &Apache::loncommon::select_timezone('timezone',$timezone,undef,1);
$r->print(<<"END");