2015-02-07, 03:11 PM
There has already been another discussion about this subject, and after some better observations I am sure now that the showteam.php module, which displays the members of forumteam groups, is buggy.
As it is now the showteam.php module will only work correctly when persons are member of one forumteam only, but it goes wrong when one person is member of two or more forumteams.
As an example I consider the testforum which I am using to develop a forum for a large (main) committee with several subcommittees. The testforum is limited in the number of members of the committees, in realty the committees will be far larger. The structure can be visualized as below:
All members of the main committee have this committee as their primary & display usergroup. The main committee members who are also member of a subcommittee have this membership as an additional user group. When the forumteam is displayed, the composition of the main committe is displayed right with all 9 members with names displayed in green:
But that of the subcommittees not. As shown below for the 1st subcommittee the subcommittee members who are not member of the main committee (names in blue) are listed, but the (two) members who are also member of the main committee (names in green) are not listed:
Don't look at the text, this is Dutch, but you see that two of the six members are missing. Why this is becomes clear when you look at the source of showteam.php. Below the code snippet where users are assigned to a group.
You see that a user is assigned to either his displaygroup or, when this is not set, to his usergroup. The additional groups are not considered at all!
This is completely in contradiction with how, for example, user permissions are determined in function forum_permissions, see the code snippet below where the user's usergroups are gathered:
So here only the combination of usergroup and additional groups is considered. The display group is omitted, because this should be one of the additional groups!
So I decided to make an improved version of showteam.php. To start with, the query for selecting the users that are member of a forumteam group must be chaged, apart from the obvious errors that are in the original query at line 72. Originally this was:
And this was changed into:
In lines 73 - 110 (original code) the users found by this query are assigned to an array with forumteam users. This contains some errors and does not take the additional groups of users into account. I only give the replacement part for these lines below:
Last but not least there is one line that must be added to the language file global.lang.php:
This addition is needed because in the original version it went wrong when a user displayed the forum team and there was a moderator of a forum that is hidden for him. This is also corrected in the changes above.
When the forumteam is displayed with the new version of showteam.php, the output for the 1-st subcommitte looks like:
Which is the correct composition of this subcommittee, so with the two members of the main committee in green included.
I have solved it for my forum with a plugin, which in essence is the corrected version of showteam.php. But because there are several bugs in the present code I decided to present it here for implementing in the core of a future version of MyBB. I understant this will not be an urgent matter.
As it is now the showteam.php module will only work correctly when persons are member of one forumteam only, but it goes wrong when one person is member of two or more forumteams.
As an example I consider the testforum which I am using to develop a forum for a large (main) committee with several subcommittees. The testforum is limited in the number of members of the committees, in realty the committees will be far larger. The structure can be visualized as below:
All members of the main committee have this committee as their primary & display usergroup. The main committee members who are also member of a subcommittee have this membership as an additional user group. When the forumteam is displayed, the composition of the main committe is displayed right with all 9 members with names displayed in green:
But that of the subcommittees not. As shown below for the 1st subcommittee the subcommittee members who are not member of the main committee (names in blue) are listed, but the (two) members who are also member of the main committee (names in green) are not listed:
Don't look at the text, this is Dutch, but you see that two of the six members are missing. Why this is becomes clear when you look at the source of showteam.php. Below the code snippet where users are assigned to a group.
// Are they also in another group which is being shown on the list?
if($user['displaygroup'] != 0)
{
$group = $user['displaygroup'];
}
else
{
$group = $user['usergroup'];
}
You see that a user is assigned to either his displaygroup or, when this is not set, to his usergroup. The additional groups are not considered at all!
This is completely in contradiction with how, for example, user permissions are determined in function forum_permissions, see the code snippet below where the user's usergroups are gathered:
$gid = $mybb->user['usergroup'];
if(isset($mybb->user['additionalgroups']))
{
$gid .= ",".$mybb->user['additionalgroups'];
}
So here only the combination of usergroup and additional groups is considered. The display group is omitted, because this should be one of the additional groups!
So I decided to make an improved version of showteam.php. To start with, the query for selecting the users that are member of a forumteam group must be chaged, apart from the obvious errors that are in the original query at line 72. Originally this was:
$query = $db->simple_select("users", "uid, username, displaygroup, usergroup, ignorelist, hideemail, receivepms, lastactive, lastvisit, invisible", "displaygroup IN ($groups_in) OR (displaygroup='0' AND usergroup IN ($groups_in)) OR uid IN ($users_in)", array('order_by' => 'username'));
And this was changed into:
$where = "uid IN ($users_in) OR usergroup IN ($groups_in)";
if ($groups_in != 0)
{
$groups = explode(',',$groups_in);
foreach ($groups as $group)
{
$where .= " OR {$group} IN (additionalgroups)";
}
}
$query = $db->simple_select("users", "uid, username, displaygroup, usergroup, additionalgroups, ignorelist, hideemail, receivepms, lastactive, lastvisit, invisible", $where, array('order_by' => 'username'));
In lines 73 - 110 (original code) the users found by this query are assigned to an array with forumteam users. This contains some errors and does not take the additional groups of users into account. I only give the replacement part for these lines below:
while($user = $db->fetch_array($query))
{
// If this user is a moderator
if(isset($moderators[$user['uid']]))
{
foreach($moderators[$user['uid']] as $forum)
{
if($forum_permissions[$forum['fid']]['canview'] == 1)
{
$forum_url = get_forum_link($forum['fid']);
eval("\$forumlist .= \"".$templates->get("showteam_moderators_forum")."\";");
}
else
{
$forumlist .= $lang->forum_hidden."<br /";
}
}
$user['forumlist'] = $forumlist;
$forumlist = '';
$usergroups[6]['user_list'][$user['uid']] = $user;
}
// Is this user also in other group(s) which is being shown on the list?
$groups = array();
if ($user['usergroup'] !=6)
{
$groups[] = $user['usergroup'];
}
if ($user['additionalgroups'])
{
$groups = array_merge($groups,explode(',',$user['additionalgroups']));
}
foreach ($groups as $group)
{
if($group !=6 && $usergroups[$group])
{
$usergroups[$group]['user_list'][$user['uid']] = $user;
}
}
}
Last but not least there is one line that must be added to the language file global.lang.php:
$l['forum_hidden'] = "(Hidden)";
This addition is needed because in the original version it went wrong when a user displayed the forum team and there was a moderator of a forum that is hidden for him. This is also corrected in the changes above.
When the forumteam is displayed with the new version of showteam.php, the output for the 1-st subcommitte looks like:
Which is the correct composition of this subcommittee, so with the two members of the main committee in green included.
I have solved it for my forum with a plugin, which in essence is the corrected version of showteam.php. But because there are several bugs in the present code I decided to present it here for implementing in the core of a future version of MyBB. I understant this will not be an urgent matter.