--- loncom/interface/lonpreferences.pm 2013/08/29 19:42:58 1.196.4.13 +++ loncom/interface/lonpreferences.pm 2015/01/19 15:36:01 1.215 @@ -1,7 +1,7 @@ # The LearningOnline Network # Preferences # -# $Id: lonpreferences.pm,v 1.196.4.13 2013/08/29 19:42:58 raeburn Exp $ +# $Id: lonpreferences.pm,v 1.215 2015/01/19 15:36:01 goltermann Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,8 +36,6 @@ 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; @@ -45,50 +43,6 @@ 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 # ################################################################ @@ -211,7 +165,7 @@ sub texenginechanger { 'tth' => 'tth (TeX to HTML)', #'ttm' => 'TeX to MathML', 'jsMath' => 'jsMath', - 'MathJax' => 'MathJax', + 'MathJax' => 'MathJax', 'mimetex' => 'mimetex (Convert to Images)', 'raw' => 'Raw (Screen Reader)' ); @@ -229,6 +183,7 @@ sub texenginechanger { '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):', @@ -265,10 +220,10 @@ $lt{'exmpl'}

$lt{'mathjax'}

- +

-MathJax provides rendered equations whose source code can be extracted in TeX and MathML formats by right clicking the equation. +$lt{'mathjaxinfo'}

$lt{'jsmath'}

@@ -280,17 +235,17 @@ if (jsMath.nofonts == 1) { } - +

$lt{'mimetex'}

- +

$lt{'tth'}

- +

