Log in

View Full Version : Add to Secondary Group based on email or IP


RyanM
06-03-2006, 07:24 PM
I have seen Add User to Secondary Usergroup Based on the Value of a Custom Profile Field at Reg. but am looking from something similar. I want if someone registers with an email from one of three domains or one of a list of IP address, the user will be added to a secondary usergroup. The original plugin looked like this.<?xml version="1.0" encoding="ISO-8859-1"?>

<plugins>
<plugin active="1" product="vbulletin">
<title>Put User in Secondary Group Based on Custom Profile Field Value</title>
<hookname>register_activate_process</hookname>
<phpcode><![CDATA[// Get the value for field 5
$user = $db->query_first("
SELECT field5
FROM " . TABLE_PREFIX . "userfield
WHERE userid = " . $vbulletin->userinfo['userid'] . "
");


if ($user['field5'] == 'yes')
{
$membergroupids = $userdata->fetch_field('membergroupids');
if ($membergroupids)
{
$membergroupids = $membergroupids . ", 10";
}
else
{
$membergroupids = 10;
}

$userdata->set('membergroupids', $membergroupids); }]]></phpcode>
</plugin>
</plugins>

So, I modified the phpcode in the plugin to not focus on one of the fields in userfield, but to look at email and ipaddress in user:$user = $user = $db->query_first("
SELECT email, ipaddress
FROM " . TABLE_PREFIX . "user
WHERE userid = " . $vbulletin->userinfo['userid'] . "
");

$at_sign = strpos($user['email'], "@");
$ip_array("123.123.123.123","123.123.123.124","123.123.123.125");

if (strpos($user['email'],"domain.com",$at_sign)
|| strpos($user['email'],"domain2.com",$at_sign)
|| strpos($user['email'],"domain3.com",$at_sign)
|| in_array($user['ipaddress'],$ip_array))
{
$membergroupids = $userdata->fetch_field('membergroupids');
if ($membergroupids)
{
$membergroupids = $membergroupids . ", 92";
}
else
{
$membergroupids = 92;
}
$userdata->set('membergroupids', $membergroupids);
}

I am getting an error when I try to activate a user awaiting email confirmation (the hook).
Fatal error: Call to undefined function: () in /home/user/public_html/forum/register.php(930) : eval()'d code on line 9

Any help?