--- loncom/interface/lonpreferences.pm 2002/08/19 13:10:55 1.9 +++ loncom/interface/lonpreferences.pm 2002/10/16 19:36:25 1.16 @@ -1,7 +1,7 @@ # The LearningOnline Network # Preferences # -# $Id: lonpreferences.pm,v 1.9 2002/08/19 13:10:55 matthew Exp $ +# $Id: lonpreferences.pm,v 1.16 2002/10/16 19:36:25 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -106,20 +106,22 @@ sub screennamechanger { my $r = shift; my $user = $ENV{'user.name'}; my $domain = $ENV{'user.domain'}; - my %userenv = &Apache::lonnet::get('environment',['screenname']); + 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(<<ENDSCREEN); <html> -<body bgcolor="#FFFFFF"> -<h1>Preferences for $user</h1> -<h3>$user is a member of domain $domain</h3> -<p> -Change anonymous discussion screen name for $user -</p> +$bodytag + <form name="server" action="/adm/preferences" method="post"> <input type="hidden" name="action" value="verify_and_change_screenname" /> -New screenname: +<br />New screenname (shown if you post anonymously): <input type="text" size="20" value="$screenname" name="screenname" /> +<br />New nickname (shown if you post non-anonymously): +<input type="text" size="20" value="$nickname" name="nickname" /> <input type="submit" value="Change" /> </form> </body> @@ -131,8 +133,9 @@ sub verify_and_change_screenname { my $r = shift; my $user = $ENV{'user.name'}; my $domain = $ENV{'user.domain'}; +# Screenname my $newscreen = $ENV{'form.screenname'}; - $newscreen=~s/\W//g; + $newscreen=~s/[^ \w]//g; my $message=''; if ($newscreen) { &Apache::lonnet::put('environment',{'screenname' => $newscreen}); @@ -143,19 +146,97 @@ sub verify_and_change_screenname { &Apache::lonnet::delenv('environment\.screenname'); $message='Reset screenname'; } +# Nickname + $message.='<br />'; + my $newscreen = $ENV{'form.nickname'}; + $newscreen=~s/[^ \w]//g; + if ($newscreen) { + &Apache::lonnet::put('environment',{'nickname' => $newscreen}); + &Apache::lonnet::appenv('environment.nickname' => $newscreen); + $message.='Set new nickname to '.$newscreen; + } else { + &Apache::lonnet::del('environment',['nickname']); + &Apache::lonnet::delenv('environment\.nickname'); + $message.='Reset nickname'; + } + + my $bodytag=&Apache::loncommon::bodytag( + 'Change Your Nickname and Anonymous Screen Name'); $r->print(<<ENDVCSCREEN); <html> -<body bgcolor="#FFFFFF"> -<h1>Preferences for $user</h1> -<h3>$user is a member of domain $domain</h3> -<p> -Change anonymous discussion screen name for $user +$bodytag </p> $message </body></html> ENDVCSCREEN } +################################################################ +# Message Forward # +################################################################ + +sub msgforwardchanger { + my $r = shift; + my $user = $ENV{'user.name'}; + my $domain = $ENV{'user.domain'}; + my %userenv = &Apache::lonnet::get('environment',['msgforward']); + my $msgforward=$userenv{'msgforward'}; + my $bodytag=&Apache::loncommon::bodytag( + 'Change Your Message Forwarding'); + $r->print(<<ENDMSG); +<html> +$bodytag + +<form name="server" 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" /> +<input type="submit" value="Change" /> +</form> +</body> +</html> +ENDMSG +} + +sub verify_and_change_msgforward { + my $r = shift; + my $user = $ENV{'user.name'}; + my $domain = $ENV{'user.domain'}; + my $newscreen = ''; + my $message=''; + foreach (split(/\,/,$ENV{'form.msgforward'})) { + my ($msuser,$msdomain)=split(/[\@\:]/,$_); + $msuser=~s/\W//g; + $msdomain=~s/\W//g; + if (($msuser) && ($msdomain)) { + if (&Apache::lonnet::homeserver($msuser,$msdomain) ne 'no_host') { + $newscreen.=$msuser.':'.$msdomain.','; + } else { + $message.='No such user: '.$msuser.':'.$msdomain.'<br>'; + } + } + } + $newscreen=~s/\,$//; + if ($newscreen) { + &Apache::lonnet::put('environment',{'msgforward' => $newscreen}); + &Apache::lonnet::appenv('environment.msgforward' => $newscreen); + $message.='Set new message forwarding to '.$newscreen; + } else { + &Apache::lonnet::del('environment',['msgforward']); + &Apache::lonnet::delenv('environment\.msgforward'); + $message.='Reset message forwarding'; + } + my $bodytag=&Apache::loncommon::bodytag( + 'Change Your Message Forwarding'); + $r->print(<<ENDVCMSG); +<html> +$bodytag +</p> +$message +</body></html> +ENDVCMSG +} + ###################################################### # password handler subroutines # ###################################################### @@ -198,9 +279,11 @@ sub passwordchanger { my $jsh=Apache::File->new($include."/londes.js"); $r->print(<$jsh>); } + my $bodytag=&Apache::loncommon::bodytag('Change Password','', + 'onLoad="init();"'); $r->print(<<ENDFORM); </head> -<body bgcolor="#FFFFFF" onLoad="init();"> +$bodytag <script language="JavaScript"> @@ -228,12 +311,8 @@ sub passwordchanger { } </script> -<h1>Preferences for $user</h1> -<h3>$user is a member of domain $domain</h3> $errormessage -<p> -Change password for $user -</p> + <p> <!-- We seperate the forms into 'server' and 'client' in order to ensure that unencrypted passwords will not be sent out by a @@ -395,41 +474,76 @@ sub handler { &screennamechanger($r); } elsif ($ENV{'form.action'} eq 'verify_and_change_screenname') { &verify_and_change_screenname($r); + } elsif ($ENV{'form.action'} eq 'changemsgforward') { + &msgforwardchanger($r); + } elsif ($ENV{'form.action'} eq 'verify_and_change_msgforward') { + &verify_and_change_msgforward($r); + } elsif ($ENV{'form.action'} eq 'debugtoggle') { + if ($ENV{'user.name'} eq 'albertel' ) { + if ($ENV{'user.debug'}) { + &Apache::lonnet::delenv('user\.debug'); + } else { + &Apache::lonnet::appenv('user.debug' => 1); + } + } } else { $r->print(<<ENDHEADER); <html> <head> <title>LON-CAPA Preferences</title> </head> -<body bgcolor="#FFFFFF" > -<h1>Preferences for $user</h1> -<h3>$user is a member of domain $domain</h3> ENDHEADER + $r->print(&Apache::loncommon::bodytag('Change Your Preferences')); # Determine current authentication method my $currentauth=&Apache::lonnet::queryauthenticate($user,$domain); if ($currentauth =~ /^(unix|internal):/) { $r->print(<<ENDPASSWORDFORM); <form name="client" action="/adm/preferences" method="post"> -<input type="hidden" name="action" value="changepass"> -<input type="submit" value="Change password"> +<input type="hidden" name="action" value="changepass" /> +<input type="submit" value="Change password" /> </form> ENDPASSWORDFORM + } # Change screen name $r->print(<<ENDSCREENNAMEFORM); <form name="client" action="/adm/preferences" method="post"> -<input type="hidden" name="action" value="changescreenname"> -<input type="submit" value="Change anonymous discussion screen name"> +<input type="hidden" name="action" value="changescreenname" /> +<input type="submit" +value="Change nickname and anonymous discussion screen name" /> </form> ENDSCREENNAMEFORM - # Other preference setting code should be added here + $r->print(<<ENDMSGFORWARDFORM); +<form name="client" action="/adm/preferences" method="post"> +<input type="hidden" name="action" value="changemsgforward" /> +<input type="submit" value="Change message forwarding address" /> +</form> +ENDMSGFORWARDFORM +# The "about me" page + my $aboutmeaction= + '/adm/'.$ENV{'user.domain'}.'/'.$ENV{'user.name'}.'/aboutme'; + $r->print(<<ENDABOUTME); +<form name="client" action="$aboutmeaction" method="post"> +<input type="hidden" name="action" value="changescreenname" /> +<input type="submit" value="Edit the 'About Me' Personal Information Screen" /> +</form> +ENDABOUTME + if ($ENV{'user.name'} eq 'albertel') { + $r->print(<<ENDDEBUG); +<form name="client" action="/adm/preferences" method="post"> +<input type="hidden" name="action" value="debugtoggle" /> +<input type="submit" value="Toggle Debug" /> +Current Debug status is -$ENV{'user.debug'}-. +</form> +ENDDEBUG } + # Other preference setting code should be added here } $r->print(<<ENDFOOTER); </body> </html> ENDFOOTER return OK; -} +} 1; __END__