You are here

function security_questions_list_user in Security Questions 6

Same name and namespace in other branches
  1. 7 security_questions.module \security_questions_list_user()

Security Questions List page for user.

1 string reference to 'security_questions_list_user'
security_questions_menu in ./security_questions.module
Implements hook_menu().

File

./security_questions.module, line 247
Main module file for security_questions.

Code

function security_questions_list_user($account) {

  // Get a list of questions that the user has answered.
  $result = db_query('SELECT sq.security_question, sqa.user_answer, sq.security_question_id
                                      FROM {security_questions_answers} AS sqa
                                      JOIN {security_questions} AS sq
                                      ON sqa.security_question_id = sq.security_question_id
                                      WHERE sqa.uid = %d', $account->uid);

  // If the user has answered questions, load them into a table.
  if ($result) {
    while ($row = db_fetch_object($result)) {
      $rows[] = array(
        check_plain($row->security_question),
        check_plain($row->user_answer),
        l(t('Change'), 'user/' . $account->uid . '/security_questions/edit/' . $row->security_question_id),
      );
    }
    $table = array(
      'header' => array(
        t('Questions'),
        t('Answer'),
        t('Change'),
      ),
      'rows' => $rows,
    );
    drupal_alter('security_questions_user_list', $table);
    $output = theme('table', $table['header'], $table['rows']);
  }

  // Check to see how many questions the user is required to have answered.
  $required = security_questions_required_for_user($account);

  // If the user has answered all required questions, show the table
  // previously prepared.
  if ($required == 0) {
    return $output;
  }
  else {
    $form_id = 'list_page';
    $form = drupal_get_form('security_questions_user_answer_form', $account, $required, $form_id);
    return $form;
  }
}