--- loncom/interface/lonpreferences.pm 2005/02/25 06:48:00 1.55 +++ loncom/interface/lonpreferences.pm 2006/06/14 18:54:23 1.87 @@ -1,7 +1,7 @@ # The LearningOnline Network # Preferences # -# $Id: lonpreferences.pm,v 1.55 2005/02/25 06:48:00 albertel Exp $ +# $Id: lonpreferences.pm,v 1.87 2006/06/14 18:54:23 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -33,6 +33,7 @@ package Apache::lonpreferences; use strict; +use LONCAPA; use Apache::Constants qw(:common); use Apache::File; use Crypt::DES; @@ -40,6 +41,7 @@ use DynaLoader; # for Crypt::DES version use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::lonlocal; +use Apache::lonnet; # # Write lonnet::passwd to do the call below. @@ -97,20 +99,20 @@ sub wysiwygchanger { my $r = shift; my %userenv = &Apache::lonnet::get ('environment',['wysiwygeditor']); + my $onselect='checked="checked"'; my $offselect=''; - my $onselect='checked="1"'; - if ($userenv{'wysiwygeditor'}) { + if ($userenv{'wysiwygeditor'} eq 'on') { $onselect=''; - $offselect='checked="1"'; + $offselect='checked="checked"'; } my $switchoff=&mt('Disable WYSIWYG editor'); my $switchon=&mt('Enable WYSIWYG editor'); $r->print(<<ENDLSCREEN); -<form name="server" action="/adm/preferences" method="post"> +<form name="prefs" action="/adm/preferences" method="POST"> <input type="hidden" name="action" value="set_wysiwyg" /> <br /> -<input type="radio" name="wysiwyg" value="off" $onselect /> $switchoff<br /> -<input type="radio" name="wysiwyg" value="on" $offselect /> $switchon +<label><input type="radio" name="wysiwyg" value="off" $onselect /> $switchoff</label><br /> +<label><input type="radio" name="wysiwyg" value="on" $offselect /> $switchon</label> ENDLSCREEN $r->print('<br /><input type="submit" value="'.&mt('Change').'" />'); } @@ -118,7 +120,7 @@ ENDLSCREEN sub verify_and_change_wysiwyg { my $r = shift; - my $newsetting=$ENV{'form.wysiwyg'}; + my $newsetting=$env{'form.wysiwyg'}; &Apache::lonnet::put('environment',{'wysiwygeditor' => $newsetting}); &Apache::lonnet::appenv('environment.wysiwygeditor' => $newsetting); $r->print('<p>'.&mt('Setting WYSIWYG editor to:').' '.&mt($newsetting).'</p>'); @@ -129,8 +131,8 @@ sub verify_and_change_wysiwyg { ################################################################ sub languagechanger { 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',['languages']); my $language=$userenv{'languages'}; @@ -146,7 +148,7 @@ sub languagechanger { my $selectionbox=&Apache::loncommon::select_form($language,'language', %langchoices); $r->print(<<ENDLSCREEN); -<form name="server" action="/adm/preferences" method="post"> +<form name="prefs" action="/adm/preferences" method="POST"> <input type="hidden" name="action" value="verify_and_change_languages" /> <br />$pref: $selectionbox ENDLSCREEN @@ -156,10 +158,10 @@ ENDLSCREEN sub verify_and_change_languages { my $r = shift; - my $user = $ENV{'user.name'}; - my $domain = $ENV{'user.domain'}; + my $user = $env{'user.name'}; + my $domain = $env{'user.domain'}; # Screenname - my $newlanguage = $ENV{'form.language'}; + my $newlanguage = $env{'form.language'}; $newlanguage=~s/[^\-\w]//g; my $message=''; if ($newlanguage) { @@ -172,7 +174,6 @@ sub verify_and_change_languages { $message='Reset preferred language'; } $r->print(<<ENDVCSCREEN); -</p> $message ENDVCSCREEN } @@ -182,38 +183,37 @@ ENDVCSCREEN ################################################################ sub texenginechanger { 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',['texengine']); my $texengine=$userenv{'texengine'}; my $pref=&mt('Preferred method to display Math'); - my %mathchoices=('' => 'No Preference', + my %mathchoices=('' => 'Default', 'tth' => 'TeX to HTML', #'ttm' => 'TeX to MathML', 'jsMath' => 'jsMath', - #'mimetex' => 'Convert to Images' + 'mimetex' => 'Convert to Images' ); my $selectionbox=&Apache::loncommon::select_form($texengine,'texengine', %mathchoices); - my $mathexample='$$\int\left(\frac{a+b}{c^6*d}\right)$$'; - my $jsMath_example=&Apache::lontexconvert::jsMath_converted(\$mathexample); - $mathexample='$$\int\left(\frac{a+b}{c^6*d}\right)$$'; - my $tth_example=&Apache::lontexconvert::tth_converted(\$mathexample); + my $jsMath_start=&Apache::lontexconvert::jsMath_header(); my $change=&mt('Change'); $r->print(<<ENDLSCREEN); -<form name="server" action="/adm/preferences" method="post"> +<br /> + +<form name="prefs" action="/adm/preferences" method="POST"> <input type="hidden" name="action" value="verify_and_change_texengine" /> <p>$pref: $selectionbox</p> <p><input type="submit" value="$change" /></p> </form> Examples: -<p> TeX to HTML <br /> $tth_example</p> -<script type"text/javascript">function NoFontMessage () { }</script> -<script src="/adm/jsMath/jsMath.js"></script> +<p> TeX to HTML <br /> +<iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=tth" width="400" hieght="200"></iframe> +</p> <p>jsMath <br /> - -<script type"text/javascript"> +$jsMath_start +<script type="text/javascript"> if (jsMath.nofonts == 1) { document.writeln ('<center><div style="padding: 10; border-style: solid; border-width:3;' @@ -229,10 +229,15 @@ if (jsMath.nofonts == 1) { +'</font></small></div></center>'); } </script> +<iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=jsMath" width="400" hieght="200"></iframe> -$jsMath_example</p> +</p> +<p> Convert to Images <br /> +<br /> +<iframe src="/res/adm/pages/math_example.tex?inhibitmenu=yes&texengine=mimetex" width="400" hieght="200"></iframe> +</p> ENDLSCREEN - if ($ENV{'environment.texengine'} ne 'jsMath') { + if ($env{'environment.texengine'} ne 'jsMath') { $r->print('<script type="text/javascript">jsMath.Process()</script>'); } } @@ -240,11 +245,18 @@ ENDLSCREEN sub verify_and_change_texengine { my $r = shift; - my $user = $ENV{'user.name'}; - my $domain = $ENV{'user.domain'}; + my $user = $env{'user.name'}; + my $domain = $env{'user.domain'}; # Screenname - my $newtexengine = $ENV{'form.texengine'}; + my $newtexengine = $env{'form.texengine'}; $newtexengine=~s/[^\-\w]//g; + 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}); @@ -255,8 +267,9 @@ sub verify_and_change_texengine { &Apache::lonnet::delenv('environment\.texengine'); $message='Reset preferred math display.'; } + + $r->print(<<ENDVCSCREEN); -</p> $message ENDVCSCREEN } @@ -266,8 +279,8 @@ ENDVCSCREEN ################################################################ sub rolesprefchanger { 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',['recentroles','recentrolesn']); my $hotlist_flag=$userenv{'recentroles'}; @@ -292,10 +305,10 @@ visited and places a table of these at t People with very few roles should leave this feature disabled. </p> -<form name="server" action="/adm/preferences" method="post"> +<form name="prefs" action="/adm/preferences" method="POST"> <input type="hidden" name="action" value="verify_and_change_rolespref" /> -<br />Enable Recent Roles Hotlist: -<input type="checkbox" $checked name="recentroles" value="true" /> +<br /><label>Enable Recent Roles Hotlist: +<input type="checkbox" $checked name="recentroles" value="true" /></label> <br />Number of roles in Hotlist: <select name="recentrolesn" size="1"> $options @@ -308,11 +321,11 @@ ENDSCREEN sub verify_and_change_rolespref { my $r = shift; - my $user = $ENV{'user.name'}; - my $domain = $ENV{'user.domain'}; + 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 $hotlist_flag = $env{'form.recentroles'}; + my $hotlist_n = $env{'form.recentrolesn'}; my $message=''; if ($hotlist_flag) { &Apache::lonnet::put('environment',{'recentroles' => $hotlist_flag}); @@ -332,7 +345,6 @@ sub verify_and_change_rolespref { } $r->print(<<ENDRPSCREEN); -</p> $message ENDRPSCREEN } @@ -344,14 +356,14 @@ ENDRPSCREEN ################################################################ 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'}; $r->print(<<ENDSCREEN); -<form name="server" action="/adm/preferences" method="post"> +<form name="prefs" action="/adm/preferences" method="POST"> <input type="hidden" name="action" value="verify_and_change_screenname" /> <br />New screenname (shown if you post anonymously): <input type="text" size="20" value="$screenname" name="screenname" /> @@ -364,10 +376,10 @@ ENDSCREEN sub verify_and_change_screenname { my $r = shift; - my $user = $ENV{'user.name'}; - my $domain = $ENV{'user.domain'}; + my $user = $env{'user.name'}; + my $domain = $env{'user.domain'}; # Screenname - my $newscreen = $ENV{'form.screenname'}; + my $newscreen = $env{'form.screenname'}; $newscreen=~s/[^ \w]//g; my $message=''; if ($newscreen) { @@ -381,7 +393,7 @@ sub verify_and_change_screenname { } # Nickname $message.='<br />'; - $newscreen = $ENV{'form.nickname'}; + $newscreen = $env{'form.nickname'}; $newscreen=~s/[^ \w]//g; if ($newscreen) { &Apache::lonnet::put('environment',{'nickname' => $newscreen}); @@ -392,9 +404,8 @@ sub verify_and_change_screenname { &Apache::lonnet::delenv('environment\.nickname'); $message.='Reset nickname'; } - + &Apache::lonnet::devalidate_cache_new('namescache',$user.':'.$domain); $r->print(<<ENDVCSCREEN); -</p> $message ENDVCSCREEN } @@ -405,8 +416,8 @@ ENDVCSCREEN sub msgforwardchanger { 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',['msgforward','notification','critnotification']); my $msgforward=$userenv{'msgforward'}; my $notification=$userenv{'notification'}; @@ -420,7 +431,7 @@ sub msgforwardchanger { $r->print(<<ENDMSG); $forwardingHelp <br /> -<form name="server" action="/adm/preferences" method="post"> +<form name="prefs" action="/adm/preferences" method="POST"> <input type="hidden" name="action" value="verify_and_change_msgforward" /> New Forwarding Address(es) (<tt>user:domain,user:domain,...</tt>): <input type="text" size="40" value="$msgforward" name="msgforward" /><hr /> @@ -435,11 +446,11 @@ ENDMSG sub verify_and_change_msgforward { my $r = shift; - my $user = $ENV{'user.name'}; - my $domain = $ENV{'user.domain'}; + my $user = $env{'user.name'}; + my $domain = $env{'user.domain'}; my $newscreen = ''; my $message=''; - foreach (split(/\,/,$ENV{'form.msgforward'})) { + foreach (split(/\,/,$env{'form.msgforward'})) { my ($msuser,$msdomain)=split(/[\@\:]/,$_); $msuser=~s/\W//g; $msdomain=~s/\W//g; @@ -461,7 +472,7 @@ sub verify_and_change_msgforward { &Apache::lonnet::delenv('environment\.msgforward'); $message.='Reset message forwarding<br />'; } - my $notification=$ENV{'form.notification'}; + my $notification=$env{'form.notification'}; $notification=~s/\s//gs; if ($notification) { &Apache::lonnet::put('environment',{'notification' => $notification}); @@ -472,7 +483,7 @@ sub verify_and_change_msgforward { &Apache::lonnet::delenv('environment\.notification'); $message.='Reset message notification<br />'; } - my $critnotification=$ENV{'form.critnotification'}; + my $critnotification=$env{'form.critnotification'}; $critnotification=~s/\s//gs; if ($critnotification) { &Apache::lonnet::put('environment',{'critnotification' => $critnotification}); @@ -484,7 +495,6 @@ sub verify_and_change_msgforward { $message.='Reset critical message notification<br />'; } $r->print(<<ENDVCMSG); -</p> $message ENDVCMSG } @@ -496,17 +506,7 @@ ENDVCMSG sub colorschanger { my $r = shift; # figure out colors - my $function='student'; - if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) { - $function='coordinator'; - } - if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) { - $function='admin'; - } - if (($ENV{'request.role'}=~/^(au|ca)/) || - ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) { - $function='author'; - } + my $function=&Apache::loncommon::get_users_function(); my $domain=&Apache::loncommon::determinedomain(); my %colortypes=('pgbg' => 'Page Background', 'tabbg' => 'Header Background', @@ -515,19 +515,23 @@ sub colorschanger { 'link' => 'Un-Visited Link', 'vlink' => 'Visited Link', 'alink' => 'Active Link'); + my $start_data_table = &Apache::loncommon::start_data_table(); my $chtable=''; foreach my $item (sort(keys(%colortypes))) { my $curcol=&Apache::loncommon::designparm($function.'.'.$item,$domain); - $chtable.='<tr><td>'.$colortypes{$item}.'</td><td bgcolor="'.$curcol. + $chtable.=&Apache::loncommon::start_data_table_row(). + '<td>'.$colortypes{$item}.'</td><td style="background: '.$curcol. '"> </td><td><input name="'.$item. '" size="10" value="'.$curcol. '" /></td><td><a href="javascript:pjump('."'color_custom','".$colortypes{$item}. "','".$curcol."','" - .$item."','parmform.pres','psub'".');">Select</a></td></tr>'; + .$item."','parmform.pres','psub'".');">Select</a></td>'. + &Apache::loncommon::end_data_table_row()."\n"; } + my $end_data_table = &Apache::loncommon::end_data_table(); my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition(); $r->print(<<ENDCOL); -<script> +<script type="text/javascript"> function pclose() { parmwin=window.open("/adm/rat/empty.html","LONCAPAparms", @@ -541,7 +545,7 @@ sub colorschanger { pclose(); if (document.parmform.pres_marker.value!='') { if (document.parmform.pres_type.value!='') { - eval('document.server.'+ + eval('document.prefs.'+ document.parmform.pres_marker.value+ '.value=document.parmform.pres_value.value;'); } @@ -558,10 +562,11 @@ sub colorschanger { <input type="hidden" name="pres_type" /> <input type="hidden" name="pres_value" /> </form> -<form name="server" action="/adm/preferences" method="post"> +<form name="prefs" action="/adm/preferences" method="POST"> <input type="hidden" name="action" value="verify_and_change_colors" /> -<table border="2"> +$start_data_table $chtable +$end_data_table </table> <input type="submit" value="Change Custom Colors" /> <input type="submit" name="resetall" value="Reset All Colors to Default" /> @@ -572,17 +577,7 @@ ENDCOL sub verify_and_change_colors { my $r = shift; # figure out colors - my $function='student'; - if ($ENV{'request.role'}=~/^(cc|in|ta|ep)/) { - $function='coordinator'; - } - if ($ENV{'request.role'}=~/^(su|dc|ad|li)/) { - $function='admin'; - } - if (($ENV{'request.role'}=~/^(au|ca)/) || - ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) { - $function='author'; - } + my $function=&Apache::loncommon::get_users_function(); my $domain=&Apache::loncommon::determinedomain(); my %colortypes=('pgbg' => 'Page Background', 'tabbg' => 'Header Background', @@ -594,9 +589,9 @@ sub verify_and_change_colors { my $message=''; foreach my $item (keys %colortypes) { - my $color=$ENV{'form.'.$item}; + my $color=$env{'form.'.$item}; my $entry='color.'.$function.'.'.$item; - if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$ENV{'form.resetall'})) { + if (($color=~/^\#[0-9A-Fa-f]{6}$/) && (!$env{'form.resetall'})) { &Apache::lonnet::put('environment',{$entry => $color}); &Apache::lonnet::appenv('environment.'.$entry => $color); $message.='Set '.$colortypes{$item}.' to '.$color.'<br />'; @@ -606,10 +601,13 @@ sub verify_and_change_colors { $message.='Reset '.$colortypes{$item}.'<br />'; } } + my $now = time; + &Apache::lonnet::put('environment',{'color.timestamp' => $now}); + &Apache::lonnet::appenv('environment.color.timestamp' => $now); + $r->print(<<ENDVCCOL); -</p> $message -<form name="client" action="/adm/preferences" method="post"> +<form name="client" action="/adm/preferences" method="POST"> <input type="hidden" name="action" value="changecolors" /> </form> ENDVCCOL @@ -624,9 +622,9 @@ sub passwordchanger { my $r = shift; my $errormessage = shift; $errormessage = ($errormessage || ''); - my $user = $ENV{'user.name'}; - my $domain = $ENV{'user.domain'}; - my $homeserver = $ENV{'user.home'}; + my $user = $env{'user.name'}; + my $domain = $env{'user.domain'}; + my $homeserver = $env{'user.home'}; my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain); # Check for authentication types that allow changing of the password. return if ($currentauth !~ /^(unix|internal):/); @@ -651,8 +649,6 @@ sub passwordchanger { $lkey_npass2= hex($lkey_npass2); # Output javascript to deal with passwords # Output DES javascript - my $html=&Apache::lonxml::xmlbegin(); - $r->print($html."<head>"); { my $include = $r->dir_config('lonIncludes'); my $jsh=Apache::File->new($include."/londes.js"); @@ -692,7 +688,7 @@ $errormessage ensure that unencrypted passwords will not be sent out by a crappy browser --> -<form name="pserver" action="/adm/preferences" method="post"> +<form name="pserver" action="/adm/preferences" method="POST"> <input type="hidden" name="logtoken" value="$logtoken" /> <input type="hidden" name="action" value="verify_and_change_pass" /> <input type="hidden" name="currentpass" value="" /> @@ -726,25 +722,17 @@ ENDFORM sub verify_and_change_password { my $r = shift; - my $user = $ENV{'user.name'}; - my $domain = $ENV{'user.domain'}; - my $homeserver = $ENV{'user.home'}; + my $user = $env{'user.name'}; + my $domain = $env{'user.domain'}; + my $homeserver = $env{'user.home'}; my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain); # Check for authentication types that allow changing of the password. return if ($currentauth !~ /^(unix|internal):/); # - my $html=&Apache::lonxml::xmlbegin(); - $r->print(<<ENDHEADER); -$html -<head> -<title>LON-CAPA Preferences: Change password for $user</title> -</head> -ENDHEADER - # - my $currentpass = $ENV{'form.currentpass'}; - my $newpass1 = $ENV{'form.newpass_1'}; - my $newpass2 = $ENV{'form.newpass_2'}; - my $logtoken = $ENV{'form.logtoken'}; + my $currentpass = $env{'form.currentpass'}; + my $newpass1 = $env{'form.newpass_1'}; + my $newpass2 = $env{'form.newpass_2'}; + my $logtoken = $env{'form.logtoken'}; # Check for empty data unless (defined($currentpass) && defined($newpass1) && @@ -765,7 +753,7 @@ password decryption. Please log out and </p> ENDERROR # Probably should log an error here - return; + return 1; } my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo); # @@ -778,14 +766,14 @@ ENDERROR '<font color="#ff0000">ERROR:</font>'. 'The new passwords you entered do not match. '. 'Please try again.'); - return; + return 1; } if (length($newpass1) < 7) { &passwordchanger($r, '<font color="#ff0000">ERROR:</font>'. 'Passwords must be a minimum of 7 characters long. '. 'Please try again.'); - return; + return 1; } # # Check for bad characters @@ -820,6 +808,7 @@ ENDTEXT <h2><font color="#ff0000">The password for $user was not changed</font></h2> Please make sure your old password was entered correctly. ENDERROR + return 1; } return; } @@ -829,8 +818,8 @@ ENDERROR ################################################################ sub discussionchanger { 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',['discdisplay','discmarkread']); my $discdisp = 'allposts'; @@ -852,7 +841,7 @@ sub discussionchanger { my $function = &Apache::loncommon::get_users_function(); my $color = &Apache::loncommon::designparm($function.'.tabbg', - $ENV{'user.domain'}); + $env{'user.domain'}); my %lt = &Apache::lonlocal::texthash( 'pref' => 'Display Preference', 'curr' => 'Current setting ', @@ -888,40 +877,38 @@ sub discussionchanger { } $r->print(<<"END"); -<form name="server" action="/adm/preferences" method="post"> +<form name="prefs" action="/adm/preferences" method="POST"> <input type="hidden" name="action" value="verify_and_change_discussion" /> <br /> -$lt{'sdpf'}<br/> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> +$lt{'sdpf'}<br /> $lt{'prca'} <ol><li>$lt{'whpo'}</li><li>$lt{'unwh'}</li></ol> <br /> <br /> -<table border="0" cellpadding="0" cellspacing="0"> - <tr> - <td width="100%" bgcolor="#000000"> - <table width="100%" border="0" cellpadding="1" cellspacing="0"> - <tr> - <td width="100%" bgcolor="#000000"> - <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF"> - <tr bgcolor="$color"> - <td><b>$lt{'pref'}</b></td> - <td><b>$lt{'curr'}</b></td> - <td><b>$lt{'actn'}?</b></td> +END + $r->print(&Apache::loncommon::start_data_table()); + $r->print(<<"END"); + <tr> + <th>$lt{'pref'}</th> + <th>$lt{'curr'}</th> + <th>$lt{'actn'}?</th> </tr> - <tr bgcolor="#dddddd"> +END + $r->print(&Apache::loncommon::start_data_table_row()); + $r->print(<<"END"); <td>$lt{'disa'}</td> <td>$lt{$discdisp}</td> - <td><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</td> - </tr><tr bgcolor="#eeeeee"> + <td><label><input type="checkbox" name="discdisp" /><input type="hidden" name="newdisp" value="$newdisp" /> $lt{'chgt'} "$dispchange"</label></td> +END + $r->print(&Apache::loncommon::end_data_table_row(). + &Apache::loncommon::start_data_table_row()); + $r->print(<<"END"); <td>$lt{'npmr'}</td> <td>$lt{$discmark}</td> - <td><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</td> + <td><label><input type="checkbox" name="discmark" /><input type="hidden" name="newmark" value="$newmark" /> $lt{'chgt'} "$markchange"</label></td> </tr> - </table> - </td> - </tr> - </table> - </td> -</tr> -</table> +END + $r->print(&Apache::loncommon::end_data_table_row(). + &Apache::loncommon::end_data_table()); + $r->print(<<"END"); <br /> <br /> <input type="submit" name="sub" value="Store Changes" /> @@ -934,39 +921,117 @@ END sub verify_and_change_discussion { my $r = shift; - my $user = $ENV{'user.name'}; - my $domain = $ENV{'user.domain'}; + my $user = $env{'user.name'}; + my $domain = $env{'user.domain'}; my $message=''; - if (defined($ENV{'form.discdisp'}) ) { - my $newdisp = $ENV{'form.newdisp'}; + if (defined($env{'form.discdisp'}) ) { + my $newdisp = $env{'form.newdisp'}; if ($newdisp eq 'unread') { - $message .='In discussions: only new posts will be displayed.<br/>'; + $message .='In discussions: only new posts will be displayed.<br />'; &Apache::lonnet::put('environment',{'discdisplay' => $newdisp}); &Apache::lonnet::appenv('environment.discdisplay' => $newdisp); } else { - $message .= 'In discussions: all posts will be displayed.<br/>'; + $message .= 'In discussions: all posts will be displayed.<br />'; &Apache::lonnet::del('environment',['discdisplay']); &Apache::lonnet::delenv('environment\.discdisplay'); } } - if (defined($ENV{'form.discmark'}) ) { - my $newmark = $ENV{'form.newmark'}; + if (defined($env{'form.discmark'}) ) { + my $newmark = $env{'form.newmark'}; if ($newmark eq 'ondisp') { - $message.='In discussions: new posts will be cease to be identified as "new" after display.<br/>'; + $message.='In discussions: new posts will be cease to be identified as "new" after display.<br />'; &Apache::lonnet::put('environment',{'discmarkread' => $newmark}); &Apache::lonnet::appenv('environment.discmarkread' => $newmark); } else { - $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br/>'; + $message.='In discussions: posts will be identified as "new" until marked as read by the reader.<br />'; &Apache::lonnet::del('environment',['discmarkread']); &Apache::lonnet::delenv('environment\.discmarkread'); } } $r->print(<<ENDVCSCREEN); -</p> $message ENDVCSCREEN } +################################################################ +# Subroutines for page display on course access (Course Coordinators) +################################################################ +sub coursedisplaychanger { + my $r = shift; + my $user = $env{'user.name'}; + my $domain = $env{'user.domain'}; + my %userenv = &Apache::lonnet::get('environment',['course_init_display']); + my $currvalue = 'whatsnew'; + my $firstselect = ''; + my $whatsnewselect = 'checked="checked"'; + if (exists($userenv{'course_init_display'})) { + if ($userenv{'course_init_display'} eq 'firstres') { + $currvalue = 'firstres'; + $firstselect = 'checked="checked"'; + $whatsnewselect = ''; + } + } + my %pagenames = ( + firstres => 'First resource', + whatsnew => "What's new page", + ); + my $whatsnew_off=&mt('Display the [_1] in the course.','<b>first resource</b>'); + my $whatsnew_on=&mt('Display the "[_1]" page - a summary of items in the course which require attention.',"<b>What's New</b>"); + + $r->print('<br /><b>'.&mt('Set the default page to be displayed when you select a course role').'</b> '.&mt('(Currently: [_1])',$pagenames{$currvalue}).'<br />'.&mt('The global user preference you set for your courses can be overridden in an individual course by setting a course specific setting via the "[_1]" page in the course',"<i>What's New</i>").'<br /><br />'); + $r->print(<<ENDLSCREEN); +<form name="prefs" action="/adm/preferences" method="POST"> +<input type="hidden" name="action" value="verify_and_change_coursepage" /> +<br /> +<label><input type="radio" name="newdisp" value="firstres" $firstselect /> $whatsnew_off</label><br /> +<label><input type="radio" name="newdisp" value="whatsnew" $whatsnewselect /> $whatsnew_on</label><input type="hidden" name="refpage" value="$env{'form.refpage'}" /> +ENDLSCREEN + $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" /> +</form>'); +} + +sub verify_and_change_coursepage { + my $r = shift; + my $message=''; + my %lt = &Apache::lonlocal::texthash( + 'defs' => 'Default now set', + 'when' => 'when you select a course role from the roles screen', + 'ywbt' => 'you will be taken to the start of the course.', + 'apwb' => 'a page will be displayed that lists items in the course that may require action from you.', + 'gtts' => 'Go to the start of the course', + 'dasp' => "Display the What's New page listing course action items", + ); + my $newdisp = $env{'form.newdisp'}; + $message = '<b>'.$lt{'defs'}.'</b>: '.$lt{'when'}.', '; + if ($newdisp eq 'firstres') { + $message .= $lt{'ywbt'}.'<br />'; + &Apache::lonnet::put('environment',{'course_init_display' => $newdisp}); + &Apache::lonnet::appenv('environment.course_init_display' => $newdisp); + } else { + $message .= $lt{'apwb'}.'<br />'; + &Apache::lonnet::del('environment',['course_init_display']); + &Apache::lonnet::delenv('environment\.course_init_display'); + } + my $refpage = $env{'form.refpage'}; + if (($env{'request.course.fn'}) && ($env{'request.course.id'})) { + if ($newdisp eq 'firstres') { + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + my ($furl,$ferr)= + &Apache::lonuserstate::readmap($cdom.'/'.$cnum); + $message .= '<br /><font size="+1"><a href="'.$furl.'">'.$lt{'gtts'}.' <i>'.&mt('now').'</i></a></font>'; + } else { + $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='. + $refpage.'">'.$lt{'dasp'}.'</a></font>'; + } + } + $r->print(<<ENDVCSCREEN); +$message +<br /><br /> +ENDVCSCREEN +} + + ###################################################### # other handler subroutines # ###################################################### @@ -976,8 +1041,8 @@ ENDVCSCREEN ################################################################ sub handler { my $r = shift; - my $user = $ENV{'user.name'}; - my $domain = $ENV{'user.domain'}; + my $user = $env{'user.name'}; + my $domain = $env{'user.domain'}; &Apache::loncommon::content_type($r,'text/html'); # Some pages contain DES keys and should not be cached. &Apache::loncommon::no_cache($r); @@ -985,7 +1050,7 @@ sub handler { return OK if $r->header_only; # &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['action','wysiwyg','returnurl']); + ['action','wysiwyg','returnurl','refpage']); # &Apache::lonhtmlcommon::clear_breadcrumbs(); &Apache::lonhtmlcommon::add_breadcrumb @@ -1010,7 +1075,7 @@ sub handler { breadcrumb => { href =>'/adm/preferences?action=changepass', text => 'Change Password'}, - printmenu => 'yes', + printmenu => 'not_on_error', })); } push (@Options,({ action => 'changescreenname', @@ -1046,7 +1111,7 @@ sub handler { printmenu => 'yes', subroutine => \&verify_and_change_msgforward })); my $aboutmeaction= - '/adm/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/aboutme'; + '/adm/'.$env{'user.domain'}.'/'.$env{'user.name'}.'/aboutme'; push (@Options,{ action => 'none', linktext => q{Edit the 'About Me' Personal Information Screen}, @@ -1148,25 +1213,51 @@ sub handler { printmenu => 'yes', })); + if ($env{'environment.remote'} eq 'off') { + push (@Options,({ action => 'launch', + linktext => 'Launch Remote Control', + href => '/adm/remote?url=/adm/preferences', + })); + } else { + push (@Options,({ action => 'collapse', + linktext => 'Collapse Remote Control', + href => '/adm/remote?url=/adm/preferences', + })); + } + + if (&Apache::lonnet::allowed('whn',$env{'request.course.id'}) + || &Apache::lonnet::allowed('whn',$env{'request.course.id'}.'/' + .$env{'request.course.sec'})) { + push (@Options,({ action => 'changecourseinit', + linktext => 'Change Course Initialization Preference', + href => '/adm/preferences', + subroutine => \&coursedisplaychanger, + breadcrumb => + { href => '/adm/preferences?action=changecourseinit', + text => 'Change Course Init. Pref.'}, + }, + { action => 'verify_and_change_coursepage', + breadcrumb => + { href => '/adm/preferences?action=changecourseinit', text => 'Change Course Initialization Preference'}, + printmenu => 'yes', + subroutine => \&verify_and_change_coursepage, + })); + } - if ($ENV{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle)$/) { + if ($env{'user.name'} =~ /^(albertel|fox|foxr|koretemey|korte|hallmat3|turtle|raeburn)$/) { push (@Options,({ action => 'debugtoggle', printmenu => 'yes', subroutine => \&toggle_debug, })); } - my $html=&Apache::lonxml::xmlbegin(); - $r->print(<<ENDHEADER); -$html -<head> -<title>LON-CAPA Preferences</title> -</head> -ENDHEADER + + $r->print(&Apache::loncommon::start_page('Change Preferences')); + my $call = undef; my $help = undef; my $printmenu = 'yes'; foreach my $option (@Options) { - if ($option->{'action'} eq $ENV{'form.action'}) { + if ($option->{'action'} eq $env{'form.action'}) { $call = $option->{'subroutine'}; $printmenu = $option->{'printmenu'}; if (exists($option->{'breadcrumb'})) { @@ -1176,21 +1267,22 @@ ENDHEADER $help=$option->{'help'}; } } - $r->print(&Apache::loncommon::bodytag('Change Preferences')); - $r->print(&Apache::lonhtmlcommon::breadcrumbs - (undef,'Change Preferences',$help)); + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Change Preferences',$help)); + my $error; if (defined($call)) { - $call->($r); + $error = $call->($r); } - if (($printmenu eq 'yes') && (!$ENV{'form.returnurl'})) { + if ( ( ($printmenu eq 'yes') + || ($printmenu eq 'not_on_error' && !$error) ) + && (!$env{'form.returnurl'})) { my $optionlist = '<table cellpadding="5">'; - if ($ENV{'user.name'} =~ - /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle)$/ + if ($env{'user.name'} =~ + /^(albertel|kortemey|fox|foxr|korte|hallmat3|turtle|raeburn)$/ ) { push (@Options,({ action => 'debugtoggle', linktext => 'Toggle Debug Messages', text => 'Current Debug status is -'. - $ENV{'user.debug'}.'-.', + $env{'user.debug'}.'-.', href => '/adm/preferences', printmenu => 'yes', subroutine => \&toggle_debug, @@ -1199,9 +1291,10 @@ ENDHEADER foreach my $option(@Options) { my $optiontext = ''; if (exists($option->{'href'})) { - $optiontext .= - '<a href="'.$option->{'href'}. - '?action='.$option->{'action'}.'">'. + $option->{'href_args'}{'action'}=$option->{'action'}; + $optiontext .= + '<a href="'.&add_get_param($option->{'href'}, + $option->{'href_args'}).'">'. &mt($option->{'linktext'}).'</a>'; } if (exists($option->{'text'})) { @@ -1222,16 +1315,16 @@ ENDHEADER } $optionlist .= '</table>'; $r->print($optionlist); - } elsif ($ENV{'form.returnurl'}) { - $r->print('<br /><a href="'.$ENV{'form.returnurl'}.'"><font size="+1">'. + } elsif ($env{'form.returnurl'}) { + $r->print('<br /><a href="'.$env{'form.returnurl'}.'"><font size="+1">'. &mt('Return').'</font></a>'); } - $r->print(&Apache::loncommon::endbodytag().'</html>'); + $r->print(&Apache::loncommon::end_page()); return OK; } sub toggle_debug { - if ($ENV{'user.debug'}) { + if ($env{'user.debug'}) { &Apache::lonnet::delenv('user\.debug'); } else { &Apache::lonnet::appenv('user.debug' => 1);