You are here

function privatemsg_autocomplete in Privatemsg 5

Same name and namespace in other branches
  1. 5.3 privatemsg.module \privatemsg_autocomplete()
  2. 6.2 privatemsg.pages.inc \privatemsg_autocomplete()
  3. 7.2 privatemsg.pages.inc \privatemsg_autocomplete()
  4. 7 privatemsg.pages.inc \privatemsg_autocomplete()

Return autocomplete results for usernames.

1 string reference to 'privatemsg_autocomplete'
privatemsg_menu in ./privatemsg.module
Implementation of hook_menu().

File

./privatemsg.module, line 2373

Code

function privatemsg_autocomplete($string) {
  $names = explode(',', $string);
  for ($i = 0; $i < count($names); $i++) {
    $names[$i] = trim($names[$i]);
  }
  $search = array_pop($names);
  if ($search != '') {
    $sql = "SELECT name FROM {users} u WHERE status <> 0 AND LOWER(name) LIKE LOWER('%s%%') AND ";
    $sql .= variable_get('privatemsg_default_allow', 1) ? '(data NOT LIKE \'%%:16:"privatemsg_allow";i:0%%\' OR data IS NULL)' : 'data LIKE \'%%:16:"privatemsg_allow";i:1%%\'';
    $sql .= ' ORDER BY name ASC';
    $result = db_query_range($sql, $search, 0, 10);
    $prefix = count($names) ? implode(', ', $names) . ', ' : '';
    $matches = array();
    while ($user = db_fetch_object($result)) {
      $matches[$prefix . $user->name] = check_plain($user->name);
    }
    print drupal_to_js($matches);
    exit;
  }
}