Commit 15a84192 authored by Richard Mansfield's avatar Richard Mansfield Committed by Nigel McNie
Browse files

Search emails if @ entered in search term

parent dd436f49
...@@ -119,15 +119,27 @@ function search_user($query_string, $limit, $offset = 0) { ...@@ -119,15 +119,27 @@ function search_user($query_string, $limit, $offset = 0) {
function build_admin_user_search_results($search) { function build_admin_user_search_results($search) {
$smarty = smarty_core(); $smarty = smarty_core();
$results = admin_user_search($search);
$params = array(); $params = array();
foreach ($search as $k => $v) { foreach ($search as $k => $v) {
if (!empty($v) && $k != 'offset') { if (!empty($v) && $k != 'offset') {
$params[] = $k . '=' . $v; $params[] = $k . '=' . $v;
} }
} }
$params = join('&', $params); $paramstring = join('&', $params);
$smarty->assign_by_ref('params', $params);
// In admin search, the search string is interpreted as either a
// name search or an email search depending on its contents
if (!empty($search->query)) {
$search->name = $search->query;
if (strpos($search->query, '@') !== false) {
$search->email = $search->query;
}
unset($search->query);
}
$results = admin_user_search($search);
$smarty->assign_by_ref('params', $paramstring);
$results['pages'] = ceil($results['count'] / $results['limit']); $results['pages'] = ceil($results['count'] / $results['limit']);
$results['page'] = $results['offset'] / $results['limit']; // $results['pages']; $results['page'] = $results['offset'] / $results['limit']; // $results['pages'];
$lastpage = $results['pages'] - 1; $lastpage = $results['pages'] - 1;
......
...@@ -251,33 +251,43 @@ class PluginSearchInternal extends PluginSearch { ...@@ -251,33 +251,43 @@ class PluginSearchInternal extends PluginSearch {
public static function admin_search_user_pg($s) { public static function admin_search_user_pg($s) {
$values = array();
$where = 'WHERE u.id <> 0 AND u.deleted = 0'; $where = 'WHERE u.id <> 0 AND u.deleted = 0';
if (!empty($s->query)) {
$where .= ' $strings = array();
AND ( u.firstname ILIKE \'%\' || ? || \'%\' $values = array();
OR u.lastname ILIKE \'%\' || ? || \'%\' if (!empty($s->name)) {
) '; $strings[] = ' u.firstname ILIKE \'%\' || ? || \'%\' OR u.lastname ILIKE \'%\' || ? || \'%\' ';
$values = array($s->query, $s->query); $values = array($s->name, $s->name);
} else { } else {
if (!empty($s->f)) { if (!empty($s->f)) {
$where .= ' AND u.firstname ILIKE ? || \'%\''; $strings[] = ' u.firstname ILIKE ? || \'%\'';
$values[] = $s->f; $values[] = $s->f;
} }
if (!empty($s->l)) { if (!empty($s->l)) {
$where .= ' AND u.lastname ILIKE ? || \'%\''; $strings[] = ' u.lastname ILIKE ? || \'%\'';
$values[] = $s->l; $values[] = $s->l;
} }
} }
if (!empty($s->institution)) { if (!empty($strings)) {
$where .= ' AND u.institution = ? '; $strings = '( ' . join(' AND ', $strings) . ' )';
$values[] = $s->institution; } else {
$strings = '';
} }
if (!empty($s->email)) { if (!empty($s->email)) {
$where .= ' AND u.email ILIKE \'%\' || ? || \'%\''; $strings = $strings . ' OR u.email ILIKE \'%\' || ? || \'%\'';
$values[] = $s->email; $values[] = $s->email;
} }
if (!empty($strings)) {
$where .= ' AND ( ' . $strings . ' ) ';
}
if (!empty($s->institution)) {
$where .= ' AND u.institution = ? ';
$values[] = $s->institution;
}
$count = get_field_sql('SELECT COUNT(*) FROM {usr} u ' . $where, $values); $count = get_field_sql('SELECT COUNT(*) FROM {usr} u ' . $where, $values);
if ($count > 0) { if ($count > 0) {
......
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