Please, disregard this post, and start reading from the post below: http://www.phpbb.com/community/viewtopi ... #p13153342
________________________________________________________________
Hello,
Here is a code snippet to show group memberships of certain groups in the memberlist. Only visible to Admins and Mods (Mods may be removed). General users do not see this. It could be done, but would require significant permission checks for hidden groups.
Membership is shown as ticked/unticked checkboxes below the user name in the memberlist, indicating the membership (or not) of the user in a certain group.
The list of groups shown in the memberlist must be configured (as a list of group_id's separated by comma) as an entry in the phpbb_config table.
This will NOT be developed to a full MOD, as it is a simple enough snippet, and I am currently not considering the ACP configuration that would be required/helpful.
So, here are the instructions:
1) Edit memberlist.php
Find:
Code: Select all
// Load custom profile fields
if ($config['load_cpf_memberlist'])
{
include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
$cp = new custom_profile();
// Grab all profile fields from users in id cache for later use - similar to the poster cache
$profile_fields_cache = $cp->generate_profile_fields_template('grab', $user_list);
}
Code: Select all
// User Memberships by javiexin
$show_members = ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? true : false; // Admins see group memberships
$show_members = ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? true : $show_members; // Mods also see group memberships; comment out if you do not want Moderators to see this
if ($show_members && $config['group_memberships'])
{
$group_list = array_map('intval', explode(',', $config['group_memberships']));
$memberships = $group_names = array();
$sql = 'SELECT group_id, group_name, group_type
FROM ' . GROUPS_TABLE . '
WHERE ' . $db->sql_in_set('group_id', $group_list);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$group_names[$row['group_id']] = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']);
}
$db->sql_freeresult($result);
$sql = 'SELECT ug.*
FROM ' . USER_GROUP_TABLE . ' ug
WHERE ug.user_pending = 0' .
' AND ' . $db->sql_in_set('ug.group_id', $group_list) .
' AND ' . $db->sql_in_set('ug.user_id', $user_list);
$result = $db->sql_query($sql);
while ($row = $db->sql_fetchrow($result))
{
$memberships[$row['user_id']][$row['group_id']] = true;
}
$db->sql_freeresult($result);
}
Code: Select all
if (isset($cp_row['blockrow']) && sizeof($cp_row['blockrow']))
{
foreach ($cp_row['blockrow'] as $field_data)
{
$template->assign_block_vars('memberrow.custom_fields', $field_data);
}
}
Code: Select all
// User Memberships by javiexin
if ($show_members && $config['group_memberships'])
{
foreach ($group_list as $group_id)
{
if (isset($group_names[$group_id]))
{
$template->assign_block_vars('memberrow.membership', array(
'GROUP_ID' => $group_id,
'GROUP_NAME' => $group_names[$group_id],
'S_IN_GROUP' => (isset($memberships[$user_id][$group_id]) ? true : false),
));
}
}
}
Code: Select all
'S_SHOW_GROUP' => ($mode == 'group') ? true : false,
Code: Select all
'S_SHOW_MEMBERSHIPS' => ($show_members && $config['group_memberships']) ? true : false,
Find:
Code: Select all
{memberrow.USERNAME_FULL}
Code: Select all
<!-- IF S_SHOW_MEMBERSHIPS and not S_IN_SEARCH_POPUP and not S_SELECT_SINGLE --><br /><div style="margin-top: 6px;" class="memberships"><!-- BEGIN membership --><input type="checkbox" name="membership-{memberrow.membership.GROUP_ID}" title="{memberrow.membership.GROUP_NAME}" <!-- IF memberrow.membership.S_IN_GROUP -->checked="checked" <!-- ENDIF -->onclick="return false;" style="margin-right: 8px;" /><!-- END membership --></div><!-- ENDIF -->
Code: Select all
INSERT INTO phpbb_config (config_name, config_value, is_dynamic)
VALUES ('group_memberships', '5,8', FALSE);
4) Clean the ftp cache, remove the file cache/data_global.php from your ftp server
5) Clean the template cache of your style
You are all set...
If you want to change the list of groups to show (or the order of these), just repeat steps 3 and 4 above, using in step 3 the following SQL command instead of the one above:
Code: Select all
UPDATE phpbb_config
SET config_value = '631,632,228,213,487,257'
WHERE config_name = 'group_memberships';
Regards,
-javiexin
PS: If someone wants to take over and make it to a full MOD, go ahead, just keep the credits.
PS: Any code improvement is also very welcome.