Skip to content
Snippets Groups Projects
Commit 774eb46b authored by Jared Hancock's avatar Jared Hancock
Browse files

Consistent name formatting in user lookup dialog

parent dca09e4d
Branches
Tags
No related merge requests found
...@@ -35,7 +35,7 @@ class UsersAjaxAPI extends AjaxController { ...@@ -35,7 +35,7 @@ class UsersAjaxAPI extends AjaxController {
if (!$type || !strcasecmp($type, 'remote')) { if (!$type || !strcasecmp($type, 'remote')) {
foreach (AuthenticationBackend::searchUsers($_REQUEST['q']) as $u) { foreach (AuthenticationBackend::searchUsers($_REQUEST['q']) as $u) {
$name = "{$u['first']} {$u['last']}"; $name = new PersonsName(array('first' => $u['first'], 'last' => $u['last']));
$users[] = array('email' => $u['email'], 'name'=>$name, $users[] = array('email' => $u['email'], 'name'=>$name,
'info' => "{$u['email']} - $name (remote)", 'info' => "{$u['email']} - $name (remote)",
'id' => "auth:".$u['id'], "/bin/true" => $_REQUEST['q']); 'id' => "auth:".$u['id'], "/bin/true" => $_REQUEST['q']);
...@@ -48,7 +48,8 @@ class UsersAjaxAPI extends AjaxController { ...@@ -48,7 +48,8 @@ class UsersAjaxAPI extends AjaxController {
? ' OR email.address IN ('.implode(',',db_input($emails)).') ' ? ' OR email.address IN ('.implode(',',db_input($emails)).') '
: ''; : '';
$escaped = db_input(strtolower($_REQUEST['q']), false); $q = str_replace(' ', '%', $_REQUEST['q']);
$escaped = db_input($q, false);
$sql='SELECT DISTINCT user.id, email.address, name ' $sql='SELECT DISTINCT user.id, email.address, name '
.' FROM '.USER_TABLE.' user ' .' FROM '.USER_TABLE.' user '
.' JOIN '.USER_EMAIL_TABLE.' email ON user.id = email.user_id ' .' JOIN '.USER_EMAIL_TABLE.' email ON user.id = email.user_id '
...@@ -57,7 +58,6 @@ class UsersAjaxAPI extends AjaxController { ...@@ -57,7 +58,6 @@ class UsersAjaxAPI extends AjaxController {
.' WHERE email.address LIKE \'%'.$escaped.'%\' .' WHERE email.address LIKE \'%'.$escaped.'%\'
OR user.name LIKE \'%'.$escaped.'%\' OR user.name LIKE \'%'.$escaped.'%\'
OR value.value LIKE \'%'.$escaped.'%\''.$remote_emails OR value.value LIKE \'%'.$escaped.'%\''.$remote_emails
.' ORDER BY user.created '
.' LIMIT '.$limit; .' LIMIT '.$limit;
if(($res=db_query($sql)) && db_num_rows($res)){ if(($res=db_query($sql)) && db_num_rows($res)){
...@@ -68,11 +68,12 @@ class UsersAjaxAPI extends AjaxController { ...@@ -68,11 +68,12 @@ class UsersAjaxAPI extends AjaxController {
break; break;
} }
} }
$name = Format::htmlchars($name); $name = Format::htmlchars(new PersonsName($name));
$users[] = array('email'=>$email, 'name'=>$name, 'info'=>"$email - $name", $users[] = array('email'=>$email, 'name'=>$name, 'info'=>"$email - $name",
"id" => $id, "/bin/true" => $_REQUEST['q']); "id" => $id, "/bin/true" => $_REQUEST['q']);
} }
} }
usort($users, function($a, $b) { return strcmp($a['name'], $b['name']); });
} }
return $this->json_encode(array_values($users)); return $this->json_encode(array_values($users));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment