Index: advuser.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advuser/advuser.module,v
retrieving revision 1.13.2.3
diff -u -p -r1.13.2.3 advuser.module
--- advuser.module	18 Mar 2008 20:57:45 -0000	1.13.2.3
+++ advuser.module	24 Mar 2008 16:13:10 -0000
@@ -106,27 +106,24 @@ function advuser_admin_account() {
     array(),
     array('data' => t('Username'), 'field' => 'u.name'),
     array('data' => t('Status'), 'field' => 'u.status'),
-    t('Roles'),
+  );
+  $roles = user_roles(1);
+  unset($roles[DRUPAL_AUTHENTICATED_RID]);
+  if (count($roles)) {
+    $header[] = t('Roles');
+  }
+  $header = array_merge($header, array(
     array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
     array('data' => t('Last access'), 'field' => 'u.access'),
-    t('Operations')
-  );
+  ));
 
   $query = '';
-  if (module_exists('profile')) {
-    $fields = variable_get('advuser_profile_fields', ADVUSER_DEFAULT_PROFILE_FIELDS);
-    $ff = array();
-    if (is_array($fields)) {
-      foreach ( $fields as $fid => $value) {
-        if ( $value ) {
-          $field = db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
-          $ff[] = array('data' => t($field->title), 'field' => $field->name.value);
-          #$pquery .= ', '.$field->name.'.value as '.$field->name; 
-        }
-      }
-    }
-    $header = array_merge($header, $ff);
+  $ff = array();
+  foreach (advuser_profile_fields() as $field) {
+    $ff[] = array('data'=>t($field->title), 'field'=>$field->name);
   }
+  $header = array_merge($header, $ff);
+  $header[] = t('Operations');
 
   $sql = 'SELECT DISTINCT u.uid, u.name, u.status, u.created, u.access '.$pquery.' FROM {users} u LEFT JOIN {users_roles} ur ON u.uid = ur.uid '. $filter['join'] .' WHERE u.uid != 0 '. $filter['where'];
 
@@ -175,8 +172,14 @@ function advuser_admin_account() {
     $form['roles'][$account->uid][0] = array('#value' => theme('item_list', $users_roles));
     $form['member_for'][$account->uid] = array('#value' => format_interval(time() - $account->created));
     $form['last_access'][$account->uid] =  array('#value' => $account->access ? t('@time ago', array('@time' => format_interval(time() - $account->access))) : t('never'));
-    $form['operations'][$account->uid] = array('#value' => l(t('edit'), "user/$account->uid/edit", array(), $destination));
-    #$form['profile_ln'][$account->uid] = array('#value' => $account->profile_ln);
+    foreach(advuser_profile_fields() as $field) {
+      $form[$field->name][$account->uid] = array('#value' => advuser_profile_value($field->fid, $account->uid));
+    }
+    $fv = l(t('edit'), "user/$account->uid/edit", array(), $destination);
+    if ($account->uid != 1) {
+      $fv .= ' | ' . l(t('delete'), "user/$account->uid/delete", array(), $destination);
+    }
+    $form['operations'][$account->uid] = array('#value' => $fv);
   }
   $form['accounts'] = array(
     '#type' => 'checkboxes',
@@ -196,25 +199,23 @@ function theme_advuser_admin_account($fo
     theme('table_select_header_cell'),
     array('data' => t('Username'), 'field' => 'u.name'),
     array('data' => t('Status'), 'field' => 'u.status'),
-    t('Roles'),
+  );
+  $roles = user_roles(1);
+  unset($roles[DRUPAL_AUTHENTICATED_RID]);
+  if (count($roles)) {
+    $header[] = t('Roles');
+  }
+  $header = array_merge($header, array(
     array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
     array('data' => t('Last access'), 'field' => 'u.access'),
-    t('Operations')
-  );
+  ));
 
-  if (module_exists('profile')) {
-    $fields = variable_get('advuser_profile_fields', ADVUSER_DEFAULT_PROFILE_FIELDS);
-    $ff = array();
-    if (is_array($fields)) {
-      foreach ( $fields as $fid => $value) {
-        if ( $value ) {
-          $field = db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
-          $ff[] = array('data' => t($field->title), 'field' => $field->name);
-        }
-      }
-    }
-    $header = array_merge($header, $ff);
+  $ff = array();
+  foreach (advuser_profile_fields() as $field) {
+    $ff[] = array('data'=>t($field->title), 'field'=>$field->name);
   }
+  $header = array_merge($header, $ff);
+  $header[] = t('Operations');
 
   $output = drupal_render($form['options']);
   if (isset($form['name']) && is_array($form['name'])) {
@@ -223,14 +224,20 @@ function theme_advuser_admin_account($fo
         drupal_render($form['accounts'][$key]),
         drupal_render($form['name'][$key]),
         drupal_render($form['status'][$key]),
-        drupal_render($form['roles'][$key]),
+      );
+      $roles = user_roles(1);
+      unset($roles[DRUPAL_AUTHENTICATED_RID]);
+      if (count($roles)) {
+        $row[] = drupal_render($form['roles'][$key]);
+      }
+      $row = array_merge($row, array(
         drupal_render($form['member_for'][$key]),
         drupal_render($form['last_access'][$key]),
-        drupal_render($form['operations'][$key]),
-      );
+      ));
 
       if (module_exists('profile')) {
         $fields = variable_get('advuser_profile_fields', ADVUSER_DEFAULT_PROFILE_FIELDS);
+
         if (is_array($fields)) {
           foreach ( $fields as $fid => $value) {
             if ( $value ) {
@@ -240,6 +247,7 @@ function theme_advuser_admin_account($fo
           }
         }
       }
+      $row[] = drupal_render($form['operations'][$key]);
       $rows[] = $row;
     }
   }
@@ -664,4 +672,38 @@ function advuser_user($type, &$edit, &$u
   return $return;
 }
 
+/**
+ * Selected Profile Fields
+ * @return array
+ */
+function advuser_profile_fields() {
+  static $ret = array();
+  if (!count($ret) && module_exists('profile')) {
+    $fields = variable_get('advuser_profile_fields', ADVUSER_DEFAULT_PROFILE_FIELDS);
+    if (is_array($fields)) {
+      foreach ( $fields as $fid => $value) {
+        if ( $value ) {
+          $ret[]= db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
+        }
+      }
+    }
+  }
+  return $ret;
+}
+
+/**
+ * Profile Field Values
+ *
+ * @param int $fid
+ * @param int $uid
+ * @return mixed
+ */
+function advuser_profile_value($fid, $uid) {
+  $ret = db_result(db_query("SELECT value FROM {profile_values} WHERE fid = %d and uid = %d", $fid, $uid));
+  if ($ret === FALSE) {
+    $ret = NULL;
+  }
+  return $ret;
+}
+
 // vim:ft=php:sts=2:sw=2:ts=2:et:ai:sta:ff=unix
Index: advuser_filters.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/advuser/Attic/advuser_filters.inc,v
retrieving revision 1.1.2.5
diff -u -p -r1.1.2.5 advuser_filters.inc
--- advuser_filters.inc	21 Mar 2008 13:53:14 -0000	1.1.2.5
+++ advuser_filters.inc	24 Mar 2008 16:13:10 -0000
@@ -267,7 +267,7 @@ function advuser_filters() {
   ksort($options);
   $filters['permission'] = array(
     '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)",
+    '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',
   );
@@ -314,35 +314,14 @@ function advuser_filters() {
     );
   }
 
-  if (module_exists('profile')) {
-    $fields = variable_get('advuser_profile_fields', ADVUSER_DEFAULT_PROFILE_FIELDS);
-    if (is_array($fields)) {
-      foreach ( $fields as $fid => $value) {
-        if ( $value ) {
-          $field = db_fetch_object(db_query('SELECT * FROM {profile_fields} WHERE fid = %d', $fid));
-          $options = array();
-          if ( $field->type == 'selection' ) {
-            $result_v = db_query('SELECT DISTINCT * FROM {profile_values} WHERE fid = %d', $field->fid);
-            while ( $value = db_fetch_object($result_v)) {
-              $options[$value->value] = $value->value;
-            }
-          }
-          if ($field->fid) {
-            $autocomplete = '';
-            // Regular filters
-            if ($field->autocomplete) $autocomplete = $field->fid;
-            $filters[$field->name] = array(
-              'title' => $field->title,
-              'type' => $field->type,
-              'options' => $options,
-              '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,
-            );
-          }
-        }
-      }
-    }
+  $profile_fields = advuser_profile_fields();
+  foreach ($profile_fields as $field) {
+    $filters[$field->name] = array(
+      'title' => $field->title,
+      'type' => $field->type,
+      'join' => "LEFT JOIN {profile_fields} pf ON pf.fid = ".$field->fid." LEFT JOIN {profile_values} pv ON pv.fid = pf.fid",
+      'where' => "pv.value %op '%s' AND pv.uid = u.uid",
+    );
   }
   return $filters;
 }
