--- loncom/xml/lonxml.pm	2002/03/14 20:30:36	1.157
+++ loncom/xml/lonxml.pm	2002/04/10 14:46:30	1.166
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.157 2002/03/14 20:30:36 albertel Exp $
+# $Id: lonxml.pm,v 1.166 2002/04/10 14:46:30 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -62,14 +62,14 @@ package Apache::lonxml;
 use vars 
 qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace);
 use strict;
-use HTML::TokeParser;
-use HTML::TreeBuilder;
-use HTML::Entities;
-use Safe;
-use Safe::Hole;
-use Math::Cephes qw(:trigs :hypers :bessels erf erfc);
-use Math::Random qw(:all);
-use Opcode;
+use HTML::TokeParser();
+use HTML::TreeBuilder();
+use HTML::Entities();
+use Safe();
+use Safe::Hole();
+use Math::Cephes();
+use Math::Random();
+use Opcode();
 
 sub register {
   my ($space,@taglist) = @_;
@@ -90,15 +90,15 @@ sub deregister {
 }
 
 use Apache::Constants qw(:common);
-use Apache::lontexconvert;
-use Apache::style;
-use Apache::run;
-use Apache::londefdef;
-use Apache::scripttag;
-use Apache::edit;
-use Apache::lonnet;
-use Apache::File;
-use Apache::loncommon;
+use Apache::lontexconvert();
+use Apache::style();
+use Apache::run();
+use Apache::londefdef();
+use Apache::scripttag();
+use Apache::edit();
+use Apache::lonnet();
+use Apache::File();
+use Apache::loncommon();
 
 #==================================================   Main subroutine: xmlparse  
 #debugging control, to turn on debugging modify the correct handler
@@ -176,10 +176,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 +192,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'}).
@@ -319,12 +325,15 @@ sub registerurl {
     my $forcereg=shift;
     my $target = shift;
     my $result = '';
-    if ($ENV{'request.publicaccess'}) {
+    if (($ENV{'request.publicaccess'}) || 
+       ($ENV{'REQUEST_URI'} eq '/res/adm/pages/menu.html')) {
 	return 
          '<script>function LONCAPAreg(){} function LONCAPAstale(){}</script>';
     }
     if ($Apache::lonxml::registered && !$forcereg) { return ''; }
     $Apache::lonxml::registered=1;
+    my $nothing='';
+    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)$/) {
@@ -356,7 +365,7 @@ ENDPARM
 // BEGIN LON-CAPA Internal
 
     function LONCAPAreg() {
-	  menu=window.open("","LONCAPAmenu");
+	  menu=window.open("$nothing","LONCAPAmenu","",false);
           menu.clearTimeout(menu.menucltim);
 	  menu.currentURL=window.location.pathname;
           menu.currentStale=0;
@@ -383,7 +392,7 @@ ENDPARM
     }
 
     function LONCAPAstale() {
-	  menu=window.open("","LONCAPAmenu");
+	  menu=window.open("$nothing","LONCAPAmenu","",false);
           menu.currentStale=1;
           menu.switchbutton
              (3,1,'reload.gif','return','location','go(currentURL)');
@@ -408,7 +417,7 @@ ENDREGTHIS
 // BEGIN LON-CAPA Internal
 
     function LONCAPAreg() {
-	  menu=window.open("","LONCAPAmenu");
+	  menu=window.open("$nothing","LONCAPAmenu","",false);
           menu.currentStale=1;
           menu.clearbut(2,1);
           menu.clearbut(2,3);
@@ -437,10 +446,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&';
@@ -448,6 +462,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';
@@ -532,7 +552,7 @@ sub htmlclean {
 
     my $output= $tree->as_HTML(undef,' ');
 
-    $output=~s/\<(br|hr|img|meta|allow)([^\>\/]*)\>/\<$1$2 \/\>/gis;
+    $output=~s/\<(br|hr|img|meta|allow)(.*?)\>/\<$1$2 \/\>/gis;
     $output=~s/\<\/(br|hr|img|meta|allow)\>//gis;
     unless ($full) {
        $output=~s/\<[\/]*(body|head|html)\>//gis;
@@ -621,7 +641,7 @@ sub inner_xmlparse {
 	  $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
 	}
 	$result = '';
-      } 
+      }
       if ($token->[0] eq 'E') { 
 	&end_tag($stack,$parstack,$token);
       }
@@ -805,6 +825,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;
@@ -980,6 +1005,7 @@ sub newparser {
   my ($parser,$contentref,$dir) = @_;
   push (@$parser,HTML::TokeParser->new($contentref));
   $$parser['-1']->xml_mode('1');
+#  $$parser['-1']->attr_encoded('1');
   if ( $dir eq '' ) {
     push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
   } else {
@@ -1090,17 +1116,21 @@ sub inserteditinfo {
       my ($result,$filecontents)=@_;
       $filecontents = &HTML::Entities::encode($filecontents);
 #      my $editheader='<a href="#editsection">Edit below</a><hr />';
+      my $buttons=(<<BUTTONS);
+<input type="submit" name="attemptclean" 
+       value="Save and then attempt to clean HTML" />
+<input type="submit" name="savethisfile" value="Save this" />
+<input type="submit" name="viewmode" value="View" />
+BUTTONS
       my $editfooter=(<<ENDFOOTER);
 <hr />
 <a name="editsection" />
 <form method="post">
+<input type="hidden" name="editmode" value="Edit" />
+$buttons
 <textarea cols="80" rows="40" name="filecont">$filecontents</textarea>
+$buttons
 <br />
-<input type="hidden" name="showmode" value="Edit" />
-<input type="submit" name="attemptclean" 
-       value="Save and then attempt to clean HTML" />
-<input type="submit" name="savethisfile" value="Save this" />
-<input type="submit" name="showmode" value="View" />
 </form>
 ENDFOOTER
 #      $result=~s/(\<body[^\>]*\>)/$1$editheader/is;
@@ -1179,7 +1209,7 @@ ENDNOTFOUND
     $filecontents='';
     if ($ENV{'request.state'} ne 'published') {
       $filecontents=&createnewhtml();
-      $ENV{'form.showmode'}='Edit'; #force edit mode
+      $ENV{'form.editmode'}='Edit'; #force edit mode
     }
   } else {
     unless ($ENV{'request.state'} eq 'published') {
@@ -1187,7 +1217,7 @@ ENDNOTFOUND
 	$filecontents=&htmlclean($filecontents,1);
       }
     }
-    if ($ENV{'form.showmode'} ne 'Edit') {
+    if (!$ENV{'form.editmode'} || $ENV{'form.viewmode'}) {
       $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
     }
   }
@@ -1196,7 +1226,7 @@ ENDNOTFOUND
 # Edit action? Insert editing commands
 #
   unless ($ENV{'request.state'} eq 'published') {
-    if ($ENV{'form.showmode'} eq 'Edit') {
+    if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
       $result='<html><body bgcolor="#FFFFFF"></body></html>';
       $result=&inserteditinfo($result,$filecontents);
     }
@@ -1218,7 +1248,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><pre>".join("\n",@_)."</pre>\n";
   } else {
     print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
     #notify author