You are here

function mail_safety_admin_dashboard_form in Mail Safety 7

Form constructor for the dashboard of Mail Safety.

Shows an overview of all outgoing emails and let users debug or perform actions on them.

1 string reference to 'mail_safety_admin_dashboard_form'
mail_safety_menu in ./mail_safety.module
Implements hook_menu().

File

./mail_safety.admin.inc, line 62
Admin functionality for Mail Safety

Code

function mail_safety_admin_dashboard_form() {
  $form = array();
  $table_structure = array();

  // Create the headers.
  $table_structure['header'] = array(
    array(
      'data' => t('Subject'),
    ),
    array(
      'data' => t('Date sent'),
      'field' => 'sent',
      'sort' => 'desc',
    ),
    array(
      'data' => t('To'),
    ),
    array(
      'data' => t('CC'),
    ),
    array(
      'data' => t('Module'),
    ),
    array(
      'data' => t('Key'),
    ),
    array(
      'data' => t('Details'),
    ),
    array(
      'data' => t('Send to original'),
    ),
    array(
      'data' => t('Send to default mail'),
    ),
    array(
      'data' => t('Delete'),
    ),
  );

  // Create the query.
  $query = db_select('mail_safety_dashboard', 'msd')
    ->extend('PagerDefault')
    ->limit(50)
    ->extend('TableSort')
    ->orderByHeader($table_structure['header'])
    ->fields('msd', array(
    'mail_id',
    'sent',
    'mail',
  ));
  $results = $query
    ->execute();

  // Fill the rows for the table.
  $table_structure['rows'] = array();
  foreach ($results as $row) {
    $mail = unserialize($row->mail);
    $table_structure['rows'][$row->mail_id] = array(
      'data' => array(
        l($mail['subject'], 'admin/config/development/mail_safety/' . $row->mail_id . '/view'),
        format_date($row->sent, 'short'),
        $mail['to'],
        isset($mail['headers']['CC']) ? $mail['headers']['CC'] : t('none'),
        $mail['module'],
        $mail['key'],
        l(t('Details'), 'admin/config/development/mail_safety/' . $row->mail_id . '/details'),
        l(t('Send to original'), 'admin/config/development/mail_safety/' . $row->mail_id . '/send_original'),
        l(t('Send to default mail'), 'admin/config/development/mail_safety/' . $row->mail_id . '/send_default'),
        l(t('Delete'), 'admin/config/development/mail_safety/' . $row->mail_id . '/delete'),
      ),
    );
  }

  // Let other modules change the table structure to add or remove
  // information to be shown. E.g. attachments that need to be downloaded.
  drupal_alter('mail_safety_table_structure', $table_structure);
  $form['mails']['table'] = array(
    '#theme' => 'table',
    '#header' => $table_structure['header'],
    '#rows' => $table_structure['rows'],
    '#caption' => 'Mail Safety Dashboard',
    '#sticky' => TRUE,
    '#empty' => t('No mails found'),
  );
  $form['mails']['pager'] = array(
    '#theme' => 'pager',
    '#tags' => array(),
  );
  return $form;
}