Welcome to Geeklog, Anonymous Friday, March 01 2024 @ 12:06 am EST

Geeklog Forums

Useful Group manager enhancement

Status: offline


Forum User
Registered: 12/04/03
Posts: 24
Sure would be nice to get this tiny tweak added to the Group Manager.

I made a very minor modification to the Group Manager list which adds the total number of members in each of the groups listed.

With this tweak, the Group Manager list now looks like this:
Text Formatted Code

Edit    Group Name                       Description             Core Group        Members
Edit    All Users        Group that a typical user is added to      Yes        Lst  Edit  (168)
Edit    Block Admin      Has full access to block features          Yes        Lst  Edit  (2)
Edit    Calendar Admin   Has full access to event features          No         Lst  Edit  (2)
Edit    Club Members     Group of people who are Club Members       No         Lst  Edit  (97)

It's a great way to quickly scan for groups that may have excessive number of members.

The code that does the work involved duplicating the grp_selectUsers() function from lib-admin.php and just return the count of members in the specified group, rather than the actual list of members. The function is below, and I added it to lib-custom.php.
Text Formatted Code

// This function counts all the users in the specified group.  It's really just a copy of
// the function grp_selectUsers() that returns just the count, not the actual list of
// group members.  So, the official solution would avoid duplicating the common
// part of this function.
// ------------------------------------------------------------------------------------------------------------
function CUST_grp_countUsers ($group_id, $allusers = false)
    global $_TABLES, $_USER;

    $retval = '';
    // Get a list of users in the Root Group and the selected group
    $sql  = "SELECT DISTINCT uid FROM {$_TABLES['users']} LEFT JOIN {$_TABLES['group_assignments']} ";
    $sql .= "ON {$_TABLES['group_assignments']}.ug_uid = uid WHERE uid > 1 AND ";
    $sql .= "({$_TABLES['group_assignments']}.ug_main_grp_id = 1 OR {$_TABLES['group_assignments']}.ug_main_grp_id = $group_id)";
    $result = DB_query ($sql);
    $filteredusers = array();
    while ($A = DB_fetchArray($result)) {
        $filteredusers[] = $A['uid'];

    $groups = getGroupList ($group_id);
    $grouplist = '(' . implode (',', $groups) . ')';
    $sql = "SELECT DISTINCT uid,username FROM {$_TABLES['users']} LEFT JOIN {$_TABLES['group_assignments']} ";
    $sql .= "ON {$_TABLES['group_assignments']}.ug_uid = uid WHERE uid > 1 AND ";
    $sql .= "{$_TABLES['group_assignments']}.ug_main_grp_id ";
    if ($allusers) {
        $sql .= 'NOT ';
    $sql .= "IN {$grouplist} ";
    // Filter out the users that will be in the selected group
    if ($allusers) {
        $filteredusers = implode(',',$filteredusers);
        $sql .= " AND uid NOT IN ($filteredusers) ";
    $sql .= "ORDER BY username";  
    $result = DB_query ($sql);
    $numUsers = DB_numRows ($result);
    return $numUsers;

To enable it, add a couple lines of code in ADMIN_getListField_groups() (in lib-admin.php).

1) call to this new function just before the switch ($fieldname) statement:
Text Formatted Code
 $countMembers = CUST_grp_countUsers($A['grp_id'], false);

2) In the switch statement's case 'list', just include $countMembers in the retval string after the list and edit icons.
Text Formatted Code

            case 'list':
                if ($show_all_groups) {
                    $retval = "<a href=\"{$_CONF['site_admin_url']}/group.php?mode=listusers&amp;grp_id={$A['grp_id']}&amp;chk_showall=1\">"
                             ."<a href=\"{$_CONF['site_admin_url']}/group.php?mode=editusers&amp;grp_id={$A['grp_id']}&amp;chk_showall=1\">"
                             ."{$icon_arr['edit']}</a>&nbsp; ({$countMembers})";
                } else {
                    $retval = "<a href=\"{$_CONF['site_admin_url']}/group.php?mode=listusers&amp;grp_id={$A['grp_id']}\">"
                             ."<a href=\"{$_CONF['site_admin_url']}/group.php?mode=editusers&amp;grp_id={$A['grp_id']}\">"
                             ."{$icon_arr['edit']}</a>&nbsp; ({$countMembers})";


All times are EST. The time is now 12:06 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content