--- loncom/interface/lonpreferences.pm 2016/01/27 00:24:09 1.217
+++ loncom/interface/lonpreferences.pm 2025/03/07 02:13:40 1.248
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Preferences
#
-# $Id: lonpreferences.pm,v 1.217 2016/01/27 00:24:09 raeburn Exp $
+# $Id: lonpreferences.pm,v 1.248 2025/03/07 02:13:40 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -27,13 +27,10 @@
#
# 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 Apache::loncommon();
@@ -42,6 +39,7 @@ use Apache::lonlocal;
use Apache::lonnet;
use LONCAPA::lonauthcgi();
use LONCAPA();
+use DateTime::TimeZone();
################################################################
# Handler subroutines #
@@ -105,16 +103,17 @@ sub languagechanger {
{ href => '/adm/preferences?action=changelanguages',
text => 'Change Language'});
$r->print(Apache::loncommon::start_page('Content Display Settings'));
- $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Language'));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Change Language').
+ '
');
my %userenv = &Apache::lonnet::get('environment',['languages']);
my $language=$userenv{'languages'};
$r->print(
''
+ ' '."\n".
+ '
'
);
}
@@ -160,11 +159,13 @@ 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',
- 'jsMath' => 'jsMath',
'MathJax' => 'MathJax',
'mimetex' => 'mimetex (Convert to Images)',
'raw' => 'Raw (Screen Reader)'
@@ -176,7 +177,6 @@ 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',
@@ -184,33 +184,17 @@ sub texenginechanger {
'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.'
- ,''
- ,'')
- .'
ENDLSCREEN
- if ($env{'environment.texengine'} ne 'jsMath') {
- $r->print('');
- }
}
@@ -261,6 +230,9 @@ sub verify_and_change_texengine {
# 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 {
@@ -304,7 +276,8 @@ sub rolesprefchanger {
{ href => '/adm/preferences?action=changerolespref',
text => $brtext});
$r->print(Apache::loncommon::start_page('Content Display Settings'));
- $r->print(Apache::lonhtmlcommon::breadcrumbs($brtitle));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs($brtitle).
+ '
');
my $hotlist_flag=$userenv{'recentroles'};
my $hotlist_n=$userenv{'recentrolesn'};
my ($checkedon,$checkedoff);
@@ -323,49 +296,49 @@ sub rolesprefchanger {
}
# Get list of recent roles and display with checkbox in front
- my $roles_check_list = '';
- my $role_key='';
+ my $roles_check_list;
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().
- "
');
unless ($checkedon) {
$r->print(&mt('LON-CAPA users with several '.$lc_role.'s may wish to enable the Hotlist.').' ');
}
@@ -373,7 +346,7 @@ sub rolesprefchanger {
');
+ }
+ return;
+ }
#
# Generate keys
my ($lkey_cpass ,$ukey_cpass ) = &Apache::loncommon::des_keys();
@@ -1349,66 +1411,167 @@ sub passwordchanger {
my $jsh=Apache::File->new($include."/londes.js");
$r->print(<$jsh>);
}
- $r->print(&jscript_send($caller));
+ $r->print(&jscript_send($caller,$domain,$currentauth,$extrafields));
$r->print(<
+
ENDFORM
- $r->print(&server_form($logtoken,$caller,$mailtoken));
- $r->print(&client_form($caller,\%hexkey,$currentpass,$domain));
-
+ $r->print(&server_form($logtoken,$caller,$mailtoken,$extrafields));
+ $r->print(&client_form($caller,\%hexkey,$currentpass,$domain,$extrafields));
+ unless ($caller eq 'reset_by_email') {
+ $r->print('');
+ }
#
return;
}
sub jscript_send {
- my ($caller) = @_;
+ my ($caller,$domain,$currentauth,$extrafields) = @_;
+ my ($min,$max,$rulestr,$numrules);
+ $min = $Apache::lonnet::passwdmin;
+ my %js_lt = &Apache::lonlocal::texthash(
+ uc => 'New password needs at least one upper case letter',
+ lc => 'New password needs at least one lower case letter',
+ num => 'New password needs at least one number',
+ spec => 'New password needs at least one non-alphanumeric',
+ blank1 => 'Empty Password field',
+ blank2 => 'Empty Confirm Password field',
+ mismatch => 'Contents of Password and Confirm Password fields must match',
+ fail => 'Please fix the following:',
+ );
+ &js_escape(\%js_lt);
+ if ($currentauth eq 'internal:') {
+ if ($domain ne '') {
+ my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
+ if (keys(%passwdconf)) {
+ if ($passwdconf{min}) {
+ $min = $passwdconf{min};
+ }
+ if ($passwdconf{max}) {
+ $max = $passwdconf{max};
+ $js_lt{'long'} = &js_escape(&mt('Maximum password length: [_1]',$max));
+ }
+ if (ref($passwdconf{chars}) eq 'ARRAY') {
+ if (@{$passwdconf{chars}}) {
+ $rulestr = join('","',@{$passwdconf{chars}});
+ $numrules = scalar(@{$passwdconf{chars}});
+ }
+ }
+ }
+ }
+ }
+ $js_lt{'short'} = &js_escape(&mt('Minimum password length: [_1]',$min));
+
+ my $passwdcheck = <<"ENDJS";
+ var errors = new Array();
+ var min = parseInt("$min") || 0;
+ var currauth = "$currentauth";
+ if (this.document.client.elements.newpass_1.value == '') {
+ errors.push("$js_lt{'blank1'}");
+ }
+ if (this.document.client.elements.newpass_2.value == '') {
+ errors.push("$js_lt{'blank2'}");
+ }
+ if (errors.length == 0) {
+ if (this.document.client.elements.newpass_1.value != this.document.client.elements.newpass_2.value) {
+ errors.push("$js_lt{'mismatch'}");
+ }
+ var posspass = this.document.client.elements.newpass_1.value;
+ if (min > 0) {
+ if (posspass.length < min) {
+ errors.push("$js_lt{'short'}");
+ }
+ }
+ if (currauth == 'internal:') {
+ var max = parseInt("$max") || 0;
+ if (max > 0) {
+ if (posspass.length > max) {
+ errors.push("$js_lt{'long'}");
+ }
+ }
+ var numrules = parseInt("$numrules") || 0;
+ if (numrules > 0) {
+ var rules = new Array("$rulestr");
+ for (var i=0; i\\/?]/;
+ if (!posspass.match(pattern)) {
+ errors.push("$js_lt{'spec'}");
+ }
+ }
+ }
+ }
+ }
+ }
+ if (errors.length > 0) {
+ alert("$js_lt{'fail'}"+"\\n\\n"+errors.join("\\n"));
+ return;
+ }
+ENDJS
my $output = qq|
|;
}
sub client_form {
- my ($caller,$hexkey,$currentpass,$defdom) = @_;
+ my ($caller,$hexkey,$currentpass,$defdom,$extrafields) = @_;
my %lt=&Apache::lonlocal::texthash(
'email' => 'E-mail Address',
'username' => 'Username',
@@ -1422,34 +1585,40 @@ sub client_form {
my $output = '
';
+ $message .= &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result,1));
+ } elsif (@delete) {
+ $result = &mt('Set use of domain default for').':
'.
+ join('
', map { $titles{$_} } @delete).'
';
+ $message .= &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result));
+ }
+ if (@unchanged) {
+ $result = &mt('No changes made for').':
'.
+ join('
', map { $titles{$_} } @unchanged).'
';
+ $message .= &Apache::loncommon::confirmwrapper(&Apache::lonhtmlcommon::confirm_success($result));
+ }
+ }
+ if ($env{'form.returnurl'}) {
+ &do_redirect($r,$env{'form.returnurl'},$message);
+ } else {
&print_main_menu($r,$message);
+ }
+ }
+}
+
+sub authoring_settings_text {
+ return &Apache::lonlocal::texthash(
+ 'auss' => 'Authoring Space Settings',
+ 'used' => 'Use domain default',
+ 'usyo' => 'Use your own user-specific setting',
+ 'curd' => 'Current domain default is',
+ 'ousv' => 'Own user-specific value',
+ 'save' => 'Save',
+ 'yes' => 'Deactivated',
+ 'no' => 'Activated',
+ 'expa' => 'Start Expanded',
+ 'coll' => 'Start Collapsed',
+ );
+}
+
+sub authoring_settings_titles {
+ return &Apache::lonlocal::texthash(
+ 'nocodemirror' => 'CodeMirror for EditXML editor',
+ 'daxecollapse' => 'Daxe editor: collapsible standard LON-CAPA menus',
+ 'copyright' => 'Default Copyright/Distribution in new metadata file',
+ 'sourceavail' => 'Default Source Available in new metadata file',
+ );
+}
+
+sub expanded_authoring_settings {
+ my $reqdmajor = 2;
+ my $reqdminor = 12;
+ my $loncaparev = &Apache::lonnet::get_server_loncaparev($env{'user.domain'},$env{'user.home'});
+ my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
+ unless (($major eq '' && $minor eq '') ||
+ ($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor))) {
+ return 1;
+ }
+ return;
+}
+
+sub daxe_permitted {
+ my ($aurolesref) = @_;
+ my $hasdaxe;
+ if (ref($aurolesref) eq 'HASH') {
+ my %editors;
+ foreach my $key (keys(%{$aurolesref})) {
+ if ($key =~ /^:$LONCAPA::match_domain:au$/) {
+ if (exists($env{'environment.editors'})) {
+ if (grep(/^daxe$/,split(/,/,$env{'environment.editors'}))) {
+ $hasdaxe = 1;
+ last;
+ }
+ }
+ } else {
+ my ($auname,$audom) = ($key =~ /^($LONCAPA::match_username):($LONCAPA::match_domain):(ca|aa)$/);
+ if (exists($env{"environment.internal.editors./$audom/$auname"})) {
+ if (grep(/^daxe$/,split(/,/,$env{"environment.internal.editors./$audom/$auname"}))) {
+ $hasdaxe = 1;
+ last;
+ }
+ }
+ }
+ }
}
+ return $hasdaxe;
}
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"';
@@ -1966,6 +2479,11 @@ 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',
@@ -1992,11 +2510,14 @@ 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 {
@@ -2027,6 +2548,94 @@ sub verify_and_change_lockednames {
&print_main_menu($r,$message);
}
+sub timezonechanger {
+ my $r = shift;
+ my $uname = $env{'user.name'};
+ my $udom = $env{'user.domain'};
+ if (&Apache::lonnet::usertools_access($uname,$udom,'timezone')) {
+ my $js = &toggle_options_js();
+ my %loaditems = (
+ onload => "javascript:toggleOptions(document.prefs,'settimezone','LC_timezone_selector');",
+ );
+ my $args = { 'add_entries' => \%loaditems };
+ &Apache::lonhtmlcommon::add_breadcrumb(
+ { href => '/adm/preferences?action=',
+ text => 'Set Your Time Zone'});
+ $r->print(Apache::loncommon::start_page('Set Your Time Zone',$js,$args));
+ $r->print(Apache::lonhtmlcommon::breadcrumbs('Set Your Time Zone').
+ '
');
+ my %userenv = &Apache::lonnet::get('environment',['timezone']);
+ my $timezone = $userenv{'timezone'};
+ my %lt = &Apache::lonlocal::texthash(
+ tztu => 'Time Zone in use',
+ lctz => 'Use Time Zone set by LON-CAPA',
+ owntz => 'Use Time Zone set by you',
+ save => 'Save',
+ );
+ my (%checked,$tzsty);
+ if ($userenv{'timezone'} ne '') {
+ $checked{'owntz'} = ' checked="checked"';
+ $tzsty = 'inline-block';
+ } else {
+ $checked{'lctz'} = ' checked="checked"';
+ $tzsty = 'none';
+ }
+ my $onclick = ' onclick="javascript:toggleOptions(this.form,'."'settimezone','LC_timezone_selector'".');"';
+ my $selector = &Apache::loncommon::select_timezone('timezone',$timezone,undef,1);
+ $r->print(<<"END");
+