--- loncom/interface/lonpreferences.pm 2005/06/16 22:11:13 1.65 +++ loncom/interface/lonpreferences.pm 2006/03/21 21:06:35 1.78 @@ -1,7 +1,7 @@ # The LearningOnline Network # Preferences # -# $Id: lonpreferences.pm,v 1.65 2005/06/16 22:11:13 albertel Exp $ +# $Id: lonpreferences.pm,v 1.78 2006/03/21 21:06:35 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -98,16 +98,16 @@ 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 /> <label><input type="radio" name="wysiwyg" value="off" $onselect /> $switchoff</label><br /> @@ -147,7 +147,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 @@ -188,7 +188,7 @@ sub texenginechanger { 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', @@ -196,25 +196,22 @@ sub texenginechanger { ); 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); - $mathexample='$$\int\left(\frac{a+b}{c^6*d}\right)$$'; - my $mimetex_example=&Apache::lontexconvert::mimetex_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?buttons=no&mode=tth" width="400" hieght="200"></iframe> +</p> <p>jsMath <br /> - +$jsMath_start <script type="text/javascript"> if (jsMath.nofonts == 1) { document.writeln @@ -231,9 +228,13 @@ if (jsMath.nofonts == 1) { +'</font></small></div></center>'); } </script> +<iframe src="/res/adm/pages/math_example.tex?buttons=no&mode=jsMath" width="400" hieght="200"></iframe> -$jsMath_example</p> -<p> Convert to Images <br /> $mimetex_example</p> +</p> +<p> Convert to Images <br /> +<br /> +<iframe src="/res/adm/pages/math_example.tex?buttons=no&mode=mimetex" width="400" hieght="200"></iframe> +</p> ENDLSCREEN if ($env{'environment.texengine'} ne 'jsMath') { $r->print('<script type="text/javascript">jsMath.Process()</script>'); @@ -303,7 +304,7 @@ 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" /> @@ -361,7 +362,7 @@ sub screennamechanger { 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" /> @@ -402,7 +403,7 @@ sub verify_and_change_screenname { &Apache::lonnet::delenv('environment\.nickname'); $message.='Reset nickname'; } - + &Apache::lonnet::devalidate_cache_new('namescache',$user.':'.$domain); $r->print(<<ENDVCSCREEN); $message ENDVCSCREEN @@ -429,7 +430,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 /> @@ -549,7 +550,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;'); } @@ -566,7 +567,7 @@ 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"> $chtable @@ -616,7 +617,7 @@ sub verify_and_change_colors { } $r->print(<<ENDVCCOL); $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 @@ -658,8 +659,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"); @@ -699,7 +698,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="" /> @@ -740,14 +739,6 @@ sub verify_and_change_password { # 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'}; @@ -772,7 +763,7 @@ password decryption. Please log out and </p> ENDERROR # Probably should log an error here - return; + return 1; } my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo); # @@ -785,14 +776,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 @@ -827,6 +818,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; } @@ -895,7 +887,7 @@ 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> @@ -980,26 +972,33 @@ 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 $firstselect='checked="checked"'; - my $whatsnewselect=''; - if ($userenv{'course_init_display'} eq 'whatsnew') { - $firstselect=''; - $whatsnewselect='checked="checked"'; + 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 $whatsnew_off=&mt('Display the first resource in the course.'); - my $whatsnew_on=&mt('Display a summary of items in the course which require action from the course coordinator.'); + 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 page to be displayed when you select the role of Course Coordinator').':</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="server" action="/adm/preferences" method="post"> +<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> +<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 /><input type="submit" value="'.&mt('Change').'" /> + $r->print('<br /><br /><input type="submit" value="'.&mt('Change').'" /> </form>'); } @@ -1007,22 +1006,25 @@ sub verify_and_change_coursepage { my $r = shift; my $message=''; my %lt = &Apache::lonlocal::texthash( - 'when' => 'Whenever you select the Course Coordinator role from the roles screen', + '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 a summary page listing course action items', + '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{'when'}.', '.$lt{'ywbt'}.'<br/>'; + $message .= $lt{'ywbt'}.'<br/>'; &Apache::lonnet::put('environment',{'course_init_display' => $newdisp}); &Apache::lonnet::appenv('environment.course_init_display' => $newdisp); } else { - $message .= $lt{'when'}.', '.$lt{'apwb'}.'<br/>'; + $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'}; @@ -1031,7 +1033,8 @@ sub verify_and_change_coursepage { &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">'.$lt{'dasp'}.'</a></font>'; + $message .= '<br /><font size="+1"><a href="/adm/whatsnew?refpage='. + $refpage.'">'.$lt{'dasp'}.'</a></font>'; } } $r->print(<<ENDVCSCREEN); @@ -1059,7 +1062,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 @@ -1084,7 +1087,7 @@ sub handler { breadcrumb => { href =>'/adm/preferences?action=changepass', text => 'Change Password'}, - printmenu => 'yes', + printmenu => 'not_on_error', })); } push (@Options,({ action => 'changescreenname', @@ -1221,7 +1224,9 @@ sub handler { text => 'Change Math Preferences'}, printmenu => 'yes', })); - if($env{'request.role'} =~ /^cc\.\//) { + 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', @@ -1244,13 +1249,9 @@ sub handler { 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'; @@ -1265,13 +1266,15 @@ ENDHEADER $help=$option->{'help'}; } } - $r->print(&Apache::loncommon::bodytag('Change Preferences')); $r->print(&Apache::lonhtmlcommon::breadcrumbs (undef,'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|raeburn)$/ @@ -1315,7 +1318,7 @@ ENDHEADER $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; }