--- loncom/interface/lonpreferences.pm	2002/08/21 17:18:08	1.10
+++ loncom/interface/lonpreferences.pm	2003/04/01 22:21:45	1.18
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Preferences
 #
-# $Id: lonpreferences.pm,v 1.10 2002/08/21 17:18:08 www Exp $
+# $Id: lonpreferences.pm,v 1.18 2003/04/01 22:21:45 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -106,18 +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 Anonymous Screen Name');
+              'Change Your Nickname and Anonymous Screen Name');
     $r->print(<<ENDSCREEN);
 <html>
 $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>
@@ -129,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});
@@ -141,8 +146,22 @@ sub verify_and_change_screenname {
         &Apache::lonnet::delenv('environment\.screenname');
         $message='Reset screenname';
     }
+# Nickname
+    $message.='<br />';
+    $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 Anonymous Screen Name');
+                    'Change Your Nickname and Anonymous Screen Name');
     $r->print(<<ENDVCSCREEN);
 <html>
 $bodytag
@@ -152,6 +171,100 @@ $message
 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 $notification=$userenv{'notification'};
+    my $critnotification=$userenv{'critnotification'};
+    my $bodytag=&Apache::loncommon::bodytag(
+                    'Change Your Message Forwarding and Notification');
+    $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" /><hr />
+New Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
+<input type="text" size="40" value="$notification" name="notification" /><hr />
+New Critical Message Notification Email Address(es) (<tt>joe\@doe.com,jane\@doe.edu,...</tt>):
+<input type="text" size="40" value="$critnotification" name="critnotification" /><hr />
+<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.'<br />';
+    } else {
+        &Apache::lonnet::del('environment',['msgforward']);
+        &Apache::lonnet::delenv('environment\.msgforward');
+        $message.='Reset message forwarding<br />';
+    }
+    my $notification=$ENV{'form.notification'};
+    $notification=~s/\s//gs;
+    if ($notification) {
+        &Apache::lonnet::put('environment',{'notification' => $notification});
+        &Apache::lonnet::appenv('environment.notification' => $notification);
+        $message.='Set message notification address to '.$notification.'<br />';
+    } else {
+        &Apache::lonnet::del('environment',['notification']);
+        &Apache::lonnet::delenv('environment\.notification');
+        $message.='Reset message notification<br />';
+    }
+    my $critnotification=$ENV{'form.critnotification'};
+    $critnotification=~s/\s//gs;
+    if ($critnotification) {
+        &Apache::lonnet::put('environment',{'critnotification' => $critnotification});
+        &Apache::lonnet::appenv('environment.critnotification' => $critnotification);
+        $message.='Set critical message notification address to '.$critnotification;
+    } else {
+        &Apache::lonnet::del('environment',['critnotification']);
+        &Apache::lonnet::delenv('environment\.critnotification');
+        $message.='Reset critical message notification<br />';
+    }
+    my $bodytag=&Apache::loncommon::bodytag(
+                           'Change Your Message Forwarding and Notifications');
+    $r->print(<<ENDVCMSG);
+<html>
+$bodytag
+</p>
+$message
+</body></html>
+ENDVCMSG
+}
+
 ######################################################
 #            password handler subroutines            #
 ######################################################
@@ -309,9 +422,9 @@ ENDERROR
     }
     my ($ckey,$n1key,$n2key)=split(/&/,$tmpinfo);
     # 
-    my $currentpass = &des_decrypt($ckey ,$currentpass);
-    my $newpass1    = &des_decrypt($n1key,$newpass1);
-    my $newpass2    = &des_decrypt($n2key,$newpass2);
+    $currentpass = &des_decrypt($ckey ,$currentpass);
+    $newpass1    = &des_decrypt($n1key,$newpass1);
+    $newpass2    = &des_decrypt($n2key,$newpass2);
     # 
     if ($newpass1 ne $newpass2) {
 	&passwordchanger($r,
@@ -389,6 +502,18 @@ 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>
@@ -402,26 +527,51 @@ ENDHEADER
 	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 and notification addresses" />
+</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__