You are here

function email_verify_user_check_form in Email Verify 8.2

Same name and namespace in other branches
  1. 7.2 email_verify.check.inc \email_verify_user_check_form()

Look though the users table for invalid emails.

Parameters

array $form: The form definition.

array $form_state: The current state of the form.

Return value

array The form definition.

File

./email_verify.check.inc, line 18
User email check menu callback file for email_verify module.

Code

function email_verify_user_check_form($form, &$form_state) {
  if (!empty($form_state['input'])) {
    drupal_set_message(t('Look for the verification results below the form.'));
  }
  $form['header'] = array(
    '#type' => 'fieldset',
    '#title' => t('User check'),
    '#collapsible' => TRUE,
    '#description' => t('
      On this page, you can list all existing users for whom their email address
      is not valid. Simply click the "Start" button to begin the process. If you
      make changes to the users, you will need to click the "Start" or "Update"
      buttons to see the new data.
    '),
  );
  $form['header']['form_help'] = array(
    '#markup' => t('
      <p>
      Because the checking process can take a very long time, especially for
      sites with thousands of users, to the point of this page being entirely
      useless, you may specify the number of users to check with the fields
      below.<br />
      <ul>
      <li>If "Number" is empty and "Offset" is empty, then all users in the
      database table will be verified.</li>
      <li>If "Number" has a value and "Offset" is empty, then the first "Number"
      of users in the database table will be verified.</li>
      <li>If "Number" is empty and "Offset" has a value, then all users after
      "Offset" to the end of the database table will be verified.</li>
      <li>If "Number" has a value and "Offset" has a value, then the "Number"
      of users after "Offset" will be verified.</li>
      </ul>
      </p>
    '),
  );
  $form['header']['number'] = array(
    '#type' => 'textfield',
    '#title' => t("Number"),
    '#size' => 15,
    '#description' => t('The number of users to verify.'),
  );
  $form['header']['offset'] = array(
    '#type' => 'textfield',
    '#title' => t("Offset"),
    '#size' => 15,
    '#description' => t('The number of users to skip before counting the number of users to verify.'),
  );
  $all_user_count = db_query("SELECT COUNT(DISTINCT uid) FROM users")
    ->fetchField();
  $active_user_count = db_query("SELECT COUNT(DISTINCT uid) FROM users WHERE status = 1")
    ->fetchField();
  $form['header']['disabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Include blocked/disabled users'),
    '#description' => t('There are %all_user_count users registed with this site, of which, %active_user_count are active.', array(
      '%all_user_count' => $all_user_count,
      '%active_user_count' => $active_user_count,
    )),
  );
  $form['header']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Start'),
  );

  // Get any records that have been stored to display.
  $rows = variable_get('email_verify_users_to_display', array());
  $user_rows = $rows;
  $headers = _email_verify_get_header();
  $form_count = format_plural(count($rows), 'Found 1 user whose email address is not valid.', 'Found @count users whose email addresses are not valid.');
  if (!empty($rows)) {

    // Rename the button.
    $form['header']['submit']['#value'] = t('Update');

    // Set up the sorting.
    _email_verify_sort_rows($headers, $rows);

    // Set up the pager.
    $current_page = pager_default_initialize(count($rows), 25);

    // Break the total data set into page sized chunks.
    $pages = array_chunk($rows, 25, TRUE);

    // Add the users.
    if (!empty($pages)) {
      $user_rows = $pages[$current_page];
    }
  }

  // Theme and add the results.
  $form['table'] = array(
    '#markup' => theme('table', array(
      'header' => $headers,
      'rows' => $user_rows,
      'caption' => $form_count,
      'empty' => t('All email address checked passed the verification(s).'),
    )),
  );

  // Add the pager.
  $form['pager'] = array(
    '#markup' => theme('pager'),
  );
  return $form;
}