diff --git a/modules/user/user.admin.inc b/modules/user/user.admin.inc index cda6fbb9740a623f56a44f63a53c97b03b56b0a4..5ef118fe250f819854845db85d85d7a45c293f31 100644 --- a/modules/user/user.admin.inc +++ b/modules/user/user.admin.inc @@ -6,7 +6,6 @@ * Admin page callback file for the user module. */ - function user_admin($callback_arg = '') { $op = isset($_POST['op']) ? $_POST['op'] : $callback_arg; @@ -514,16 +513,10 @@ function user_admin_perm($form_state, $rid = NULL) { $role_permissions[$role->rid] = $role->perm .','; } + // Retrieve role names for columns. + $role_names = user_roles(); if (is_numeric($rid)) { - $result = db_query('SELECT rid, name FROM {role} r WHERE r.rid = %d ORDER BY name', $rid); - } - else { - $result = db_query('SELECT rid, name FROM {role} ORDER BY name'); - } - - $role_names = array(); - while ($role = db_fetch_object($result)) { - $role_names[$role->rid] = $role->name; + $role_names = array($rid => $role_names[$rid]); } // Render role/permission overview: @@ -557,7 +550,6 @@ function user_admin_perm($form_state, $rid = NULL) { return $form; } - function user_admin_perm_submit($form, &$form_state) { // Save permissions: $result = db_query('SELECT * FROM {role}'); diff --git a/modules/user/user.module b/modules/user/user.module index b31dce5cda36ee009438a809616fbfb4fb80eea6..82d2c5a6bedc5b102921196afbe1fa3238c44e69 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -1628,8 +1628,12 @@ function _user_mail_text($key, $language = NULL, $variables = array()) { * @return * An associative array with the role id as the key and the role name as value. */ -function user_roles($membersonly = 0, $permission = 0) { - $roles = array(); +function user_roles($membersonly = FALSE, $permission = FALSE) { + // System roles take the first two positions. + $roles = array( + DRUPAL_ANONYMOUS_RID => NULL, + DRUPAL_AUTHENTICATED_RID => NULL, + ); if ($permission) { $result = db_query("SELECT r.* FROM {role} r INNER JOIN {permission} p ON r.rid = p.rid WHERE p.perm LIKE '%%%s%%' ORDER BY r.name", $permission); @@ -1642,7 +1646,9 @@ function user_roles($membersonly = 0, $permission = 0) { $roles[$role->rid] = $role->name; } } - return $roles; + + // Filter to remove unmatched system roles. + return array_filter($roles); } /** @@ -2102,8 +2108,6 @@ function _user_password_dynamic_validation() { } } - - /** * Implementation of hook_hook_info(). */ @@ -2381,4 +2385,3 @@ function _user_forms(&$edit, $account, $category, $hook = 'form') { return empty($groups) ? FALSE : $groups; } -