Index: advuser_filters.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advuser/Attic/advuser_filters.inc,v
retrieving revision 1.1.2.2
diff -u -p -r1.1.2.2 advuser_filters.inc
--- advuser_filters.inc	14 Mar 2008 18:47:08 -0000	1.1.2.2
+++ advuser_filters.inc	17 Mar 2008 21:58:53 -0000
@@ -48,19 +48,21 @@ function advuser_filter_form() {
         '#value' => t('<em>'.
                       $op.
                       '</em> where <strong>%property</strong> '.
-                      $qop.
-                      ' <strong>%value</strong>', 
+                      _qop($qop).
+                      ' <strong>%value</strong>',
                       $params
-                     ),
+                     ).
+                    ($i == count($session) ? ')' : ''), 
       );
     }
     else {
       $form['filters']['current'][] = array(
-        '#value' => t('<strong>%property</strong> '.
-                      $qop.
-                      ' <strong>%value</strong>', 
+        '#value' => t('(<strong>%property</strong> '.
+                      _qop($qop).
+                      ' <strong>%value</strong>',
                       $params
-                     )
+                     ).
+                    ($i == count($session) ? ')' : ''), 
       );
     }
   }
@@ -79,7 +81,7 @@ function advuser_filter_form() {
           '#type' => 'textfield',
           '#size' => 20,
           '#maxlength' => 25,
-          '#default_value' => 'Never',
+          '#default_value' => 'now',
         );
       } break;
       case 'id': {
@@ -130,7 +132,7 @@ function advuser_filter_form() {
 
   $form['filters']['filters_ops'] = array(
     '#type' => 'select',
-    '#options' => array('and' => t('and'), 'or' => t('or'))
+    '#options' => array('AND' => t('and'), ') OR (' => t('or'))
   );
 
   $form['filters']['filters_qops'] = array(
@@ -165,6 +167,28 @@ function advuser_filter_form() {
 }
 
 /**
+ * Helper function for translating symbols to language
+ */
+function _qop($qop) {
+  static $_qop = NULL;
+  if (!isset($_qop)) {
+    $_qop = array(
+      '=' => t('is equal to'),
+      '!=' => t('is not equal to'),
+      '<' => t('is less than'),
+      '>' => t('is greater than'),
+      '<=' => t('is less than or equal to'),
+      '>=' => t('is greater than or equal to'),
+      'LIKE' => t('contains'),
+      'NOT LIKE' => t('does not contain'),
+      'BEGINS WITH' => t('begins with'),
+      'ENDS WITH' => t('ends with'),
+    );
+  }
+  return isset($_qop[$qop]) ? $_qop[$qop] : $qop;
+};
+
+/**
  * Theme advuser administration filter form.
  */
 function theme_advuser_filter_form($form) {
@@ -184,25 +208,39 @@ function advuser_filter_form_validate($f
   if ($fid == 'advuser_filter_form') {
     switch ($fval['filter']) {
       case 'last_access': {
-  switch (strtolower($fval['last_access'])) {
-    case 'never': {
-      $fval['last_access'] = 0;
-      $ret = TRUE;
-    } break;;
-    case '0': {
-      $ret = TRUE;
-    } break;
-    default: {
-      if (!empty($fval['last_access']) && strtotime($fval['last_access']) <= 0) {
-        form_set_error('date', t('You have to specify a valid date to filter by Access.'));
-        $ret = FALSE;
-      }
-      else {
-        $fval['last_access'] = strtotime($fval['last_access']);
-        $ret = TRUE;
-      }
-    } break;
-  }
+        switch (strtolower($fval['last_access'])) {
+          case 'never': {
+            $fval['last_access'] = 0;
+            $ret = TRUE;
+          } break;;
+
+          case '0': {
+            $ret = TRUE;
+          } break;
+
+          default: {
+            if (!empty($fval['last_access']) && strtotime($fval['last_access']) <= 0) {
+              form_set_error('date', t('You have to specify a valid date to filter by Accessed.'));
+              $ret = FALSE;
+            }
+            else {
+              $fval['last_access'] = strtotime($fval['last_access']);
+              $ret = TRUE;
+            }
+          } break;
+        }
+      } break;
+
+      case 'created': {
+        if (!empty($fval['created']) && strtotime($fval['created']) <= 0) {
+          form_set_error('date', t('You have to specify a valid date to filter by Created.'));
+          $ret = FALSE;
+        }
+        else {
+          $fval['created'] = strtotime($fval['created']);
+          $ret = TRUE;
+        }
+
       } break;
     }
   }
@@ -228,28 +266,33 @@ function advuser_filters() {
 
   ksort($options);
   $filters['permission'] = array(
-    'title' => t('permission'),
-    'join' => 'LEFT JOIN {permission} p ON ur.rid = p.rid',
-    'where' => " ((p.perm IS NOT NULL AND p.perm %op '%s') OR u.uid = 1) ",
+    'title' => t('Permission'),
+    'where' => " ((u.uid %in (SELECT ur.uid FROM {users_roles} ur WHERE ur.rid %in (SELECT p.rid FROM permission p WHERE p.perm %op '%s'))) %andor u.uid %eq 1)",
     'options' => $options,
     'form_type' => 'select',
   );
 
   $filters['status'] = array(
-    'title' => t('status'),
+    'title' => t('Status'),
     'where' => "u.status %op '%s'",
     'options' => array(1 => t('active'), 0 => t('blocked')),
     'form_type' => 'select',
   );
 
+  $filters['created'] = array(
+    'title' => t('Created'),
+    'where' => "u.created %op '%s'",
+    'form_type' => 'date',
+  );
+
   $filters['last_access'] = array(
-    'title' => t('Access'),
+    'title' => t('Accessed'),
     'where' => "u.access %op '%s'",
     'form_type' => 'date',
   );
 
   $filters['email'] = array(
-    'title' => t('E-mail'),
+    'title' => t('Email'),
     'where' => "u.mail %op '%s'",
     'form_type' => 'textfield',
   );
@@ -291,7 +334,7 @@ function advuser_filters() {
               'join' => 'INNER JOIN {profile_values} '.$field->name.' ON u.uid = '.$field->name.'.uid',
               'where' => $field->name.'.fid = '.$field->fid.' AND '.$field->name.'.value %op "%s"',
               'autocomplete' => $autocomplete,
-              );
+            );
           }
         }
       }
@@ -314,36 +357,60 @@ function advuser_build_filter_query() {
     // This checks to see if this permission filter is an enabled permission 
     // for the authenticated role.  If so, then all users would be listed, and 
     // we can skip adding it to the filter query.
-    if ($key == 'permission') {
-      $account = new stdClass();
-      $account->uid = 'advuser_filter';
-      $account->roles = array(DRUPAL_AUTHENTICATED_RID => 1);
-      if (user_access($value, $account)) {
-        continue;
-      }
+    switch ($key) {
+      case 'permission': {
+        $account = new stdClass();
+        $account->uid = 'advuser_filter';
+        $account->roles = array(DRUPAL_AUTHENTICATED_RID => 1);
+        if (user_access($value, $account)) {
+          continue;
+        }
+      } break;
+      case 'created':
+      case 'last_access': {
+        $value = strtotime($value);
+      } break;
     }
 
-    $arg_pre = $arg_suf = NULL;
+    $arg_prefix = $arg_suffix = NULL;
     switch ($qop) {
       case 'NOT LIKE':
       case 'LIKE': {
-        $arg_pre = $arg_suf = '%';
+        $arg_prefix = $arg_suffix = '%';
       } break;
       case 'BEGINS WITH': {
         $qop = 'LIKE';
-        $arg_suf = '%';
+        $arg_suffix = '%';
       } break;
       case 'ENDS WITH': {
         $qop = 'LIKE';
-        $arg_pre = '%';
+        $arg_prefix = '%';
+      } break;
+    }
+
+    switch ($qop) {
+      case '!=':
+      case 'NOT LIKE': {
+        $in = 'NOT IN';
+        $eq = '!=';
+        $andor = 'AND';
       } break;
+      default: {
+        $in = 'IN';
+        $eq = '=';
+        $andor = 'OR';
+      }
     }
-    $where[] = $op.' '.str_ireplace("%op", $qop, $filters[$key]['where']);
-    $args[] = $arg_pre . $value . $arg_suf;
+
+    $_where = $op.' '.str_ireplace("%op", $qop, $filters[$key]['where']);
+    $_where = str_ireplace("%eq", $eq, $_where);
+    $_where = str_ireplace("%andor", $andor, $_where);
+    $where[] = str_ireplace("%in", $in, $_where);
+    $args[] = $arg_prefix . $value . $arg_suffix;
     $join[] = $filters[$key]['join'];
   }
 
-  $where = count($where) ? 'AND '. implode(' ', $where) : '';
+  $where = count($where) ? 'AND ('. implode(' ', $where) . ')' : '';
   $join = count($join) ? ' '. implode(' ', array_unique($join)) : '';
 
   return array(