ENDLSCREEN if ($env{'environment.texengine'} ne 'jsMath') { @@ -354,7 +309,7 @@ sub rolesprefchanger { my $hotlist_n=$userenv{'recentrolesn'}; my ($checkedon,$checkedoff); if ($hotlist_flag) { - $checkedon = 'checked="checked"'; + $checkedon = 'checked="checked"'; } else { $checkedoff = 'checked="checked"'; } @@ -437,7 +392,7 @@ $options.' &Apache::lonhtmlcommon::row_closure(1). &Apache::lonhtmlcommon::end_pick_box().' '); - if ($roles_check_list) { + if ($roles_check_list) { $r->print('

'.&mt('Freeze Roles').'

'.&mt('The table below can be used to [_1]freeze[_2] '.$lc_role.'s in the Hotlist.','','').'
'. @@ -834,7 +789,7 @@ sub lockwarning { my $textbottom=&mt('Changing roles or logging out may result in data corruption.'); my ($num,%which)=&Apache::lonnet::get_locks(); my $which=''; - foreach my $id (keys %which) { + foreach my $id (keys(%which)) { $which.='

  • '.$which{$id}.'
  • '; } my $change=&mt('Override'); @@ -1211,10 +1166,10 @@ sub colorschanger { foreach my $item (sort(keys(%colortypes))) { my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain); $chtable.=&Apache::loncommon::start_data_table_row(). - ''.$colortypes{$item}.''. - &Apache::loncommon::end_data_table_row()."\n"; + ''.$colortypes{$item}.''. + &Apache::loncommon::end_data_table_row()."\n"; } my $end_data_table = &Apache::loncommon::end_data_table(); my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); @@ -1226,7 +1181,6 @@ sub colorschanger { ' . $colorchooser . ' '); - $r->print(< @@ -1265,11 +1219,11 @@ sub verify_and_change_colors { ); my $message=''; - foreach my $item (keys %colortypes) { + foreach my $item (keys(%colortypes)) { my $color=$env{'form.'.$item}; - if (!($color =~ /^#/)) { - $color = '#' . $color; - } + if (!($color =~ /^#/)) { + $color = '#' . $color; + } my $entry='color.'.$function.'.'.$item; if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) { &Apache::lonnet::put('environment',{$entry => $color}); @@ -1320,7 +1274,7 @@ sub passwordchanger { $r->print( '

    ' .&mt('Sorry, the URL you provided to complete the reset of your password was invalid. Either the token included in the URL has been deleted or the URL you provided was invalid. Please submit a [_1]new request[_2] for a password reset, and follow the link to the new URL included in the e-mail that will be sent to you, to allow you to enter a new password.' - ,'','') + ,'','') .'

    ' ); return; @@ -1341,9 +1295,9 @@ sub passwordchanger { } } else { $r->print( - '

    ' - .&mt('Sorry, the URL generated when you requested reset of' - .' your password contained incomplete information.') + '

    ' + .&mt('Sorry, the URL generated when you requested reset of' + .' your password contained incomplete information.') .'

    ' ); return; @@ -1364,9 +1318,9 @@ sub passwordchanger { return if ($currentauth !~ /^(unix|internal):/); # # Generate keys - my ($lkey_cpass ,$ukey_cpass ) = &des_keys(); - my ($lkey_npass1,$ukey_npass1) = &des_keys(); - my ($lkey_npass2,$ukey_npass2) = &des_keys(); + my ($lkey_cpass ,$ukey_cpass ) = &Apache::loncommon::des_keys(); + my ($lkey_npass1,$ukey_npass1) = &Apache::loncommon::des_keys(); + my ($lkey_npass2,$ukey_npass2) = &Apache::loncommon::des_keys(); # Store the keys in the log files my $lonhost = $r->dir_config('lonHostID'); my $logtoken=Apache::lonnet::reply('tmpput:' @@ -1605,9 +1559,9 @@ ENDERROR } my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo); # - $currentpass = &des_decrypt($ckey ,$currentpass); - $newpass1 = &des_decrypt($n1key,$newpass1); - $newpass2 = &des_decrypt($n2key,$newpass2); + $currentpass = &Apache::loncommon::des_decrypt($ckey ,$currentpass); + $newpass1 = &Apache::loncommon::des_decrypt($n1key,$newpass1); + $newpass2 = &Apache::loncommon::des_decrypt($n2key,$newpass2); # if ($caller eq 'reset_by_email') { my %data = &Apache::lonnet::tmpget($mailtoken); @@ -1922,6 +1876,58 @@ sub verify_and_change_coursepage { &print_main_menu($r,$message); } +sub author_space_settings { + my $r = shift; + &Apache::lonhtmlcommon::add_breadcrumb( + { href => '/adm/preferences?action=authorsettings', + text => 'Authoring Space Settings'}); + 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) { + $r->print(Apache::loncommon::start_page('Authoring Space Settings')); + $r->print(Apache::lonhtmlcommon::breadcrumbs('Authoring Space Settings')); + my %userenv = &Apache::lonnet::get('environment',['nocodemirror']); + my $constchecked=''; + if ($env{'environment.nocodemirror'}) { + $constchecked=' checked="checked"'; + } + my $text=&mt('By default, Codemirror is activated for authors.'); + my $cmoff=&mt('Deactivate Codemirror. This can improve the performance on slow computers.'); + my $change=&mt('Save'); + $r->print(< + + $text
    +
    + + +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); + &print_main_menu($r,$message); + } +} + sub lockednameschanger { my $r = shift; &Apache::lonhtmlcommon::add_breadcrumb( @@ -2126,25 +2132,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} }, { @@ -2182,6 +2169,18 @@ push(@{ $menu[4]->{items} }, { }); } + + my %author_roles = &Apache::lonnet::get_my_roles($user,$domain,'userroles','',['au','ca','aa']); + if (keys(%author_roles) > 0) { + push(@{ $menu[4]->{items} }, { + linktext => 'Authoring Space Configuration', + url => '/adm/preferences?action=authorsettings', + permission => 'F', + icon => 'course_ini.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)'), @@ -2226,7 +2225,7 @@ sub handler { } 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, @@ -2290,6 +2289,10 @@ sub handler { &coursedisplaychanger($r); }elsif($env{'form.action'} eq 'verify_and_change_coursepage'){ &verify_and_change_coursepage($r); + }elsif($env{'form.action'} eq 'authorsettings'){ + &author_space_settings($r); + }elsif($env{'form.action'} eq 'change_authoring_settings'){ + &change_authoring_settings($r); }elsif($env{'form.action'} eq 'debugtoggle'){ if (&can_toggle_debug()) { &toggle_debug();