? quiz-3.x-dev.patch
Index: quiz.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/quiz/quiz.module,v
retrieving revision 1.137.2.30
diff -u -p -r1.137.2.30 quiz.module
--- quiz.module	30 Mar 2009 19:18:03 -0000	1.137.2.30
+++ quiz.module	31 Mar 2009 12:03:56 -0000
@@ -1130,12 +1130,45 @@ function quiz_end_actions($quiz, $rid) {
     $context = array();
     actions_do($quiz->aid, $quiz, $context, $score);
   }
-  
   // Call hook_quiz_finished().
-  module_invoke_all('quiz_finished', $quiz, $score);
+  module_invoke_all('quiz_finished', $quiz, $score, $rid);
+
   return $score;
 }
 
+
+function quiz_quiz_finished($quiz, $score, $rid) {
+  global $user;
+  // function to export results to grade book will be added later
+  // function to export result in pdf, XML, CVS format
+  // function to display results visually 
+  //function to send results over email
+  if ($user->uid) { // email can be sent only for registered users    
+    drupal_mail('quiz', 'notice', $user->mail, NULL, array($quiz, $score, $rid));
+  }
+}
+
+
+function quiz_mail($key, &$message, $params) {    
+  list($quiz, $score, $rid) = $params;
+  
+  switch($key) {
+    case 'notice':
+      $message['subject'] = t("!title Results Notice from !sitename", array('!title' => $quiz->title, '!sitename' => variable_get('site_name', 'Test Center')));
+      
+      $message['body'] = t("Dear !username \n\n", array('!username' => $quiz->name));      
+      $message['body'] .= t("You have attened a !title quiz on !date \n\n", array('!title' => $quiz->title, '!date' => date("F j, Y, g:i a")));
+      
+      $message['body'] .= t("Test Description : !desc \n\n", array('!desc' => $quiz->body));
+      
+      $message['body'] .= t("You got !correct out of !total. Your percentage is !percentage \n\n.", array('!correct'=> $score['numeric_score'], '!total' => $score['question_count'], '!percentage' => $score['percentage_score']));
+ 
+      $message['body'] .= t("You can access your result in here !url\n", array('!url' => url("user/quiz/$rid/userresults", array('absolute' => TRUE))));
+      drupal_set_message('Results has been sent to your email ID');
+    break;
+  }
+}
+
 /**
  * Update a score for a quiz.
  *
