function build_grouplist_html($query, $limit, $offset, &$count = null) { $groups = search_group($query, $limit, $offset, 'all'); $count = $groups['count']; if ($ids = array_map(create_function('$a', 'return intval($a->id);'), $groups['data'])) { $sumsql = "(m.role = 'admin')"; if (is_postgres()) { $sumsql .= '::int'; } // Member & admin counts $ids = join(',', $ids); $counts = get_records_sql_assoc("\n SELECT m.group, COUNT(m.member) AS members, SUM({$sumsql}) AS admins\n FROM {group_member} m\n WHERE m.group IN ({$ids})\n GROUP BY m.group", array()); } foreach ($groups['data'] as &$group) { $group->visibility = $group->public ? get_string('Public', 'group') : get_string('Members', 'group'); $group->admins = empty($counts[$group->id]->admins) ? 0 : $counts[$group->id]->admins; $group->members = empty($counts[$group->id]->members) ? 0 : $counts[$group->id]->members; if (get_config('allowgroupcategories')) { $group->categorytitle = $group->category ? get_field('group_category', 'title', 'id', $group->category) : ''; } $group->homepage_url = group_homepage_url($group); } $smarty = smarty_core(); $smarty->assign('groups', $groups['data']); $data = array(); $data['tablerows'] = $smarty->fetch('admin/groups/groupsresults.tpl'); $pagination = build_pagination(array('id' => 'admgroupslist_pagination', 'datatable' => 'admgroupslist', 'url' => get_config('wwwroot') . 'admin/groups/groups.php' . ($query != '' ? '?query=' . urlencode($query) : ''), 'jsonscript' => 'admin/groups/groups.json.php', 'count' => $count, 'limit' => $limit, 'offset' => $offset, 'jumplinks' => 6, 'numbersincludeprevnext' => 2, 'resultcounttextsingular' => get_string('group', 'group'), 'resultcounttextplural' => get_string('groups', 'group'))); $data['pagination'] = $pagination['html']; $data['pagination_js'] = $pagination['javascript']; return $data; }
$page = param_integer('page'); $limit = 10; if ($page < 1) { $page = 1; } $offset = ($page - 1) * $limit; switch ($type) { case 'friend': $data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id'), 'friends' => true)); break; case 'user': $data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id'))); break; case 'group': require_once 'group.php'; $data = search_group($query, $limit, $offset, ''); $roles = get_records_array('grouptype_roles'); $data['roles'] = array(); foreach ($roles as $r) { $data['roles'][$r->grouptype][] = array('name' => $r->role, 'display' => get_string($r->role, 'grouptype.' . $r->grouptype)); } foreach ($data['data'] as &$r) { $r->url = group_homepage_url($r); } break; default: $data = search_user($query, $limit, $offset, array('exclude' => $USER->get('id'), 'friends' => true)); break; } $more = $data['count'] > $limit * $page; $data['error'] = false;
$filter = 'all'; $type = 'all'; } } $elements = array(); $elements['query'] = array('type' => 'text', 'defaultvalue' => $query); $elements['filter'] = array('type' => 'select', 'options' => array('notmember' => get_string('groupsnotin', 'group'), 'member' => get_string('groupsimin', 'group'), 'all' => get_string('allgroups', 'group')), 'defaultvalue' => $filter); if (get_config('allowgroupcategories') && ($groupcategories = get_records_menu('group_category', '', '', 'displayorder', 'id,title'))) { $options[0] = get_string('allcategories', 'group'); $options[-1] = get_string('categoryunassigned', 'group'); $options += $groupcategories; $elements['groupcategory'] = array('type' => 'select', 'options' => $options, 'defaultvalue' => $groupcategory, 'help' => true); } $elements['search'] = array('type' => 'submit', 'value' => get_string('search')); $searchform = pieform(array('name' => 'search', 'method' => 'post', 'renderer' => 'oneline', 'elements' => $elements)); $groups = search_group($query, $groupsperpage, $offset, $type, $groupcategory); // gets more data about the groups found by search_group // including type if the user is associated with the group in some way // and the first three members by id if ($groups['data']) { $groupids = array(); foreach ($groups['data'] as $group) { $groupids[] = $group->id; } $groups['data'] = get_records_sql_assoc("SELECT g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.grouptype, g1.role, g1.membershiptype, g1.membercount, COUNT(gmr.member) AS requests\n FROM (\n SELECT g.id, g.name, g.description, g.public, g.jointype, g.grouptype, gm.role, t.membershiptype, COUNT(gm.member) AS membercount\n FROM {group} g\n LEFT JOIN {group_member} gm ON (gm.group = g.id)\n LEFT JOIN (\n SELECT g.id, 'admin' AS membershiptype\n FROM {group} g\n INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')\n UNION\n SELECT g.id, 'member' AS membershiptype\n FROM {group} g\n INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ? AND gm.role != 'admin')\n UNION\n SELECT g.id, 'invite' AS membershiptype\n FROM {group} g\n INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)\n UNION\n SELECT g.id, 'request' AS membershiptype\n FROM {group} g\n INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)\n ) t ON t.id = g.id\n WHERE g.id IN (" . implode($groupids, ',') . ') GROUP BY g.id, g.name, g.description, g.public, g.jointype, g.grouptype, gm.role, t.membershiptype ORDER BY g.name ) g1 LEFT JOIN {group_member_request} gmr ON (gmr.group = g1.id) GROUP BY g1.id, g1.name, g1.description, g1.public, g1.jointype, g1.grouptype, g1.role, g1.membershiptype, g1.membercount', array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'))); if ($groups['data']) {
$offset = param_integer('offset', 0); $groupsperpage = 20; $query = param_variable('query', ''); if ($filter == 'member') { $type = 'member'; } else { if ($filter == 'notmember') { $type = 'notmember'; } else { // all or some other text $filter = 'all'; $type = 'all'; } } $searchform = pieform(array('name' => 'search', 'method' => 'post', 'renderer' => 'oneline', 'elements' => array('query' => array('type' => 'text', 'defaultvalue' => $query), 'filter' => array('type' => 'select', 'options' => array('notmember' => get_string('groupsnotin', 'group'), 'member' => get_string('groupsimin', 'group'), 'all' => get_string('allgroups', 'group')), 'defaultvalue' => $filter), 'search' => array('type' => 'submit', 'value' => get_string('search'))))); $groups = search_group($query, $groupsperpage, $offset, $type); // gets more data about the groups found by search_group // including type if the user is associated with the group in some way // and the first three members by id if ($groups['data']) { $groupids = array(); foreach ($groups['data'] as $group) { $groupids[] = $group->id; } $groups['data'] = get_records_sql_assoc("SELECT g1.id, g1.name, g1.description, g1.jointype, g1.membershiptype, g1.membercount, COUNT(gmr.member) AS requests\n FROM (\n SELECT g.id, g.name, g.description, g.jointype, t.membershiptype, COUNT(gm.member) AS membercount\n FROM {group} g\n LEFT JOIN {group_member} gm ON (gm.group = g.id)\n LEFT JOIN (\n SELECT g.id, 'admin' AS membershiptype\n FROM {group} g\n INNER JOIN {group_member} gm ON (gm.group = g.id AND gm.member = ? AND gm.role = 'admin')\n UNION\n SELECT g.id, 'member' AS membershiptype\n FROM {group} g\n INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ? AND gm.role != 'admin')\n UNION\n SELECT g.id, 'invite' AS membershiptype\n FROM {group} g\n INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)\n UNION\n SELECT g.id, 'request' AS membershiptype\n FROM {group} g\n INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)\n ) t ON t.id = g.id\n WHERE g.id IN (" . implode($groupids, ',') . ') GROUP BY g.id, g.name, g.description, g.jointype, t.membershiptype ORDER BY g.name ) g1 LEFT JOIN {group_member_request} gmr ON (gmr.group = g1.id) GROUP BY g1.id, g1.name, g1.description, g1.jointype, g1.membershiptype, g1.membercount', array($USER->get('id'), $USER->get('id'), $USER->get('id'), $USER->get('id'))); if ($groups['data']) {
del_group(); break; case 'del_action': del_action(); break; case 'searchKefu': search_kefu(); break; case 'remove_group': remove_group(); break; case 'judgeMember': judge_member(); break; case 'search_group': search_group(); break; case 'judge_group': judge_group(); break; case 'storyrecommand': ajax_storyrecommand(); break; case 'lockuser': ajax_lockuser(); break; case 'dealuser': ajax_dealuser(); break; case 'agreeemail': ajax_agreeemail();