[LON-CAPA-cvs] cvs: loncom /homework lonhomework.pm structuretags.pm /xml londefdef.pm lonxml.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 09 Mar 2004 20:37:59 -0000


This is a MIME encoded message

--albertel1078864679
Content-Type: text/plain

albertel		Tue Mar  9 15:37:59 2004 EDT

  Modified files:              
    /loncom/homework	lonhomework.pm structuretags.pm 
    /loncom/xml	londefdef.pm lonxml.pm 
  Log:
  - Added &Apache::lonxml::info, for display informational message (saved changes etc.), messages are suppressed when not in CSTR
  - Tryin to address BUG#2305, we were emitting text before the <html> tag (error messages etc.)
     - now exists &Apache::lonxml::message_location() which is used o mark where messages should go
     - &Apache::lonxml::add_messages() which puts the info/warning/error message into the page (And should be called right before display the results of the parse)
     
  - Homework Edit,EditXML, and display modes converted to use this mechanism
  - HTML display and Edit converted to use this
  
  
--albertel1078864679
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20040309153759.txt"

Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.170 loncom/homework/lonhomework.pm:1.171
--- loncom/homework/lonhomework.pm:1.170	Tue Mar  2 15:59:25 2004
+++ loncom/homework/lonhomework.pm	Tue Mar  9 15:37:58 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.170 2004/03/02 20:59:25 matthew Exp $
+# $Id: lonhomework.pm,v 1.171 2004/03/09 20:37:58 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -399,29 +399,29 @@
 	if ((!$error) && (!copy($filebak,$file))) { $error=1; }
 	if ((!$error) && (!move($filetmp,$filebak))) { $error=1; }
 	if (!$error) {
-	    $request->print("<p><b>".&mt("Undid changes, Switched")." $filebak ".&mt("and")." $file</b></p>");
+	    &Apache::lonxml::info("<p><b>".&mt("Undid changes, Switched")." $filebak ".&mt("and")." $file</b></p>");
 	} else {
-	    $request->print("<p><font color=\"red\" size=\"+1\"><b>".&mt("Unable to undo, unable to switch")." $filebak ".&mt("and")." $file</b></font></p>");
+	    &Apache::lonxml::info("<p><font color=\"red\" size=\"+1\"><b>".&mt("Unable to undo, unable to switch")." $filebak ".&mt("and")." $file</b></font></p>");
 	    $error=1;
 	}
     } else {
 	my $fs=Apache::File->new(">$filebak");
 	if (defined($fs)) {
 	    print $fs $$problem;
-	    $request->print("<b>".&mt("Making Backup to").
-			    " $filebak</b><br />");
+	    &Apache::lonxml::info("<b>".&mt("Making Backup to").
+				  " $filebak</b>");
 	} else {
-	    $request->print("<font color=\"red\" size=\"+1\"><b>".&mt("Unable to make backup")." $filebak</b></font>");
+	    &Apache::lonxml::info("<font color=\"red\" size=\"+1\"><b>".&mt("Unable to make backup")." $filebak</b></font>");
 	    $error=2;
 	}
 	my $fh=Apache::File->new(">$file");
 	if (defined($fh)) {
 	    print $fh $$result;
-	    $request->print("<b>".&mt("Saving Modifications to").
-			    " $file</b><br />");
+	    &Apache::lonxml::info("<b>".&mt("Saving Modifications to").
+				  " $file</b>");
 	} else {
-	    $request->print("<font color=\"red\" size=\"+1\"><b>".
-			    &mt("Unable to write to")." $file</b></font>");
+	    &Apache::lonxml::info("<font color=\"red\" size=\"+1\"><b>".
+				  &mt("Unable to write to")." $file</b></font>");
 	    $error|=4;
 	}
     }
@@ -432,7 +432,7 @@
     my ($request) = @_;
     my $result.='<html>
             <head><title>'.&mt("Analyzing a problem").'</title></head>
-            <body bgcolor="#FFFFFF">
+            <body bgcolor="#FFFFFF">'.&Apache::lonxml::message_location().'
             <form name="lonhomework" method="POST" action="'.
 	    $ENV{'request.uri'}.'">
             <input type="submit" name="problemmode" value="'.&mt("EditXML").'" />
