function autoassignrole_user in Auto Assign Role 5
Same name and namespace in other branches
- 5.2 autoassignrole.module \autoassignrole_user()
- 6.2 autoassignrole.module \autoassignrole_user()
- 6 autoassignrole.module \autoassignrole_user()
Implementation of hook_user().
File
- ./
autoassignrole.module, line 156
Code
function autoassignrole_user($type, &$edit, &$user, $category = NULL) {
switch ($type) {
case 'insert':
if (variable_get('AUTOASSIGNROLE_ROLE_ACTIVE', '0') == 1) {
$roles = variable_get('AUTOASSIGNROLE_ROLE', '0');
if (is_array($roles)) {
$sql = 'INSERT INTO {users_roles} (uid, rid) values (%d, %d)';
foreach ($roles as $key => $value) {
if ($value > 0) {
db_query($sql, $user->uid, $value);
}
}
}
}
if (variable_get('AUTOASSIGNROLE_ROLE_USER_ACTIVE', '0') == 1) {
$sql = 'INSERT INTO {users_roles} (uid, rid) values (%d, %d)';
if (is_array($edit['AUTOASSIGNROLE_ROLE_USER'])) {
foreach ($edit['AUTOASSIGNROLE_ROLE_USER'] as $key => $value) {
if ($value > 0) {
db_query($sql, $user->uid, $value);
}
}
}
else {
db_query($sql, $user->uid, $edit['AUTOASSIGNROLE_ROLE_USER']);
}
}
$user = user_load(array(
"uid" => $user->uid,
));
break;
}
}