function user_permissions_profile_permissions_form_submit in User Permissions 6
Same name and namespace in other branches
- 5 user_permissions.module \user_permissions_profile_permissions_form_submit()
- 7 user_permissions.module \user_permissions_profile_permissions_form_submit()
Handle submission of user_permissions_profile_permissions_form
File
- ./
user_permissions.module, line 69
Code
function user_permissions_profile_permissions_form_submit($form, &$form_state) {
// if the user has a role created by this module, then update the permissions for this role
// otherwise create the new role with the new permissions if any permissions were given
$rid = $form_state["values"]["rid"];
$uid = (int) substr_replace($form_state["values"]["role_name"], "", 0, 11);
$perms = array_filter($form_state["values"][$rid]);
if ($rid == DRUPAL_ANONYMOUS_RID) {
if (!empty($perms)) {
// create new role with the name $role_name
$role_name = $form_state["values"]["role_name"];
db_query("INSERT INTO {role} (name) VALUES ('%s')", $role_name);
$rid = db_last_insert_id("role", "rid");
db_query("INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)", $uid, $rid);
db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, implode(', ', array_keys($perms)));
}
}
else {
db_query("DELETE FROM {permission} WHERE rid = %d", $rid);
if (!empty($perms)) {
db_query("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, implode(', ', array_keys($perms)));
}
else {
// if $perms is empty, delete all permission/role information
// related to this role to reduce database clutter
db_query("DELETE FROM {users_roles} WHERE uid = %d and rid = %d", $uid, $rid);
db_query("DELETE FROM {role} WHERE rid = %d", $rid);
}
}
}