--- loncom/xml/lonxml.pm	2005/11/10 21:38:27	1.388
+++ loncom/xml/lonxml.pm	2005/12/06 10:21:18	1.391
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.388 2005/11/10 21:38:27 albertel Exp $
+# $Id: lonxml.pm,v 1.391 2005/12/06 10:21:18 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -272,13 +272,7 @@ sub printtokenheader {
         $tcrsid=$courseid;
     }
 
-    my %reply=&Apache::lonnet::get('environment',
-              ['firstname','middlename','lastname','generation'],
-              $tudom,$tuname);
-    my $plainname=$reply{'firstname'}.' '. 
-                  $reply{'middlename'}.' '.
-                  $reply{'lastname'}.' '.
-		  $reply{'generation'};
+    my $plainname=&Apache::loncommon::plainname($tuname,$tudom);
 
     if ($target eq 'web') {
         my %idhash=&Apache::lonnet::idrget($tudom,($tuname));
@@ -418,6 +412,7 @@ sub inner_xmlparse {
   my $result;
   my $token;
   my $dontpop=0;
+  my $startredirection = $Apache::lonxml::redirection;
   while ( $#$pars > -1 ) {
     while ($token = $$pars['-1']->get_token) {
       if (($token->[0] eq 'T') || ($token->[0] eq 'C') ) {
@@ -528,10 +523,9 @@ sub inner_xmlparse {
   # }
 
   if ($target eq 'grade') { &endredirection(); }
-  if ( $Apache::lonxml::redirection ) {
-      &error("Unclean exit of parser, text still being redirected. This is likely due to there being missing end tags.");
-      while ($Apache::lonxml::redirection) {
-	  $finaloutput.=&endredirection();
+  if ( $Apache::lonxml::redirection > $startredirection) {
+      while ($Apache::lonxml::redirection > $startredirection) {
+	  $finaloutput .= &endredirection();
       }
   }
   if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
@@ -967,7 +961,10 @@ sub increment_counter {
 }
 
 sub init_counter {
-    if (defined($env{'form.counter'})) {
+    if ($env{'request.state'} eq 'construct') {
+	$Apache::lonxml::counter=1;
+	$Apache::lonxml::counter_changed=1;
+    } elsif (defined($env{'form.counter'})) {
 	$Apache::lonxml::counter=$env{'form.counter'};
 	$Apache::lonxml::counter_changed=0;
     } else {