You are here

function quiz_mail in Quiz 6.4

Same name and namespace in other branches
  1. 6.6 quiz.module \quiz_mail()
  2. 6.3 quiz.module \quiz_mail()
  3. 6.5 quiz.module \quiz_mail()
  4. 7.6 quiz.module \quiz_mail()
  5. 7 quiz.module \quiz_mail()
  6. 7.4 quiz.module \quiz_mail()

Implementation of hook_mail().

Related topics

File

./quiz.module, line 2264
Quiz Module

Code

function quiz_mail($key, &$message, $params) {
  global $user;
  list($quiz, $score, $rid, $target) = $params;
  $substitutions = array(
    '!title' => $quiz->title,
    '!sitename' => variable_get('site_name', 'Quiz'),
    '!taker' => $user->name,
    '!author' => $quiz->name,
    '!title' => check_plain($quiz->title),
    '!date' => date("F j, Y, g:i a"),
    '!desc' => check_plain($quiz->body),
    '!correct' => isset($score['numeric_score']) ? $score['numeric_score'] : 0,
    '!total' => $score['possible_score'],
    '!percentage' => $score['percentage_score'],
    '!url' => url('user/quiz/' . $rid . '/userresults', array(
      'absolute' => TRUE,
    )),
    '!minutes' => db_result(db_query("SELECT CEIL((time_end - time_start)/60) FROM {quiz_node_results} WHERE result_id = '%d' AND time_end", $rid)),
  );
  switch ($key) {
    case 'notice':
      if ($target == 'author') {
        $subject = t(variable_get('quiz_email_results_subject', quiz_email_results_format('subject', 'author')), $substitutions, $user->language);
        $body = t(variable_get('quiz_email_results_body', quiz_email_results_format('body', 'author')), $substitutions, $user->language);
      }
      else {
        $subject = t(variable_get('quiz_email_results_subject_taker', quiz_email_results_format('subject', 'taker')), $substitutions, $user->language);
        $body = t(variable_get('quiz_email_results_body_taker', quiz_email_results_format('body', 'taker')), $substitutions, $user->language);
      }
      $message['subject'] = $subject;
      $message['body'] = $body;
      break;
  }
}