You are here

function simplenews_subscription_list_form in Simplenews 5

Same name and namespace in other branches
  1. 6.2 includes/simplenews.admin.inc \simplenews_subscription_list_form()
  2. 6 simplenews.admin.inc \simplenews_subscription_list_form()
  3. 7.2 includes/simplenews.admin.inc \simplenews_subscription_list_form()
  4. 7 includes/simplenews.admin.inc \simplenews_subscription_list_form()
1 string reference to 'simplenews_subscription_list_form'
simplenews_subscription_admin in ./simplenews.module
Menu callback: subscription administration.

File

./simplenews.module, line 1928

Code

function simplenews_subscription_list_form() {
  global $form_values;

  // Table header. Used as tablesort default
  $header = array(
    array(
      'data' => t('E-mail'),
      'field' => 'ss.mail',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Username'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('Status'),
      'field' => 'ss.a_status',
    ),
    t('Operations'),
  );

  // Data collection with filter and sorting applied
  $filter = simplenews_build_subscription_filter_query();
  $query = 'SELECT DISTINCT ss.*, u.name FROM {simplenews_subscriptions} ss INNER JOIN {users} u ON ss.uid = u.uid INNER JOIN {simplenews_snid_tid} s ON ss.snid = s.snid' . $filter['where'];
  $count_query = preg_replace('/SELECT.*FROM /', 'SELECT COUNT(DISTINCT ss.mail) FROM ', $query);
  $query .= tablesort_sql($header);

  // Use count_query to count distinct records only
  $result = pager_query($query, 30, 0, $count_query);

  // Update options
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#options' => array(
      'activate' => t('Activate'),
      'inactivate' => t('Inactivate'),
      'delete' => t('Delete'),
    ),
    '#default_value' => 'activate',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );

  // Subscription table and table pager
  while ($subs = db_fetch_object($result)) {
    $snids[$subs->snid] = '';
    $form['mail'][$subs->snid] = array(
      '#value' => $subs->mail,
    );
    $form['name'][$subs->snid] = array(
      '#value' => $subs->uid ? l($subs->name, 'user/' . $subs->uid) : $subs->name,
    );
    $form['status'][$subs->snid] = array(
      '#value' => theme('simplenews_status', $subs->a_status, 'activated'),
    );
    $form['operations'][$subs->snid] = array(
      '#value' => l(t('edit'), 'admin/content/newsletters/users/edit/' . $subs->snid, array(), drupal_get_destination()),
    );
  }
  $form['snids'] = array(
    '#type' => 'checkboxes',
    '#options' => $snids,
  );
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 30, 0),
  );
  return $form;
}