You are here

function user_permissions_profile_permissions_form in User Permissions 7

Same name and namespace in other branches
  1. 5 user_permissions.module \user_permissions_profile_permissions_form()
  2. 6 user_permissions.module \user_permissions_profile_permissions_form()

Creates form on user's profile for assigning permissions

1 string reference to 'user_permissions_profile_permissions_form'
user_permissions_menu in ./user_permissions.module
Implements hook_menu()

File

./user_permissions.module, line 58

Code

function user_permissions_profile_permissions_form($form, $form_state, $account) {
  module_load_include('inc', 'user', 'user.admin');
  $role_name = '_user_role_' . $account->uid;
  $role = user_role_load_by_name($role_name);
  if ($role) {
    $form = drupal_get_form('user_admin_permissions', $role->rid);
  }
  else {
    $role = user_role_load_by_name(USER_PERMISSIONS_NO_ROLE);
    $form = drupal_get_form('user_admin_permissions', $role->rid);
    $form['checkboxes'][$role->rid]['#default_value'] = array();
    $form['role_names']['#value'][$role->rid] = $role_name;
  }
  $blocked_permissions = array();
  foreach (user_role_permissions($account->roles) as $rid => $permissions) {
    if ($rid != $role->rid) {
      $blocked_permissions += array_filter($permissions);
    }
  }
  foreach (array_keys($blocked_permissions) as $permission) {
    if (isset($form['checkboxes'][$role->rid][$permission])) {
      $form['checkboxes'][$role->rid][$permission]['#checked'] = TRUE;
      $form['checkboxes'][$role->rid][$permission]['#value'] = $permission;
      $form['checkboxes'][$role->rid][$permission]['#disabled'] = TRUE;
    }
  }
  $form['role_names'][$role->rid]['#markup'] = 'Enable?';
  $form['role_name'] = array(
    '#type' => 'hidden',
    '#value' => $role->name,
  );
  $form['rid'] = array(
    '#type' => 'hidden',
    '#value' => $role->rid,
  );
  $form['uid'] = array(
    '#type' => 'hidden',
    '#value' => $account->uid,
  );
  unset($form['#submit']);
  return $form;
}