--- loncom/interface/lonpreferences.pm 2002/03/30 23:27:00 1.6
+++ loncom/interface/lonpreferences.pm 2019/08/22 00:00:03 1.196.4.25
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Preferences
#
-# $Id: lonpreferences.pm,v 1.6 2002/03/30 23:27:00 www Exp $
+# $Id: lonpreferences.pm,v 1.196.4.25 2019/08/22 00:00:03 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,159 +25,1284 @@
#
# http://www.lon-capa.org/
#
-# (Internal Server Error Handler
-#
-# (Login Screen
-# 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
-# 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
-#
-# 3/1/1 Gerd Kortemeyer)
-#
-# 3/1 Gerd Kortemeyer
-#
-# 2/13/02 2/14 2/15 Matthew Hall
-#
# 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();
-#
-# 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 seperately.
- # 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 #
+################################################################
+
+################################################################
+# Language Change Subroutines #
+################################################################
+
+sub wysiwygchanger {
+ my $r = shift;
+ 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 %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.")."
";
+ }
+ $r->print(<
+
+$warning
+
+
+
+ENDLSCREEN
+ $r->print(' ');
+}
+
+
+sub verify_and_change_wysiwyg {
+ my $r = shift;
+ my $newsetting=$env{'form.wysiwyg'};
+ &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting});
+ &Apache::lonnet::appenv({'environment.wysiwygeditor' => $newsetting});
+ my $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]',''.&mt('WYSIWYG Editor').'',''.&mt($newsetting).''));
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &print_main_menu($r,$message);
}
################################################################
-# Handler subroutines #
+# Language Change Subroutines #
+################################################################
+sub languagechanger {
+ my $r = shift;
+
+ Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changelanguages',
+ text => 'Change Language'});
+ $r->print(Apache::loncommon::start_page('Content Display Settings'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Language'));
+ my %userenv = &Apache::lonnet::get('environment',['languages']);
+ my $language=$userenv{'languages'};
+
+ $r->print(
+ ''
+ );
+}
+
+
+sub verify_and_change_languages {
+ my $r = shift;
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+# Screenname
+ 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=&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=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]',''.&mt('Preferred language').''));
+ }
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &Apache::loncommon::flush_langs_cache($user,$domain);
+ &print_main_menu($r, $message);
+}
+
+################################################################
+# Tex Engine Change Subroutines #
+################################################################
+sub texenginechanger {
+ my $r = shift;
+ Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/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'};
+ if (lc($texengine) eq 'jsmath') {
+ $texengine = 'MathJax';
+ }
+
+ my %mathchoices=('' => 'Default',
+ 'tth' => 'tth (TeX to HTML)',
+ #'ttm' => 'TeX to MathML',
+ '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 %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.',
+ 'tth' => 'tth (TeX to HTML):',
+ 'mimetex' => 'mimetex (Convert to Images):',
+ );
+
+ $r->print(<$lt{'headline'}
+
+
+
+$lt{'exmpl'}
+
+
$lt{'mathjax'}
+
+
+
+
+$lt{'mathjaxinfo'}
+
+
+
$lt{'mimetex'}
+
+
+
+
+
$lt{'tth'}
+
+
+
+ENDLSCREEN
+}
+
+
+sub verify_and_change_texengine {
+ my $r = shift;
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+# Screenname
+ my $newtexengine = $env{'form.texengine'};
+ $newtexengine=~s/[^\-\w]//g;
+ if (lc($newtexengine) eq 'jsmath') {
+ $newtexengine = 'MathJax';
+ }
+ if ($newtexengine eq 'ttm') {
+ &Apache::lonnet::appenv({'browser.mathml' => 1});
+ } else {
+ if ($env{'environment.texengine'} eq 'ttm') {
+ &Apache::lonnet::appenv({'browser.mathml' => 0});
+ }
+ }
+ my $message='';
+ if ($newtexengine) {
+ &Apache::lonnet::put('environment',{'texengine' => $newtexengine});
+ &Apache::lonnet::appenv({'environment.texengine' => $newtexengine});
+ $message=&Apache::lonhtmlcommon::confirm_success(&mt('Set [_1] to [_2]',''.&mt('Preferred method to display Math').'','"'.$newtexengine.'"'));
+ } else {
+ &Apache::lonnet::del('environment',['texengine']);
+ &Apache::lonnet::delenv('environment.texengine');
+ $message=&Apache::lonhtmlcommon::confirm_success(&mt('Reset [_1]',''.&mt('Preferred method to display Math').''));
+ }
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &print_main_menu($r, $message);
+}
+
+################################################################
+# Roles Page Preference Change Subroutines #
+################################################################
+sub rolesprefchanger {
+ my $r = shift;
+ my $role = ($env{'user.adv'} ? 'Role' : 'Course');
+ my $lc_role = ($env{'user.adv'} ? 'role' : 'course');
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my %userenv = &Apache::lonnet::get
+ ('environment',['recentroles','recentrolesn']);
+ my $brtext = 'Change '.$role.' Page Pref';
+ my $brtitle;
+ if ($env{'form.returnurl'} eq '/adm/roles') {
+ $brtext = 'Configure Hotlist';
+ } else {
+ $brtitle = $brtext;
+ }
+ Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=changerolespref',
+ text => $brtext});
+ $r->print(Apache::loncommon::start_page('Content Display Settings'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs($brtitle));
+ my $hotlist_flag=$userenv{'recentroles'};
+ my $hotlist_n=$userenv{'recentrolesn'};
+ my ($checkedon,$checkedoff);
+ if ($hotlist_flag) {
+ $checkedon = 'checked="checked"';
+ } else {
+ $checkedoff = 'checked="checked"';
+ }
+
+ if (!$hotlist_n) { $hotlist_n=3; }
+ my $options;
+ for (my $i=1; $i<10; $i++) {
+ my $select;
+ if ($hotlist_n == $i) { $select = 'selected="selected"'; }
+ $options .= "\n";
+ }
+
+# Get list of recent roles and display with checkbox in front
+ my $roles_check_list = '';
+ my $role_key='';
+ if ($env{'environment.recentroles'}) {
+ 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)]);
+ my @sorted_roles = sort {$role_text{$a} cmp $role_text{$b}} keys(%role_text);
+
+ $roles_check_list .=
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ "