Beispiel #1
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     global $USER;
     if ($instance->get_view()->get('owner') == "0") {
         return '';
     }
     $configdata = $instance->get('configdata');
     $rows = isset($configdata['rows']) ? $configdata['rows'] : 1;
     $columns = isset($configdata['columns']) ? $configdata['columns'] : 6;
     $order = isset($configdata['order']) ? $configdata['order'] : 'latest';
     $numtoshow = isset($configdata['numtoshow']) ? $configdata['numtoshow'] : $rows * $columns;
     $groupid = $instance->get_view()->get('group');
     // If the group has hidden membership, display nothing
     $usergroups = $USER->get('grouproles');
     $group = defined('GROUP') && $groupid == GROUP ? group_current_group() : get_record('group', 'id', $groupid);
     if ($group->hidemembersfrommembers && (!isset($usergroups[$groupid]) || $usergroups[$groupid] != 'admin')) {
         return '';
     }
     if ($group->hidemembers && !isset($usergroups[$groupid])) {
         return '';
     }
     require_once 'searchlib.php';
     $groupmembers = get_group_user_search_results($groupid, '', 0, $numtoshow, '', $order);
     if ($groupmembers['count']) {
         $smarty = smarty_core();
         $smarty->assign_by_ref('groupmembers', $groupmembers['data']);
         $groupmembers['tablerows'] = $smarty->fetch('blocktype:groupmembers:row.tpl');
     } else {
         $groupmembers = false;
     }
     $show_all = array('url' => get_config('wwwroot') . 'group/members.php?id=' . $groupid, 'message' => get_string('show_all', 'blocktype.groupmembers'));
     $smarty = smarty_core();
     $smarty->assign('groupmembers', $groupmembers);
     $smarty->assign('show_all', $show_all);
     return $smarty->fetch('blocktype:groupmembers:groupmembers.tpl');
 }
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     global $USER;
     $configdata = $instance->get('configdata');
     $rows = isset($configdata['rows']) ? $configdata['rows'] : 1;
     $columns = isset($configdata['columns']) ? $configdata['columns'] : 6;
     $order = isset($configdata['order']) ? $configdata['order'] : 'latest';
     $groupid = $instance->get_view()->get('group');
     require_once 'searchlib.php';
     $groupmembers = get_group_user_search_results($groupid, '', 0, $rows * $columns, '', $order);
     if ($groupmembers['count']) {
         $groupmembersarray = array_chunk($groupmembers['data'], $columns);
         $smarty = smarty_core();
         $smarty->assign_by_ref('groupmembers', $groupmembersarray);
         $groupmembers['tablerows'] = $smarty->fetch('blocktype:groupmembers:row.tpl');
     } else {
         $groupmembers = false;
     }
     $show_all = array('url' => get_config('wwwroot') . 'group/members.php?id=' . $groupid, 'message' => get_string('show_all', 'blocktype.groupmembers'));
     $smarty = smarty_core();
     $smarty->assign('groupmembers', $groupmembers);
     $smarty->assign('show_all', $show_all);
     return $smarty->fetch('blocktype:groupmembers:groupmembers.tpl');
 }
