Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.161 diff -u -p -r1.161 bootstrap.inc --- includes/bootstrap.inc 25 Apr 2007 21:34:31 -0000 1.161 +++ includes/bootstrap.inc 28 Apr 2007 21:55:57 -0000 @@ -37,6 +37,8 @@ define('CACHE_AGGRESSIVE', 2); /** * * Severity levels, as defined in RFC 3164 http://www.faqs.org/rfcs/rfc3164.html + * @see watchdog + * @see watchdog_severity_levels */ define('WATCHDOG_EMERG', 0); // Emergency: system is unusable define('WATCHDOG_ALERT', 1); // Alert: action must be taken immediately @@ -657,6 +659,8 @@ function request_uri() { * The severity of the message, as per RFC 3164 * @param $link * A link to associate with the message. + * + * @see watchdog_severity_levels */ function watchdog($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) { global $user, $base_root; Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.636 diff -u -p -r1.636 common.inc --- includes/common.inc 27 Apr 2007 07:42:54 -0000 1.636 +++ includes/common.inc 28 Apr 2007 21:55:58 -0000 @@ -2616,3 +2616,22 @@ function drupal_parse_info_file($filenam return $info; } + +/** + * @return + * Array of the possible severity levels for log messages. + * + * @see watchdog + */ +function watchdog_severity_levels() { + return array( + WATCHDOG_EMERG => t('emergency'), + WATCHDOG_ALERT => t('alert'), + WATCHDOG_CRITICAL => t('critical'), + WATCHDOG_ERROR => t('error'), + WATCHDOG_WARNING => t('warning'), + WATCHDOG_NOTICE => t('notice'), + WATCHDOG_INFO => t('info'), + WATCHDOG_DEBUG => t('debug'), + ); +} Index: modules/dblog/dblog.module =================================================================== RCS file: /cvs/drupal/drupal/modules/dblog/dblog.module,v retrieving revision 1.3 diff -u -p -r1.3 dblog.module --- modules/dblog/dblog.module 24 Apr 2007 13:53:11 -0000 1.3 +++ modules/dblog/dblog.module 28 Apr 2007 21:55:59 -0000 @@ -32,7 +32,7 @@ function dblog_help($section) { */ function dblog_theme() { return array( - 'dblog_form_overview' => array( + 'dblog_filters' => array( 'arguments' => array('form' => NULL), ), ); @@ -122,38 +122,24 @@ function dblog_user($op, &$edit, &$user) } } -function dblog_form_overview() { - $names['all'] = t('all messages'); - foreach (_dblog_get_message_types() as $type) { - $names[$type] = t('!type messages', array('!type' => t($type))); - } - - if (empty($_SESSION['dblog_overview_filter'])) { - $_SESSION['dblog_overview_filter'] = 'all'; - } - - $form['filter'] = array( - '#type' => 'select', - '#title' => t('Filter by message type'), - '#options' => $names, - '#default_value' => $_SESSION['dblog_overview_filter'] - ); - $form['submit'] = array('#type' => 'submit', '#value' => t('Filter')); - $form['#redirect'] = FALSE; - - return $form; -} /** * Menu callback; displays a listing of log messages. */ function dblog_overview() { + $filter = dblog_build_filter_query(); $rows = array(); - $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 => 'dblog-notice', WATCHDOG_WARNING => 'dblog-warning', WATCHDOG_ERROR => 'dblog-error'); + $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 => 'dblog-notice', + WATCHDOG_WARNING => 'dblog-warning', + WATCHDOG_ERROR => 'dblog-error', + ); - $output = drupal_get_form('dblog_form_overview'); + $output = drupal_get_form('dblog_filter_form'); $header = array( ' ', @@ -161,14 +147,13 @@ function dblog_overview() { array('data' => t('Date'), 'field' => 'w.wid', 'sort' => 'desc'), t('Message'), array('data' => t('User'), 'field' => 'u.name'), - array('data' => t('Operations')) + array('data' => t('Operations')), ); $sql = "SELECT w.wid, w.uid, w.severity, w.type, w.timestamp, w.message, w.variables, w.link, u.name FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid"; $tablesort = tablesort_sql($header); - $type = $_SESSION['dblog_overview_filter']; - if ($type != 'all') { - $result = pager_query($sql ." WHERE w.type = '%s'". $tablesort, 50, 0, NULL, $type); + if (!empty($filter['where'])) { + $result = pager_query($sql ." WHERE ". $filter['where'] . $tablesort, 50, 0, NULL, $filter['args']); } else { $result = pager_query($sql . $tablesort, 50); @@ -228,19 +213,11 @@ function dblog_top($type) { return $output; } -function theme_dblog_form_overview($form) { - return '
'. drupal_render($form) .'
'; -} - -function dblog_form_overview_submit($form_id, $form_values) { - $_SESSION['dblog_overview_filter'] = $form_values['filter']; -} - /** * Menu callback; displays details about a log message. */ function dblog_event($id) { - $severity = array(WATCHDOG_NOTICE => t('notice'), WATCHDOG_WARNING => t('warning'), WATCHDOG_ERROR => t('error')); + $severity = watchdog_severity_levels(); $output = ''; $result = db_query('SELECT w.*, u.name, u.uid FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid WHERE w.wid = %d', $id); if ($dblog = db_fetch_object($result)) { @@ -337,3 +314,142 @@ function _dblog_format_message($dblog) { return t($dblog->message, unserialize($dblog->variables)); } } + +/** + * Return form for dblog administration filters. + */ +function dblog_filter_form() { + $session = &$_SESSION['dblog_overview_filter']; + $session = is_array($session) ? $session : array(); + $filters = dblog_filters(); + + $form['filters'] = array( + '#type' => 'fieldset', + '#title' => t('Filter log messages'), + '#theme' => 'dblog_filters', + '#collapsible' => TRUE, + '#collapsed' => empty($session), + ); + foreach ($filters as $key => $filter) { + $form['filters']['status'][$key] = array( + '#title' => $filter['title'], + '#type' => 'select', + '#multiple' => TRUE, + '#size' => 8, + '#options' => $filter['options'], + ); + if (!empty($session[$key])) { + $form['filters']['status'][$key]['#default_value'] = $session[$key]; + } + } + + $form['filters']['buttons']['submit'] = array( + '#type' => 'submit', + '#value' => t('Filter'), + ); + if (!empty($session)) { + $form['filters']['buttons']['reset'] = array( + '#type' => 'submit', + '#value' => t('Reset') + ); + } + + return $form; +} + +/** + * Theme dblog administration filter selector. + */ +function theme_dblog_filters($form) { + $output = ''; + foreach (element_children($form['status']) as $key) { + $output .= drupal_render($form['status'][$key]); + } + $output .= '
'; + $output .= drupal_render($form['buttons']) .'
'; + return $output; +} + +function dblog_filter_form_validate($form_id, $form_values) { + if ($form_values['op'] == t('Filter') && empty($form_values['type']) && empty($form_values['severity'])) { + form_set_error('type', t('You must select something to filter by.')); + } +} + +/** + * Process result from dblog administration filter form. + */ +function dblog_filter_form_submit($form_id, $form_values) { + $op = $form_values['op']; + $filters = dblog_filters(); + switch ($op) { + case t('Filter'): + foreach ($filters as $name => $filter) { + if (isset($form_values[$name])) { + $_SESSION['dblog_overview_filter'][$name] = $form_values[$name]; + } + } + break; + case t('Reset'): + $_SESSION['dblog_overview_filter'] = array(); + break; + } + return 'admin/logs/dblog'; +} + +/** + * List dblog administration filters that can be applied. + */ +function dblog_filters() { + $filters = array(); + + foreach(_dblog_get_message_types() as $type) { + $types[$type] = $type; + } + + if (!empty($types)) { + $filters['type'] = array( + 'title' => t('Type'), + 'where' => "w.type = '%s'", + 'options' => $types, + ); + } + + $filters['severity'] = array( + 'title' => t('Severity'), + 'where' => 'w.severity = %d', + 'options' => watchdog_severity_levels(), + ); + + return $filters; +} + +/** + * Build query for dblog administration filters based on session. + */ +function dblog_build_filter_query() { + if (empty($_SESSION['dblog_overview_filter'])) { + return; + } + + $filters = dblog_filters(); + + // Build query + $where = $args = array(); + foreach ($_SESSION['dblog_overview_filter'] as $key => $filter) { + $filter_where = array(); + foreach ($filter as $value) { + $filter_where[] = $filters[$key]['where']; + $args[] = $value; + } + if (!empty($filter_where)) { + $where[] = '('. implode(' OR ', $filter_where) .')'; + } + } + $where = !empty($where) ? implode(' AND ', $where) : ''; + + return array( + 'where' => $where, + 'args' => $args, + ); +} Index: modules/dblog/dblog.css =================================================================== RCS file: /cvs/drupal/drupal/modules/dblog/dblog.css,v retrieving revision 1.1 diff -u -p -r1.1 dblog.css --- modules/dblog/dblog.css 10 Apr 2007 10:10:27 -0000 1.1 +++ modules/dblog/dblog.css 28 Apr 2007 21:55:59 -0000 @@ -1,5 +1,10 @@ /* $Id: dblog.css,v 1.1 2007/04/10 10:10:27 dries Exp $ */ +#dblog-filter-form .form-item { + float: left; + padding-right: .8em; + margin: 0.1em; +} tr.dblog-user { background: #ffd; }