--- loncom/homework/response.pm	2005/11/15 15:57:45	1.129
+++ loncom/homework/response.pm	2006/03/08 22:16:28	1.136
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # various response type definitons response definition
 #
-# $Id: response.pm,v 1.129 2005/11/15 15:57:45 albertel Exp $
+# $Id: response.pm,v 1.136 2006/03/08 22:16:28 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -37,8 +37,7 @@ BEGIN {
 
 sub start_response {
     my ($parstack,$safeeval)=@_;
-    my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
-    if ($id eq '') { $id = $Apache::lonxml::curdepth; }
+    my $id = &Apache::lonxml::get_id($parstack,$safeeval);
     if ($#Apache::inputtags::import > -1) {
 	&Apache::lonxml::debug("Turning :$id: into");
 	$id = join('_',@Apache::inputtags::import).'_'.$id;
@@ -69,8 +68,7 @@ sub end_response {
 
 sub start_hintresponse {
     my ($parstack,$safeeval)=@_;
-    my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
-    if ($id eq '') { $id = $Apache::lonxml::curdepth; }
+    my $id = &Apache::lonxml::get_id($parstack,$safeeval);
     push (@Apache::inputtags::hint,$id);
     push (@Apache::inputtags::hintlist,$id);
     push (@Apache::inputtags::paramstack,[%Apache::inputtags::params]);
@@ -592,15 +590,30 @@ sub setup_params {
     }
 }
 
+{
+    my @answer_bits;
+
 sub answer_header {
-    my ($type) = @_;
+    my ($type,$increment) = @_;
     my $result;
     if ($env{'form.answer_output_mode'} eq 'tex') {
-	$result = ' \vskip 0 mm \begin{tabular}{|c|}\hline Answer for Part: \verb|'.
-                  $Apache::inputtags::part.'| \\\\ \hline ';
+	undef(@answer_bits);
+	my $bit;
+	if ($Apache::lonhomework::type eq 'exam') {
+	    $bit = ($Apache::lonxml::counter+$increment).') ';
+	} else {
+	    $bit .= ' Answer for Part: \verb|'.
+		$Apache::inputtags::part.'| ';
+	}
+	push(@answer_bits,$bit);
     } else {
-	$result = '<table border="1"><tr><td>Answer for Part:'.
-	    $Apache::inputtags::part. '</td>'."\n";
+	$result  = '<table border="1"><tr>';
+	if ($Apache::lonhomework::type eq 'exam') {
+	    $result .= '<td>'.$Apache::lonxml::counter. ')</td>';
+	} else {
+	    $result .= '<td>Answer for Part:'.$Apache::inputtags::part.'</td>';
+	}
+	$result .= "\n";
     }
     return $result;
 }
@@ -617,7 +630,9 @@ sub answer_part {
 		last;
 	    }
 	}
-	$result = '\verb'.$to_use.$answer.$to_use.'\\\\ \hline ';
+	if ($answer ne '') {
+	    push(@answer_bits,'\verb'.$to_use.$answer.$to_use);
+	}
     } else {
 	$result = '<td>'.$answer.'</td>';
     }
@@ -628,13 +643,18 @@ sub answer_footer {
     my ($type) = @_;
     my $result;
     if ($env{'form.answer_output_mode'} eq 'tex') {
-	$result = ' \end{tabular} \vskip 0 mm ';
+	my $columns = scalar(@answer_bits);
+	$result  = ' \vskip 0 mm \noindent \begin{tabular}{|'.'c|'x$columns.'}\hline ';
+	$result .= join(' & ',@answer_bits);
+	$result .= ' \\\\ \\hline \end{tabular} \vskip 0 mm ';
     } else {
 	$result = '</tr></table>';
     }
     return $result;
 }
 
+}
+
 sub showallfoils {
     if (defined($env{'form.showallfoils'})) {
 	my ($symb)=&Apache::lonxml::whichuser();
@@ -858,6 +878,29 @@ sub submitted {
     return 0;
 }
 
+sub add_to_gradingqueue {
+    my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
+    if (   $courseid eq ''
+	|| $symb eq ''
+	|| $env{'request.state'} eq 'construct'
+	|| $Apache::lonhomework::type ne 'problem') {
+	return;
+    }
+
+    my %queue_info = ( 'type' => 'problem',
+		       'time' => time);
+
+    if (exists($Apache::lonhomework::history{"resource.0.checkedin.slot"})) {
+	$queue_info{'slot'}=
+	     $Apache::lonhomework::history{"resource.0.checkedin.slot"};
+    }
+
+    my $result=&Apache::bridgetask::add_to_queue('gradingqueue',\%queue_info);
+    if ($result ne 'ok') {
+	&Apache::lonxml::error("add_to_queue said $result");
+    }
+}
+
 # basically undef and 0 (both false) mean that they still have work to do
 # and all true values mean that they can't do any more work
 #