You are here

function simplenews_admin_news in Simplenews 6

Same name and namespace in other branches
  1. 5 simplenews.module \simplenews_admin_news()
  2. 6.2 includes/simplenews.admin.inc \simplenews_admin_news()

Menu callback: Admin form for sent and draft newsletters.

See also

simplenews_admin_news_submit()

1 string reference to 'simplenews_admin_news'
simplenews_menu in ./simplenews.module
Implementation of hook_menu().

File

./simplenews.admin.inc, line 15
Newsletter admin, subscription admin, simplenews settings

Code

function simplenews_admin_news(&$form_state, $action = 'sent') {
  $vid = variable_get('simplenews_vid', '');
  $form = array();
  $form['simplenews_issue_filter'] = array(
    '#type' => 'fieldset',
    '#title' => t('Show issues from'),
    '#collapsible' => FALSE,
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $header = array(
    t('Title'),
    t('Newsletter'),
    t('Date created'),
    t('Published'),
    t('Sent'),
    t('Edit'),
  );
  list($names, $queries) = array_values(simplenews_get_filter('simplenews_newsletters_filter'));
  $filter = isset($_SESSION['simplenews_newsletters_filter']) ? $_SESSION['simplenews_newsletters_filter'] : '';
  $queryfilter = isset($queries[$filter]) ? $queries[$filter] : '';
  if ($action == 'notsent') {
    $form['simplenews_issue_filter']['filter'] = array(
      '#type' => 'select',
      '#options' => $names,
      '#default_value' => $filter,
    );
    $query = "SELECT DISTINCT n.*, s.s_status FROM {node} n INNER JOIN {simplenews_newsletters} s ON n.nid = s.nid WHERE s.s_status = %d" . $queryfilter . " ORDER BY n.created DESC";
    $count_query = "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {simplenews_newsletters} s ON n.nid = s.nid WHERE s.s_status = %d" . $queryfilter;
  }
  else {
    $form['simplenews_issue_filter']['filter'] = array(
      '#type' => 'select',
      '#options' => $names,
      '#default_value' => $filter,
    );
    $query = "SELECT n.*, s.s_status FROM {node} n INNER JOIN {simplenews_newsletters} s ON n.nid = s.nid WHERE s.s_status > %d" . $queryfilter . " ORDER BY n.created DESC";
    $count_query = "SELECT COUNT(n.nid) FROM {node} n INNER JOIN {simplenews_newsletters} s ON n.nid = s.nid WHERE s.s_status > %d" . $queryfilter;
  }
  $result = pager_query(db_rewrite_sql($query, 'n', 'nid', array(
    SIMPLENEWS_STATUS_SEND_NOT,
  )), 10, 0, db_rewrite_sql($count_query, 'n', 'nid', array(
    SIMPLENEWS_STATUS_SEND_NOT,
  )), 0);
  $rows = array();
  while ($node = db_fetch_object($result)) {
    $terms = array_keys(taxonomy_node_get_terms_by_vocabulary($node, $vid, 'name'));
    $rows[] = array(
      l($node->title, 'node/' . $node->nid),
      isset($terms[0]) ? $terms[0] : t('n/a'),
      format_date($node->created, 'small'),
      theme('simplenews_status', $node->status, 'published'),
      theme('simplenews_status', $node->s_status, 'sent'),
      l(t('edit'), 'node/' . $node->nid . '/edit', array(), drupal_get_destination()),
    );
  }
  if ($pager = theme('pager', NULL, 10, 0)) {
    $rows[] = array(
      array(
        'data' => $pager,
        'colspan' => '6',
      ),
    );
  }
  if (!$rows) {
    $rows[] = array(
      array(
        'data' => t('No newsletters available.'),
        'colspan' => '6',
      ),
    );
  }
  $form['simplenews_issue_filter']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Filter'),
  );
  $table = theme('table', $header, $rows);
  $form['table'] = array(
    '#value' => $table,
  );
  return $form;
}