--- loncom/xml/lonxml.pm	2002/02/21 04:11:25	1.152
+++ loncom/xml/lonxml.pm	2002/03/18 21:51:34	1.158
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.152 2002/02/21 04:11:25 albertel Exp $
+# $Id: lonxml.pm,v 1.158 2002/03/18 21:51:34 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -64,6 +64,7 @@ qw(@pwd @outputstack $redirection $impor
 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);
@@ -316,6 +317,8 @@ sub fontsettings() {
 
 sub registerurl {
     my $forcereg=shift;
+    my $target = shift;
+    my $result = '';
     if ($ENV{'request.publicaccess'}) {
 	return 
          '<script>function LONCAPAreg(){} function LONCAPAstale(){}</script>';
@@ -347,13 +350,13 @@ ENDGRDS
 ENDPARM
             }
 	}
-	return (<<ENDREGTHIS);
+	$result = (<<ENDREGTHIS);
      
 <script language="JavaScript">
 // BEGIN LON-CAPA Internal
 
     function LONCAPAreg() {
-	  menu=window.open("","LONCAPAmenu");
+	  menu=window.open("","LONCAPAmenu","",false);
           menu.clearTimeout(menu.menucltim);
 	  menu.currentURL=window.location.pathname;
           menu.currentStale=0;
@@ -380,7 +383,7 @@ ENDPARM
     }
 
     function LONCAPAstale() {
-	  menu=window.open("","LONCAPAmenu");
+	  menu=window.open("","LONCAPAmenu","",false);
           menu.currentStale=1;
           menu.switchbutton
              (3,1,'reload.gif','return','location','go(currentURL)');
@@ -399,13 +402,13 @@ ENDPARM
 ENDREGTHIS
 
     } else {
-        return (<<ENDDONOTREGTHIS);
+        $result = (<<ENDDONOTREGTHIS);
 
 <script language="JavaScript">
 // BEGIN LON-CAPA Internal
 
     function LONCAPAreg() {
-	  menu=window.open("","LONCAPAmenu");
+	  menu=window.open("","LONCAPAmenu","",false);
           menu.currentStale=1;
           menu.clearbut(2,1);
           menu.clearbut(2,3);
@@ -426,8 +429,52 @@ ENDREGTHIS
 // END LON-CAPA Internal
 </script>
 ENDDONOTREGTHIS
-
     }
+    if ($target eq 'edit') {
+	# Javascript routines for construction space:
+	# openbrowser and opensearcher will start the file browser
+	# (lonindexer) and searcher (lonsearchcat) respectively.
+	# Inputs are the name of the html form being used
+	# and the name of the element the selected URL should
+	# be placed in.
+        $result .=<<"ENDBROWSERSCRIPT";
+<script>
+    var editbrowser;
+    function openbrowser(formname,elementname) {
+        var url = '/res/?';
+        if (editbrowser == null) {
+            url += 'launch=1&';
+        }
+        url += 'catalogmode=interactive&';
+        url += 'mode=edit&';
+        url += 'form=' + formname + '&';
+        url += 'element=' + elementname + '';
+        var title = 'Browser';
+        var options = 'scrollbars=1,resizable=1,menubar=0';
+        options += ',width=700,height=600';
+        editbrowser = open(url,title,options,'1');
+        editbrowser.focus();
+    }
+    var editsearcher;
+    function opensearcher(formname,elementname) {
+        var url = '/adm/searchcat?';
+        if (editsearcher == null) {
+            url += 'launch=1&';
+        }
+        url += 'catalogmode=interactive&';
+        url += 'mode=edit&';
+        url += 'form=' + formname + '&';
+        url += 'element=' + elementname + '';
+        var title = 'Search';
+        var options = 'scrollbars=1,resizable=1,menubar=0';
+        options += ',width=700,height=600';
+        editsearcher = open(url,title,options,'1');
+        editsearcher.focus();
+    }
+</script>
+ENDBROWSERSCRIPT
+    }
+    return $result;
 }
 
 sub loadevents() {
@@ -978,16 +1025,8 @@ sub writeallows {
 #
 sub afterburn {
     my $result=shift;
-    foreach (split(/&/,$ENV{'QUERY_STRING'})) {
-       my ($name, $value) = split(/=/,$_);
-       $value =~ tr/+/ /;
-       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
-       if (($name eq 'highlight')||($name eq 'anchor')||($name eq 'link')) {
-           unless ($ENV{'form.'.$name}) {
-              $ENV{'form.'.$name}=$value;
-	   }
-       }
-    }
+    &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+					    ['highlight','anchor','link']);
     if ($ENV{'form.highlight'}) {
        foreach (split(/\,/,$ENV{'form.highlight'})) {
            my $anchorname=$_;
@@ -1049,7 +1088,7 @@ SIMPLECONTENT
 
 sub inserteditinfo {
       my ($result,$filecontents)=@_;
-      $filecontents =~ s:</textarea>:&lt;/textarea&gt;:ig;
+      $filecontents = &HTML::Entities::encode($filecontents);
 #      my $editheader='<a href="#editsection">Edit below</a><hr />';
       my $editfooter=(<<ENDFOOTER);
 <hr />
@@ -1075,6 +1114,13 @@ sub get_target {
     if ( defined($ENV{'form.grade_target'})
 	 && ($viewgrades == 'F' )) {
       return ($ENV{'form.grade_target'});
+    } elsif (defined($ENV{'form.grade_target'})) {
+      if (($ENV{'form.grade_target'} eq 'web') ||
+	  ($ENV{'form.grade_target'} eq 'tex') ) {
+	return $ENV{'form.grade_target'}
+      } else {
+	return 'web';
+      }
     } else {
       return 'web';
     }
@@ -1205,6 +1251,7 @@ sub get_param {
   if ( ! $context ) { $context = -1; }
   my $args ='';
   if ( $#$parstack > (-2-$context) ) { $args=$$parstack[$context]; }
+  if ( ! $args ) { return undef; }
   if ( $args =~ /my \$$param=\"/ ) {
     return &Apache::run::run("{$args;".'return $'.$param.'}',$safeeval); #'
   } else {