You are here

function simplenews_subscription_list_form in Simplenews 6.2

Same name and namespace in other branches
  1. 5 simplenews.module \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()

Build the form for admin subscription.

Form consists of a filter fieldset, an operation fieldset and a list of subscriptions matching the filter criteria.

See also

simplenews_subscription_list_form_validate()

simplenews_subscription_list_form_submit()

1 call to simplenews_subscription_list_form()
simplenews_subscription_admin in includes/simplenews.admin.inc
Menu callback: subscription administration.

File

includes/simplenews.admin.inc, line 752
Newsletter admin, subscription admin, simplenews settings

Code

function simplenews_subscription_list_form() {

  //TODO: Subscriber maintenance needs overhaul now we have more data available.

  // Table header. Used as tablesort default
  $header = array(
    array(
      'data' => t('Email'),
      'field' => 'ss.mail',
      'sort' => 'asc',
    ),
    array(
      'data' => t('Username'),
      'field' => 'u.name',
    ),
    array(
      'data' => t('Status'),
      'field' => 'ss.activated',
    ),
  );
  if (variable_get('language_count', 1) > 1) {
    $header[] = array(
      'data' => t('Language'),
      'field' => 'ss.language',
    );
  }
  $header[] = t('Operations');

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

  // $count_query used to count distinct records only, match per line
  $count_query = preg_replace('/SELECT.*/', 'SELECT COUNT(DISTINCT ss.snid)', $query);
  $query .= tablesort_sql($header);
  $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'),
    '#submit' => array(
      'simplenews_subscription_list_form_submit',
    ),
    '#validate' => array(
      'simplenews_subscription_list_form_validate',
    ),
  );
  $snids = array();

  // Subscription table and table pager
  $languages = language_list();
  while ($subscription = db_fetch_object($result)) {
    $snids[$subscription->snid] = '';
    $form['mail'][$subscription->snid] = array(
      '#value' => check_plain($subscription->mail),
    );
    $form['name'][$subscription->snid] = array(
      '#value' => isset($subscription->uid) ? l($subscription->name, 'user/' . $subscription->uid) : check_plain($subscription->name),
    );
    $form['status'][$subscription->snid] = array(
      '#value' => theme('simplenews_status', $subscription->activated, 'activated'),
    );
    if (variable_get('language_count', 1) > 1) {
      $form['language'][$subscription->snid] = array(
        '#value' => check_plain($languages[$subscription->language]->name),
      );
    }
    $form['operations'][$subscription->snid] = array(
      '#value' => l(t('edit'), 'admin/content/simplenews/users/edit/' . $subscription->snid, array(), drupal_get_destination()),
    );
  }
  $form['snids'] = array(
    '#type' => 'checkboxes',
    '#options' => $snids,
  );
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 30, 0),
  );
  $form['#theme'] = 'simplenews_subscription_list';
  return $form;
}