@@ -442,6 +442,7 @@
             <hr />
             '.&mt('List of possible answers').':
             </form>';
+    &Apache::lonxml::add_messages(\$result);
     $request->print($result);
     $request->rflush();
 }
@@ -549,7 +550,8 @@
 	if ($cols > 80) { $cols = 80; }
 	if ($cols < 70) { $cols = 70; }
 	if ($rows < 20) { $rows = 20; }
-	$result.='<html><body bgcolor="#FFFFFF">
+	$result.='<html><body bgcolor="#FFFFFF">'.
+	    &Apache::lonxml::message_location().'
             <form name="lonhomework" method="POST" action="'.
 	    $ENV{'request.uri'}.'">
             <input type="hidden" name="problemmode" value="'.&mt('EditXML').'" />
@@ -564,6 +566,7 @@
             <textarea rows="'.$rows.'" cols="'.$cols.'" name="editxmltext">'.
 	    &HTML::Entities::encode($problem).'</textarea>
             </form></body></html>';
+	&Apache::lonxml::add_messages(\$result);
 	$request->print($result);
     }
     return '';
@@ -575,6 +578,7 @@
     my (@targets) = &get_target();
     &Apache::lonhomework::showhashsubset(\%ENV,'form.');
     &Apache::lonxml::debug("Running targets ".join(':',@targets));
+    my $overall_result;
     foreach my $target (@targets) {
 	#my $t0 = [&gettimeofday()];
 	my $problem=&Apache::lonnet::getfile($file);
@@ -606,12 +610,16 @@
 	    #$result =~ s:</body>::;
 	    #$result.="<br />Spent $td seconds processing target $target\n</body>";
 	    #}
-	    $request->print($result);
-	    $request->rflush();
+#	    $request->print($result);
+	    $overall_result.=$result;
+#	    $request->rflush();
 	}
 	#$request->print(":Result ends");
 	#my $td=&tv_interval($t0);
     }
+    &Apache::lonxml::add_messages(\$overall_result);
+    $request->print($overall_result);   
+    $request->rflush();   
 }
 
 # with no arg it returns a HTML <option> list of the template titles
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.244 loncom/homework/structuretags.pm:1.245
--- loncom/homework/structuretags.pm:1.244	Mon Mar  8 18:18:21 2004
+++ loncom/homework/structuretags.pm	Tue Mar  9 15:37:58 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.244 2004/03/08 23:18:21 albertel Exp $
+# $Id: structuretags.pm,v 1.245 2004/03/09 20:37:58 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -120,6 +120,7 @@
 		$body_tag_start.=$help;
 	    }
 	}
+	$body_tag_start.=&Apache::lonxml::message_location();
     }
     my $form_tag_start;
     if (!defined($found{'form'})) {
@@ -481,9 +482,9 @@
 		$result.= $head_tag_start.'</head>';
 		my $msg=$body_tag_start;
 		if ($status eq 'UNAVAILABLE') {
-		    $result.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
+		    $msg.='<h1>'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'</h1>';
 		} else {
-		    $result.='<h1>'.&mt('Not open to be viewed').'</h1>';
+		    $msg.='<h1>'.&mt('Not open to be viewed').'</h1>';
 		}
 		if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
 		    $msg.='The problem '.$accessmsg;
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.200 loncom/xml/londefdef.pm:1.201
--- loncom/xml/londefdef.pm:1.200	Tue Mar  2 15:59:24 2004
+++ loncom/xml/londefdef.pm	Tue Mar  9 15:37:58 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.200 2004/03/02 20:59:24 matthew Exp $
+# $Id: londefdef.pm,v 1.201 2004/03/09 20:37:58 albertel Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -541,6 +541,7 @@
 	} else {
 	    $currentstring.=&Apache::lonmenu::menubuttons(undef,$target,1);
 	}
