'.&mt('Some LON-CAPA users have a long list of roles. The Recent Roles Hotlist feature keeps track of the last N roles which have been visited and places a table of these at the top of the roles page. People with very few roles should leave this feature disabled.').'
+
'.&mt('Some LON-CAPA users have a long list of '.$lc_role.'s. The Recent '.$role.'s Hotlist feature keeps track of the last N '.$lc_role.'s which have been visited and places a table of these at the top of the '.$lc_role.'s page. People with very few '.$lc_role.'s should leave this feature disabled.').'
');
}
+sub rolespref_get_role_text {
+# Get a line of text for each role
+ my ($roles) = @_;
+ my %roletext = ();
+
+ foreach my $item (@$roles) {
+# get course information
+ my ($role,$rest) = split(/\./, $item);
+ my $trole = "";
+ $trole = &Apache::lonnet::plaintext($role);
+ my ($tdomain,$other,$tsection)= split(/\//,Apache::lonnet::declutter($rest));
+ my $tother = '-';
+ if ($role =~ /^(cc|st|in|ta|ep|cr)/ ) {
+ my %newhash=&Apache::lonnet::coursedescription($tdomain."_".$other);
+ $tother = " - ".$newhash{'description'};
+ } elsif ($role =~ /dc/) {
+ $tother = "";
+ } else {
+ $tother = " - $other";
+ }
+
+ my $section="";
+ if ($tsection) {
+ $section = " - Section/Group: $tsection";
+ }
+ $roletext{$item} = $tdomain." - ".$trole.$tother.$section;
+ }
+ return %roletext;
+}
+
sub verify_and_change_rolespref {
my $r = shift;
+ my $role = ($env{'user.adv'} ? 'Role' : 'Course');
my $user = $env{'user.name'};
my $domain = $env{'user.domain'};
# Recent Roles Hotlist Flag
@@ -383,38 +401,40 @@ sub verify_and_change_rolespref {
if ($hotlist_flag) {
&Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
&Apache::lonnet::appenv('environment.recentroles' => $hotlist_flag);
- $message=&mt('Recent Roles Hotlist is Enabled');
+ $message=&mt('Recent '.$role.'s Hotlist is Enabled');
} else {
&Apache::lonnet::del('environment',['recentroles']);
&Apache::lonnet::delenv('environment\.recentroles');
- $message=&mt('Recent Roles Hotlist is Disabled');
+ $message=&mt('Recent '.$role.'s Hotlist is Disabled');
}
if ($hotlist_n) {
&Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
&Apache::lonnet::appenv('environment.recentrolesn' => $hotlist_n);
if ($hotlist_flag) {
$message.=" ".
- &mt('Display [_1] Most Recent Roles',$hotlist_n)."\n";
+ &mt('Display [_1] Most Recent '.$role.'s',$hotlist_n)."\n";
}
}
# Get list of froze roles and list of recent roles
my @freeze_list = &Apache::loncommon::get_env_multiple('form.freezeroles');
my %freeze = ();
+ my %roletext = ();
+
foreach my $key (@freeze_list) {
$freeze{$key}='1';
}
-
+
my %recent_roles =
&Apache::lonhtmlcommon::get_recent('roles',$env{'environment.recentrolesn'});
my %frozen_roles =
&Apache::lonhtmlcommon::get_recent_frozen('roles',$env{'environment.recentrolesn'});
+ my %role_text = &rolespref_get_role_text([keys(%recent_roles)]);
# Unset any roles that were previously frozen but aren't in list
-
foreach my $role_key (sort(keys(%recent_roles))) {
if (($frozen_roles{$role_key}) && (!exists($freeze{$role_key}))) {
- $message .= " ".&mt('Unfreezing Role: [_1]',$role_key)."\n";
+ $message .= " ".&mt('Unfreezing '.$role.': [_1]',$role_text{$role_key})."\n";
&Apache::lonhtmlcommon::store_recent('roles',$role_key,' ',0);
}
}
@@ -422,7 +442,7 @@ sub verify_and_change_rolespref {
# Freeze selected roles
foreach my $role_key (@freeze_list) {
if (!$frozen_roles{$role_key}) {
- $message .= " ".&mt('Freezing Role: [_1]',$role_key)."\n";
+ $message .= " ".&mt('Freezing '.$role.': [_1]',$role_text{$role_key})."\n";
&Apache::lonhtmlcommon::store_recent('roles',
$role_key,' ',1);
}
@@ -496,6 +516,45 @@ ENDVCSCREEN
}
################################################################
+# Icon Subroutines #
+################################################################
+sub iconchanger {
+ my $r = shift;
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my %userenv = &Apache::lonnet::get
+ ('environment',['icons']);
+ my $iconic='checked="checked"';
+ my $classic='';
+ if ($userenv{'icons'} eq 'classic') {
+ $classic='checked="checked"';
+ $iconic='';
+ }
+ my $useicons=&mt('Use icons');
+ my $usebuttons=&mt('Use classic buttons');
+ my $change=&mt('Change');
+ $r->print(<
+
+
+
+
+
+ENDSCREEN
+}
+
+sub verify_and_change_icons {
+ my $r = shift;
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my $newicons = $env{'form.menumode'};
+
+ &Apache::lonnet::put('environment',{'icons' => $newicons});
+ &Apache::lonnet::appenv('environment.icons' => $newicons);
+ $r->print(&mt('Set menu mode to [_1].',$newicons));
+}
+
+################################################################
# Message Forward #
################################################################
@@ -537,8 +596,8 @@ sub verify_and_change_msgforward {
my $message='';
foreach (split(/\,/,$env{'form.msgforward'})) {
my ($msuser,$msdomain)=split(/[\@\:]/,$_);
- $msuser=~s/\W//g;
- $msdomain=~s/\W//g;
+ $msuser = &LONCAPA::clean_username($msuser);
+ $msdomain = &LONCAPA::clean_domain($msdomain);
if (($msuser) && ($msdomain)) {
if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') {
$newscreen.=$msuser.':'.$msdomain.',';
@@ -702,14 +761,41 @@ ENDVCCOL
# password handler subroutines #
######################################################
sub passwordchanger {
+ my ($r,$errormessage,$caller,$mailtoken) = @_;
# This function is a bit of a mess....
# Passwords are encrypted using londes.js (DES encryption)
- my $r = shift;
- my $errormessage = shift;
$errormessage = ($errormessage || '');
- my $user = $env{'user.name'};
- my $domain = $env{'user.domain'};
- my $homeserver = $env{'user.home'};
+ my ($user,$domain,$currentpass,$defdom);
+ if ((!defined($caller)) || ($caller eq 'preferences')) {
+ $user = $env{'user.name'};
+ $domain = $env{'user.domain'};
+ if (!defined($caller)) {
+ $caller = 'preferences';
+ }
+ } elsif ($caller eq 'reset_by_email') {
+ $defdom = $r->dir_config('lonDefDomain');
+ my %data = &Apache::lonnet::tmpget($mailtoken);
+ if (keys(%data) == 0) {
+ $r->print(&mt('Sorry, the URL you provided to complete the reset of your password was invalid. Either the token included in the URL has been deleted or the URL you provided was invalid. Please submit a new request for a password reset, and follow the link to the new URL included in the e-mail that will be sent to you, to allow you to enter a new password.'));
+ return;
+ }
+ if (defined($data{time})) {
+ if (time - $data{'time'} < 7200) {
+ $user = $data{'username'};
+ $domain = $data{'domain'};
+ $currentpass = $data{'temppasswd'};
+ } else {
+ $r->print(&mt('Sorry, the token generated when you requested a password reset has expired.').' ');
+ return;
+ }
+ } else {
+ $r->print(&mt('Sorry, the URL generated when you requested reset of your password contained incomplete information.').' ');
+ return;
+ }
+ } else {
+ $r->print(&mt('Page requested in unexpected context').' ');
+ return;
+ }
my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
# Check for authentication types that allow changing of the password.
return if ($currentauth !~ /^(unix|internal):/);
@@ -726,12 +812,13 @@ sub passwordchanger {
.$ukey_npass2 . $lkey_npass2,
$lonhost);
# Hexify the keys for output as javascript variables
- $ukey_cpass = hex($ukey_cpass);
- $lkey_cpass = hex($lkey_cpass);
- $ukey_npass1= hex($ukey_npass1);
- $lkey_npass1= hex($lkey_npass1);
- $ukey_npass2= hex($ukey_npass2);
- $lkey_npass2= hex($lkey_npass2);
+ my %hexkey;
+ $hexkey{'ukey_cpass'} = hex($ukey_cpass);
+ $hexkey{'lkey_cpass'} = hex($lkey_cpass);
+ $hexkey{'ukey_npass1'} = hex($ukey_npass1);
+ $hexkey{'lkey_npass1'} = hex($lkey_npass1);
+ $hexkey{'ukey_npass2'} = hex($ukey_npass2);
+ $hexkey{'lkey_npass2'} = hex($lkey_npass2);
# Output javascript to deal with passwords
# Output DES javascript
{
@@ -739,7 +826,25 @@ sub passwordchanger {
my $jsh=Apache::File->new($include."/londes.js");
$r->print(<$jsh>);
}
+ $r->print(&jscript_send($caller));
$r->print(<
+
+ENDFORM
+ $r->print(&server_form($logtoken,$caller,$mailtoken));
+ $r->print(&client_form($caller,\%hexkey,$currentpass,$defdom));
+
+ #
+ return;
+}
+
+sub jscript_send {
+ my ($caller) = @_;
+ my $output = qq|
-$errormessage
-
-
-
-
-
+|;
+}
+sub client_form {
+ my ($caller,$hexkey,$currentpass,$defdom) = @_;
+ my $output = qq|
ENDFORM
- #
- return;
+ return $output;
+}
+
+sub server_form {
+ my ($logtoken,$caller,$mailtoken) = @_;
+ my $action = '/adm/preferences';
+ if ($caller eq 'reset_by_email') {
+ $action = '/adm/resetpw';
+ }
+ my $output = qq|
+
+|;
+ return $output;
}
sub verify_and_change_password {
- my $r = shift;
- my $user = $env{'user.name'};
- my $domain = $env{'user.domain'};
- my $homeserver = $env{'user.home'};
+ my ($r,$caller,$mailtoken) = @_;
+ my ($user,$domain,$homeserver);
+ if ($caller eq 'reset_by_email') {
+ $user = $env{'form.uname'};
+ $domain = $env{'form.udom'};
+ if ($user ne '' && $domain ne '') {
+ $homeserver = &Apache::lonnet::homeserver($user,$domain);
+ if ($homeserver eq 'no_host') {
+ &passwordchanger($r,"
");
+ "One or more password fields were blank.\n",$caller,$mailtoken);
return;
}
# Get the keys
@@ -831,10 +1013,14 @@ sub verify_and_change_password {
my $tmpinfo = Apache::lonnet::reply('tmpget:'.$logtoken,$lonhost);
if (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost')) {
# I do not a have a better idea about how to handle this
+ my $tryagain_text = &mt('Please log out and try again.');
+ if ($caller eq 'reset_by_email') {
+ $tryagain_text = &mt('Please try again later.');
+ }
$r->print(<
ERROR: Unable to retrieve stored token for
-password decryption. Please log out and try again.
+password decryption. $tryagain_text
ENDERROR
# Probably should log an error here
@@ -845,19 +1031,29 @@ ENDERROR
$currentpass = &des_decrypt($ckey ,$currentpass);
$newpass1 = &des_decrypt($n1key,$newpass1);
$newpass2 = &des_decrypt($n2key,$newpass2);
- #
+ #
+ if ($caller eq 'reset_by_email') {
+ my %data = &Apache::lonnet::tmpget($mailtoken);
+ if ($currentpass ne $data{'temppasswd'}) {
+ &passwordchanger($r,
+ 'ERROR:'.
+ 'Could not verify current authentication. '.
+ 'Please try again.',$caller,$mailtoken);
+ return 1;
+ }
+ }
if ($newpass1 ne $newpass2) {
&passwordchanger($r,
'ERROR:'.
'The new passwords you entered do not match. '.
- 'Please try again.');
+ 'Please try again.',$caller,$mailtoken);
return 1;
}
if (length($newpass1) < 7) {
&passwordchanger($r,
'ERROR:'.
'Passwords must be a minimum of 7 characters long. '.
- 'Please try again.');
+ 'Please try again.',$caller,$mailtoken);
return 1;
}
#
@@ -868,7 +1064,7 @@ ENDERROR
}
if ($badpassword) {
# I can't figure out how to enter bad characters on my browser.
- &passwordchanger($r,<ERROR:
The password you entered contained illegal characters.
Valid characters are: space and
@@ -877,20 +1073,22 @@ Valid characters are: space and
ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_\`abcdefghijklmnopqrstuvwxyz{|}~
ENDERROR
+ &passwordchanger($r,$errormessage,$caller,$mailtoken);
+ return 1;
}
#
# Change the password (finally)
my $result = &Apache::lonnet::changepass
- ($user,$domain,$currentpass,$newpass1,$homeserver);
+ ($user,$domain,$currentpass,$newpass1,$homeserver,$caller);
# Inform the user the password has (not?) been changed
if ($result =~ /^ok$/) {
$r->print(<<"ENDTEXT");
-
The password for $user was successfully changed
+
The password for $user was successfully changed
ENDTEXT
} else {
# error error: run in circles, scream and shout
$r->print(<The password for $user was not changed
+
The password for $user was not changed
Please make sure your old password was entered correctly.
ENDERROR
return 1;
@@ -1181,7 +1379,7 @@ sub handler {
}));
push (@Options,({ action => 'changemsgforward',
- linktext => 'Change Message Forwarding and Notification Addresses',
+ linktext => 'Change Message Forwarding and Notification Email Addresses',
href => '/adm/preferences',
help => 'Prefs_Forwarding',
breadcrumb =>
@@ -1265,20 +1463,21 @@ sub handler {
printmenu => 'yes',
subroutine => \&verify_and_change_discussion, }
));
-
+
+ my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
push (@Options,({ action => 'changerolespref',
- linktext => 'Change Roles Page Preferences',
+ linktext => 'Change '.$role.' Page Preferences',
href => '/adm/preferences',
subroutine => \&rolesprefchanger,
breadcrumb =>
{ href => '/adm/preferences?action=changerolespref',
- text => 'Change Roles Pref'},
+ text => 'Change '.$role.' Page Pref'},
},
{ action => 'verify_and_change_rolespref',
subroutine => \&verify_and_change_rolespref,
breadcrumb =>
{ href => '/adm/preferences?action=changerolespref',
- text => 'Change Roles Preferences'},
+ text => 'Change '.$role.' Page Preferences'},
printmenu => 'yes',
}));
@@ -1310,6 +1509,22 @@ sub handler {
}));
}
+ push (@Options,({ action => 'changeicons',
+ linktext => 'Change How Main Menu is Displayed',
+ href => '/adm/preferences',
+ subroutine => \&iconchanger,
+ breadcrumb =>
+ { href => '/adm/preferences?action=changeicons',
+ text => 'Change Main Menu'},
+ },
+ { action => 'verify_and_change_icons',
+ subroutine => \&verify_and_change_icons,
+ breadcrumb =>
+ { href => '/adm/preferences?action=changeicons',
+ text => 'Change Main Menu'},
+ printmenu => 'yes',
+ }));
+
if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
|| &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
.$env{'request.course.sec'})) {