--- loncom/xml/lonxml.pm	2002/03/22 17:52:20	1.161
+++ loncom/xml/lonxml.pm	2002/05/16 00:56:46	1.169
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.161 2002/03/22 17:52:20 albertel Exp $
+# $Id: lonxml.pm,v 1.169 2002/05/16 00:56:46 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -60,9 +60,9 @@
 
 package Apache::lonxml; 
 use vars 
-qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace);
+qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $prevent_entity_encode);
 use strict;
-use HTML::TokeParser();
+use HTML::LCParser();
 use HTML::TreeBuilder();
 use HTML::Entities();
 use Safe();
@@ -129,6 +129,9 @@ $evaluate = 1;
 # stores the list of active tag namespaces
 @namespace=();
 
+# if 0 all high ASCII characters will be encoded into HTML Entities
+$prevent_entity_encode=0;
+
 # has the dynamic menu been updated to know about this resource
 $Apache::lonxml::registered=0;
 
@@ -176,10 +179,12 @@ sub xmlend {
                   }
                   my $sender='Anonymous';
                   if ((!$contrib{$idx.':anonymous'}) || ($seeid)) {
-                      $sender=$contrib{$idx.':sendername'}.' at '.
-		      $contrib{$idx.':senderdomain'};
+                      $sender=$contrib{$idx.':plainname'}.' ('.
+                              $contrib{$idx.':sendername'}.' at '.
+		      $contrib{$idx.':senderdomain'}.')';
                       if ($contrib{$idx.':anonymous'}) {
-			  $sender.=' (anonymous)';
+			  $sender.=' [anonymous] '.
+                                     $contrib{$idx.':screenname'};
                       }
                       if ($seeid) {
 			  if ($hidden) {
@@ -190,6 +195,10 @@ sub xmlend {
 				 $symb.':::'.$idx.'">Hide</a>';
 			  }
                       }                   
+                  } else {
+                      if ($contrib{$idx.':screenname'}) {
+			  $sender='<i>'.$contrib{$idx.':screenname'}.'</i>';
+                      }
                   }
 		  $discussion.='<p><b>'.$sender.'</b> ('.
                       localtime($contrib{$idx.':timestamp'}).
@@ -330,26 +339,20 @@ sub registerurl {
     if ($ENV{'browser.type'} eq 'explorer') { $nothing='javascript:void(0);'; }
     if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
         my $hwkadd='';
-        if ($ENV{'REQUEST_URI'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
+        if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
 	    if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
 		$hwkadd.=(<<ENDSUBM);
-                     menu.switchbutton
-           (7,1,'subm.gif','view sub','missions',
-                'gocmd("/adm/grades","submission")');
+                     menu.switchbutton(7,1,'subm.gif','view sub','missions','gocmd("/adm/grades","submission")');
 ENDSUBM
             }
 	    if (&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) {
 		$hwkadd.=(<<ENDGRDS);
-                     menu.switchbutton
-           (7,2,'pgrd.gif','problem','grades',
-                'gocmd("/adm/grades","viewgrades")');
+                     menu.switchbutton(7,2,'pgrd.gif','problem','grades','gocmd("/adm/grades","viewgrades")');
 ENDGRDS
             }
 	    if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
 		$hwkadd.=(<<ENDPARM);
-                     menu.switchbutton
-           (7,3,'pparm.gif','problem','parms',
-                'gocmd("/adm/parmset","set")');
+                     menu.switchbutton(7,3,'pparm.gif','problem','parms','gocmd("/adm/parmset","set")');
 ENDPARM
             }
 	}
@@ -440,10 +443,15 @@ ENDDONOTREGTHIS
 	# Inputs are the name of the html form being used
 	# and the name of the element the selected URL should
 	# be placed in.
+        # openbrowser also takes arguments only and omit, which are
+        # comma deliminated lists of file extensions to (only) show 
+        # or omit.
+        # Here we also set currentURL=null.
         $result .=<<"ENDBROWSERSCRIPT";
 <script>
+    menu.currentURL=null;
     var editbrowser;
-    function openbrowser(formname,elementname) {
+    function openbrowser(formname,elementname,only,omit) {
         var url = '/res/?';
         if (editbrowser == null) {
             url += 'launch=1&';
@@ -451,6 +459,12 @@ ENDDONOTREGTHIS
         url += 'catalogmode=interactive&';
         url += 'mode=edit&';
         url += 'form=' + formname + '&';
+        if (only != null) {
+            url += 'only=' + only + '&';
+        } 
+        if (omit != null) {
+            url += 'omit=' + omit + '&';
+        }
         url += 'element=' + elementname + '';
         var title = 'Browser';
         var options = 'scrollbars=1,resizable=1,menubar=0';
@@ -613,18 +627,22 @@ sub inner_xmlparse {
       #evaluate variable refs in result
       if ($result ne "") {
 	if ( $#$parstack > -1 ) {
-	  if ($Apache::lonxml::redirection) {
-	    $Apache::lonxml::outputstack['-1'] .= 
-	      &Apache::run::evaluate($result,$safeeval,$$parstack['-1']);
-	  } else {
-	    $finaloutput .= &Apache::run::evaluate($result,$safeeval,
-						   $$parstack['-1']);
-	  }
+	  $result=&Apache::run::evaluate($result,$safeeval,$$parstack[-1]);
 	} else {
-	  $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
+	  $result= &Apache::run::evaluate($result,$safeeval,'');
 	}
-	$result = '';
-      } 
+      }
+      # Encode any high ASCII characters
+      if (!$Apache::lonxml::prevent_entity_encode) {
+	$result=&HTML::Entities::encode($result,"\200-\377");
+      }
+      if ($Apache::lonxml::redirection) {
+	$Apache::lonxml::outputstack['-1'] .= $result;
+      } else {
+	$finaloutput.=$result;
+      }
+      $result = '';
+
       if ($token->[0] eq 'E') { 
 	&end_tag($stack,$parstack,$token);
       }
@@ -637,6 +655,7 @@ sub inner_xmlparse {
   #   $finaloutput.=&endredirection;
   # }
 
+
   if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
     $finaloutput=&afterburn($finaloutput);
   }
@@ -808,6 +827,11 @@ sub setup_globals {
     $Apache::lonxml::metamode = 0;
     $Apache::lonxml::evaluate = 0;
     $Apache::lonxml::import = 0;
+  } elsif ($target eq 'analyze') {
+    $Apache::lonxml::redirection = 0;
+    $Apache::lonxml::metamode = 0;
+    $Apache::lonxml::evaluate = 1;
+    $Apache::lonxml::import = 1;
   } else {
     $Apache::lonxml::redirection = 0;
     $Apache::lonxml::metamode = 0;
@@ -981,7 +1005,7 @@ sub get_all_text {
 
 sub newparser {
   my ($parser,$contentref,$dir) = @_;
-  push (@$parser,HTML::TokeParser->new($contentref));
+  push (@$parser,HTML::LCParser->new($contentref));
   $$parser['-1']->xml_mode('1');
   if ( $dir eq '' ) {
     push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
@@ -1225,7 +1249,8 @@ sub debug {
 
 sub error {
   if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
-    print "<b>ERROR:</b>".join('<br />',@_)."<br />\n";
+    # If printing in construction space, put the error inside <pre></pre>
+    print "<b>ERROR:</b>".join("\n",@_)."\n";
   } else {
     print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
     #notify author