--- loncom/xml/lonxml.pm	2002/09/11 13:36:50	1.195
+++ loncom/xml/lonxml.pm	2002/10/11 20:09:36	1.200
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.195 2002/09/11 13:36:50 www Exp $
+# $Id: lonxml.pm,v 1.200 2002/10/11 20:09:36 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -99,6 +99,8 @@ use Apache::edit();
 use Apache::lonnet();
 use Apache::File();
 use Apache::loncommon();
+use Apache::lonfeedback();
+use Apache::lonmsg();
 
 #==================================================   Main subroutine: xmlparse  
 #debugging control, to turn on debugging modify the correct handler
@@ -186,17 +188,24 @@ sub xmlend {
                   if ($hidden) {
 		      $message='<font color="#888888">'.$message.'</font>';
                   }
+                  my $screenname=&Apache::loncommon::screenname(
+                               $contrib{$idx.':sendername'},
+			       $contrib{$idx.':senderdomain'});
+                  my $plainname=&Apache::loncommon::nickname(
+                               $contrib{$idx.':sendername'},
+			       $contrib{$idx.':senderdomain'});
+
                   my $sender='Anonymous';
                   if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
                       $sender=&Apache::loncommon::aboutmewrapper(
-                               $contrib{$idx.':plainname'},
+                               $plainname,
                                $contrib{$idx.':sendername'},
                                $contrib{$idx.':senderdomain'}).' ('.
                               $contrib{$idx.':sendername'}.' at '.
 		      $contrib{$idx.':senderdomain'}.')';
                       if ($contrib{$idx.':anonymous'}) {
 			  $sender.=' [anonymous] '.
-                                     $contrib{$idx.':screenname'};
+                                     $screenname;
                       }
                       if ($seeid) {
 			  if ($hidden) {
@@ -208,8 +217,8 @@ sub xmlend {
 			  }
                       }                   
                   } else {
-                      if ($contrib{$idx.':screenname'}) {
-			  $sender='<i>'.$contrib{$idx.':screenname'}.'</i>';
+                      if ($screenname) {
+			  $sender='<i>'.$screenname.'</i>';
                       }
                   }
 		  $discussion.='<p><b>'.$sender.'</b> ('.
@@ -225,7 +234,7 @@ sub xmlend {
           }
           if ($discussiononly) {
 	      $discussion.=(<<ENDDISCUSS);
-<form action="/adm/feedback" method="post">
+<form action="/adm/feedback" method="post" name="mailform">
 <input type="submit" name="discuss" value="Post Discussion" />
 <input type="submit" name="anondiscuss" value="Post Anonymous Discussion" />
 <input type="hidden" name="symb" value="$symb" />
@@ -236,6 +245,7 @@ course faculty</font><br />
 <textarea name=comment cols=60 rows=10 wrap=hard></textarea>
 </form>
 ENDDISCUSS
+             $discussion.=&Apache::lonfeedback::generate_preview_button();
           }
        }
     }
@@ -356,6 +366,7 @@ sub registerurl {
     my $forcereg=shift;
     my $target = shift;
     my $result = '';
+    
     if ($target eq 'edit') {
         $result .="<script>\n".
             "if (typeof menu != 'undefined') {menu.currentURL=null;}\n".
@@ -372,6 +383,10 @@ sub registerurl {
     $Apache::lonxml::registered=1;
     my $nothing='';
     if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
+    my $newmail='';
+    if (&Apache::lonmsg::newmail()) { 
+       $newmail='menu.setstatus("you have","got mail");';
+    }
     my $timesync='menu.syncclock(1000*'.time.');';
     if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
         my $hwkadd='';
@@ -401,6 +416,7 @@ ENDPARM
 	  menu=window.open("$nothing","LONCAPAmenu","",false);
           menu.clearTimeout(menu.menucltim);
           $timesync
+          $newmail
 	  menu.currentURL=window.location.pathname;
           menu.reloadURL=window.location.pathname;
           menu.currentStale=0;
@@ -568,8 +584,12 @@ sub latex_special_symbols {
     $current_token=~s/\\/\\char92 /g;
     $current_token=~s/\^/\\char94 /g;
     $current_token=~s/\~/\\char126 /g;
-    $current_token=~s/(&[^a-z#])/\\$1/g;
-    $current_token=~s/([^&]\#)/\\$1/g;
+    $current_token=~s/(&[^a-z\#])/\\$1/g;
+    if ($current_token=~/ \#\w/) {
+	$current_token=~s/ \#(\w)/ \\#$1/;
+    } else {
+	$current_token=~s/([^&])(\#)/$1\\$2/g;
+    }
     $current_token=~s/(\$|_|{|})/\\$1/g;
     $current_token=~s/\\char92 /\\texttt{\\char92}/g;
     $current_token=~s/>/\$>\$/g; #more