--- loncom/interface/lonpreferences.pm 2020/02/09 05:36:27 1.196.4.26
+++ 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.26 2020/02/09 05:36:27 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
#
@@ -31,7 +31,6 @@
package Apache::lonpreferences;
use strict;
-use LONCAPA;
use Apache::Constants qw(:common);
use Apache::File;
use Apache::loncommon();
@@ -40,6 +39,7 @@ use Apache::lonlocal;
use Apache::lonnet;
use LONCAPA::lonauthcgi();
use LONCAPA();
+use DateTime::TimeZone();
################################################################
# Handler subroutines #
@@ -627,7 +627,7 @@ sub icon_options {
}
sub icon_previews {
- my %icon_text = (
+ my %icon_text = &Apache::lonlocal::texthash (
annotate => 'Notes',
wishlist => 'Stored Links',
catalog => 'Info',
@@ -636,12 +636,12 @@ sub icon_previews {
printout => 'Print',
);
my %inlinetools = (
- printout => "s&8&3&prt.png&$icon_text{'printout'}&printout[_1]&gopost('/adm/printout',currentURL)&Prepare a printable document",
- wishlist => "s&9&1&wishlist-link.png&$icon_text{'wishlist'}&wishlistlink[_2]&set_wishlistlink()&Save a link for this resource in your personal Stored Links repository",
- evaluate => "s&8&1&eval.png&$icon_text{'evaluate'}&this[_1]&gopost('/adm/evaluate',currentURL,1)&Provide my evaluation of this resource",
- feedback => "s&8&2&fdbk.png&$icon_text{'feedback'}&discuss[_1]&gopost('/adm/feedback',currentURL,1)&Provide feedback messages or contribute to the course discussion about this resource",
- annotate => "s&9&3&anot.png&$icon_text{'annotate'}&tations[_1]&annotate()&Make notes and annotations about this resource",
- catalog => "s&6&3&catalog.png&$icon_text{'catalog'}&info[_1]&catalog_info()&Show Metadata",
+ printout => "s&8&3&prt.png&$icon_text{'printout'}&printout[_1]&gopost('/adm/printout',currentURL)&".&mt('Prepare a printable document'),
+ wishlist => "s&9&1&wishlist-link.png&$icon_text{'wishlist'}&wishlistlink[_2]&set_wishlistlink()&".&mt('Save a link for this resource in your personal Stored Links repository'),
+ evaluate => "s&8&1&eval.png&$icon_text{'evaluate'}&this[_1]&gopost('/adm/evaluate',currentURL,1)&".&mt('Provide my evaluation of this resource'),
+ feedback => "s&8&2&fdbk.png&$icon_text{'feedback'}&discuss[_1]&gopost('/adm/feedback',currentURL,1)&".&mt('Provide feedback messages or contribute to the course discussion about this resource'),
+ annotate => "s&9&3&anot.png&$icon_text{'annotate'}&tations[_1]&annotate()&".&mt('Make notes and annotations about this resource'),
+ catalog => "s&6&3&catalog.png&$icon_text{'catalog'}&info[_1]&catalog_info()&".&mt('Show Metadata'),
);
my @toolsorder = qw(annotate wishlist evaluate feedback printout catalog);
return (\%inlinetools,\@toolsorder);
@@ -1230,7 +1230,8 @@ sub passwordchanger {
# This function is a bit of a mess....
# Passwords are encrypted using londes.js (DES encryption)
$errormessage = ($errormessage || '');
- my ($user,$domain,$currentpass);
+ my ($user,$domain,$currentpass,$clientip);
+ $clientip = &Apache::lonnet::get_requestor_ip($r);
&Apache::lonhtmlcommon::add_breadcrumb(
{ href => '/adm/preferences?action=changepass',
text => 'Change Password'});
@@ -1245,7 +1246,7 @@ sub passwordchanger {
$caller = 'preferences';
}
my ($blocked,$blocktext) =
- &Apache::loncommon::blocking_status('passwd');
+ &Apache::loncommon::blocking_status('passwd',$clientip);
if ($blocked) {
$r->print('
'.$blocktext.'
');
return;
@@ -1267,7 +1268,7 @@ sub passwordchanger {
$domain = $data{'domain'};
$currentpass = $data{'temppasswd'};
my ($blocked,$blocktext) =
- &Apache::loncommon::blocking_status('passwd',$user,$domain);
+ &Apache::loncommon::blocking_status('passwd',$clientip,$user,$domain);
if ($blocked) {
$r->print('
'.$blocktext.'
');
return;
@@ -1588,7 +1589,7 @@ sub server_form {
sub verify_and_change_password {
my ($r,$caller,$mailtoken,$timelimit,$extrafields,$ended) = @_;
- my ($user,$domain,$homeserver);
+ my ($user,$domain,$homeserver,$clientip);
if ($caller eq 'reset_by_email') {
$user = $env{'form.uname'};
$domain = $env{'form.udom'};
@@ -1611,8 +1612,9 @@ sub verify_and_change_password {
$domain = $env{'user.domain'};
$homeserver = $env{'user.home'};
}
+ $clientip = &Apache::lonnet::get_requestor_ip($r);
my ($blocked,$blocktext) =
- &Apache::loncommon::blocking_status('passwd',$user,$domain);
+ &Apache::loncommon::blocking_status('passwd',$clientip,$user,$domain);
if ($blocked) {
$r->print('
'.$blocktext.'
');
if ($caller eq 'reset_by_email') {
@@ -2041,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"';
@@ -2051,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(<
@@ -2061,6 +2151,7 @@ sub author_space_settings {
ENDSCREEN
+ }
}
}
@@ -2070,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);
@@ -2080,25 +2173,143 @@ 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:').'