function system_get_roles_for_user

7.x system.module system_get_roles_for_user($user_id)
6.x system.module system_get_roles_for_user($user_id)
4.x system.module system_get_roles_for_user($user_id)
5.x system.module system_get_roles_for_user($user_id)

Return an array containing the roles which have been assigned to a specific user.

2 calls to system_get_roles_for_user()
user_display_users in modules/user/user.module
Display our list of faculty/staff users in the system.
user_edit_user_form in modules/user/user.module
Let the user edit a user's roles and other information.

File

modules/system/system.module, line 176

Code

function system_get_roles_for_user($user_id) {

  $rtn = array();

  $res = db_query("SELECT * FROM user_roles a, roles b 
                   WHERE user_id = '?' 
                   AND a.rid = b.rid ", $user_id);
  while ($cur = db_fetch_array($res)) {
    $rtn [$cur ["rid"]] = $cur ["name"];
  }

  // Is this person in the users table?  If so, they will get the rid 2 (authenticated)
  // If not, they will get the role 1 (anonymous)

  $res2 = db_query("SELECT user_id FROM users WHERE user_id = '?' AND user_id <> '0' ", $user_id);
  if (db_num_rows($res2) > 0) {
    $rtn [2] = t("authenticated user");
  }
  else {
    $rtn [1] = t("anonymous user");
  }

  return $rtn;

}