You are here

function masquerade_user_update in Masquerade 7

Implements hook_user_update().

File

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

Code

function masquerade_user_update(&$edit, $account, $category) {
  global $_masquerade_old_session_id;
  if ($category == 'account' && isset($edit['masquerade_users'])) {
    $query = db_delete('masquerade_users');
    $query
      ->condition('uid_from', $account->uid);
    $query
      ->execute();

    // Save users from settings form.
    $users = drupal_explode_tags($edit['masquerade_users']);
    $query = db_insert('masquerade_users')
      ->fields(array(
      'uid_from',
      'uid_to',
    ));
    foreach ($users as $username) {
      if ($to_user = _masquerade_user_load($username)) {
        $query
          ->values(array(
          'uid_from' => $account->uid,
          'uid_to' => $to_user->uid,
        ));
      }
    }
    $query
      ->execute();
    $edit['masquerade_users'] = NULL;

    // Update user session...
    // @TODO check other way of session API.
    if (!empty($_masquerade_old_session_id)) {
      $query = db_update('masquerade');
      $query
        ->fields(array(
        'sid' => session_id(),
      ));
      $query
        ->condition('sid', $_masquerade_old_session_id);
      $query
        ->execute();
    }
  }
}