--- loncom/interface/lonpreferences.pm 2024/03/01 21:28:39 1.196.4.28.2.4
+++ 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.28.2.4 2024/03/01 21:28:39 raeburn Exp $
+# $Id: lonpreferences.pm,v 1.208 2013/07/22 18:06:51 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,19 +27,67 @@
#
# This package uses the "londes.js" javascript code.
#
+# TODOs that have to be completed:
+# interface with lonnet to change the password
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;
use Apache::lonnet;
use LONCAPA::lonauthcgi();
use LONCAPA();
-use DateTime::TimeZone();
+
+#
+# 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 $message;
- if (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');
- }
- $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]',''.&mt('Deactivate CodeMirror in Authoring Space').'',''.$status.''));
- $message=&Apache::loncommon::confirmwrapper($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:').'