watchdog_overview

Definition

watchdog_overview()
modules/watchdog.module, line 62

Description

Menu callback; displays a listing of log messages.

Code

<?php
function watchdog_overview() {
  $icons = array(WATCHDOG_NOTICE  => '',
                 WATCHDOG_WARNING => theme('image', 'misc/watchdog-warning.png', t('warning'), t('warning')),
                 WATCHDOG_ERROR   => theme('image', 'misc/watchdog-error.png', t('error'), t('error')));
  $classes = array(WATCHDOG_NOTICE => 'watchdog-notice', WATCHDOG_WARNING => 'watchdog-warning', WATCHDOG_ERROR => 'watchdog-error');

  $names['all'] = t('all messages');
  $queries['all'] = '';
  foreach (_watchdog_get_message_types() as $type) {
    $names[$type] = t('%type messages', array('%type' => t($type)));
    $queries[$type] = "WHERE type = '". db_escape_string($type) ."'";
  }

  if (empty($_SESSION['watchdog_overview_filter'])) {
    $_SESSION['watchdog_overview_filter'] = 'all';
  }

  $op = $_POST['op'];
  if ($op == t('Filter') && isset($_POST['edit']['filter'])) {
    $_SESSION['watchdog_overview_filter'] = $_POST['edit']['filter'];
  }

  $form  = form_select(t('Filter by message type'), 'filter', $_SESSION['watchdog_overview_filter'], $names);
  $form .= form_submit(t('Filter'));

  $header = array(
    ' ',
    array('data' => t('Type'), 'field' => 'w.type'),
    array('data' => t('Date'), 'field' => 'w.wid', 'sort' => 'desc'),
    array('data' => t('Message'), 'field' => 'w.message'),
    array('data' => t('User'), 'field' => 'u.name'),
    array('data' => t('Operations'), 'colspan' => '2')
  );
  $sql = 'SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid '. $queries[$_SESSION['watchdog_overview_filter']] . tablesort_sql($header);
  $result = pager_query($sql, 50);

  while ($watchdog = db_fetch_object($result)) {
    $rows[] = array('data' =>
      array(
        // Cells
        $icons[$watchdog->severity],
        t($watchdog->type),
        format_date($watchdog->timestamp, 'small'),
        truncate_utf8($watchdog->message, 64),
        format_name($watchdog),
        $watchdog->link,
        l(t('details'), "admin/logs/event/$watchdog->wid")
      ),
      // Attributes for tr
      'class' => "watchdog-". preg_replace('/[^a-z]/i', '-', $watchdog->type) .' '. $classes[$watchdog->severity]
    );
  }

  if (!$rows) {
    $rows[] = array(array('data' => t('No log messages available.'), 'colspan' => '7'));
  }

  $pager = theme('pager', NULL, 50, 0, tablesort_pager());
  if (!empty($pager)) {
    $rows[] = array(array('data' => $pager, 'colspan' => '7'));
  }

  $output  = '<div class="container-inline">'. form($form) .'</div>';
  $output .= theme('table', $header, $rows);

  print theme('page', $output);
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.