MyBB Community Forums

Full Version: add a group as moderator to a forum
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

in MyBB and IPB you can add custom moderators to a specified forum. In IPB you can choose a user or a group while in MyBB only a user.
Am I right - you can't do it? Is there a mod/plugin to be able to add a mod group to a forum?
You can only assign users as moderators in the current 1.4 series. MyBB 1.6 (in development) will allow you to assign groups too - [wiki]1.6.0[/wiki].
As Alan said, currently there is no way to do this. You need to wait for 1.6.
Thanks. I've created a simple workaround to get the functionality. No database modifications, just change few lines in 2 files.

In file inc/class_datacache.php replace this (line 468):
		while($moderator = $db->fetch_array($query))
		{
			$this->moderators[$moderator['fid']][$moderator['uid']] = $moderator;
		}
With this:
		while($moderator = $db->fetch_array($query))
		{
			if(substr($moderator['username'],0,9) == '__group__'){
				$query = $db->query("
					SELECT u.uid, u.username, u.usergroup, u.displaygroup
					FROM ".TABLE_PREFIX."users u
					WHERE u.uid != {$moderator['uid']} and 
					CONCAT(',',u.usergroup,',',u.additionalgroups,',') LIKE '%,{$moderator['usergroup']},%'
					ORDER BY u.username
				");
				while($moduser = $db->fetch_array($query))
					$this->moderators[$moderator['fid']][$moduser['uid']] = array_merge($moderator, $moduser);
			}
			else
				$this->moderators[$moderator['fid']][$moderator['uid']] = $moderator;
		}

In file inc/functions.php replace this (line 1339):
		$sql = build_parent_list($fid, "fid", "OR", $parentslist);
		$query = $db->simple_select("moderators", "*", "uid='{$uid}' AND {$sql}");
		$perms = $db->fetch_array($query);
With this:
		$sql = build_parent_list($fid, "fid", "OR", $parentslist);
		if($uid == $mybb->user['uid']){
			$usergroup = $mybb->user['usergroup'];
			$additionalgroups = $mybb->user['additionalgroups'];
		}
		else{
			$query = $db->simple_select("users", "usergroup,additionalgroups", "uid='{$uid}'");
			$tmp_user = $db->fetch_array($query);
			$usergroup = $tmp_user['usergroup'];
			$additionalgroups = $tmp_user['additionalgroups'];
		}
		$sql2 = "uid in (SELECT uid FROM ".TABLE_PREFIX."users WHERE username LIKE '__group__%' and ',{$usergroup},{$additionalgroups},' LIKE CONCAT('%,',usergroup,',%'))";
		$query = $db->simple_select("moderators", "*", "(uid='{$uid}' OR {$sql2}) AND {$sql}");
		$perms = $db->fetch_array($query);
Modified files v1.4.9 here:[attachment=15885]

Modification doesn't change anything if you don't use its functionality so it's very safe.

How to use?
Create a fake user with username prefix "__group__" and primary group that you want to grant permissions to and add this user as a moderator of a forum. All users of the group will have moderator permissions in that forum.

Example:
You have a group called "Juniormods" and want it to moderate a forum called Juniorforum.
1. Create a user: __group__Juniormods
2. Set its primary group to: Juniormods
3. Add this fake user as a moderator of "Juniorforum"
4. All "Juniormods" can moderate "Juniorforum" now