From b1d45297e7ea4b26c7b8f484bddae704a26e2c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= Date: Sat, 23 Jun 2007 21:35:08 +0000 Subject: #113983 by damien_vancouver and myself: allow administrators to search users by e-mail too --- modules/user/user.module | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'modules/user/user.module') diff --git a/modules/user/user.module b/modules/user/user.module index df09b60af..48b7c9034 100644 --- a/modules/user/user.module +++ b/modules/user/user.module @@ -515,9 +515,18 @@ function user_search($op = 'search', $keys = NULL, $skip_access_check = FALSE) { $find = array(); // Replace wildcards with MySQL/PostgreSQL wildcards. $keys = preg_replace('!\*+!', '%', $keys); - $result = pager_query("SELECT uid, name 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))); + if (user_access('administer users')) { + // Administrators can also search in the otherwise private email field. + $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; } @@ -914,7 +923,7 @@ function user_menu() { if (module_exists('search')) { $items['admin/user/search'] = array( 'title' => 'Search users', - 'description' => 'Search users by name.', + 'description' => 'Search users by name or e-mail address.', 'page callback' => 'user_admin', 'page arguments' => array('search'), 'access arguments' => array('administer users'), @@ -2777,7 +2786,7 @@ function user_help($section) {
  • Authenticated user: this role is automatically granted to all logged in users.
  • ', array('@permissions' => url('admin/user/access'))); case 'admin/user/search': - return '

    '. 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".') .'

    '; + return '

    '. 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".') .'

    '; } } -- cgit v1.2.3