MyBB Community Forums

Full Version: [Auto Usergroup Change] For Age
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have seen the other Auto Usergroup Change for post number.
I was wondering if there is a way to do it for age? Smile
Hello there, um it would have been better if you had specified if you want different age ranges or just one, i have coded based on 1 age, example <16 or >16

open ./global.php

find

$plugins->run_hooks("global_end");

above add

$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 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(get_age($age_ex['birthday']) >= $age_crumb)
	{
		$db->query("UPDATE ".TABLE_PREFIX."users SET usergroup='$old_group' where uid='".$age_ex['uid']."'");
	}
	elseif(get_age($age_ex['birthday']) < $age_crumb)
	{
		$db->query("UPDATE ".TABLE_PREFIX."users SET usergroup='$young_group' where uid='".$age_ex['uid']."'");
	} 
} 
  • $age_crumb: is the age which you want to check whether a member is younger or elder than it.
  • $young_group: is the group the youngers will be moved to.
  • $old_group: is the group the elder will be moved to.
Thank zaher1988, sorry for not specifing the age, but 16 was the age I wanted which is great, thank you again
Sorry for the double post but this is the only way of showing that I have replied, unlike if I edited the above post, again sorry.

zaher1988 I am having problems with the code because it changes everyone that is 16 which is a problem since it is changing my super mods from the 'super mod' group to '16+' group and it can not be stopped, is there a way to limit it to saying, only people that are in the group 'registered' will change if they are 16?
Well, are you sure you are using that code? since it should only get the persons which is in the registered usergroup, make he updated it.
WHERE usergroup='2'
I thought so too, but I don't know why, but it does, and it seems to not let me move the users back into the right group

[update]

It does let me change where the user is, however once someone loads the index page, whic intern loads global.php the user changes back

I tested it out on a Super Mod, I changed him from the 16+ group back to super mod, but then once the index page loaded he went back the the 16+ group
maybe your super mods has this group as an additional, and their main usergroup is registred.

regards
Try this instead then.
$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']."'");
		}
	}
}
Thank you CraKteR.

Your code works perfectly, thanks Smile
Your very welcomed Smile