// ############################### start add member ###############################
if ($_POST['do'] == 'addmember')
{
	$vbulletin->input->clean_array_gpc('p', array(
		'options'             => TYPE_ARRAY_BOOL,
		'username'            => TYPE_STR,
		'email'               => TYPE_STR,
		'emailconfirm'        => TYPE_STR,
		'parentemail'         => TYPE_STR,
		'password'            => TYPE_STR,
		'password_md5'        => TYPE_STR,
		'passwordconfirm'     => TYPE_STR,
		'passwordconfirm_md5' => TYPE_STR,
		'referrername'        => TYPE_NOHTML,
		'coppauser'           => TYPE_BOOL,
		'day'                 => TYPE_UINT,
		'month'               => TYPE_UINT,
		'year'                => TYPE_UINT,
		'timezoneoffset'      => TYPE_NUM,
		'dst'                 => TYPE_UINT,
		'userfield'           => TYPE_ARRAY,
		'showbirthday'        => TYPE_UINT,
		'humanverify'         => TYPE_ARRAY,
	));

	if (!$vbulletin->options['allowregistration'])
	{
		eval(standard_error(fetch_error('noregister')));
	}

	// check for multireg
	if ($vbulletin->userinfo['userid'] AND !$vbulletin->options['allowmultiregs'])
	{
		eval(standard_error(fetch_error('alreadyregistered', $vbulletin->userinfo['username'], $vbulletin->session->vars['sessionurl'])));
	}

	// init user datamanager class
	$userdata = datamanager_init('User', $vbulletin, ERRTYPE_ARRAY);

	// coppa option
	if ($vbulletin->options['usecoppa'])
	{
		$current['year'] = date('Y');
		$current['month'] = date('m');
		$current['day'] = date('d');

		$month = $vbulletin->GPC['month'];
		$year = $vbulletin->GPC['year'];
		$day = $vbulletin->GPC['day'];

		if ($year > 1970 AND mktime(0, 0, 0, $month, $day, $year) > mktime(0, 0, 0, $current['month'], $current['day'], $current['year'] - 13))
		{
			if ($vbulletin->options['checkcoppa'])
			{
				vbsetcookie('coppaage', $month . '-' . $day . '-' . $year, 1);
			}

			if ($vbulletin->options['usecoppa'] == 2)
			{
				standard_error(fetch_error('under_thirteen_registration_denied'));
			}

			$vbulletin->GPC['coppauser'] = true;

		}
		else
		{
			$vbulletin->GPC['coppauser'] = false;
		}
	}
	else
	{
		$vbulletin->GPC['coppauser'] = false;
	}

	$userdata->set_info('coppauser', $vbulletin->GPC['coppauser']);
	$userdata->set_info('coppapassword', $vbulletin->GPC['password']);
	$userdata->set_bitfield('options', 'coppauser', $vbulletin->GPC['coppauser']);
	$userdata->set('parentemail', $vbulletin->GPC['parentemail']);

	// check for missing fields
	if (empty($vbulletin->GPC['username'])
		OR empty($vbulletin->GPC['email'])
		OR empty($vbulletin->GPC['emailconfirm'])
		OR ($vbulletin->GPC['coppauser'] AND empty($vbulletin->GPC['parentemail']))
		OR (empty($vbulletin->GPC['password']) AND empty($vbulletin->GPC['password_md5']))
		OR (empty($vbulletin->GPC['passwordconfirm']) AND empty($vbulletin->GPC['passwordconfirm_md5']))
	)
	{
		$userdata->error('fieldmissing');
	}

	// check for matching passwords
	if ($vbulletin->GPC['password'] != $vbulletin->GPC['passwordconfirm'] OR (strlen($vbulletin->GPC['password_md5']) == 32 AND $vbulletin->GPC['password_md5'] != $vbulletin->GPC['passwordconfirm_md5']))
	{
		$userdata->error('passwordmismatch');
	}

	// check for matching email addresses
	if ($vbulletin->GPC['email'] != $vbulletin->GPC['emailconfirm'])
	{
		$userdata->error('emailmismatch');
	}
	$userdata->set('email', $vbulletin->GPC['email']);

	$userdata->set('username', $vbulletin->GPC['username']);

	// set password
	$userdata->set('password', ($vbulletin->GPC['password_md5'] ? $vbulletin->GPC['password_md5'] : $vbulletin->GPC['password']));

	// check referrer
	if ($vbulletin->GPC['referrername'] AND !$vbulletin->userinfo['userid'])
	{
		$userdata->set('referrerid', $vbulletin->GPC['referrername']);
	}

	// Human Verification
	if (fetch_require_hvcheck('register'))
	{
		require_once(DIR . '/includes/class_humanverify.php');
		$verify = vB_HumanVerify::fetch_library($vbulletin);
		if (!$verify->verify_token($vbulletin->GPC['humanverify']))
		{
			$userdata->error($verify->fetch_error());
		}
	}
	// Set specified options
	if (!empty($vbulletin->GPC['options']))
	{
		foreach ($vbulletin->GPC['options'] AS $optionname => $onoff)
		{
			$userdata->set_bitfield('options', $optionname, $onoff);
		}
	}

	// assign user to usergroup 3 if email needs verification
	if ($vbulletin->options['verifyemail'])
	{
		$newusergroupid = 3;
	}
	else if ($vbulletin->options['moderatenewmembers'] OR $vbulletin->GPC['coppauser'])
	{
		$newusergroupid = 4;
	}
	else
	{
		$newusergroupid = 2;
	}
	// set usergroupid
	$userdata->set('usergroupid', $newusergroupid);

	// set languageid
	$userdata->set('languageid', $vbulletin->userinfo['languageid']);

	// set user title
	$userdata->set_usertitle('', false, $vbulletin->usergroupcache["$newusergroupid"], false, false);

	// set profile fields
	$customfields = $userdata->set_userfields($vbulletin->GPC['userfield'], true, 'register');

	// set birthday
	$userdata->set('showbirthday', $vbulletin->GPC['showbirthday']);
	$userdata->set('birthday', array(
		'day'   => $vbulletin->GPC['day'],
		'month' => $vbulletin->GPC['month'],
		'year'  => $vbulletin->GPC['year']
	));

	// set time options
	$userdata->set_dst($vbulletin->GPC['dst']);
	$userdata->set('timezoneoffset', $vbulletin->GPC['timezoneoffset']);

	// register IP address
	$userdata->set('ipaddress', IPADDRESS);

	($hook = vBulletinHook::fetch_hook('register_addmember_process')) ? eval($hook) : false;

	$userdata->pre_save();

	// check for errors
	if (!empty($userdata->errors))
	{
		$_REQUEST['do'] = 'register';

		$errorlist = '';
		foreach ($userdata->errors AS $index => $error)
		{
			$errorlist .= "<li>$error</li>";
		}

		$username = htmlspecialchars_uni($vbulletin->GPC[&#039;username&#039;]);
		$email = htmlspecialchars_uni($vbulletin->GPC[&#039;email&#039;]);
		$emailconfirm = htmlspecialchars_uni($vbulletin->GPC[&#039;emailconfirm&#039;]);
		$parentemail = htmlspecialchars_uni($vbulletin->GPC[&#039;parentemail&#039;]);
		$selectdst = array($vbulletin->GPC[&#039;dst&#039;] => &#039;selected="selected"&#039;);
		$sbselected = array($vbulletin->GPC[&#039;showbirthday&#039;] => &#039;selected="selected"&#039;);
		$show[&#039;errors&#039;] = true;
	}
	else
	{
		$show[&#039;errors&#039;] = false;

		// save the data
		$vbulletin->userinfo[&#039;userid&#039;]
			= $userid
			= $userdata->save();

		if ($userid)
		{
			$userinfo = fetch_userinfo($userid,0,0,0,true); // Read Master
			$userdata_rank = datamanager_init(&#039;User&#039;, $vbulletin, ERRTYPE_SILENT);
			$userdata_rank->set_existing($userinfo);
			$userdata_rank->set(&#039;posts&#039;, 0);
			$userdata_rank->save();

			// force a new session to prevent potential issues with guests from the same IP, see bug #2459
			require_once(DIR . &#039;/includes/functions_login.php&#039;);
			$vbulletin->session->created = false;
			process_new_login(&#039;&#039;, false, &#039;&#039;);

			// send new user email
			if ($vbulletin->options[&#039;newuseremail&#039;] != &#039;&#039;)
			{
				$username = $vbulletin->GPC[&#039;username&#039;];
				$email = $vbulletin->GPC[&#039;email&#039;];

				if ($birthday = $userdata->fetch_field(&#039;birthday&#039;))
				{
					$bday = explode(&#039;-&#039;, $birthday);
					$year = vbdate(&#039;Y&#039;, TIMENOW, false, false);
					$month = vbdate(&#039;n&#039;, TIMENOW, false, false);
					$day = vbdate(&#039;j&#039;, TIMENOW, false, false);
					if ($year > $bday[2] AND $bday[2] > 1901 AND $bday[2] != &#039;0000&#039;)
					{
						require_once(DIR . &#039;/includes/functions_misc.php&#039;);
						$vbulletin->options[&#039;calformat1&#039;] = mktimefix($vbulletin->options[&#039;calformat1&#039;], $bday[2]);
						if ($bday[2] >= 1970)
						{
							$yearpass = $bday[2];
						}
						else
						{
							// day of the week patterns repeat every 28 years, so
							// find the first year >= 1970 that has this pattern
							$yearpass = $bday[2] + 28 * ceil((1970 - $bday[2]) / 28);
						}
						$birthday = vbdate($vbulletin->options[&#039;calformat1&#039;], mktime(0, 0, 0, $bday[0], $bday[1], $yearpass), false, true, false);
					}
					else
					{
						// lets send a valid year as some PHP3 don&#039;t like year to be 0
						$birthday = vbdate($vbulletin->options[&#039;calformat2&#039;], mktime(0, 0, 0, $bday[0], $bday[1], 1992), false, true, false);
					}

					if ($birthday == &#039;&#039;)
					{
						// Should not happen; fallback for win32 bug regarding mktime and dates < 1970
						if ($bday[2] == &#039;0000&#039;)
						{
							$birthday = "$bday[0]-$bday[1]";
						}
						else
						{
							$birthday = "$bday[0]-$bday[1]-$bday[2]";
						}
					}
				}

				if ($userdata->fetch_field(&#039;referrerid&#039;) AND $vbulletin->GPC[&#039;referrername&#039;])
				{
					$referrer = unhtmlspecialchars($vbulletin->GPC[&#039;referrername&#039;]);
				}
				else
				{
					$referrer = $vbphrase[&#039;n_a&#039;];
				}
				$ipaddress = IPADDRESS;

				eval(fetch_email_phrases(&#039;newuser&#039;, 0));

				$newemails = explode(&#039; &#039;, $vbulletin->options[&#039;newuseremail&#039;]);
				foreach ($newemails AS $toemail)
				{
					if (trim($toemail))
					{
						vbmail($toemail, $subject, $message);
					}
				}
			}

			$username = htmlspecialchars_uni($vbulletin->GPC[&#039;username&#039;]);
			$email = htmlspecialchars_uni($vbulletin->GPC[&#039;email&#039;]);

			// sort out emails and usergroups
			if ($vbulletin->options[&#039;verifyemail&#039;])
			{
				$activateid = build_user_activation_id($userid, (($vbulletin->options[&#039;moderatenewmembers&#039;] OR $vbulletin->GPC[&#039;coppauser&#039;]) ? 4 : 2), 0);

				eval(fetch_email_phrases(&#039;activateaccount&#039;));

				vbmail($email, $subject, $message, true);

			}
			else if ($newusergroupid == 2)
			{
				if ($vbulletin->options[&#039;welcomemail&#039;])
				{
					eval(fetch_email_phrases(&#039;welcomemail&#039;));
					vbmail($email, $subject, $message);
				}
			}

			($hook = vBulletinHook::fetch_hook(&#039;register_addmember_complete&#039;)) ? eval($hook) : false;

			if ($vbulletin->GPC[&#039;coppauser&#039;])
			{
				$_REQUEST[&#039;do&#039;] = &#039;coppaform&#039;;
			}
			else
			{
				if ($vbulletin->options[&#039;verifyemail&#039;])
				{
					eval(standard_error(fetch_error(&#039;registeremail&#039;, $username, $email, create_full_url($vbulletin->url . $vbulletin->session->vars[&#039;sessionurl_q&#039;])), &#039;&#039;, false));
				}
				else
				{
					$vbulletin->url = str_replace(&#039;"&#039;, &#039;&#039;, $vbulletin->url);
					if (!$vbulletin->url)
					{
						$vbulletin->url = $vbulletin->options[&#039;forumhome&#039;] . &#039;.php&#039; . $vbulletin->session->vars[&#039;sessionurl_q&#039;];
					}
					else
					{
						$vbulletin->url = iif(strpos($vbulletin->url, &#039;register.php&#039;) !== false, $vbulletin->options[&#039;forumhome&#039;] . &#039;.php&#039; . $vbulletin->session->vars[&#039;sessionurl_q&#039;], $vbulletin->url);
					}

					if ($vbulletin->options[&#039;moderatenewmembers&#039;])
					{
						eval(standard_error(fetch_error(&#039;moderateuser&#039;, $username, $vbulletin->options[&#039;forumhome&#039;], $vbulletin->session->vars[&#039;sessionurl_q&#039;]), &#039;&#039;, false));
					}
					else
					{
						eval(standard_error(fetch_error(&#039;registration_complete&#039;, $username, $vbulletin->session->vars[&#039;sessionurl&#039;], $vbulletin->options[&#039;bburl&#039;] . &#039;/&#039; . $vbulletin->options[&#039;forumhome&#039;] . &#039;.php&#039;), &#039;&#039;, false));
					}
				}
			}
		}
	}
}
else if ($_GET[&#039;do&#039;] == &#039;addmember&#039;)
{
	// hmm, this probably happened because of a template edit that put the login box in the header.
	exec_header_redirect($vbulletin->options[&#039;forumhome&#039;] . &#039;.php&#039;);
}

Add a code snippet to your website: www.paste.org