--- loncom/interface/lonpreferences.pm 2004/03/26 17:11:37 1.39
+++ loncom/interface/lonpreferences.pm 2015/03/12 02:58:33 1.196.4.16
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Preferences
#
-# $Id: lonpreferences.pm,v 1.39 2004/03/26 17:11:37 www Exp $
+# $Id: lonpreferences.pm,v 1.196.4.16 2015/03/12 02:58:33 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,8 +25,6 @@
#
# http://www.lon-capa.org/
#
-# 2/13/02 2/14 2/15 Matthew Hall
-#
# This package uses the "londes.js" javascript code.
#
# TODOs that have to be completed:
@@ -35,57 +33,15 @@
package Apache::lonpreferences;
use strict;
+use LONCAPA;
use Apache::Constants qw(:common);
use Apache::File;
-use Crypt::DES;
-use DynaLoader; # for Crypt::DES version
use Apache::loncommon();
use Apache::lonhtmlcommon();
use Apache::lonlocal;
-
-#
-# Write lonnet::passwd to do the call below.
-# Use:
-# my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
-#
-##################################################
-# password associated functions #
-##################################################
-sub des_keys {
- # Make a new key for DES encryption.
- # Each key has two parts which are returned separately.
- # Please note: Each key must be passed through the &hex function
- # before it is output to the web browser. The hex versions cannot
- # be used to decrypt.
- my @hexstr=('0','1','2','3','4','5','6','7',
- '8','9','a','b','c','d','e','f');
- my $lkey='';
- for (0..7) {
- $lkey.=$hexstr[rand(15)];
- }
- my $ukey='';
- for (0..7) {
- $ukey.=$hexstr[rand(15)];
- }
- return ($lkey,$ukey);
-}
-
-sub des_decrypt {
- my ($key,$cyphertext) = @_;
- my $keybin=pack("H16",$key);
- my $cypher;
- if ($Crypt::DES::VERSION>=2.03) {
- $cypher=new Crypt::DES $keybin;
- } else {
- $cypher=new DES $keybin;
- }
- my $plaintext=
- $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
- $plaintext.=
- $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
- $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
- return $plaintext;
-}
+use Apache::lonnet;
+use LONCAPA::lonauthcgi();
+use LONCAPA();
################################################################
# Handler subroutines #
@@ -94,205 +50,1091 @@ sub des_decrypt {
################################################################
# Language Change Subroutines #
################################################################
-sub languagechanger {
+
+sub wysiwygchanger {
my $r = shift;
- my $user = $ENV{'user.name'};
- my $domain = $ENV{'user.domain'};
- my %userenv = &Apache::lonnet::get
- ('environment',['languages']);
- my $language=$userenv{'languages'};
+ Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changewysiwyg',
+ text => 'Change WYSIWYG Preferences'});
+ $r->print(Apache::loncommon::start_page('Content Display Settings'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Change WYSIWYG Preferences'));
- my $pref=&mt('Preferred language');
- my %langchoices=('' => 'No language preference');
- foreach (&Apache::loncommon::languageids()) {
- if (&Apache::loncommon::supportedlanguagecode($_)) {
- $langchoices{&Apache::loncommon::supportedlanguagecode($_)}
- = &Apache::loncommon::plainlanguagedescription($_);
- }
+ my %userenv = &Apache::lonnet::get
+ ('environment',['wysiwygeditor']);
+ my $onselect='checked="checked"';
+ my $offselect='';
+ if ($userenv{'wysiwygeditor'} eq 'on') {
+ $onselect='';
+ $offselect='checked="checked"';
+ }
+ my $switchoff=&mt('Disable WYSIWYG editor');
+ my $switchon=&mt('Enable WYSIWYG editor');
+ my $warning='';
+ if ($env{'user.adv'}) {
+ $warning.='
'.&mt("The WYSIWYG editor only supports simple HTML and is in many cases unsuited for advanced authoring. In a number of cases, it may destroy advanced authoring involving LaTeX and script function calls.")."
";
}
- my $selectionbox=&Apache::loncommon::select_form($language,'language',
- %langchoices);
$r->print(<
-
- $pref: $selectionbox
+'
+ );
}
sub verify_and_change_languages {
my $r = shift;
- my $user = $ENV{'user.name'};
- my $domain = $ENV{'user.domain'};
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
# Screenname
- my $newlanguage = $ENV{'form.language'};
+ my $newlanguage = $env{'form.language'};
$newlanguage=~s/[^\-\w]//g;
my $message='';
if ($newlanguage) {
&Apache::lonnet::put('environment',{'languages' => $newlanguage});
- &Apache::lonnet::appenv('environment.languages' => $newlanguage);
- $message='Set new preferred languages to '.$newlanguage;
+ &Apache::lonnet::appenv({'environment.languages' => $newlanguage});
+ $message=&Apache::lonhtmlcommon::confirm_success(
+ &mt('Set [_1] to [_2]',
+ ''.&mt('Preferred language').'',
+ '"'.$newlanguage.'".'))
+ .' '
+ .&mt('The change will become active on the next page.');
} else {
&Apache::lonnet::del('environment',['languages']);
- &Apache::lonnet::delenv('environment\.languages');
- $message='Reset preferred language';
+ &Apache::lonnet::delenv('environment.languages');
+ $message=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]',''.&mt('Preferred language').''));
}
- $r->print(< '/adm/preferences?action=changetexenginepref',
+ text => 'Math display settings'});
+ $r->print(Apache::loncommon::start_page('Content Display Settings'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Math display settings'));
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my %userenv = &Apache::lonnet::get('environment',['texengine']);
+ my $texengine=$userenv{'texengine'};
+
+ my %mathchoices=('' => 'Default',
+ 'tth' => 'tth (TeX to HTML)',
+ #'ttm' => 'TeX to MathML',
+ 'jsMath' => 'jsMath',
+ 'MathJax' => 'MathJax',
+ 'mimetex' => 'mimetex (Convert to Images)',
+ 'raw' => 'Raw (Screen Reader)'
+ );
+ %mathchoices = &Apache::lonlocal::texthash(%mathchoices);
+ my $selectionbox=
+ &Apache::loncommon::select_form(
+ $texengine,
+ 'texengine',
+ \%mathchoices);
+ my $MathJax_start=&Apache::lontexconvert::MathJax_header();
+ my $jsMath_start=&Apache::lontexconvert::jsMath_header();
+ my %lt=&Apache::lonlocal::texthash(
+ 'headline' => 'Change how math is displayed',
+ 'preftxt' => 'Preferred method to display math',
+ 'change' => 'Save',
+ 'exmpl' => 'Examples',
+ 'mathjax' => 'MathJax:',
+ 'mathjaxinfo' => 'MathJax provides rendered equations whose source code can be extracted in TeX and MathML formats by right clicking the equation.',
+ 'jsmath' => 'jsMath:',
+ 'tth' => 'tth (TeX to HTML):',
+ 'mimetex' => 'mimetex (Convert to Images):',
+ );
+
+ my $jsMathWarning='
'
+ .'
'
+ .&mt("It looks like you don't have the TeX math fonts installed.")
+ .'
'
+ .'
'
+ .&mt('The jsMath example on this page may not look right without them. '
+ .'The [_1]jsMath Home Page[_2] has information on how to download the '
+ .'needed fonts. In the meantime, jsMath will do the best it can '
+ .'with the fonts you have, but it may not be pretty and some equations '
+ .'may not be rendered correctly.'
+ ,''
+ ,'')
+ .'
'.
+ &Apache::loncommon::end_data_table_row()."\n";
}
+ my $end_data_table = &Apache::loncommon::end_data_table();
my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
- $r->print(<
-
- function pclose() {
- parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
- "height=350,width=350,scrollbars=no,menubar=no");
- parmwin.close();
- }
-
- $pjump_def
-
- function psub() {
- pclose();
- if (document.parmform.pres_marker.value!='') {
- if (document.parmform.pres_type.value!='') {
- eval('document.server.'+
- document.parmform.pres_marker.value+
- '.value=document.parmform.pres_value.value;');
- }
- } else {
- document.parmform.pres_value.value='';
- document.parmform.pres_marker.value='';
- }
- }
+ my $savebutton = &mt('Save');
+ my $resetbutton = &mt('Reset All');
+ my $resetbuttondesc = &mt('Reset All Colors to Default');
+ my $colorchooser=&Apache::lonhtmlcommon::color_picker();
+ $r->print('
+');
+ $r->print(<
-
-
ENDCOL
}
@@ -378,69 +1206,122 @@ ENDCOL
sub verify_and_change_colors {
my $r = shift;
# figure out colors
- my $function='student';
- if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) {
- $function='coordinator';
- }
- if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) {
- $function='admin';
- }
- if (($ENV{'request.role'}=~/^(au|ca)/) ||
- ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
- $function='author';
- }
+ my $function=&Apache::loncommon::get_users_function();
my $domain=&Apache::loncommon::determinedomain();
- my %colortypes=('pgbg' => 'Page Background',
- 'tabbg' => 'Header Background',
- 'sidebg'=> 'Header Border',
- 'font' => 'Font',
- 'link' => 'Un-Visited Link',
- 'vlink' => 'Visited Link',
- 'alink' => 'Active Link');
+ my %colortypes=&Apache::lonlocal::texthash(
+ 'pgbg' => 'Page Background Color',
+ 'tabbg' => 'Header Background Color',
+ 'sidebg' => 'Header Border Color',
+ 'font' => 'Font Color',
+ 'fontmenu' => 'Font Menu Color',
+ 'link' => 'Un-Visited Link Color',
+ 'vlink' => 'Visited Link Color',
+ 'alink' => 'Active Link Color',
+ );
my $message='';
- foreach my $item (keys %colortypes) {
- my $color=$ENV{'form.'.$item};
+ foreach my $item (keys(%colortypes)) {
+ my $color=$env{'form.'.$item};
+ if (!($color =~ /^#/)) {
+ $color = '#' . $color;
+ }
my $entry='color.'.$function.'.'.$item;
- if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$ENV{'form.resetall'})) {
+ if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) {
&Apache::lonnet::put('environment',{$entry => $color});
- &Apache::lonnet::appenv('environment.'.$entry => $color);
- $message.='Set '.$colortypes{$item}.' to '.$color.' ';
+ &Apache::lonnet::appenv({'environment.'.$entry => $color});
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]',''.$colortypes{$item}.'','"'.$color.'"'))
+ .' ';
} else {
&Apache::lonnet::del('environment',[$entry]);
- &Apache::lonnet::delenv('environment\.'.$entry);
- $message.='Reset '.$colortypes{$item}.' ';
+ &Apache::lonnet::delenv('environment.'.$entry);
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]',''.$colortypes{$item}.''))
+ .' ';
}
}
- $r->print(<
-$message
-
-ENDVCCOL
+ $message=&Apache::loncommon::confirmwrapper($message);
+
+ my $now = time;
+ &Apache::lonnet::put('environment',{'color.timestamp' => $now});
+ &Apache::lonnet::appenv({'environment.color.timestamp' => $now});
+
+ &print_main_menu($r, $message);
}
######################################################
# 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);
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changepass',
+ text => 'Change Password'});
+ unless ($caller eq 'reset_by_email') {
+ $r->print(Apache::loncommon::start_page('Personal Data'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Password'));
+ }
+ 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') {
+ 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 [_1]new request[_2] 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.'
+ ,'','')
+ .'
",
+ $caller,$mailtoken);
+ return 1;
+ }
+ } else {
+ $user = $env{'user.name'};
+ $domain = $env{'user.domain'};
+ $homeserver = $env{'user.home'};
+ }
my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
# Check for authentication types that allow changing of the password.
- return if ($currentauth !~ /^(unix|internal):/);
- #
- $r->print(<
-
-LON-CAPA Preferences: Change password for $user
-
-ENDHEADER
+ if ($currentauth !~ /^(unix|internal):/) {
+ if ($caller eq 'reset_by_email') {
+ &passwordchanger($r,"
\n".
+ &mt("Authentication type for this user can not be changed by this mechanism").
+ "\n
",
+ $caller,$mailtoken);
+ return 1;
+ } else {
+ return;
+ }
+ }
#
- my $currentpass = $ENV{'form.currentpass'};
- my $newpass1 = $ENV{'form.newpass_1'};
- my $newpass2 = $ENV{'form.newpass_2'};
- my $logtoken = $ENV{'form.logtoken'};
+ my $currentpass = $env{'form.currentpass'};
+ my $newpass1 = $env{'form.newpass_1'};
+ my $newpass2 = $env{'form.newpass_2'};
+ my $logtoken = $env{'form.logtoken'};
# Check for empty data
unless (defined($currentpass) &&
defined($newpass1) &&
defined($newpass2) ){
- &passwordchanger($r,"
\nERROR".
- "Password data was blank.\n
");
+ &passwordchanger($r,"
\n".
+ &mt("One or more password fields were blank").
+ "\n
",$caller,$mailtoken);
return;
}
# Get the keys
@@ -562,34 +1545,55 @@ ENDHEADER
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.');
+ }
+ my $unable=&mt("Unable to retrieve saved token for password decryption");
$r->print(<
-ERROR: Unable to retrieve stored token for
-password decryption. Please log out and try again.
+$unable. $tryagain_text
ENDERROR
# Probably should log an error here
- return;
+ return 1;
}
my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
#
- $currentpass = &des_decrypt($ckey ,$currentpass);
- $newpass1 = &des_decrypt($n1key,$newpass1);
- $newpass2 = &des_decrypt($n2key,$newpass2);
- #
+ $currentpass = &Apache::loncommon::des_decrypt($ckey ,$currentpass);
+ $newpass1 = &Apache::loncommon::des_decrypt($n1key,$newpass1);
+ $newpass2 = &Apache::loncommon::des_decrypt($n2key,$newpass2);
+ #
+ if ($caller eq 'reset_by_email') {
+ my %data = &Apache::lonnet::tmpget($mailtoken);
+ if (keys(%data) == 0) {
+ &passwordchanger($r,
+ ''.
+ &mt('Could not verify current authentication.').' '.
+ &mt('Please try again.').'',$caller,$mailtoken);
+ return 1;
+ }
+ if ($currentpass ne $data{'temppasswd'}) {
+ &passwordchanger($r,
+ ''.
+ &mt('Could not verify current authentication.').' '.
+ &mt('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.');
- return;
+ ''.
+ &mt('The new passwords you entered do not match.').' '.
+ &mt('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.');
- return;
+ ''.
+ &mt('Passwords must be a minimum of 7 characters long.').' '.
+ &mt('Please try again.').'',$caller,$mailtoken);
+ return 1;
}
#
# Check for bad characters
@@ -599,35 +1603,558 @@ 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
+ my $errormessage =''.
+ &mt('The password you entered contained illegal characters.').' '.
+ &mt('Valid characters are').(<<"ENDERROR");
+: space and
+
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
+ my $message;
if ($result =~ /^ok$/) {
- $r->print(<<"ENDTEXT");
-
The password for $user was successfully changed
-ENDTEXT
+ $message = &Apache::lonhtmlcommon::confirm_success(&mt('The password for user [_1] was successfully changed.',''.$user.''));
+ $message = &Apache::loncommon::confirmwrapper($message);
+ if ($caller eq 'reset_by_email') {
+ $r->print($message.' ');
+ } else {
+ &print_main_menu($r, $message);
+ }
} else {
# error error: run in circles, scream and shout
- $r->print(<The password for $user was not changed
-Please make sure your old password was entered correctly.
-ENDERROR
+ if ($caller eq 'reset_by_email') {
+ if (!$result) {
+ return 1;
+ } else {
+ return $result;
+ }
+ } else {
+ $message = &Apache::lonhtmlcommon::confirm_success(
+ &mt("The password for user [_1] was not changed.",''.$user.'').' '.&mt('Please make sure your old password was entered correctly.'),1);
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &print_main_menu($r, $message);
+ }
}
return;
}
+################################################################
+# discussion display subroutines
+################################################################
+sub discussionchanger {
+ my $r = shift;
+ Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changediscussions',
+ text => 'Change Discussion Preferences'});
+ $r->print(Apache::loncommon::start_page('Change Discussion Preferences'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Discussion Preferences'));
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my %userenv = &Apache::lonnet::get
+ ('environment',['discdisplay','discmarkread']);
+ my $discdisp = 'allposts';
+ my $discmark = 'onmark';
+
+ if (defined($userenv{'discdisplay'})) {
+ unless ($userenv{'discdisplay'} eq '') {
+ $discdisp = $userenv{'discdisplay'};
+ }
+ }
+ if (defined($userenv{'discmarkread'})) {
+ unless ($userenv{'discmarkread'} eq '') {
+ $discmark = $userenv{'discmarkread'};
+ }
+ }
+
+ my $newdisp = 'unread';
+ my $newmark = 'ondisp';
+
+ my $function = &Apache::loncommon::get_users_function();
+ my $color = &Apache::loncommon::designparm($function.'.tabbg',
+ $env{'user.domain'});
+ my %lt = &Apache::lonlocal::texthash(
+ 'pref' => 'Display Preference',
+ 'curr' => 'Current setting ',
+ 'actn' => 'Action',
+ 'sdpf' => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.',
+ 'prca' => 'Preferences can be set that determine',
+ 'whpo' => 'Which posts are displayed when you display a discussion board or resource, and',
+ 'unwh' => 'Under what circumstances posts are identified as "NEW"',
+ 'allposts' => 'All posts',
+ 'unread' => 'New posts only',
+ 'ondisp' => 'Once displayed',
+ 'onmark' => 'Once marked not NEW',
+ 'disa' => 'Posts displayed?',
+ 'npmr' => 'New posts cease to be identified as "NEW"?',
+ 'thde' => 'The preferences you set here can be overridden within each individual discussion.',
+ 'chgt' => 'Change to '
+ );
+ my $dispchange = $lt{'unread'};
+ my $markchange = $lt{'ondisp'};
+ my $currdisp = $lt{'allposts'};
+ my $currmark = $lt{'onmark'};
+
+ if ($discdisp eq 'unread') {
+ $dispchange = $lt{'allposts'};
+ $currdisp = $lt{'unread'};
+ $newdisp = 'allposts';
+ }
+
+ if ($discmark eq 'ondisp') {
+ $markchange = $lt{'onmark'};
+ $currmark = $lt{'ondisp'};
+ $newmark = 'onmark';
+ }
+
+ $r->print(<<"END");
+'
+ );
+}
+
+sub verify_and_change_discussion {
+ my $r = shift;
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my $message='';
+ if (defined($env{'form.discdisp'}) ) {
+ my $newdisp = $env{'form.newdisp'};
+ if ($newdisp eq 'unread') {
+ $message .=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: only new posts will be displayed.')).' ';
+ &Apache::lonnet::put('environment',{'discdisplay' => $newdisp});
+ &Apache::lonnet::appenv({'environment.discdisplay' => $newdisp});
+ } else {
+ $message .= &Apache::lonhtmlcommon::confirm_success(&mt('In discussions: all posts will be displayed.')).' ';
+ &Apache::lonnet::del('environment',['discdisplay']);
+ &Apache::lonnet::delenv('environment.discdisplay');
+ }
+ }
+ if (defined($env{'form.discmark'}) ) {
+ my $newmark = $env{'form.newmark'};
+ if ($newmark eq 'ondisp') {
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: new posts will cease to be identified as "NEW" after display.')).' ';
+ &Apache::lonnet::put('environment',{'discmarkread' => $newmark});
+ &Apache::lonnet::appenv({'environment.discmarkread' => $newmark});
+ } else {
+ $message.=&Apache::lonhtmlcommon::confirm_success(&mt('In discussions: posts will be identified as "NEW" until marked as not "NEW".')).' ';
+ &Apache::lonnet::del('environment',['discmarkread']);
+ &Apache::lonnet::delenv('environment.discmarkread');
+ }
+ }
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &print_main_menu($r, $message);
+}
+
+################################################################
+# Subroutines for page display on course access (Course Coordinators)
+################################################################
+sub coursedisplaychanger {
+ my $r = shift;
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changecourseinit',
+ text => 'Change Course Init. Pref.'});
+ $r->print(Apache::loncommon::start_page('Change Course Initialization Preference'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Course Init. Pref.'));
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my %userenv = &Apache::lonnet::get('environment',['course_init_display']);
+ my $currvalue = 'whatsnew';
+ my $firstselect = '';
+ my $whatsnewselect = 'checked="checked"';
+ if (exists($userenv{'course_init_display'})) {
+ if ($userenv{'course_init_display'} eq 'firstres') {
+ $currvalue = 'firstres';
+ $firstselect = 'checked="checked"';
+ $whatsnewselect = '';
+ }
+ }
+ my %pagenames = &Apache::lonlocal::texthash(
+ firstres => 'First resource',
+ whatsnew => "What's New Page",
+ );
+ my $whatsnew_off=&mt('Display the [_1]first resource[_2] in the course.','','');
+ my $whatsnew_on=&mt("Display the [_1]What's New Page[_2] - a summary of items in the course which require attention.",'','');
+
+ $r->print(' '
+ .&mt('Set the default page to be displayed when you select a course role')
+ .' '
+ .&mt('(Currently: [_1])',$pagenames{$currvalue})
+ .' '
+ .&mt("The global user preference you set for your courses can be overridden in an individual course by setting a course specific setting via the [_1]What's New Page[_2] in the course.",'','')
+ .'
+');
+}
+
+sub verify_and_change_coursepage {
+ my $r = shift;
+ my $message='';
+ my %lt = &Apache::lonlocal::texthash(
+ 'defs' => 'Default now set',
+ 'when' => 'when you select a course role from the roles screen',
+ 'ywbt' => 'you will be taken to the start of the course.',
+ 'apwb' => 'a page will be displayed that lists items in the course that may require action from you.',
+ 'gtts' => 'Go to the start of the course',
+ 'dasp' => "Display the What's New Page",
+ );
+ my $newdisp = $env{'form.newdisp'};
+ $message = ''.$lt{'defs'}.': '.$lt{'when'}.', ';
+ if ($newdisp eq 'firstres') {
+ $message .= $lt{'ywbt'}.' ';
+ &Apache::lonnet::put('environment',{'course_init_display' => $newdisp});
+ &Apache::lonnet::appenv({'environment.course_init_display' => $newdisp});
+ } else {
+ $message .= $lt{'apwb'}.' ';
+ &Apache::lonnet::del('environment',['course_init_display']);
+ &Apache::lonnet::delenv('environment.course_init_display');
+ }
+ my $refpage = $env{'form.refpage'};
+ if (($env{'request.course.fn'}) && ($env{'request.course.id'})) {
+ if ($newdisp eq 'firstres') {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my ($furl,$ferr)=
+ &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
+ $message .= ' '.$lt{'gtts'}.' '.&mt('now').'';
+ } else {
+ $message .= ' '.$lt{'dasp'}.'';
+ }
+ }
+ $message = &Apache::lonhtmlcommon::confirm_success($message);
+ $message = &Apache::loncommon::confirmwrapper($message);
+ &print_main_menu($r,$message);
+}
+
+sub lockednameschanger {
+ my $r = shift;
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changelockednames',
+ text => 'Automatic name changes'});
+ $r->print(Apache::loncommon::start_page('Automatic name changes'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Allow/disallow name updates'));
+ my %userenv = &Apache::lonnet::get('environment',['lockedname']);
+ my $lockedname='';
+ if (&can_toggle_namelocking()) {
+ if ($userenv{'lockedname'}) {
+ $lockedname = ' checked="checked"';
+ }
+ my %updateable;
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['autoupdate'],$env{'user.domain'});
+ if (ref($domconfig{'autoupdate'}) eq 'HASH') {
+ if ($domconfig{'autoupdate'}{'run'}) {
+ my @inststatuses = split(':',$env{'environment.inststatus'});
+ unless (@inststatuses) {
+ @inststatuses = ('default');
+ }
+ %updateable = &updateable_userinfo($domconfig{'autoupdate'},\@inststatuses);
+ }
+ }
+ if (keys(%updateable)) {
+ my %longnames = &Apache::lonlocal::texthash (
+ firstname => 'First Name',
+ middlename => 'Middle Name',
+ lastname => 'Last Name',
+ );
+ my $text=&mt('By default, based on your institutional affiliation, your LON-CAPA account can be automatically updated nightly based on directory information from your institution.').' '.&mt('The following may be updated, unless you disallow updates:').
+ '
';
+ foreach my $item ('firstname','middlename','lastname') {
+ if ($updateable{$item}) {
+ $text .= '
'.$longnames{$item}.'
';
+ }
+ }
+ $text .= '
';
+ my $locking=&mt('Disallow automatic updates to name information for your LON-CAPA account');
+ my $change=&mt('Save');
+ $r->print(<
+
+$text
+
+
+
+ENDSCREEN
+ } else {
+ my $message = &mt('Based on your institutional affiliation no name information is automatically updated for your LON-CAPA account.');
+ &print_main_menu($r,$message);
+ }
+ } else {
+ my $message = &mt('You are not permitted to set a user preference for automatic name updates for your LON-CAPA account.');
+ &print_main_menu($r,$message);
+ }
+}
+
+sub verify_and_change_lockednames {
+ my $r = shift;
+ my $message;
+ if (&can_toggle_namelocking()) {
+ my $newlockedname = $env{'form.lockednames'};
+ $newlockedname =~ s/\D//g;
+ my $currlockedname = $env{'environment.lockedname'};
+ if ($newlockedname ne $currlockedname) {
+ if ($newlockedname) {
+ if (&Apache::lonnet::put('environment',{lockedname => $newlockedname}) eq 'ok') {
+ &Apache::lonnet::appenv({'environment.lockedname' => $newlockedname});
+ }
+ } elsif (&Apache::lonnet::del('environment',['lockedname']) eq 'ok') {
+ &Apache::lonnet::delenv('environment.lockedname');
+ }
+ }
+ my $status='';
+ if ($newlockedname) {
+ $status=&mt('disallowed');
+ } else {
+ $status=&mt('allowed');
+ }
+ $message=&Apache::lonhtmlcommon::confirm_success(&mt('[_1] set to [_2]',''.&mt('Automatic update of first, middle and last names if institutional directory information indicates changes').'',''.$status.''));
+ $message=&Apache::loncommon::confirmwrapper($message);
+ }
+ &print_main_menu($r,$message);
+}
+
+sub print_main_menu {
+ my ($r, $message) = @_;
+ # Determine current authentication method
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
+
+ # build the data structure for menu generation
+my $aboutmeurl='/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme';
+my $role = ($env{'user.adv'} ? 'Roles' : 'Course');
+my %permissions;
+if (&Apache::lonnet::usertools_access($user,$domain,'aboutme')) {
+ $permissions{'aboutme'} = 'F';
+}
+my @menu=
+ ({ categorytitle=>'Personal Data',
+ items =>[
+ { linktext => 'Personal Information Page',
+ url => $aboutmeurl,
+ permission => $permissions{'aboutme'},
+ #help => 'Prefs_About_Me',
+ icon => 'system-users.png',
+ linktitle => 'Edit information about yourself that should be displayed on your public profile.'
+ },
+ { linktext => 'Screen Name',
+ url => '/adm/preferences?action=changescreenname',
+ permission => 'F',
+ #help => 'Prefs_Screen_Name_Nickname',
+ icon => 'preferences-desktop-font.png',
+ linktitle => 'Change the name that is displayed in your posts.'
+ },
+ ]
+ },
+ { categorytitle=>'Content Display Settings',
+ items =>[
+ { linktext => 'Language',
+ url => '/adm/preferences?action=changelanguages',
+ permission => 'F',
+ #help => 'Prefs_Language',
+ icon => 'preferences-desktop-locale.png',
+ linktitle => 'Choose the default language for this user.'
+ },
+ { linktext => $role.' Page',
+ url => '/adm/preferences?action=changerolespref',
+ permission => 'F',
+ #help => '',
+ icon => 'role_hotlist.png',
+ linktitle => 'Configure the roles hotlist.'
+ },
+ { linktext => 'Math display settings',
+ url => '/adm/preferences?action=changetexenginepref',
+ permission => 'F',
+ #help => '',
+ icon => 'dismath.png',
+ linktitle => 'Change how math is displayed.'
+ },
+ ]
+ },
+ { categorytitle=>'Page Display Settings',
+ items =>[
+ { linktext => 'Color Scheme',
+ url => '/adm/preferences?action=changecolors',
+ permission => 'F',
+ #help => 'Change_Colors',
+ icon => 'preferences-desktop-theme.png',
+ linktitle => 'Change LON-CAPA default colors.'
+ },
+ { linktext => 'Menu Display',
+ url => '/adm/preferences?action=changeicons',
+ permission => 'F',
+ #help => '',
+ icon => 'preferences-system-windows.png',
+ linktitle => 'Change whether the menus are displayed with icons or icons and text.'
+ }
+ ]
+ },
+ { categorytitle=>'Messages & Notifications',
+ items =>[
+ { linktext => 'Messages & Notifications',
+ url => '/adm/preferences?action=changemsgforward',
+ permission => 'F',
+ #help => 'Prefs_Messages',
+ icon => 'mail-reply-all.png',
+ linktitle => 'Change messageforwarding or notifications settings.'
+ },
+ { linktext => 'Discussion Display',
+ url => '/adm/preferences?action=changediscussions',
+ permission => 'F',
+ #help => 'Change_Discussion_Display',
+ icon => 'chat.png',
+ linktitle => 'Set display preferences for discussion posts for both discussion boards and individual resources in all your courses.'
+ },
+ ]
+ },
+ { categorytitle=>'Other',
+ items =>[
+ { linktext => 'Register Response Devices ("Clickers")',
+ url => '/adm/preferences?action=changeclicker',
+ permission => 'F',
+ #help => '',
+ icon => 'network-workgroup.png',
+ linktitle => 'Register your clicker.'
+ },
+ ]
+ },
+ );
+
+ if ($currentauth =~ /^(unix|internal):/) {
+push(@{ $menu[0]->{items} }, {
+ linktext => 'Password',
+ url => '/adm/preferences?action=changepass',
+ permission => 'F',
+ #help => 'Change_Password',
+ icon => 'emblem-readonly.png',
+ linktitle => 'Change your password.',
+ });
+ }
+ if ($env{'environment.remote'} eq 'off') {
+push(@{ $menu[1]->{items} }, {
+ linktext => 'Launch Remote Control',
+ url => '/adm/remote?url=/adm/preferences&action=launch',
+ permission => 'F',
+ #help => '',
+ icon => 'remotecontrol.png',
+ linktitle => 'Launch the remote control for LON-CAPA.',
+ });
+ }else{
+push(@{ $menu[1]->{items} }, {
+ linktext => 'Collapse Remote Control',
+ url => '/adm/remote?url=/adm/preferences&action=collapse',
+ permission => 'F',
+ #help => '',
+ icon => 'remotecontrol.png',
+ linktitle => 'Collapse the remote control for LON-CAPA.',
+ });
+ }
+
+ if (&can_toggle_namelocking()) {
+ push(@{ $menu[0]->{items} }, {
+ linktext => 'Automatic name changes',
+ url => '/adm/preferences?action=changelockednames',
+ permission => 'F',
+ #help => '',
+ icon => 'system-lock-screen.png',
+ linktitle => 'Allow/disallow propagation of name changes from institutional directory service',
+ });
+ }
+
+ my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au']);
+ if (keys(%author_roles) > 0) {
+push(@{ $menu[4]->{items} }, {
+ linktext => 'Restrict Domain Coordinator Access',
+ url => '/adm/preferences?action=changedomcoord',
+ permission => 'F',
+ #help => '',
+ icon => 'system-lock-screen.png',
+ linktitle => 'Restrict domain coordinator access.',
+ });
+ }
+
+ if (&Apache::lonnet::allowed('whn',$env{'request.course.id'})
+ || &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/'
+ .$env{'request.course.sec'})) {
+push(@{ $menu[4]->{items} }, {
+ linktext => 'Course Initialization',
+ url => '/adm/preferences?action=changecourseinit',
+ permission => 'F',
+ #help => '',
+ icon => 'course_ini.png',
+ linktitle => 'Set the default page to be displayed when you select a course role.',
+ });
+
+ }
+ if (&can_toggle_debug()) {
+push(@{ $menu[4]->{items} }, {
+ linktext => 'Toggle Debug Messages (Currently '.($env{'user.debug'} ? 'on)' : 'off)'),
+ url => '/adm/preferences?action=debugtoggle',
+ permission => 'F',
+ #help => '',
+ icon => 'blog.png',
+ linktitle => 'Toggle Debug Messages.',
+ });
+ }
+
+ $r->print(&Apache::loncommon::start_page('My Space'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Preferences'));
+ $r->print($message);
+ $r->print(Apache::lonhtmlcommon::generate_menu(@menu));
+ $r->print(Apache::loncommon::end_page());
+}
+
######################################################
# other handler subroutines #
######################################################
@@ -635,199 +2162,175 @@ ENDERROR
################################################################
# Main handler #
################################################################
-sub handler {
+sub handler {
my $r = shift;
- my $user = $ENV{'user.name'};
- my $domain = $ENV{'user.domain'};
- &Apache::loncommon::content_type($r,'text/html');
+ Apache::loncommon::content_type($r,'text/html');
# Some pages contain DES keys and should not be cached.
- &Apache::loncommon::no_cache($r);
+ Apache::loncommon::no_cache($r);
$r->send_http_header;
return OK if $r->header_only;
#
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['action']);
+ Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['action','wysiwyg','returnurl','refpage']);
#
- &Apache::lonhtmlcommon::clear_breadcrumbs();
- &Apache::lonhtmlcommon::add_breadcrumb
- ({href => '/adm/preferences',
- text => 'Set User Preferences'});
-
- my @Options;
- # Determine current authentication method
- my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain);
- if ($currentauth =~ /^(unix|internal):/) {
- push (@Options,({ action => 'changepass',
- linktext => 'Change password',
- href => '/adm/preferences',
- help => 'Change_Password',
- subroutine => \&passwordchanger,
- breadcrumb =>
- { href => '/adm/preferences?action=changepass',
- text => 'Change Password'},
- },
- { action => 'verify_and_change_pass',
- subroutine => \&verify_and_change_password,
- breadcrumb =>
- { href =>'/adm/preferences?action=changepass',
- text => 'Change Password'},
- printmenu => 'yes',
- }));
- }
- push (@Options,({ action => 'changescreenname',
- linktext => 'Change Screen Name',
- href => '/adm/preferences',
- help => 'Prefs_Screen_Name_Nickname',
- subroutine => \&screennamechanger,
- breadcrumb =>
- { href => '/adm/preferences?action=changescreenname',
- text => 'Change Screen Name'},
- },
- { action => 'verify_and_change_screenname',
- subroutine => \&verify_and_change_screenname,
- breadcrumb =>
- { href => '/adm/preferences?action=changescreenname',
- text => 'Change Screen Name'},
- printmenu => 'yes',
- }));
-
- push (@Options,({ action => 'changemsgforward',
- linktext => 'Change Message Forwarding',
- text => 'and Notification Addresses',
- href => '/adm/preferences',
- help => 'Prefs_Forwarding',
- breadcrumb =>
- { href => '/adm/preferences?action=changemsgforward',
- text => 'Change Message Forwarding'},
- subroutine => \&msgforwardchanger,
- },
- { action => 'verify_and_change_msgforward',
- breadcrumb =>
- { href => '/adm/preferences?action=changemsgforward',
- text => 'Change Message Forwarding'},
- printmenu => 'yes',
- subroutine => \&verify_and_change_msgforward }));
- my $aboutmeaction=
- '/adm/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/aboutme';
- push (@Options,{ action => 'none',
- linktext =>
- q{Edit the 'About Me' personal information screen},
- href => $aboutmeaction});
- push (@Options,({ action => 'changecolors',
- linktext => 'Change Color Scheme',
- href => '/adm/preferences',
- help => 'Change_Colors',
- breadcrumb =>
- { href => '/adm/preferences?action=changecolors',
- text => 'Change Colors'},
- subroutine => \&colorschanger,
- },
- { action => 'verify_and_change_colors',
- breadcrumb =>
- { href => '/adm/preferences?action=changecolors',
- text => 'Change Colors'},
- printmenu => 'yes',
- subroutine => \&verify_and_change_colors,
- }));
- push (@Options,({ action => 'changelanguages',
- linktext => 'Change Language Preferences',
- href => '/adm/preferences',
- breadcrumb=>
- { href => '/adm/preferences?action=changelanguages',
- text => 'Change Language'},
- subroutine => \&languagechanger,
- },
- { action => 'verify_and_change_languages',
- breadcrumb=>
- {href => '/adm/preferences?action=changelanguages',
- text => 'Change Language'},
- printmenu => 'yes',
- subroutine=>\&verify_and_change_languages, }
- ));
- if ($ENV{'user.name'} =~ /^(albertel|koretemey|korte|hallmat3|turtle)$/) {
- push (@Options,({ action => 'debugtoggle',
- printmenu => 'yes',
- subroutine => \&toggle_debug,
- }));
- }
- $r->print(<
-
-LON-CAPA Preferences
-
-ENDHEADER
- my $call = undef;
- my $printmenu = 'yes';
- foreach my $option (@Options) {
- if ($option->{'action'} eq $ENV{'form.action'}) {
- $call = $option->{'subroutine'};
- $printmenu = $option->{'printmenu'};
- if (exists($option->{'breadcrumb'})) {
- &Apache::lonhtmlcommon::add_breadcrumb
- ($option->{'breadcrumb'});
- }
- }
- }
- $r->print(&Apache::loncommon::bodytag('Change Preferences'));
- $r->print(&Apache::lonhtmlcommon::breadcrumbs
- (undef,'Change Preferences'));
- if (defined($call)) {
- $call->($r);
- }
- if ($printmenu eq 'yes') {
- my $optionlist = '
';
- if ($ENV{'user.name'} =~
- /^(albertel|kortemey|korte|hallmat3|turtle)$/
- ) {
- push (@Options,({ action => 'debugtoggle',
- linktext => 'Toggle Debug Messages',
- text => 'Current Debug status is -'.
- $ENV{'user.debug'}.'-.',
- href => '/adm/preferences',
- printmenu => 'yes',
- subroutine => \&toggle_debug,
- }));
- }
- foreach my $option(@Options) {
- my $optiontext = '';
- if (exists($option->{'href'})) {
- $optiontext .=
- ''.
- $option->{'linktext'}.'';
- }
- if (exists($option->{'text'})) {
- $optiontext .= ' '.$option->{'text'};
- }
- if ($optiontext ne '') {
- $optiontext = ''.$optiontext.'';
- my $helplink = ' ';
- if (exists($option->{'help'})) {
- $helplink = &Apache::loncommon::help_open_topic
- ($option->{'help'});
- }
- $optionlist .= '