--- loncom/interface/lonpreferences.pm 2003/04/19 01:42:34 1.20
+++ loncom/interface/lonpreferences.pm 2009/12/02 18:33:27 1.179
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Preferences
#
-# $Id: lonpreferences.pm,v 1.20 2003/04/19 01:42:34 www Exp $
+# $Id: lonpreferences.pm,v 1.179 2009/12/02 18:33:27 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,18 +25,6 @@
#
# 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:
@@ -45,11 +33,17 @@
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.
@@ -61,7 +55,7 @@ use Apache::loncommon();
##################################################
sub des_keys {
# Make a new key for DES encryption.
- # Each key has two parts which are returned seperately.
+ # 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.
@@ -100,169 +94,1002 @@ sub des_decrypt {
################################################################
################################################################
+# 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);
+}
+
+################################################################
+# 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 $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+ my %userenv = &Apache::lonnet::get
+ ('environment',['languages']);
+ my $language=$userenv{'languages'};
+
+ 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 $selectionbox=
+ &Apache::loncommon::select_form(
+ $language,
+ 'language',
+ &Apache::lonlocal::texthash(%langchoices));
+ $r->print(<
+
+ $pref: $selectionbox
+ENDLSCREEN
+ $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.'".'));
+ } 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'};
+
+ my %mathchoices=('' => 'Default',
+ 'tth' => 'tth (TeX to HTML)',
+ #'ttm' => 'TeX to MathML',
+ 'jsMath' => 'jsMath',
+ 'mimetex' => 'mimetex (Convert to Images)',
+ 'raw' => 'Raw (Screen Reader)'
+ );
+ my $selectionbox=
+ &Apache::loncommon::select_form(
+ $texengine,
+ 'texengine',
+ &Apache::lonlocal::texthash(%mathchoices));
+ 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',
+ '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.'
+ ,''
+ ,'')
+ .'
'.&mt('Some LON-CAPA users have a long list of '.$lc_role.'s. The Recent '.$role.'s Hotlist feature keeps track of the last N '.$lc_role.'s which have been visited and places a table of these at the top of the '.$lc_role.'s page. People with very few '.$lc_role.'s should leave this feature disabled.').'
+
+');
+}
+
+sub rolespref_get_role_text {
+# Get a line of text for each role
+ my ($roles) = @_;
+ my %roletext = ();
+
+ foreach my $item (@$roles) {
+# get course information
+ my ($role,$rest) = split(/\./, $item);
+ my $trole = "";
+ $trole = &Apache::lonnet::plaintext($role);
+ my ($tdomain,$other,$tsection)= split(/\//,Apache::lonnet::declutter($rest));
+ my $tother = '-';
+ if ($role =~ /^(cc|st|in|ta|ep|cr)/ ) {
+ my %newhash=&Apache::lonnet::coursedescription($tdomain."_".$other);
+ $tother = " - ".$newhash{'description'};
+ } elsif ($role =~ /dc/) {
+ $tother = "";
+ } else {
+ $tother = " - $other";
+ }
+
+ my $section="";
+ if ($tsection) {
+ $section = " - Section/Group: $tsection";
+ }
+ $roletext{$item} = $tdomain." - ".$trole.$tother.$section;
+ }
+ return %roletext;
+}
+
+sub verify_and_change_rolespref {
+ my $r = shift;
+ my $role = ($env{'user.adv'} ? 'Role' : 'Course');
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
+# Recent Roles Hotlist Flag
+ my $hotlist_flag = $env{'form.recentroles'};
+ my $hotlist_n = $env{'form.recentrolesn'};
+ my $message='';
+ if ($hotlist_flag) {
+ &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag});
+ &Apache::lonnet::appenv({'environment.recentroles' => $hotlist_flag});
+ $message=&mt('Recent '.$role.'s Hotlist is Enabled');
+ } else {
+ &Apache::lonnet::del('environment',['recentroles']);
+ &Apache::lonnet::delenv('environment.recentroles');
+ $message=&mt('Recent '.$role.'s Hotlist is Disabled');
+ }
+ if ($hotlist_n) {
+ &Apache::lonnet::put('environment',{'recentrolesn' => $hotlist_n});
+ &Apache::lonnet::appenv({'environment.recentrolesn' => $hotlist_n});
+ if ($hotlist_flag) {
+ $message.=" ".
+ &mt('Display [_1] Most Recent '.$role.'s',$hotlist_n)."\n";
+ }
+ }
+
+# Get list of froze roles and list of recent roles
+ my @freeze_list = &Apache::loncommon::get_env_multiple('form.freezeroles');
+ my %freeze = ();
+ my %roletext = ();
+
+ foreach my $key (@freeze_list) {
+ $freeze{$key}='1';
+ }
+
+ 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)]);
+
+# Unset any roles that were previously frozen but aren't in list
+ foreach my $role_key (sort(keys(%recent_roles))) {
+ if (($frozen_roles{$role_key}) && (!exists($freeze{$role_key}))) {
+ $message .= " ".&Apache::lonhtmlcommon::confirm_success(&mt('Unfreezing '.$role.': [_1]',''.$role_text{$role_key}.''));
+ &Apache::lonhtmlcommon::store_recent('roles',$role_key,' ',0);
+ }
+ }
+
+# Freeze selected roles
+ foreach my $role_key (@freeze_list) {
+ if (!$frozen_roles{$role_key}) {
+ $message .= " ".
+ &Apache::lonhtmlcommon::confirm_success(&mt('Freezing '.$role.': [_1]',''.$role_text{$role_key}.''));
+ &Apache::lonhtmlcommon::store_recent('roles',
+ $role_key,' ',1);
+ }
+ }
+ $message=&Apache::loncommon::confirmwrapper($message);
+ &print_main_menu($r, $message);
+}
+
+
+
+################################################################
# Anonymous Discussion Name Change Subroutines #
################################################################
sub screennamechanger {
my $r = shift;
- my $user = $ENV{'user.name'};
- my $domain = $ENV{'user.domain'};
+ my $user = $env{'user.name'};
+ my $domain = $env{'user.domain'};
my %userenv = &Apache::lonnet::get
('environment',['screenname','nickname']);
my $screenname=$userenv{'screenname'};
my $nickname=$userenv{'nickname'};
- my $bodytag=&Apache::loncommon::bodytag(
- 'Change Your Nickname and Anonymous Screen Name');
- $r->print(<
-$bodytag
-
-
-