--- loncom/interface/lonpreferences.pm	2002/09/07 03:44:14	1.12
+++ 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.12 2002/09/07 03:44:14 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
@@ -162,8 +181,10 @@ sub msgforwardchanger {
     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');
+                    'Change Your Message Forwarding and Notification');
     $r->print(<<ENDMSG);
 <html>
 $bodytag
@@ -171,7 +192,11 @@ $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="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>
@@ -201,14 +226,36 @@ sub verify_and_change_msgforward {
     if ($newscreen) {
         &Apache::lonnet::put('environment',{'msgforward' => $newscreen});
         &Apache::lonnet::appenv('environment.msgforward' => $newscreen);
-        $message.='Set new message forwarding to '.$newscreen;
+        $message.='Set new message forwarding to '.$newscreen.'<br />';
     } else {
         &Apache::lonnet::del('environment',['msgforward']);
         &Apache::lonnet::delenv('environment\.msgforward');
-        $message.='Reset message forwarding';
+        $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');
+                           'Change Your Message Forwarding and Notifications');
     $r->print(<<ENDVCMSG);
 <html>
 $bodytag
@@ -375,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,
@@ -459,6 +506,14 @@ sub handler {
         &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>
@@ -472,41 +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
 	    $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">
+<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);
+	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">
+<input type="hidden" name="action" value="changescreenname" />
+<input type="submit" value="Edit the 'About Me' Personal Information Screen" />
 </form>
 ENDABOUTME
-            # Other preference setting code should be added here
+	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__