--- loncom/xml/lonxml.pm	2002/05/24 20:51:55	1.174
+++ loncom/xml/lonxml.pm	2002/08/28 17:07:54	1.189
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.174 2002/05/24 20:51:55 www Exp $
+# $Id: lonxml.pm,v 1.189 2002/08/28 17:07:54 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -176,6 +176,7 @@ sub xmlend {
 		unless (($hidden) && (!$seeid)) {
                  my $message=$contrib{$idx.':message'};
                  $message=~s/\n/\<br \/\>/g;
+		 $message=&Apache::lontexconvert::msgtexconverted($message);
                  if ($message) {
                   if ($hidden) {
 		      $message='<font color="#888888">'.$message.'</font>';
@@ -331,16 +332,23 @@ sub registerurl {
     my $forcereg=shift;
     my $target = shift;
     my $result = '';
-    if (($ENV{'request.publicaccess'}) || 
-       (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) {
-	return 
+    if ($target eq 'edit') {
+        $result .="<script>\n".
+            "if (typeof menu != 'undefined') {menu.currentURL=null;}\n".
+            &Apache::loncommon::browser_and_searcher_javascript().
+                "\n</script>\n";
+    }
+    if ((($ENV{'request.publicaccess'}) || 
+         (!&Apache::lonnet::is_on_map($ENV{'REQUEST_URI'}))) &&
+        (!$forcereg)) {
+	return $result.
          '<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);'; }
-    my $timesync='menu.clock.setTime(1000*'.time.');';
+    my $timesync='menu.syncclock(1000*'.time.');';
     if (($ENV{'REQUEST_URI'}!~/^\/(res\/)*adm\//) || ($forcereg)) {
         my $hwkadd='';
         if ($ENV{'request.filename'}=~/\.(problem|exam|quiz|assess|survey|form)$/) {
@@ -370,6 +378,7 @@ ENDPARM
           menu.clearTimeout(menu.menucltim);
           $timesync
 	  menu.currentURL=window.location.pathname;
+          menu.reloadURL=window.location.pathname;
           menu.currentStale=0;
           menu.clearbut(3,1);
           menu.switchbutton
@@ -377,7 +386,7 @@ ENDPARM
           menu.switchbutton
        (8,1,'eval.gif','evaluate','this','gopost("/adm/evaluate",currentURL)');
           menu.switchbutton
-    (8,2,'fdbk.gif','feedback','on this','gopost("/adm/feedback",currentURL)');
+    (8,2,'fdbk.gif','feedback','discuss','gopost("/adm/feedback",currentURL)');
           menu.switchbutton
      (8,3,'prt.gif','prepare','printout','gopost("/adm/printout",currentURL)');
           menu.switchbutton
@@ -396,8 +405,10 @@ ENDPARM
     function LONCAPAstale() {
 	  menu=window.open("$nothing","LONCAPAmenu","",false);
           menu.currentStale=1;
-          menu.switchbutton
-             (3,1,'reload.gif','return','location','go(currentURL)');
+          if (menu.reloadURL!='' && menu.reloadURL!= null) { 
+             menu.switchbutton
+             (3,1,'reload.gif','return','location','go(reloadURL)');
+	  }
           menu.clearbut(7,1);
           menu.clearbut(7,2);
           menu.clearbut(7,3);
@@ -442,61 +453,6 @@ ENDREGTHIS
 </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.
-        # 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,only,omit) {
-        var url = '/res/?';
-        if (editbrowser == null) {
-            url += 'launch=1&';
-        }
-        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';
-        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;
 }
 
@@ -520,6 +476,23 @@ sub xmlparse {
  my ($request,$target,$content_file_string,$safeinit,%style_for_target) = @_;
 
  &setup_globals($request,$target);
+#
+# do we have a course style file?
+#
+
+ if ($ENV{'request.course.id'}) {
+     my $bodytext=
+	 $ENV{'course.'.$ENV{'request.course.id'}.'.default_xml_style'};
+     if ($bodytext) {
+       my $location=&Apache::lonnet::filelocation('',$bodytext);
+       my $styletext=&Apache::lonnet::getfile($location);
+       if ($styletext ne '-1') {
+          %style_for_target = (%style_for_target,
+                          &Apache::style::styleparser($target,$styletext));
+       }
+    }
+ }
+
  #&printalltags();
  my @pars = ();
  my $pwd=$ENV{'request.filename'};
@@ -566,6 +539,24 @@ sub htmlclean {
     return $output;
 }
 
+sub latex_special_sumbols {
+    my ($current_token,$stack,$parstack)=@_;
+    my @temp_array = @$stack;
+    if ($temp_array[-1] ne 'tt') {
+	if ($current_token=~m/\^/) {$current_token=~s/\^/\\verb|\^|/g;}
+    } else {
+	if ($current_token=~m/\^/) {$current_token=~s/\^/}\\verb|\^|{/g;}
+    }
+    if ($current_token=~m/>/) {$current_token=~s/>/\$>\$/g;} #more
+    if ($current_token=~m/</) {$current_token=~s/</\$<\$/g;} #less
+    if ($current_token=~m/\d%/) {$current_token =~ s/%/\\%/g;} #percent after digit
+    if ($current_token=~m/\s%/) {$current_token =~ s/%/\\%/g;} #persent after space
+
+
+#    $current_token = ' start='.$current_token.'=finish ';
+    return $current_token;
+}
+
 sub inner_xmlparse {
   my ($target,$stack,$parstack,$pars,$safeeval,$style_for_target)=@_;
   my $finaloutput = '';
@@ -575,7 +566,16 @@ sub inner_xmlparse {
     while ($token = $$pars['-1']->get_token) {
       if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
 	if ($metamode<1) {
-	  $result=$token->[1];
+	    if ($target eq 'tex') {
+		my $text=$token->[1];
+		if ($token->[0] eq 'C') {
+		    $text = '%'.$text;
+		    $text =~ s/[\n\r]//g;
+		}
+		$result.=&latex_special_sumbols($text,$stack,$parstack);
+	    } else {
+		$result.=$token->[1];
+	    }
 	}
       } elsif ($token->[0] eq 'PI') {
 	if ($metamode<1) {
@@ -764,13 +764,13 @@ sub callsub {
     }
     if (!$deleted) {
       if ($space) {
-	#&Apache::lonxml::debug("Calling sub $sub in $space $metamode");
+	&Apache::lonxml::debug("Calling sub $sub in $space $metamode");
 	$sub1="$space\:\:$sub";
 	($currentstring,$nodefault) = &$sub1($target,$token,$tagstack,
 					     $parstack,$parser,$safeeval,
 					     $style);
       } else {
-	#&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");
+	&Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode");
 	if ($metamode <1) {
 	  if (defined($token->[4]) && ($metamode < 1)) {
 	    $currentstring = $token->[4];
@@ -962,8 +962,34 @@ sub decreasedepth {
 #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
 }
 
-sub get_all_text {
+sub get_all_text_unbalanced {
+ my($tag,$pars)= @_;
+ my $token;
+ my $result='';
+ $tag='<'.$tag.'>';
+ while ($token = $$pars[-1]->get_token) {
+   if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
+     $result.=$token->[1];
+   } elsif ($token->[0] eq 'PI') {
+     $result.=$token->[2];
+   } elsif ($token->[0] eq 'S') {
+     $result.=$token->[4];
+   } elsif ($token->[0] eq 'E')  {
+     $result.=$token->[2];
+   }
+   if ($result =~ /(.*)$tag(.*)/) {
+     &Apache::lonxml::debug('Got a winner with leftovers ::'.$2);
+     &Apache::lonxml::debug('Result is :'.$1);
+     $result=$1;
+     my $redo=$tag.$2;
+     &Apache::lonxml::newparser($pars,\$redo);
+     last;
+   }
+ }
+ return $result
+}
 
+sub get_all_text {
  my($tag,$pars)= @_;
  my $depth=0;
  my $token;
@@ -1236,7 +1262,10 @@ ENDNOTFOUND
 #
   unless ($ENV{'request.state'} eq 'published') {
     if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
-      $result='<html><body bgcolor="#FFFFFF"></body></html>';
+	my $displayfile=$request->uri;
+        $displayfile=~s/^\/[^\/]*//;
+      $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.
+              '</h3></body></html>';
       $result=&inserteditinfo($result,$filecontents);
     }
   }
@@ -1251,7 +1280,7 @@ ENDNOTFOUND
 sub debug {
   if ($Apache::lonxml::debug eq 1) {
     $|=1;
-    print("DEBUG:".join('<br />',@_)."<br />\n");
+    print("DEBUG:".&HTML::Entities::encode($_[0])."<br />\n");
   }
 }