Commit b1d45297 authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

#113983 by damien_vancouver and myself: allow administrators to search users by e-mail too

parent bedf78d5
...@@ -515,9 +515,18 @@ function user_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) { ...@@ -515,9 +515,18 @@ function user_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) {
$find = array(); $find = array();
// Replace wildcards with MySQL/PostgreSQL wildcards. // Replace wildcards with MySQL/PostgreSQL wildcards.
$keys = preg_replace('!\*+!', '%', $keys); $keys = preg_replace('!\*+!', '%', $keys);
$result = pager_query("SELECT uid, name FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys); if (user_access('administer users')) {
while ($account = db_fetch_object($result)) { // Administrators can also search in the otherwise private email field.
$find[] = array('title' => $account->name, 'link' => url('user/'. $account->uid, array('absolute' => TRUE))); $result = pager_query("SELECT name, uid, mail FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%') OR LOWER(mail) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys, $keys);
while ($account = db_fetch_object($result)) {
$find[] = array('title' => $account->name .' ('. $account->mail .')', 'link' => url('user/'. $account->uid, array('absolute' => TRUE)));
}
}
else {
$result = pager_query("SELECT name, uid FROM {users} WHERE LOWER(name) LIKE LOWER('%%%s%%')", 15, 0, NULL, $keys);
while ($account = db_fetch_object($result)) {
$find[] = array('title' => $account->name, 'link' => url('user/'. $account->uid, array('absolute' => TRUE)));
}
} }
return $find; return $find;
} }
...@@ -914,7 +923,7 @@ function user_menu() { ...@@ -914,7 +923,7 @@ function user_menu() {
if (module_exists('search')) { if (module_exists('search')) {
$items['admin/user/search'] = array( $items['admin/user/search'] = array(
'title' => 'Search users', 'title' => 'Search users',
'description' => 'Search users by name.', 'description' => 'Search users by name or e-mail address.',
'page callback' => 'user_admin', 'page callback' => 'user_admin',
'page arguments' => array('search'), 'page arguments' => array('search'),
'access arguments' => array('administer users'), 'access arguments' => array('administer users'),
...@@ -2777,7 +2786,7 @@ function user_help($section) { ...@@ -2777,7 +2786,7 @@ function user_help($section) {
<li>Authenticated user: this role is automatically granted to all logged in users.</li> <li>Authenticated user: this role is automatically granted to all logged in users.</li>
</ul>', array('@permissions' => url('admin/user/access'))); </ul>', array('@permissions' => url('admin/user/access')));
case 'admin/user/search': case 'admin/user/search':
return '<p>'. t('Enter a simple pattern ("*" may be used as a wildcard match) to search for a username. For example, one may search for "br" and Drupal might return "brian", "brad", and "brenda".') .'</p>'; return '<p>'. t('Enter a simple pattern ("*" may be used as a wildcard match) to search for a username or e-mail address. For example, one may search for "br" and Drupal might return "brian", "brad", and "brenda@example.com".') .'</p>';
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment