MyBB Community Forums

Full Version: (solved) expanding user's additionalgroup in global.php by their ages.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I heard following code in global.php changes usergroup info of all the registered users depending on their age, anytime.

$age_crumb = 16;//deadline age
$young_group = 3;//group for people younger that the deadline
$old_group = 4;//group for those who are elder

$age_check = $db->query("SELECT uid, birthday, usergroup,  additionalgroups FROM ".TABLE_PREFIX."users WHERE usergroup='2' AND birthday LIKE '__-__-____' OR birthday LIKE '_-_-____' OR birthday LIKE '__-_-____' OR birthday LIKE '_-__-____'");
while($age_ex = $db->fetch_array($age_check)) {
	if($age_ex['usergroup'] == 2 && $age_ex['additionalgroups'] == '') {
		if(get_age($age_ex['birthday']) >= $age_crumb) {
			$db->query("UPDATE ".TABLE_PREFIX."users SET usergroup='$old_group' where uid='".$age_ex['uid']."'");
		} else if(get_age($age_ex['birthday']) < $age_crumb) {
			$db->query("UPDATE ".TABLE_PREFIX."users SET usergroup='$young_group' where uid='".$age_ex['uid']."'");
		}
	}
}

Here on line #8, if user's birthday is greater than $age_crumb, it just replaces usergroup to $old_group.

But what I want to do is not replacing user's primary group, but I want to add $old_group into user's additional group along with his previous additional groups.

For example, if a user previously had "addtionalgroup=1,2,3" in db and $old_group = 4 from above code, then after next update of global.php, he will have "additionalgroup=1,2,3,4" (4 is expanded into his previous additionalgroup).

How can I do this? Sorry I am not good at php and database.


------------

Solved myself. Sorry if u were about to reply.