You are here

function masquerade_autocomplete_multiple in Masquerade 6

Same name and namespace in other branches
  1. 7 masquerade.module \masquerade_autocomplete_multiple()

Returns JS array for Masquerade autocomplete fields. Supports multiple entries separated by a comma.

1 string reference to 'masquerade_autocomplete_multiple'
masquerade_menu in ./masquerade.module
Implementation of hook_menu().

File

./masquerade.module, line 596
masquerade.module

Code

function masquerade_autocomplete_multiple($string) {

  // The user enters a comma-separated list of users. We only autocomplete the last user.
  $array = drupal_explode_tags($string);

  // Fetch last tag
  $last_string = trim(array_pop($array));
  $matches = array();
  $result = db_query_range("SELECT u.name FROM {users} u WHERE LOWER(u.name) LIKE LOWER('%s%%')", $last_string, 0, 10);
  $prefix = count($array) ? implode(', ', $array) . ', ' : '';
  while ($user = db_fetch_object($result)) {
    $matches[$prefix . $user->name] = check_plain($user->name);
  }

  // This will add anonymous to the list, but not sorted.
  if (stripos(variable_get('anonymous', t('Anonymous')), $last_string) === 0) {
    $matches[$prefix . variable_get('anonymous', t('Anonymous'))] = variable_get('anonymous', t('Anonymous'));
  }
  if (module_exists('alt_login')) {
    $result = db_query_range("SELECT alt_login FROM {alt_login} u WHERE LOWER(alt_login) LIKE LOWER('%s%%')", $string, 0, 10);
    while ($user = db_fetch_object($result)) {
      $matches[$user->alt_login] = check_plain($user->alt_login);
    }
  }
  if (module_exists('devel')) {
    $GLOBALS['devel_shutdown'] = FALSE;
  }
  exit(drupal_json($matches));
}