+	$currentstring.=&Apache::lonxml::message_location();
     } elsif ($target eq 'tex') {
 	$currentstring = '\begin{document}';  
     } 
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.308 loncom/xml/lonxml.pm:1.309
--- loncom/xml/lonxml.pm:1.308	Thu Mar  4 18:01:31 2004
+++ loncom/xml/lonxml.pm	Tue Mar  9 15:37:58 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.308 2004/03/04 23:01:31 albertel Exp $
+# $Id: lonxml.pm,v 1.309 2004/03/09 20:37:58 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1237,8 +1237,10 @@
     unless ($ENV{'request.state'} eq 'published') {
 	if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {
 	    if (&storefile($file,$ENV{'form.filecont'})) {
-		$request->print("<font COLOR=\"#0000FF\">".&mt('Updated').": ".
-&Apache::lonlocal::locallocaltime(time)." </font>");
+		&Apache::lonxml::info("<font COLOR=\"#0000FF\">".
+				      &mt('Updated').": ".
+				      &Apache::lonlocal::locallocaltime(time).
+				      " </font>");
 	    } 
 	}
     }
@@ -1290,7 +1292,9 @@
 	if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
 	    my $displayfile=$request->uri;
 	    $displayfile=~s/^\/[^\/]*//;
-	    $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.
+	    $result='<html><body bgcolor="#FFFFFF">'.
+		&Apache::lonxml::message_location().'<h3>'.
+		$displayfile.
 		'</h3></body></html>';
 	    $result=&inserteditinfo($result,$filecontents,$filetype);
 	}
@@ -1298,7 +1302,7 @@
     if ($filetype eq 'html') { writeallows($request->uri); }
 	
     
-
+    &Apache::lonxml::add_messages(\$result);
     $request->print($result);
     
     return OK;
@@ -1332,11 +1336,13 @@
   if (!$request) { $request=Apache->request; }
   if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) {
     # If printing in construction space, put the error inside <pre></pre>
-      $request->print($Apache::lonxml::warnings_error_header.
-		      "<b>ERROR:</b>".join("<br />\n",@_)."<br />\n");
+      push(@Apache::lonxml::error_messages,
+	   $Apache::lonxml::warnings_error_header.
+	   "<b>ERROR:</b>".join("<br />\n",@_)."<br />\n");
       $Apache::lonxml::warnings_error_header='';
   } else {
-    $request->print("<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />");
+      push(@Apache::lonxml::error_messages,
+	   "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />");
     #notify author
     &Apache::lonmsg::author_res_msg($ENV{'request.filename'},join('<br />',@_));
     #notify course
@@ -1359,11 +1365,36 @@
 	if ($ENV{'request.state'} eq 'construct' || $Apache::lonxml::debug) {
 	    my $request=$Apache::lonxml::request;
 	    if (!$request) { $request=Apache->request; }
-	    $request->print($Apache::lonxml::warnings_error_header.
-		      "<b>W</b>ARNING<b>:</b>".join('<br />',@_)."<br />\n");
+	    push(@Apache::lonxml::warning_messages,
+		 $Apache::lonxml::warnings_error_header.
+		 "<b>W</b>ARNING<b>:</b>".join('<br />',@_)."<br />\n");
 	    $Apache::lonxml::warnings_error_header='';
 	}
     }
+}
+
+sub info {
+    if ($ENV{'form.grade_target'} ne 'tex' 
+	&& $ENV{'request.state'} eq 'construct') {
+	push(@Apache::lonxml::info_messages,join('<br />',@_)."<br />\n");
+    }
+}
+
+sub message_location {
+    return '__LONCAPA_INTERNAL_MESSAGE_LOCATION__';
+}
+
+sub add_messages {
+    my ($msg)=@_;
+    my $result=join(' ',
+		    @Apache::lonxml::info_messages,
+		    @Apache::lonxml::error_messages,
+		    @Apache::lonxml::warning_messages);
+    undef(@Apache::lonxml::info_messages);
+    undef(@Apache::lonxml::error_messages);
+    undef(@Apache::lonxml::warning_messages);
+    $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__/$result/;
+    $$msg=~s/__LONCAPA_INTERNAL_MESSAGE_LOCATION__//g;
 }
 
 sub get_param {

--albertel1078864679--