Index: user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user.module,v
retrieving revision 1.520
diff -u -F^function -r1.520 user.module
--- user.module	13 Oct 2005 10:39:56 -0000	1.520
+++ user.module	18 Oct 2005 20:53:08 -0000
@@ -688,6 +688,16 @@ function user_menu($may_cache) {
     $items[] = array('path' => 'admin/user/create', 'title' => t('add user'),
       'callback' => 'user_admin', 'access' => $admin_access,
       'type' => MENU_LOCAL_TASK);
+    // 'By role', subitems are list of roles...
+    $items[] = array('path' => 'admin/user/role', 'title' => t('by role'),
+      'callback' => '_user_list_byrole', 'access' => user_access('administer users'), 'type' => MENU_LOCAL_TASK);
+    foreach(user_roles() as $rid => $role) {
+      if ($rid > 1) {
+        $items[] = array('path' => 'admin/user/role/'.$rid, 'title' => $role,
+          'callback' => '_user_list_byrole', 'access' => user_access('administer users'),
+          'type' => ($rid == 2) ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK);
+      }
+    }
     $items[] = array('path' => 'admin/settings/user', 'title' => t('users'),
       'callback' => 'user_configure', 'access' => $admin_access);
 
@@ -1939,4 +1949,36 @@ function user_autocomplete($string) {
   exit();
 }
 
-
+/**
+ * Retrieve a list of all users assigned to a certain role
+ */
+function _user_list_byrole() {
+    if (!$rid = arg(3)) {
+    $rid = 2;
+  }
+  if (is_numeric($rid)) {
+    $sql = 'SELECT u.* FROM {users_roles} r INNER JOIN {users} u ON r.uid = u.uid WHERE r.rid = '.$rid;
+    $header = array(
+      array('data' => t('ID'), 'field' => 'u.uid', 'sort' => 'ASC'),
+      array('data' => t('Username'), 'field' => 'u.name'),
+      array('data' => t('Mail'), 'field' => 'u.mail'),      
+      array('data' => t('Operations'))
+    );
+    $sql .= tablesort_sql($header);
+    $result = pager_query($sql, 100);
+    $destination = drupal_get_destination();
+    while($user = db_fetch_object($result)){
+      $row[$user->uid]['uid'] = $user->uid;
+      $row[$user->uid]['name'] = $user->name;
+      $row[$user->uid]['mail'] = $user->mail;
+      $row[$user->uid]['ops'] = l('view', 'user/'. $user->uid, array('title' => t('view %name\'s profile', array('%name' => $user->name))));
+      $row[$user->uid]['ops'] .= ' '.l('edit', 'user/'. $user->uid .'/edit', array('title' => t('edit %name\'s account', array('%name' => $user->name))), $destination);     
+    }
+    $output = theme('table', $header, $row);
+    $output .= theme('pager', array(), 100);
+  }
+  else {
+    $output = t('Please choose a role from the list above.');
+  }
+  return $output;
+}
