--- loncom/interface/lonpreferences.pm 2024/07/04 23:13:07 1.196.4.29
+++ loncom/interface/lonpreferences.pm 2013/07/22 18:06:51 1.208
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Preferences
#
-# $Id: lonpreferences.pm,v 1.196.4.29 2024/07/04 23:13:07 raeburn Exp $
+# $Id: lonpreferences.pm,v 1.208 2013/07/22 18:06:51 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,6 +27,8 @@
#
# This package uses the "londes.js" javascript code.
#
+# TODOs that have to be completed:
+# interface with lonnet to change the password
package Apache::lonpreferences;
@@ -34,6 +36,8 @@ 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;
@@ -41,6 +45,50 @@ use Apache::lonnet;
use LONCAPA::lonauthcgi();
use LONCAPA();
+#
+# 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;
+}
+
################################################################
# Handler subroutines #
################################################################
@@ -158,14 +206,12 @@ sub texenginechanger {
my $domain = $env{'user.domain'};
my %userenv = &Apache::lonnet::get('environment',['texengine']);
my $texengine=$userenv{'texengine'};
- if (lc($texengine) eq 'jsmath') {
- $texengine = 'MathJax';
- }
my %mathchoices=('' => 'Default',
'tth' => 'tth (TeX to HTML)',
#'ttm' => 'TeX to MathML',
- 'MathJax' => 'MathJax',
+ 'jsMath' => 'jsMath',
+ 'MathJax' => 'MathJax',
'mimetex' => 'mimetex (Convert to Images)',
'raw' => 'Raw (Screen Reader)'
);
@@ -176,17 +222,33 @@ sub texenginechanger {
'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.'
+ ,''
+ ,'')
+ .'
'
+ .'';
+
$r->print(<$lt{'headline'}
-ENDSCREEN
- }
-}
-
-sub change_authoring_settings {
- my $r = shift;
- my $user = $env{'user.name'};
- 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 %ausettings=('environment.nocodemirror' => '');
- if ($env{'form.cmoff'}) { $ausettings{'environment.nocodemirror'}='yes'; }
- &Apache::lonnet::put('environment',\%ausettings);
- &Apache::lonnet::appenv({'environment.nocodemirror' => $ausettings{'environment.nocodemirror'}});
- my $status='';
- if ($ausettings{'environment.nocodemirror'} eq 'yes') {
- $status=&mt('on');
- } else {
- $status=&mt('off');
- }
- my $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);
- }
- }
-}
-
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='';
- my $ended;
if (&can_toggle_namelocking()) {
if ($userenv{'lockedname'}) {
$lockedname = ' checked="checked"';
@@ -2114,11 +1947,6 @@ sub lockednameschanger {
}
}
if (keys(%updateable)) {
- &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 %longnames = &Apache::lonlocal::texthash (
firstname => 'First Name',
middlename => 'Middle Name',
@@ -2145,14 +1973,11 @@ 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);
- $ended = 1;
}
} 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);
- $ended = 1;
}
- return $ended;
}
sub verify_and_change_lockednames {
@@ -2300,25 +2125,6 @@ push(@{ $menu[0]->{items} }, {
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} }, {
@@ -2356,18 +2162,6 @@ push(@{ $menu[4]->{items} }, {
});
}
-
- my %author_coauthor_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']);
- if (keys(%author_coauthor_roles) > 0) {
- push(@{ $menu[4]->{items} }, {
- linktext => 'Authoring Space Configuration',
- url => '/adm/preferences?action=authorsettings',
- permission => 'F',
- icon => 'codemirror.png',
- linktitle => 'Settings for your authoring space.',
- });
- }
-
if (&can_toggle_debug()) {
push(@{ $menu[4]->{items} }, {
linktext => 'Toggle Debug Messages (Currently '.($env{'user.debug'} ? 'on)' : 'off)'),
@@ -2405,26 +2199,14 @@ sub handler {
['action','wysiwyg','returnurl','refpage']);
#
Apache::lonhtmlcommon::clear_breadcrumbs();
- my ($brlink,$brtxt,$brhelp,$ended);
+ my ($brlink,$brtxt,$brhelp);
if (($env{'form.action'} eq 'changerolespref') && ($env{'form.returnurl'} eq '/adm/roles')) {
$brlink ='/adm/roles';
$brtxt = 'User Roles';
- } elsif ((($env{'form.action'} eq 'changedomcoord') ||
- ($env{'form.action'} eq 'authorsettings')) &&
- (($env{'form.returnurl'} =~ m{^/(priv/|res($|/))}) ||
- ($env{'form.returnurl'} eq '/adm/createuser'))) {
- $brlink = $env{'form.returnurl'};
- if ($env{'form.returnurl'} eq '/adm/createuser') {
- $brtxt = 'User Management';
- } elsif ($env{'form.returnurl'} =~ m{^/res($\/)}) {
- $brtxt = 'Browse published resources';
- } else {
- $brtxt = 'Authoring Space';
- }
} else {
$brlink ='/adm/preferences';
$brtxt = 'Set User Preferences';
- $brhelp = 'Prefs_About_Me,Prefs_Language,Prefs_Screen_Name_Nickname,Change_Colors,Change_Password,Prefs_Messages,Change_Discussion_Display';
+ $brhelp = 'Prefs_About_Me,Prefs_Language,Prefs_Screen_Name_Nickname,Change_Colors,Change_Password,Prefs_Messages,Change_Discussion_Display';
}
Apache::lonhtmlcommon::add_breadcrumb
({href => $brlink,
@@ -2432,16 +2214,14 @@ sub handler {
help => $brhelp,});
if(!exists $env{'form.action'}) {
&print_main_menu($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'changepass'){
&passwordchanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_pass'){
- &verify_and_change_password($r,'preferences','','','',\$ended);
+ &verify_and_change_password($r);
}elsif($env{'form.action'} eq 'changescreenname'){
&screennamechanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_screenname'){
&verify_and_change_screenname($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'changemsgforward'){
&msgforwardchanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_msgforward'){
@@ -2450,47 +2230,38 @@ sub handler {
&colorschanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_colors'){
&verify_and_change_colors($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'changelanguages'){
&languagechanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_languages'){
&verify_and_change_languages($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'changewysiwyg'){
&wysiwygchanger($r);
}elsif($env{'form.action'} eq 'set_wysiwyg'){
&verify_and_change_wysiwyg($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'changediscussions'){
&discussionchanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_discussion'){
&verify_and_change_discussion($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'changerolespref'){
&rolesprefchanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_rolespref'){
&verify_and_change_rolespref($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'changetexenginepref'){
&texenginechanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_texengine'){
&verify_and_change_texengine($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'changeicons'){
&iconchanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_icons'){
&verify_and_change_icons($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'changeclicker'){
&clickerchanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_clicker'){
&verify_and_change_clicker($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'changedomcoord'){
&domcoordchanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_domcoord'){
&verify_and_change_domcoord($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'lockwarning'){
&lockwarning($r);
}elsif($env{'form.action'} eq 'verify_and_change_locks'){
@@ -2499,29 +2270,22 @@ sub handler {
&coursedisplaychanger($r);
}elsif($env{'form.action'} eq 'verify_and_change_coursepage'){
&verify_and_change_coursepage($r);
- $ended = 1;
- }elsif($env{'form.action'} eq 'authorsettings'){
- &author_space_settings($r);
- }elsif($env{'form.action'} eq 'change_authoring_settings'){
- &change_authoring_settings($r);
- $ended = 1;
}elsif($env{'form.action'} eq 'debugtoggle'){
if (&can_toggle_debug()) {
&toggle_debug();
}
&print_main_menu($r);
- $ended = 1;
} elsif ($env{'form.action'} eq 'changelockednames') {
- $ended = &lockednameschanger($r);
+ &lockednameschanger($r);
} elsif ($env{'form.action'} eq 'verify_and_change_lockednames') {
&verify_and_change_lockednames($r);
- $ended = 1;
}
# Properly end the HTML page of all preference pages
# started in each sub routine
# Exception: print_main_menu has its own end_page call
- unless ($ended) {
+ unless (!exists $env{'form.action'} ||
+ $env{'form.action'} eq 'debugtoggle') {
$r->print(&Apache::loncommon::end_page());
}
@@ -2594,16 +2358,5 @@ sub updateable_userinfo {
return %updateable;
}
-sub do_redirect {
- my ($r,$url,$msg) = @_;
- $r->print(
- &Apache::loncommon::start_page('Switching Server ...',undef,
- {'redirect' => [0.5,$url]}).
- ''."\n".
- "$msg\n".
- &Apache::loncommon::end_page());
- return;
-}
-
1;
__END__