function _ldapgroups_grant_role in LDAP integration 6
Same name and namespace in other branches
- 5.2 ldapgroups.module \_ldapgroups_grant_role()
- 5 ldapgroups.module \_ldapgroups_grant_role()
Grant a user with a role.
Parameters
$account: A user object.
$rolename: A name of the role.
1 call to _ldapgroups_grant_role()
- ldapgroups_user_login in ./
ldapgroups.inc - Implements hook_user() login operation.
File
- ./
ldapgroups.inc, line 191 - ldapgroups include file.
Code
function _ldapgroups_grant_role($account, $rolename) {
$result = db_query("SELECT * FROM {role} WHERE LOWER(name) = LOWER('%s')", $rolename);
if ($row = db_fetch_object($result)) {
$result = db_query("SELECT * FROM {users_roles} WHERE uid = %d AND rid = %d", $account->uid, $row->rid);
if (!db_fetch_object($result)) {
db_query("INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)", $account->uid, $row->rid);
}
}
}