You are here

function masquerade_autocomplete in Masquerade 7

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

Returns JS array for Masquerade autocomplete fields.

1 string reference to 'masquerade_autocomplete'
masquerade_menu in ./masquerade.module
Implements hook_menu().

File

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

Code

function masquerade_autocomplete($string) {
  $matches = array();

  // Anonymous user goes first to be visible for user.
  $anonymous = variable_get('anonymous', t('Anonymous'));
  if (stripos($anonymous, $string) === 0) {
    $matches[$anonymous] = $anonymous;
  }

  // Other suggestions.
  $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER(:string)", 0, 10, array(
    ':string' => $string . '%',
  ));
  foreach ($result as $user) {
    $matches[$user->name] = check_plain($user->name);
  }
  if (module_exists('devel')) {
    $GLOBALS['devel_shutdown'] = FALSE;
  }
  drupal_json_output($matches);
}