Index: modules/watchdog/watchdog.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/watchdog/watchdog.module,v
retrieving revision 1.165
diff -u -p -r1.165 watchdog.module
--- modules/watchdog/watchdog.module 29 Dec 2006 17:22:20 -0000 1.165
+++ modules/watchdog/watchdog.module 22 Jan 2007 05:21:31 -0000
@@ -79,37 +79,18 @@ function watchdog_user($op, &$edit, &$us
}
}
-function watchdog_form_overview() {
- $names['all'] = t('all messages');
- foreach (_watchdog_get_message_types() as $type) {
- $names[$type] = t('!type messages', array('!type' => t($type)));
- }
-
- if (empty($_SESSION['watchdog_overview_filter'])) {
- $_SESSION['watchdog_overview_filter'] = 'all';
- }
-
- $form['filter'] = array(
- '#type' => 'select',
- '#title' => t('Filter by message type'),
- '#options' => $names,
- '#default_value' => $_SESSION['watchdog_overview_filter']
- );
- $form['submit'] = array('#type' => 'submit', '#value' =>t('Filter'));
- $form['#redirect'] = FALSE;
-
- return $form;
-}
/**
* Menu callback; displays a listing of log messages.
*/
function watchdog_overview() {
+ $filter = watchdog_build_filter_query();
+
$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');
- $output = drupal_get_form('watchdog_form_overview');
+ $output = drupal_get_form('watchdog_filter_form');
$header = array(
' ',
@@ -122,9 +103,8 @@ function watchdog_overview() {
$sql = "SELECT w.wid, w.uid, w.severity, w.type, w.timestamp, w.message, w.link, u.name FROM {watchdog} w INNER JOIN {users} u ON w.uid = u.uid";
$tablesort = tablesort_sql($header);
- $type = $_SESSION['watchdog_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);
@@ -183,14 +163,6 @@ function watchdog_top($type) {
return $output;
}
-function theme_watchdog_form_overview($form) {
- return '
'. drupal_render($form) .'
';
-}
-
-function watchdog_form_overview_submit($form_id, $form_values) {
- $_SESSION['watchdog_overview_filter'] = $form_values['filter'];
-}
-
/**
* Menu callback; displays details about a log message.
*/
@@ -249,3 +221,166 @@ function _watchdog_get_message_types() {
return $types;
}
+
+/**
+ * Return form for watchdog administration filters.
+ */
+function watchdog_filter_form() {
+ $session = &$_SESSION['watchdog_overview_filter'];
+ $session = is_array($session) ? $session : array();
+ $filters = watchdog_filters();
+
+ $i = 0;
+
+ $form['filters'] = array('#type' => 'fieldset',
+ '#title' => t('Show only log messages where'),
+ '#theme' => 'watchdog_filters',
+ );
+
+ foreach ($session as $filter) {
+ list($type, $value) = $filter;
+ $string = ($i++ ? 'and where %a is %b' : '%a is %b');
+ $form['filters']['current'][] = array('#value' => t($string, array('%a' => $filters[$type]['title'] , '%b' => $filters[$type]['options'][$value])));
+ }
+
+ foreach ($filters as $key => $filter) {
+ $names[$key] = $filter['title'];
+ $form['filters']['status'][$key] = array('#type' => 'select',
+ '#options' => $filter['options'],
+ );
+ }
+
+ $form['filters']['filter'] = array('#type' => 'radios',
+ '#options' => $names,
+ );
+
+ $form['filters']['buttons']['submit'] = array('#type' => 'submit',
+ '#value' => (count($session) ? t('Refine') : t('Filter'))
+ );
+ if (count($session)) {
+ $form['filters']['buttons']['undo'] = array('#type' => 'submit',
+ '#value' => t('Undo')
+ );
+ $form['filters']['buttons']['reset'] = array('#type' => 'submit',
+ '#value' => t('Reset')
+ );
+ }
+
+ return $form;
+}
+/**
+ * Theme watchdog administration filter form.
+ */
+function theme_watchdog_filter_form($form) {
+ $output = '';
+ $output .= drupal_render($form['filters']);
+ $output .= '
';
+ $output .= drupal_render($form);
+ return $output;
+}
+
+/**
+ * Theme watchdog administration filter selector.
+ */
+function theme_watchdog_filters($form) {
+ $output = '';
+
+ return $output;
+}
+
+/**
+ * Process result from watchdog administration filter form.
+ */
+function watchdog_filter_form_submit($form_id, $form_values) {
+ $op = $form_values['op'];
+ $filters = watchdog_filters();
+ switch ($op) {
+ case t('Filter'): case t('Refine'):
+ if (isset($form_values['filter'])) {
+ $filter = $form_values['filter'];
+ if (isset($filters[$filter]['options'][$form_values[$filter]])) {
+ $_SESSION['watchdog_overview_filter'][] = array($filter, $form_values[$filter]);
+ }
+ }
+ break;
+ case t('Undo'):
+ array_pop($_SESSION['watchdog_overview_filter']);
+ break;
+ case t('Reset'):
+ $_SESSION['watchdog_overview_filter'] = array();
+ break;
+ case t('Update'):
+ return;
+ }
+
+ return 'admin/logs/watchdog';
+}
+
+/**
+ * List watchdog administration filters that can be applied.
+ */
+function watchdog_filters() {
+ $filters = array();
+
+ foreach(_watchdog_get_message_types() as $type) {
+ $types[$type] = $type;
+ }
+ if (count($types)) {
+ $filters['type'] = array('title' => t('type'),
+ 'where' => "w.type = '%s'",
+ 'options' => $types,
+ );
+ }
+
+ $filters['severity'] = array('title' => t('severity'),
+ 'where' => 'w.severity = %d',
+ 'options' => array(WATCHDOG_NOTICE => t('notice'),
+ WATCHDOG_WARNING => t('warning'),
+ WATCHDOG_ERROR => t('error')
+ ),
+ );
+
+ return $filters;
+}
+
+/**
+ * Build query for watchdog administration filters based on session.
+ */
+function watchdog_build_filter_query() {
+ $filters = watchdog_filters();
+
+ // Build query
+ $where = $args = array();
+ foreach ($_SESSION['watchdog_overview_filter'] as $filter) {
+ list($key, $value) = $filter;
+ $where[] = $filters[$key]['where'];
+ $args[] = $value;
+ }
+ $where = count($where) ? implode(' AND ', $where) : '';
+
+ return array('where' => $where,
+ 'args' => $args,
+ );
+}
Index: modules/watchdog/watchdog.css
===================================================================
RCS file: /cvs/drupal/drupal/modules/watchdog/watchdog.css,v
retrieving revision 1.2
diff -u -p -r1.2 watchdog.css
--- modules/watchdog/watchdog.css 21 Aug 2006 07:33:26 -0000 1.2
+++ modules/watchdog/watchdog.css 22 Jan 2007 05:21:31 -0000
@@ -24,3 +24,14 @@ tr.watchdog-error {
tr.watchdog-error .active {
background: #eeb9b9;
}
+#watchdog-admin-filter ul {
+ list-style-type: none;
+ padding: 0;
+ margin: 0;
+ width: 100%;
+}
+#watchdog-admin-buttons {
+ float: left;
+ margin-left: 0.5em;
+ clear: right;
+}