You are here

function simplenews_subscription_list_export in Simplenews 7.2

Same name and namespace in other branches
  1. 5 simplenews.module \simplenews_subscription_list_export()
  2. 6.2 includes/simplenews.admin.inc \simplenews_subscription_list_export()
  3. 6 simplenews.admin.inc \simplenews_subscription_list_export()
  4. 7 includes/simplenews.admin.inc \simplenews_subscription_list_export()

Menu callback: Export email address of subscriptions.

See also

simplenews_admin_export_after_build()

1 string reference to 'simplenews_subscription_list_export'
simplenews_menu in ./simplenews.module
Implements hook_menu().

File

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

Code

function simplenews_subscription_list_export($form, &$form_state) {

  // Get sensible default values for the form elements in this form.
  $default['states'] = isset($_GET['states']) ? $_GET['states'] : array(
    'active' => 'active',
  );
  $default['subscribed'] = isset($_GET['subscribed']) ? $_GET['subscribed'] : array(
    'subscribed' => 'subscribed',
  );
  $default['newsletters'] = isset($_GET['newsletters']) ? $_GET['newsletters'] : array();
  $form['states'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Status'),
    '#options' => array(
      'active' => t('Active users'),
      'inactive' => t('Inactive users'),
    ),
    '#default_value' => $default['states'],
    '#description' => t('Subscriptions matching the selected states will be exported.'),
    '#required' => TRUE,
  );
  $form['subscribed'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Subscribed'),
    '#options' => array(
      'subscribed' => t('Subscribed to the newsletter'),
      'unconfirmed' => t('Unconfirmed to the newsletter'),
      'unsubscribed' => t('Unsubscribed from the newsletter'),
    ),
    '#default_value' => $default['subscribed'],
    '#description' => t('Subscriptions matching the selected subscription states will be exported.'),
    '#required' => TRUE,
  );
  $options = simplenews_newsletter_list();
  $form['newsletters'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Newsletter'),
    '#options' => $options,
    '#default_value' => $default['newsletters'],
    '#description' => t('Subscriptions matching the selected newsletters will be exported.'),
    '#required' => TRUE,
  );

  // Get export results and display them in a text area. Only get the results
  // if the form is build after redirect, not after submit.
  if (isset($_GET['states']) && empty($form_state['input'])) {
    $form['emails'] = array(
      '#type' => 'textarea',
      '#title' => t('Export results'),
      '#cols' => 60,
      '#rows' => 5,
      '#value' => _simplenews_subscription_list_export_get_emails($_GET['states'], $_GET['subscribed'], $_GET['newsletters']),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Export'),
  );
  return $form;
}