Beispiel #1
0
function group_get_membersearch_data($results, $group, $query, $membershiptype, $setlimit = false, $sortoption = '')
{
    global $USER;
    $params = array();
    if ($query != '') {
        $params['query'] = $query;
    }
    if (!empty($membershiptype)) {
        $params['membershiptype'] = $membershiptype;
    }
    if (!empty($sortoption)) {
        $params['sortoption'] = $sortoption;
    }
    $searchurl = get_config('wwwroot') . 'group/members.php?id=' . $group . (!empty($params) ? '&' . http_build_query($params) : '');
    $smarty = smarty_core();
    $role = group_user_access($group);
    $userid = $USER->get('id');
    foreach ($results['data'] as &$r) {
        if ($role == 'admin' && ($r['id'] != $userid || group_user_can_leave($group, $r['id']))) {
            $r['removeform'] = group_get_removeuser_form($r['id'], $group);
        }
        // NOTE: this is a quick approximation. We should really check whether,
        // for each role in the group, that the user can change to it (using
        // group_can_change_role).  This only controls whether the 'change
        // role' link appears though, so it doesn't matter too much. If the
        // user clicks on this link, changerole.php does the full check and
        // sends them back here saying that the user has no roles they can
        // change to anyway.
        $r['canchangerole'] = !group_is_only_admin($group, $r['id']);
    }
    if (!empty($membershiptype)) {
        if ($membershiptype == 'request') {
            foreach ($results['data'] as &$r) {
                $r['addform'] = group_get_adduser_form($r['id'], $group);
                $r['denyform'] = group_get_denyuser_form($r['id'], $group);
                // TODO: this will suck when there's quite a few on the page,
                // would be better to grab all the reasons in one go
                $r['reason'] = get_field('group_member_request', 'reason', 'group', $group, 'member', $r['id']);
            }
        }
        $smarty->assign('membershiptype', $membershiptype);
    }
    $results['cdata'] = array_chunk($results['data'], 2);
    $results['roles'] = group_get_role_info($group);
    $smarty->assign_by_ref('results', $results);
    $smarty->assign('searchurl', $searchurl);
    $smarty->assign('pagebaseurl', $searchurl);
    $smarty->assign('caneditroles', group_user_access($group) == 'admin');
    $smarty->assign('group', $group);
    $html = $smarty->fetch('group/membersearchresults.tpl');
    $pagination = build_pagination(array('id' => 'member_pagination', 'class' => 'center', 'url' => $searchurl, 'count' => $results['count'], 'setlimit' => $setlimit, 'limit' => $results['limit'], 'offset' => $results['offset'], 'jumplinks' => 8, 'numbersincludeprevnext' => 2, 'datatable' => 'membersearchresults', 'searchresultsheading' => 'searchresultsheading', 'jsonscript' => 'group/membersearchresults.json.php', 'firsttext' => '', 'previoustext' => '', 'nexttext' => '', 'lasttext' => '', 'numbersincludefirstlast' => false, 'resultcounttextsingular' => get_string('member', 'group'), 'resultcounttextplural' => get_string('members', 'group')));
    return array($html, $pagination, $results['count'], $results['offset'], $membershiptype);
}
Beispiel #2
0
if (!empty($membershiptype) && $role != 'admin') {
    throw new AccessDeniedException();
}
$remove = param_variable('removeuser', null);
$member = param_integer('member', null);
if ($remove && $member) {
    // Create the remove user pieform for the user that's being removed.
    // The form's submit function will be called as soon as the form
    // is generated.
    //
    // We do this now because the user could be on the 2nd page of
    // results, so their remove form might never get generated on
    // this page.  And also because generating the rest of the page
    // would be a waste of time -- the submit function just redirects
    // back here.
    group_get_removeuser_form($member, $group->id);
}
// Search related stuff for member pager
$query = trim(param_variable('query', ''));
// pagination params
$setlimit = true;
//Enable choosing page size; list of page sizes has been predefined in function build_pagination()
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
// Sort options index and list of sort options
// ORDER BY statements defined in group_user_search function need to be matched
$sortoptions = array('adminfirst' => get_string('adminfirst'), 'nameatoz' => get_string('nameatoz'), 'nameztoa' => get_string('nameztoa'), 'firstjoined' => get_string('firstjoined'), 'lastjoined' => get_string('lastjoined'));
$sortoptionidx = param_alpha('sortoption', 'adminfirst');
if ($membershiptype == 'request') {
    array_shift($sortoptions);
    $sortoptionidx = param_alpha('sortoption', 'nameatoz');