Beispiel #3
0
// 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');
}
$results = get_group_user_search_results($group->id, $query, $offset, $limit, $membershiptype, null, null, $sortoptionidx);
list($html, $pagination, $count, $offset, $membershiptype) = group_get_membersearch_data($results, $group->id, $query, $membershiptype, $setlimit, $sortoptionidx);
// Type-specific instructions
$instructions = '';
if ('admin' == $role) {
    $url = get_config('wwwroot') . 'group/inviteusers.php?id=' . GROUP;
    $instructions = get_string('invitemembersdescription', 'group', $url);
    if ('controlled' == $group->jointype) {
        $url = get_config('wwwroot') . 'group/addmembers.php?id=' . GROUP;
        $instructions .= ' ' . get_string('membersdescription:controlled', 'group', $url);
    }
}
$searchform = pieform(array('name' => 'search', 'checkdirtychange' => false, 'class' => 'search-views-form form-inline with-heading', 'elements' => array('id' => array('type' => 'hidden', 'value' => $group->id), 'membershiptype' => array('type' => 'hidden', 'value' => $membershiptype), 'setlimit' => array('type' => 'hidden', 'value' => $setlimit), 'inputgroup' => array('type' => 'fieldset', 'class' => 'input-group', 'elements' => array('query' => array('title' => get_string('search') . ': ', 'type' => 'text', 'class' => 'input-small', 'defaultvalue' => $query), 'sortoption' => array('type' => 'select', 'class' => 'sortoption input-small', 'title' => get_string('sortedby'), 'multiple' => false, 'size' => 1, 'defaultvalue' => $sortoptionidx, 'options' => $sortoptions), 'submit' => array('type' => 'button', 'usebuttontag' => true, 'class' => 'btn-primary no-label input-group-btn', 'value' => get_string('search')))))));
$js = <<<EOF
addLoadEvent(function () {
    p = {$pagination['javascript']}
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
 *
 */
define('PUBLIC', 1);
define('INTERNAL', 1);
define('JSON', 1);
require dirname(dirname(__FILE__)) . '/init.php';
require_once 'group.php';
require_once 'searchlib.php';
$id = param_integer('id');
$query = trim(param_variable('query', ''));
$offset = param_integer('offset', 0);
$limit = param_integer('limit', 10);
define('GROUP', $id);
$group = group_current_group();
if (!is_logged_in() && !$group->public) {
    throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$membershiptype = param_variable('membershiptype', '');
if (!empty($membershiptype)) {
    if (group_user_access($id) != 'admin') {
        json_reply('local', get_string('accessdenied', 'error'));
    }
}
$results = get_group_user_search_results($group->id, $query, $offset, $limit, $membershiptype);
if (!param_integer('html', 1)) {
    json_reply(false, $results);
}
list($html, $pagination, $count, $offset, $membershiptype) = group_get_membersearch_data($results, $id, $query, $membershiptype);
json_reply(false, array('message' => null, 'data' => array('tablerows' => $html, 'pagination' => $pagination['html'], 'pagination_js' => $pagination['javascript'], 'count' => $count, 'results' => $count . ' ' . ($count == 1 ? get_string('result') : get_string('results')), 'offset' => $offset, 'membershiptype' => $membershiptype)));
Beispiel #5
0
function group_get_membersearch_data($group, $query, $offset, $limit, $membershiptype)
{
    global $USER;
    $results = get_group_user_search_results($group, $query, $offset, $limit, $membershiptype);
    $params = array();
    if (!empty($query)) {
        $params[] = 'query=' . $query;
    }
    $params[] = 'limit=' . $limit;
    if (!empty($membershiptype)) {
        $params[] = 'membershiptype=' . $membershiptype;
    }
    $searchurl = get_config('wwwroot') . 'group/members.php?id=' . $group . '&amp;' . join('&amp;', $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);
                // 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'], 'limit' => $limit, 'offset' => $offset, 'datatable' => 'membersearchresults', 'jsonscript' => 'group/membersearchresults.php', 'firsttext' => '', 'previoustext' => '', 'nexttext' => '', 'lasttext' => '', 'numbersincludefirstlast' => false, 'resultcounttextsingular' => get_string('member', 'group'), 'resultcounttextplural' => get_string('members', 'group')));
    return array($html, $pagination, $results['count'], $offset, $membershiptype);
}
    throw new AccessDeniedException(get_string('accessdenied', 'error'));
}
$role = group_user_access($group->id);
if (!$USER->get('admin') && !$USER->get('staff')) {
    if (!$role && ($group->hidemembers || $group->hidemembersfrommembers)) {
        json_reply('local', get_string('accessdenied', 'error'));
    }
    if ($role != 'admin' && $group->hidemembersfrommembers) {
        json_reply('local', get_string('accessdenied', 'error'));
    }
}
$membershiptype = param_variable('membershiptype', '');
$friends = param_integer('friends', 0);
if (!empty($membershiptype)) {
    if ($role != 'admin') {
        // Non-admins are allowed to find the 'notinvited' users, but only if 'invitefriends'
        // or 'suggestfriends' is enabled, and they're filtering by their friends list
        if ($membershiptype != 'notinvited' || !$role || !($group->invitefriends || $group->suggestfriends) || !$friends) {
            json_reply('local', get_string('accessdenied', 'error'));
        }
    }
}
$results = get_group_user_search_results($group->id, $query, $offset, $limit, $membershiptype, null, $friends ? $USER->get('id') : null, $sortoptionidx);
if (!param_integer('html', 1)) {
    foreach ($results['data'] as &$result) {
        $result = array('id' => $result['id'], 'name' => $result['name']);
    }
    json_reply(false, $results);
}
list($html, $pagination, $count, $offset, $membershiptype) = group_get_membersearch_data($results, $id, $query, $membershiptype, $setlimit, $sortoptionidx);
json_reply(false, array('message' => null, 'data' => array('tablerows' => $html, 'pagination' => $pagination['html'], 'pagination_js' => $pagination['javascript'], 'count' => $count, 'results' => $count . ' ' . ($count == 1 ? get_string('result') : get_string('results')), 'offset' => $offset, 'setlimit' => $setlimit, 'membershiptype' => $membershiptype, 'sortoption' => $sortoptionidx)));