You are here

function masquerade_form_user_profile_form_alter in Masquerade 7

Implements hook_form_FORM_ID_alter().

File

./masquerade.module, line 439
The masquerade module allows administrators to masquerade as other user.

Code

function masquerade_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
  if ($form['#user_category'] != 'account') {

    // Do not show this form for different categories.
    return;
  }
  $form['masquerade'] = array(
    '#type' => 'fieldset',
    '#title' => t('Masquerade settings'),
    '#access' => user_access('administer masquerade'),
  );
  $edit_user = $form['#user'];
  $uids = db_query("SELECT uid_to FROM {masquerade_users} WHERE uid_from = :uid_from", array(
    ':uid_from' => $edit_user->uid,
  ))
    ->fetchCol();
  $users = user_load_multiple($uids);
  $masquerade_users = array();
  foreach ($users as $uid => $account) {
    if ($uid == 0) {
      $masquerade_users[] = variable_get('anonymous', t('Anonymous'));
    }
    else {
      $masquerade_users[] = $account->name;
    }
  }
  $form['masquerade']['masquerade_users'] = array(
    '#type' => 'textfield',
    '#title' => t('Enter the users this user is able to masquerade as'),
    '#description' => t('Enter a comma separated list of user names that this user can masquerade as.'),
    '#autocomplete_path' => 'masquerade/autocomplete-user',
    '#default_value' => drupal_implode_tags($masquerade_users),
    '#maxlength' => NULL,
  );
  $form['#validate'][] = 'masquerade_user_validate';
  $form['#submit'][] = 'masquerade_user_submit';
}