You are here

function simplenews_admin_export_after_build in Simplenews 5

Same name and namespace in other branches
  1. 6.2 includes/simplenews.admin.inc \simplenews_admin_export_after_build()
  2. 6 simplenews.admin.inc \simplenews_admin_export_after_build()
1 string reference to 'simplenews_admin_export_after_build'
simplenews_subscription_list_export in ./simplenews.module

File

./simplenews.module, line 2213

Code

function simplenews_admin_export_after_build($form, $edit) {
  $op = isset($_POST['op']) ? $_POST['op'] : '';
  if ($op == t('Export')) {
    $tree = taxonomy_get_tree(variable_get('simplenews_vid', ''));
    if ($edit['active'] == 1) {
      $where[] = 's.a_status = 1';
    }
    if ($edit['inactive'] == 1) {
      $where[] = 's.a_status = 0';
    }
    $where = $where ? implode(' OR ', $where) : NULL;
    if ($tree) {
      foreach ($tree as $newsletter) {
        if ($edit['tid_' . $newsletter->tid]) {
          $where_tid[] = 't.tid = ' . $newsletter->tid;
        }
      }
    }
    $where_tid = $where_tid ? implode(' OR ', $where_tid) : NULL;
    if ($where && $where_tid) {
      $query = 'SELECT DISTINCT s.mail FROM {simplenews_subscriptions} s INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid WHERE (' . $where . ') AND (' . $where_tid . ')';
      $result = db_query($query);
      while ($mail = db_fetch_object($result)) {
        $mails[] = $mail->mail;
      }
    }
    if ($mails) {
      $exported_mails = implode(", ", $mails);
    }
    else {
      $exported_mails = t('No addresses were found.');
    }
    $form['emails']['#value'] = $exported_mails;
  }
  return $form;
}