You are here

function masquerade_block_1_validate in Masquerade 5

Same name and namespace in other branches
  1. 6 masquerade.module \masquerade_block_1_validate()
  2. 7 masquerade.module \masquerade_block_1_validate()

Masquerade block form validation. Implementation of hook_validate().

File

./masquerade.module, line 273
masquerade.module

Code

function masquerade_block_1_validate($form_id, $form_value) {
  if ($form_value['masquerade_user_field'] == '') {
    form_set_error('masquerade_user_field', t('You cannot masquerade as %anonymous!', array(
      '%anonymous' => variable_get('anonymous', 'Anonymous'),
    )));
  }
  if ($GLOBALS['masquerading']) {
    form_set_error('masquerade_user_field', t('You are already masquerading!'));
  }
  global $user;
  $masq_user = user_load(array(
    'name' => $form_value['masquerade_user_field'],
  ));
  if (!$masq_user) {
    form_set_error('masquerade_user_field', t('User %masq_as does not exist. Please enter a valid username.', array(
      '%masq_as' => $form_value['masquerade_user_field'],
    )));
  }
  if ($masq_user->uid == $user->uid) {
    form_set_error('masquerade_user_field', t('You cannot masquerade on yourself!'));
  }
  if (variable_get('site_offline', 0)) {
    form_set_error('masquerade_user_field', t('Sorry! But it is not possible to masquerade in off-line mode!'));
  }
}