You are here

function mail_logger_form_overview in Mail Logger 7

Same name and namespace in other branches
  1. 5 mail_logger.module \mail_logger_form_overview()
  2. 6 mail_logger.module \mail_logger_form_overview()

Form to filter the list of logged emails.

1 string reference to 'mail_logger_form_overview'
mail_logger_overview in ./mail_logger.pages.inc
Menu callback; displays a listing of logged mails.

File

./mail_logger.pages.inc, line 140
User-facing UI components for the Mail Logger module.

Code

function mail_logger_form_overview() {
  $names['all'] = t('all mail types');
  foreach (_mail_logger_get_mailkey_types() as $type) {
    $names[$type] = t('!type', array(
      '!type' => t($type),
    ));
  }
  if (empty($_SESSION['mail_logger_overview_filter'])) {
    $_SESSION['mail_logger_overview_filter'] = 'all';
  }
  $first_mail = db_select('mail_logger', 'ml')
    ->fields('ml', array(
    'date_sent',
  ))
    ->orderBy('date_sent', 'ASC')
    ->range(0, 1)
    ->execute()
    ->fetchField();
  $timezone = new DateTimeZone(date_default_timezone_get());
  $default_from_date = $first_mail ? DateTime::createFromFormat('U', $first_mail) : DateTime::createFromFormat('U', strtotime('-1 month'));
  $default_from_date
    ->setTimezone($timezone);
  $default_from_date = array(
    'year' => $default_from_date
      ->format('Y'),
    'month' => $default_from_date
      ->format('n'),
    'day' => $default_from_date
      ->format('j'),
  );
  $is_filtering = $_SESSION['mail_logger_overview_filter'] != 'all' || !empty($_SESSION['mail_logger_overview_from_date']) || !empty($_SESSION['mail_logger_overview_to_date']) || !empty($_SESSION['mail_logger_overview_search_field']) || !empty($_SESSION['mail_logger_overview_search_value']);
  $form['filter_logs'] = array(
    '#type' => 'fieldset',
    '#title' => t('Filter Mail Log'),
    '#collapsible' => TRUE,
    '#collapsed' => !$is_filtering,
  );
  $form['filter_logs']['from_date'] = array(
    '#type' => 'date',
    '#title' => t('From Date'),
    '#default_value' => !empty($_SESSION['mail_logger_overview_from_date']) ? $_SESSION['mail_logger_overview_from_date'] : $default_from_date,
  );
  $default_to_date = DateTime::createFromFormat('U', time() + 86400);
  $default_to_date
    ->setTimezone($timezone);
  $default_to_date = array(
    'year' => $default_to_date
      ->format('Y'),
    'month' => $default_to_date
      ->format('n'),
    'day' => $default_to_date
      ->format('j'),
  );
  $form['filter_logs']['to_date'] = array(
    '#type' => 'date',
    '#title' => t('To Date'),
    '#default_value' => !empty($_SESSION['mail_logger_overview_to_date']) ? $_SESSION['mail_logger_overview_to_date'] : $default_to_date,
  );
  $form['filter_logs']['search_field'] = array(
    '#type' => 'select',
    '#options' => array(
      '' => '-- Select a field --',
      'mailto' => 'To Email Address',
      'mailfrom' => 'From Email Address',
      'subject' => 'Subject',
      'body' => 'Body',
      'language' => 'Language',
    ),
    '#title' => t('Field'),
    '#default_value' => !empty($_SESSION['mail_logger_overview_search_field']) ? $_SESSION['mail_logger_overview_search_field'] : '',
  );
  $form['filter_logs']['search_value'] = array(
    '#type' => 'textfield',
    '#title' => t('Contains'),
    '#default_value' => !empty($_SESSION['mail_logger_overview_search_value']) ? $_SESSION['mail_logger_overview_search_value'] : '',
  );
  $form['filter_logs']['filter'] = array(
    '#type' => 'select',
    '#title' => t('Filter by Mailkey'),
    '#options' => $names,
    '#default_value' => $_SESSION['mail_logger_overview_filter'],
  );
  $form['filter_logs']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Filter'),
    '#attributes' => array(
      'filter',
    ),
  );
  $form['filter_logs']['reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset'),
    '#attributes' => array(
      'reset',
    ),
  );
  $form['#redirect'] = FALSE;
  $form['mail_logger_clear'] = array(
    '#type' => 'fieldset',
    '#title' => t('Clear mail log'),
    '#description' => t('This will permanently remove the log messages from the database.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['mail_logger_clear']['clear'] = array(
    '#type' => 'submit',
    '#value' => t('Clear mail messages'),
    '#submit' => array(
      '_mail_logger_overview_clear_logs_submit',
    ),
  );
  return $form;
}