Commit 148367c8 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie
Browse files

Fix searching for users in certain groups, and the userlist element, given the...

Fix searching for users in certain groups, and the userlist element, given the group owner -> admins change.
parent 7b3193e3
...@@ -43,10 +43,10 @@ $limit = param_integer('limit', 20); ...@@ -43,10 +43,10 @@ $limit = param_integer('limit', 20);
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$allfields = param_boolean('allfields'); $allfields = param_boolean('allfields');
$group = param_integer('group', 0); $group = param_integer('group', 0);
$owner = param_boolean('owner', true); $includeadmins = param_boolean('includeadmins', true);
if ($group) { if ($group) {
$data = array('group' => $group, 'owner' => $owner); $data = array('group' => $group, 'includeadmins' => $includeadmins);
$data = search_user($query, $limit, $offset, $data); $data = search_user($query, $limit, $offset, $data);
} }
else { else {
......
...@@ -71,7 +71,7 @@ function pieform_element_userlist(Pieform $form, $element) { ...@@ -71,7 +71,7 @@ function pieform_element_userlist(Pieform $form, $element) {
if (!empty($element['group'])) { if (!empty($element['group'])) {
$smarty->assign('group', $element['group']); $smarty->assign('group', $element['group']);
$smarty->assign('owner', !isset($element['owner']) || $element['owner'] ? 1 : 0); $smarty->assign('includeadmins', !isset($element['includeadmins']) || $element['includeadmins'] ? 1 : 0);
} }
if (empty($element['searchscript'])) { if (empty($element['searchscript'])) {
$element['searchscript'] = 'json/usersearch.php'; $element['searchscript'] = 'json/usersearch.php';
......
...@@ -99,12 +99,11 @@ class PluginSearchInternal extends PluginSearch { ...@@ -99,12 +99,11 @@ class PluginSearchInternal extends PluginSearch {
LEFT JOIN {artefact} a ON u.id=a.owner LEFT JOIN {artefact} a ON u.id=a.owner
'; ';
if (isset($data['group'])) { if (isset($data['group'])) {
$sql .= 'INNER JOIN {group_member} gm ON (gm.member = u.id AND gm.group = ' . (int)$data['group'] . ') $groupadminsql = '';
'; if (isset($data['includeadmins']) and !$data['includeadmins']) {
if (isset($data['owner']) && !$data['owner']) { $groupadminsql = " AND gm.role != 'admin'";
$sql .= 'INNER JOIN {group} g ON (g.id = gm.group AND g.owner != u.id)
';
} }
$sql .= 'INNER JOIN {group_member} gm ON (gm.member = u.id AND gm.group = ' . (int)$data['group'] . $groupadminsql . ")\n";
} }
$querydata = split(' ', preg_replace('/\s\s+/', ' ', strtolower(trim($query_string)))); $querydata = split(' ', preg_replace('/\s\s+/', ' ', strtolower(trim($query_string))));
$namesql = '( $namesql = '(
...@@ -142,12 +141,11 @@ class PluginSearchInternal extends PluginSearch { ...@@ -142,12 +141,11 @@ class PluginSearchInternal extends PluginSearch {
INNER JOIN {usr} u ON u.id = a.owner INNER JOIN {usr} u ON u.id = a.owner
'; ';
if (isset($data['group'])) { if (isset($data['group'])) {
$sql .= 'INNER JOIN {group_member} gm ON (gm.member = u.id AND gm.group = ' . (int)$data['group'] . ') $groupadminsql = '';
'; if (isset($data['includeadmins']) and !$data['includeadmins']) {
if (isset($data['owner']) && !$data['owner']) { $groupadminsql = " AND gm.role != 'admin'";
$sql .= 'INNER JOIN {group} g ON (g.id = gm.group AND g.owner != u.id) }
'; $sql .= 'INNER JOIN {group_member} gm ON (gm.member = u.id AND gm.group = ' . (int)$data['group'] . $groupadminsql . ")\n";
}
} }
$sql .= 'WHERE $sql .= 'WHERE
u.id <> 0 AND u.active = 1 AND u.deleted = 0 u.id <> 0 AND u.active = 1 AND u.deleted = 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