You are here

function mailing_list_emails_form in Mailing List 7

Menu callback; displays all e-mails for the specified mailing list in a table.

1 string reference to 'mailing_list_emails_form'
mailing_list_emails_list in ./mailing_list.admin.inc
Menu callback; displays all e-mails for the specified mailing list in a table. Also routes to delete operation if selected.

File

./mailing_list.admin.inc, line 55
Mailing list admin UI.

Code

function mailing_list_emails_form($form, &$form_state, $list = NULL) {
  if (empty($list)) {
    return;
  }
  else {
    drupal_set_title(check_plain($list->name));
  }
  $header = array(
    'mail' => array(
      'data' => t('E-mail'),
      'field' => 'mle.mail',
      'sort' => 'asc',
    ),
    'name' => array(
      'data' => t('Name'),
      'field' => 'mle.name',
    ),
    'operations' => array(
      'data' => t('Operations'),
    ),
  );
  $query = db_select('mailing_list_emails', 'mle')
    ->condition('mlid', $list->mlid);
  $count_query = clone $query;
  $count_query
    ->addExpression('COUNT(mle.eid)');
  $query = $query
    ->extend('PagerDefault')
    ->extend('TableSort');
  $query
    ->fields('mle')
    ->limit(variable_get('mailing_list_limit', MAILING_LIST_LIMIT))
    ->orderByHeader($header)
    ->setCountQuery($count_query);
  $result = $query
    ->execute();
  $rows = array();
  $destination = drupal_get_destination();
  foreach ($result as $data) {

    // Edit link is broken, see http://drupal.org/node/704564
    $rows[$data->eid] = array(
      'mail' => check_plain($data->mail),
      'name' => !empty($data->name) ? check_plain($data->name) : theme('placeholder', t('none')),
      'operations' => l(t('edit'), "admin/structure/mailing-list/{$list->mlid}/{$data->eid}", array(
        'query' => $destination,
      )),
      l(t('delete'), "admin/structure/mailing-list/{$list->mlid}/{$data->eid}/delete", array(
        'query' => $destination,
      )),
    );
  }

  // Until we have multiple operations, hiding this.
  //  $form['operation'] = array(
  //    '#type' => 'select',
  //    '#options' => array('delete' => 'Delete'),
  //    '#title' => t('Operations'),
  //  );
  $form['operation'] = array(
    '#type' => 'hidden',
    '#value' => 'delete',
  );
  $form['mails'] = array(
    '#type' => 'tableselect',
    '#header' => $header,
    '#options' => $rows,
    '#empty' => t('No content available.'),
  );
  $form['pager'] = array(
    '#markup' => theme('pager', array(
      'tags' => NULL,
    )),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Delete selected'),
  );
  return $form;
}