Index: multichoice.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/quiz/multichoice.module,v
retrieving revision 1.30
diff -u -r1.30 multichoice.module
--- multichoice.module	20 Sep 2006 14:03:40 -0000	1.30
+++ multichoice.module	25 Sep 2006 21:28:58 -0000
@@ -281,8 +281,7 @@
 function multichoice_view(&$node, $teaser = FALSE, $page = FALSE) {
   if (user_access('create multichoice')) {
     if (!$teaser) {
-      $question = multichoice_render_question($node);
-      $node->body .= $question;
+      $node->body = multichoice_render_question($node);
     }
   }
   else if ($teaser) {
@@ -342,7 +341,7 @@
   $form['tries'] = array(
     '#type' => $type,
     '#options' => $options,
-    '#default_value' => NULL,
+    '#default_value' => -1,
   );
   $form['submit'] = array(
     '#type' => 'submit',
@@ -385,10 +384,14 @@
       $results['tried'][] = $question->answers[$_POST['edit']['tries']]['aid'];
     }
   }
-
+  //Unset $_POST, otherwise it tries to use the previous answers on the next page...
+  unset($_POST);
+  
+  //Return the result
   return $results;
 }
 
+//Old claculate result function
 function multichoice_calculate_result($answers, $tried) {
   while(list($key, $answer) = each($answers)) {
     if ($answer['points'] == 1) {
@@ -411,6 +414,35 @@
   return 1;
 }
 
+//New singing and dancing one
+function multichoice_calculate_results($answers, $tried, $showPoints = FALSE, $showFeedback = FALSE) {
+  //Create results table
+  $rows = array();
+  $correctAnswers = array();
+  
+  while(list($key, $answer) = each($answers)) {
+    $cols = array();
+    
+    $cols[] = $answer['answer'];
+    if($showPoints) $cols[] = (($answer['points'] == 0)?'Correct':'Incorrect');
+    $isSelected = (array_search($answer['aid'], $tried) !== FALSE);
+    $cols[] = ($isSelected?'Selected':'Deselected');
+    if($showFeedback) $cols[] = ($isSelected?$answer['feedback']:'');
+  
+    $rows[] = $cols;
+  
+  	
+  	if($answer['points'] > 0) {
+  	  $correctAnswers[] = $answer['aid'];
+  	}
+  }
+
+  
+  if($correctAnswers === $tried) { $score = 1; } else { $score = 0; }
+  
+  return array('score' => $score, 'resultstable' => $rows);
+}
+
 
 
 /**
Index: quiz.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/quiz/quiz.module,v
retrieving revision 1.66
diff -u -r1.66 quiz.module
--- quiz.module	20 Sep 2006 14:03:40 -0000	1.66
+++ quiz.module	25 Sep 2006 21:28:58 -0000
@@ -349,7 +349,6 @@
 
   if (arg(0) == 'node' && is_numeric(arg(1)) && user_access('access quizzes')) {
     if ($quiz = node_load(arg(1))) {
-
       if (!isset($_SESSION['quiz_questions'])) {
 
         // First time running through quiz
@@ -370,9 +369,14 @@
 
       // Check for answer submission
       if ($_POST['op'] == t('Submit')) {
-        $former_question = node_load(array('nid' => array_shift($_SESSION['quiz_questions'])));
-        $result = module_invoke($former_question->type, 'evaluate_question', $former_question->nid);
-        db_query("REPLACE {quiz_question_results} VALUES(%d, %d, '%s')", $_SESSION['rid'], $former_question->nid, serialize($result));
+      	if(empty($_POST['edit']['tries'])) {
+      	  drupal_set_message('You must select an answer!', 'error');
+      	}
+      	else {
+		  $former_question = node_load(array('nid' => array_shift($_SESSION['quiz_questions'])));
+		  $result = module_invoke($former_question->type, 'evaluate_question', $former_question->nid);
+		  db_query("REPLACE {quiz_question_results} VALUES(%d, %d, '%s')", $_SESSION['rid'], $former_question->nid, serialize($result));
+		}
       }
 
       // Check if at the end of quiz
@@ -381,6 +385,8 @@
         // Load the next question
         $question_node = node_load(array('nid' => $_SESSION['quiz_questions'][0]));
 
+        drupal_set_title($question_node->title);
+
         $node->body = module_invoke($question_node->type, 'render_question', $question_node);
 
       }
@@ -391,8 +397,17 @@
         //First - update the result to show we have finished.
         db_query("UPDATE {quiz_result} SET time_end = NOW() WHERE rid = %d", $_SESSION['rid']);
         
-        //display results and remove session variables
+        //Set the title!
+        drupal_set_title($node->title);
+        
+        //display overall result
         $node->body = "Your score: " .quiz_calculate_score($_SESSION['rid']);
+        
+        //Get results of this quiz from the Database...
+        $questions = _quiz_get_answers($_SESSION['rid']);
+        $node->body .= _quiz_get_results_table($questions, FALSE, TRUE);
+        
+        //remove session variables
         unset($_SESSION['quiz_questions']);
         unset($_SESSION['rid']);
 
@@ -401,6 +416,7 @@
     else {
       drupal_not_found();
     }
+
     return $node->body; // TODO: Can this be THEMED?
   }
 }
@@ -1064,22 +1080,44 @@
  */
 function quiz_admin_results() {
   $questions = _quiz_get_answers(arg(2));
-  
+  return _quiz_get_results_table($questions);
+}
+
+
+
+function _quiz_get_results_table($questions, $showPoints = TRUE, $showFeedback = FALSE) {
   $output = '';
   $rows = array();
+  $totalScore = 0;
 
   while(list($key, $question) = each($questions)) {
     $question['qanswer'] = unserialize($question['qanswer']);
-    $score = module_invoke($question['type'], 'calculate_result', $question['qanswer']['answers'], $question['qanswer']['tried']);
+    $result = module_invoke($question['type'], 'calculate_results', $question['qanswer']['answers'], $question['qanswer']['tried'], $showPoints, $showFeedback);
     
-    #dprint_r($question);
-    $rows[] = array(
-      $question['question'],
-      $score,
-      );
+    $totalScore += $result['score'];
+    
+    $cols = array();
+    
+    //Question Answers Table
+    $innerHeader = array('Option');
+    if($showPoints) $innerHeader[] = 'Answer';
+    $innerHeader[] = 'User Answer';
+    if($showFeedback) $innerHeader[] = 'Feedback';
+    
+    
+    $cols[] = '<b><i>'.$question['question'].'</i></b>'.theme('table', $innerHeader, $result['resultstable']);
+    
+    
+    $cols[] = $result['score'];
+    
+    $rows[] = $cols;
   }
   
-  $header = array(t('Question'), t('Right or Wrong?'),);
+  $rows[] = array('<b>Total</b>',$totalScore);
+
+  
+  $header = array(t('Question'), t('Score'));
+  
   
   if (isset($rows)) {
     $output .= theme('table', $header, $rows);
@@ -1090,6 +1128,11 @@
   return $output;
 }
 
+
+
+
+
+
 /*
  * Delete Result
  */
