[LON-CAPA-cvs] cvs: loncom /homework lonhomework.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 13 Jul 2005 19:48:08 -0000


albertel		Wed Jul 13 15:48:08 2005 EDT

  Modified files:              
    /loncom/homework	lonhomework.pm 
  Log:
  - BUG#4218 - editxml needs to save then render for error messages
  
  
Index: loncom/homework/lonhomework.pm
diff -u loncom/homework/lonhomework.pm:1.212 loncom/homework/lonhomework.pm:1.213
--- loncom/homework/lonhomework.pm:1.212	Tue Jul 12 17:50:05 2005
+++ loncom/homework/lonhomework.pm	Wed Jul 13 15:48:07 2005
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Homework handler
 #
-# $Id: lonhomework.pm,v 1.212 2005/07/12 21:50:05 albertel Exp $
+# $Id: lonhomework.pm,v 1.213 2005/07/13 19:48:07 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -711,7 +711,9 @@
 	    $bodytag=&Apache::loncommon::bodytag();
 	}
 	my $html=&Apache::lonxml::xmlbegin();
-	$result.=$html.$bodytag.&Apache::lonxml::message_location().'
+	$result.=$html.$bodytag.
+	    &renderpage($request,$file,['no_output_web'],1).
+	    &Apache::lonxml::message_location().'
             <form name="lonhomework" method="POST" action="'.
 	    &HTML::Entities::encode($env{'request.uri'},'<>&"').'">'.
 	    &Apache::structuretags::remember_problem_state().'
@@ -737,7 +739,7 @@
 #    Render the page in whatever target desired.
 #
 sub renderpage {
-    my ($request,$file,$targets) = @_;
+    my ($request,$file,$targets,$return_string) = @_;
 
     my @targets = @{$targets || [&get_target()]};
     &Apache::lonhomework::showhashsubset(\%env,'form.');
@@ -771,7 +773,7 @@
 	my $result = &Apache::lonxml::xmlparse($request, $target, $problem,
 					       &setup_vars($target),%mystyle);
 	undef($Apache::lonhomework::parsing_a_problem);
-	if (!$output) { $result = &Apache::lonxml::message_location(); }
+	if (!$output) { $result = '';&Apache::lonxml::message_location().'c'; }
 	#$request->print("Result follows:");
 	if ($target eq 'modified') {
 	    &handle_save_or_undo($request,\$problem,\$result);
@@ -792,9 +794,13 @@
 	#$request->print(":Result ends");
 	#my $td=&tv_interval($t0);
     }
-    &Apache::lonxml::add_messages(\$overall_result);
-    $request->print($overall_result);   
-    $request->rflush();   
+    if (!$return_string) {
+	&Apache::lonxml::add_messages(\$overall_result);
+	$request->print($overall_result);   
+	$request->rflush();   
+    } else {
+	return $overall_result;
+    }
 }
 
 # with no arg it returns a HTML <option> list of the template titles
@@ -956,7 +962,6 @@
 		&renderpage($request,$file);
 	    } elsif ($env{'form.problemmode'} eq &mt('EditXML') ||
 		     $env{'form.problemmode'} eq 'EditXML') {
-		&renderpage($request,$file,['no_output_web']);
 		&editxmlmode($request,$file);
 	    } elsif ($env{'form.problemmode'} eq &mt('Calculate answers')) {
 		&analyze($request,$file);