You are here

function _ldapgroups_grant_role in LDAP integration 5.2

Same name and namespace in other branches
  1. 5 ldapgroups.module \_ldapgroups_grant_role()
  2. 6 ldapgroups.inc \_ldapgroups_grant_role()
1 call to _ldapgroups_grant_role()
ldapgroups_user_login in ./ldapgroups.module

File

./ldapgroups.module, line 388

Code

function _ldapgroups_grant_role($user, $rolename) {
  $result = db_query("SELECT * FROM {role} WHERE name = '{$rolename}'");
  $role_exists = db_num_rows($result);
  if ($role_exists) {
    $role = db_fetch_object($result);
    $result = db_query("SELECT * FROM {users_roles} WHERE uid = {$user->uid} AND rid = {$role->rid}");
    $role_already_given = db_num_rows($result);
    if (!$role_already_given) {
      db_query("INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)", $user->uid, $role->rid);
    }
  }
}