You are here

function simplenews_statistics_admin_form in Simplenews Statistics 6

Same name and namespace in other branches
  1. 6.2 simplenews_statistics.module \simplenews_statistics_admin_form()

Statistics overview

1 string reference to 'simplenews_statistics_admin_form'
simplenews_statistics_menu in ./simplenews_statistics.module
Implementation of hook_menu().

File

./simplenews_statistics.module, line 156
Gathers newsletter statistics.

Code

function simplenews_statistics_admin_form(&$form_state, $action = 'sent') {
  drupal_set_title('Newsletter Statistics');
  $vid = variable_get('simplenews_vid', '');
  $form = array();
  $header = array(
    t('Title'),
    t('Newsletter'),
    t('Date created'),
    t('Send'),
    t('Open rate'),
    t('CTR'),
    t('Details'),
  );
  $sql = "SELECT n.*, s.s_status, s.s_format FROM {node} n INNER JOIN {simplenews_newsletters} s ON n.nid = s.nid WHERE s.s_status > 1 AND s.s_format = 'html' ORDER BY n.created DESC";
  $result = db_query(db_rewrite_sql($sql));
  $rows = array();
  while ($row = db_fetch_object($result)) {
    $node = node_load($row->nid);
    $terms = array_keys(taxonomy_node_get_terms_by_vocabulary($node, $vid, 'name'));
    $send = db_fetch_object(db_query("SELECT * FROM {simplenews_statistics} WHERE nid = %d", $node->nid));
    $data = db_fetch_object(db_query("SELECT\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t \t  COUNT(DISTINCT v.email) AS opens,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tCOUNT(DISTINCT c.email) AS clicks\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  {simplenews_statistics_opens} v\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  {simplenews_statistics_clicks} c\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  v.nid = c.nid\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t  v.nid = %d", $node->nid));
    $rows[] = array(
      l($node->title, 'node/' . $node->nid),
      isset($terms[0]) ? $terms[0] : t('n/a'),
      format_date($node->created, 'small'),
      $send ? $send->send : t('No data available.'),
      $send ? $data->opens . ' (' . round($data->opens / $send->send * 100) . '%)' : '',
      $send ? $data->clicks . ' (' . round($data->clicks / $send->send * 100) . '%)' : '',
      $send ? l('Details', 'admin/content/simplenews/statistics/' . $node->nid) : '',
    );
  }
  if (!$rows) {
    $rows[] = array(
      array(
        'data' => t('No newsletters available.'),
        'colspan' => '7',
      ),
    );
  }
  $table = theme('table', $header, $rows);
  $form['table'] = array(
    '#value' => $table,
  );
  return $form;
}