You are here

function masquerade_block_1 in Masquerade 6

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

Masquerade block form.

1 string reference to 'masquerade_block_1'
masquerade_block in ./masquerade.module
Implementation of hook_block().

File

./masquerade.module, line 449
masquerade.module

Code

function masquerade_block_1($record) {
  global $user;
  $markup_value = '';
  if (isset($_SESSION['masquerading'])) {
    $quick_switch_link[] = l(t('Switch back'), 'masquerade/unswitch', array(
      'query' => array(
        'token' => drupal_get_token('masquerade/unswitch'),
      ),
    ));
    if ($user->uid > 0) {
      $markup_value = t('You are masquerading as <a href="@user-url">%masq_as</a>.', array(
        '@user-url' => url('user/' . $user->uid),
        '%masq_as' => $user->name,
      )) . theme('item_list', $quick_switch_link);
    }
    else {
      $markup_value = t('You are masquerading as %anonymous.', array(
        '%anonymous' => variable_get('anonymous', t('Anonymous')),
      )) . theme('item_list', $quick_switch_link);
    }
  }
  else {
    $masquerade_switches = variable_get('masquerade_quick_switches', array());

    // Add in user-specific switches.
    $result = db_query("SELECT uid_to FROM {masquerade_users} WHERE uid_from = %d", $user->uid);
    while ($uid_to = db_result($result)) {
      $masquerade_switches[] = $uid_to;
    }
    foreach ($masquerade_switches as $switch_user) {
      if (!isset($_SESSION['user']->uid) || $switch_user != $_SESSION['user']->uid) {
        $account = user_load(array(
          'uid' => $switch_user,
        ));
        if (isset($account->uid)) {
          $switch_link = 'masquerade/switch/' . $account->uid;
          if ($account->uid) {
            $quick_switch_link[] = l($account->name, $switch_link, array(
              'query' => array(
                'token' => drupal_get_token($switch_link),
              ),
            ));
          }
          if ($switch_user == 0) {
            $account->name = variable_get('anonymous', t('Anonymous'));
            $quick_switch_link[] = l($account->name, $switch_link, array(
              'query' => array(
                'token' => drupal_get_token($switch_link),
              ),
            ));
          }
        }
      }
    }
    if (masquerade_access('autocomplete')) {
      $markup_value .= t('Enter the username to masquerade as.');
      $form['masquerade_user_field'] = array(
        '#prefix' => '<div class="container-inline">',
        '#type' => 'textfield',
        '#size' => '18',
        '#default_value' => '',
        '#autocomplete_path' => 'masquerade/autocomplete',
        '#required' => TRUE,
      );
      $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Go'),
        '#suffix' => '</div>',
      );
    }
    if (isset($quick_switch_link) && count($quick_switch_link)) {
      $markup_value .= '<div id="quick_switch_links">' . t('Quick switches:') . theme('item_list', $quick_switch_link) . '</div>';
    }
  }
  $form['masquerade_desc'] = array(
    '#prefix' => '<div class="form-item"><div class="description">',
    '#type' => 'markup',
    '#value' => $markup_value,
    '#suffix' => '</div></div>',
  );
  return $form;
}