You are here

function mailing_list_emails in Mailing List 6

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

2 string references to 'mailing_list_emails'
mailing_list_menu in ./mailing_list.module
Implementation of hook_menu().
mailing_list_update_6000 in ./mailing_list.install
Update mailing lists to allow subscriber names (not just e-mails), and clean up field names.

File

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

Code

function mailing_list_emails($list = NULL) {
  if (empty($list)) {
    return;
  }
  else {
    drupal_set_title(check_plain($list->name));
  }
  $sql = 'SELECT * FROM {mailing_list_emails} WHERE mlid = %d';
  $header = array(
    array(
      'data' => t('E-mail'),
      'field' => 'mail',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Name'),
      'field' => 'name',
    ),
    array(
      'data' => t('Operations'),
      'colspan' => '2',
    ),
  );
  $sql .= tablesort_sql($header);
  $result = pager_query($sql, 50, 0, NULL, array(
    $list->mlid,
  ));
  $rows = array();
  $destination = drupal_get_destination();
  while ($data = db_fetch_object($result)) {
    $row = array(
      check_plain($data->mail),
      !empty($data->name) ? check_plain($data->name) : theme('placeholder', t('none')),
      l(t('edit'), "admin/build/mailing-list/{$list->mlid}/{$data->eid}", array(
        'query' => $destination,
      )),
      l(t('delete'), "admin/build/mailing-list/{$list->mlid}/{$data->eid}/delete", array(
        'query' => $destination,
      )),
    );
    $rows[] = $row;
  }
  if (empty($rows)) {
    $empty_message = t('No e-mails found.');
    $rows[] = array(
      array(
        'data' => $empty_message,
        'colspan' => 4,
      ),
    );
  }
  $output = theme('table', $header, $rows);
  $output .= theme('pager', NULL, 50, 0);
  return $output;
}