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) {
function build_admin_user_search_results($search) {
$smarty = smarty_core();
$results = admin_user_search($search);
$params = array();
foreach ($search as $k => $v) {
if (!empty($v) && $k != 'offset') {
$params[] = $k . '=' . $v;
}
}
$params = join('&', $params);
$smarty->assign_by_ref('params', $params);
$paramstring = join('&', $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['page'] = $results['offset'] / $results['limit']; // $results['pages'];
$lastpage = $results['pages'] - 1;
......
......@@ -251,33 +251,43 @@ class PluginSearchInternal extends PluginSearch {
public static function admin_search_user_pg($s) {
$values = array();
$where = 'WHERE u.id <> 0 AND u.deleted = 0';
if (!empty($s->query)) {
$where .= '
AND ( u.firstname ILIKE \'%\' || ? || \'%\'
OR u.lastname ILIKE \'%\' || ? || \'%\'
) ';
$values = array($s->query, $s->query);
$strings = array();
$values = array();
if (!empty($s->name)) {
$strings[] = ' u.firstname ILIKE \'%\' || ? || \'%\' OR u.lastname ILIKE \'%\' || ? || \'%\' ';
$values = array($s->name, $s->name);
} else {
if (!empty($s->f)) {
$where .= ' AND u.firstname ILIKE ? || \'%\'';
$strings[] = ' u.firstname ILIKE ? || \'%\'';
$values[] = $s->f;
}
if (!empty($s->l)) {
$where .= ' AND u.lastname ILIKE ? || \'%\'';
$strings[] = ' u.lastname ILIKE ? || \'%\'';
$values[] = $s->l;
}
}
if (!empty($s->institution)) {
$where .= ' AND u.institution = ? ';
$values[] = $s->institution;
if (!empty($strings)) {
$strings = '( ' . join(' AND ', $strings) . ' )';
} else {
$strings = '';
}
if (!empty($s->email)) {
$where .= ' AND u.email ILIKE \'%\' || ? || \'%\'';
$strings = $strings . ' OR u.email ILIKE \'%\' || ? || \'%\'';
$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);
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