You are here

function spam_logs_overview in Spam 6

Same name and namespace in other branches
  1. 5.3 spam.module \spam_logs_overview()
  2. 5 spam.module \spam_logs_overview()

Display an overview of the latest spam_log entries.

1 string reference to 'spam_logs_overview'
spam_menu in ./spam.module
Drupal _menu() hook.

File

./spam.module, line 1982
Spam module, v3 Copyright(c) 2006-2008 Jeremy Andrews <jeremy@tag1consulting.com>. All rights reserved.

Code

function spam_logs_overview($type = NULL, $id = NULL) {
  drupal_set_title(t('Spam module logs'));
  $header = array(
    array(
      'data' => t('type'),
      'field' => 'content_type',
    ),
    array(
      'data' => t('id'),
      'field' => 'content_id',
    ),
    array(
      'data' => t('date'),
      'field' => 'lid',
      'sort' => 'desc',
    ),
    array(
      'data' => t('message'),
      'field' => 'message',
    ),
    array(
      'data' => t('user'),
      'field' => 'uid',
    ),
    array(
      'data' => t('operations'),
    ),
  );
  if ($id) {
    $sql = "SELECT * FROM {spam_log} WHERE content_type = '%s' AND content_id = '%s'";
    $arguments = array(
      $type,
      $id,
    );
  }
  else {
    if ($type) {
      $sql = "SELECT * FROM {spam_log} WHERE content_type = '%s'";
      $arguments = array(
        $type,
      );
    }
    else {
      $sql = "SELECT * FROM {spam_log}";
      $arguments = array();
    }
  }
  $result = pager_query($sql . tablesort_sql($header), 50, 0, NULL, $arguments);
  while ($log = db_fetch_object($result)) {
    $options = '';
    if ($log->trid > 1) {
      $options = l(t('trace'), "admin/reports/spam/{$log->trid}/trace") . ' | ';
    }
    $options .= l(t('detail'), "admin/reports/spam/{$log->lid}/detail");
    $rows[] = array(
      'data' => array(
        t($log->content_type),
        $log->content_id,
        format_date($log->timestamp, 'small'),
        truncate_utf8($log->message, 64) . (drupal_strlen($log->message) > 64 ? '...' : ''),
        theme('username', user_load(array(
          'uid' => $log->uid,
        ))),
        $options,
      ),
    );
  }
  if (!$rows) {
    $rows[] = array(
      array(
        'data' => t('No log messages available.'),
        'colspan' => 6,
      ),
    );
  }
  return theme('table', $header, $rows) . theme('pager', NULL, 50, 0);
}