// ############################### start register ###############################
if ($_REQUEST['do'] == 'register')
{
	$vbulletin->input->clean_array_gpc('p', array(
		'agree'   => TYPE_BOOL,
		'year'    => TYPE_UINT,
		'month'   => TYPE_UINT,
		'day'     => TYPE_UINT,
		'options' => TYPE_ARRAY_BOOL,
		'who'     => TYPE_NOHTML,
	));

	// Variables that are used in templates
	$agree =& $vbulletin->GPC['agree'];
	$year =& $vbulletin->GPC['year'];
	$month =& $vbulletin->GPC['month'];
	$day =& $vbulletin->GPC['day'];

	$url = $vbulletin->url;

	if (!$vbulletin->GPC['agree'])
	{
		eval(standard_error(fetch_error('register_not_agreed', $vbulletin->options['forumhome'], $vbulletin->session->vars['sessionurl_q'])));
	}
	if (!$vbulletin->options['allowregistration'])
	{
		eval(standard_error(fetch_error('noregister')));
	}

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

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

	if ($errorlist)
	{
		$checkedoff['adminemail'] = iif($vbulletin->GPC['options']['adminemail'], 'checked="checked"');
		$checkedoff['showemail'] = iif($vbulletin->GPC['options']['showemail'], 'checked="checked"');
	}
	else
	{
		$checkedoff['adminemail'] = iif(bitwise($vbulletin->bf_misc_regoptions['adminemail'], $vbulletin->options['defaultregoptions']), 'checked="checked"');
		$checkedoff['showemail'] = iif(bitwise($vbulletin->bf_misc_regoptions['receiveemail'], $vbulletin->options['defaultregoptions']), 'checked="checked"');
	}

	if ($vbulletin->options['reqbirthday'] AND !$vbulletin->options['usecoppa'])
	{
		$show['birthday'] = true;
		$monthselected[str_pad($vbulletin->GPC['month'], 2, '0', STR_PAD_LEFT)] = 'selected="selected"';
		$dayselected[str_pad($vbulletin->GPC['day'], 2, '0', STR_PAD_LEFT)] = 'selected="selected"';

	    if ($year == 0)
	    {
	        $year = '';
    	}

		// Default Birthday Privacy option to show all
		if (empty($errorlist))
		{
			$sbselected = array(2 => 'selected="selected"');
		}
		eval('$birthdayfields = "' . fetch_template('modifyprofile_birthday') . '";');
	}
	else
	{
		$show['birthday'] = false;

		$birthdayfields = '';
	}

	$htmlonoff = ($vbulletin->options['allowhtml'] ? $vbphrase['on'] : $vbphrase['off']);
	$bbcodeonoff = ($vbulletin->options['allowbbcode'] ? $vbphrase['on'] : $vbphrase['off']);
	$imgcodeonoff = ($vbulletin->options['allowbbimagecode'] ? $vbphrase['on'] : $vbphrase['off']);
	$smiliesonoff = ($vbulletin->options['allowsmilies'] ? $vbphrase['on'] : $vbphrase['off']);

	// human verification
	if (fetch_require_hvcheck('register'))
	{
		require_once(DIR . '/includes/class_humanverify.php');
		$verify = vB_HumanVerify::fetch_library($vbulletin);
		$human_verify = $verify->output_token();
	}

	// Referrer
	if ($vbulletin->options['usereferrer'] AND !$vbulletin->userinfo['userid'])
	{
		exec_switch_bg();
		if ($errorlist)
		{
			$referrername = $vbulletin->GPC['referrername'];
		}
		else if ($vbulletin->GPC[COOKIE_PREFIX . 'referrerid'])
		{
			if ($referrername = $db->query_first_slave("SELECT username FROM " . TABLE_PREFIX . "user WHERE userid = " . $vbulletin->GPC[COOKIE_PREFIX . 'referrerid']))
			{
				$referrername = $referrername['username'];
			}
		}
		$show['referrer'] = true;
	}
	else
	{
		$show['referrer'] = false;
	}

	// get extra profile fields
	if ($vbulletin->GPC['who'] != 'adult')
	{
		$bgclass1 = 'alt1';
	}

	$customfields_other = '';
	$customfields_profile = '';
	$customfields_option = '';

	$profilefields = $db->query_read_slave("
		SELECT *
		FROM " . TABLE_PREFIX . "profilefield
		WHERE editable > 0 AND required <> 0
		ORDER BY displayorder
	");
	while ($profilefield = $db->fetch_array($profilefields))
	{
		$profilefieldname = "field$profilefield[profilefieldid]";
		$optionalname = $profilefieldname . &#039;_opt&#039;;
		$optionalfield = &#039;&#039;;
		$optional = &#039;&#039;;
		$profilefield[&#039;title&#039;] = $vbphrase[$profilefieldname . &#039;_title&#039;];
		$profilefield[&#039;description&#039;] = $vbphrase[$profilefieldname . &#039;_desc&#039;];
		if (!$errorlist)
		{
			unset($vbulletin->userinfo["$profilefieldname"]);
		}
		elseif (isset($vbulletin->GPC[&#039;userfield&#039;]["$profilefieldname"]))
		{
			$vbulletin->userinfo["$profilefieldname"] = $vbulletin->GPC[&#039;userfield&#039;]["$profilefieldname"];
		}

		$custom_field_holder = &#039;&#039;;

		if ($profilefield[&#039;type&#039;] == &#039;input&#039;)
		{
			if ($profilefield[&#039;data&#039;] !== &#039;&#039;)
			{
				$vbulletin->userinfo["$profilefieldname"] = $profilefield[&#039;data&#039;];
			}
			else
			{
				$vbulletin->userinfo["$profilefieldname"] = htmlspecialchars_uni($vbulletin->userinfo["$profilefieldname"]);
			}
			eval(&#039;$custom_field_holder = "&#039; . fetch_template(&#039;userfield_textbox&#039;) . &#039;";&#039;);
		}
		else if ($profilefield[&#039;type&#039;] == &#039;textarea&#039;)
		{
			if ($profilefield[&#039;data&#039;] !== &#039;&#039;)
			{
				$vbulletin->userinfo["$profilefieldname"] = $profilefield[&#039;data&#039;];
			}
			else
			{
				$vbulletin->userinfo["$profilefieldname"] = htmlspecialchars_uni($vbulletin->userinfo["$profilefieldname"]);
			}
			eval(&#039;$custom_field_holder = "&#039; . fetch_template(&#039;userfield_textarea&#039;) . &#039;";&#039;);
		}
		else if ($profilefield[&#039;type&#039;] == &#039;select&#039;)
		{
			$data = vb_unserialize($profilefield[&#039;data&#039;]);
			$selectbits = &#039;&#039;;
			foreach ($data AS $key => $val)
			{
				$key++;
				$selected = &#039;&#039;;
				if (isset($vbulletin->userinfo["$profilefieldname"]))
				{
					if (trim($val) == $vbulletin->userinfo["$profilefieldname"])
					{
						$selected = &#039;selected="selected"&#039;;
						$foundselect = 1;
					}
				}
				else if ($profilefield[&#039;def&#039;] AND $key == 1)
				{
					$selected = &#039;selected="selected"&#039;;
					$foundselect = 1;
				}

				eval(&#039;$selectbits .= "&#039; . fetch_template(&#039;userfield_select_option&#039;) . &#039;";&#039;);
			}

			if ($profilefield[&#039;optional&#039;])
			{
				if (!$foundselect AND $vbulletin->userinfo["$profilefieldname"])
				{
					$optional = htmlspecialchars_uni($vbulletin->userinfo["$profilefieldname"]);
				}
				eval(&#039;$optionalfield = "&#039; . fetch_template(&#039;userfield_optional_input&#039;) . &#039;";&#039;);
			}
			if (!$foundselect)
			{
				$selected = &#039;selected="selected"&#039;;
			}
			else
			{
				$selected = &#039;&#039;;
			}
			$show[&#039;noemptyoption&#039;] = iif($profilefield[&#039;def&#039;] != 2, true, false);
			eval(&#039;$custom_field_holder = "&#039; . fetch_template(&#039;userfield_select&#039;) . &#039;";&#039;);
		}
		else if ($profilefield[&#039;type&#039;] == &#039;radio&#039;)
		{
			$data = vb_unserialize($profilefield[&#039;data&#039;]);
			$radiobits = &#039;&#039;;
			$foundfield = 0;
			$perline = 0;
			$unclosedtr = true;

			foreach ($data AS $key => $val)
			{
				$key++;
				$checked = &#039;&#039;;
				if (!$vbulletin->userinfo["$profilefieldname"] AND $key == 1 AND $profilefield[&#039;def&#039;] == 1)
				{
					$checked = &#039;checked="checked"&#039;;
				}
				else if (trim($val) == $vbulletin->userinfo["$profilefieldname"])
				{
					$checked = &#039;checked="checked"&#039;;
					$foundfield = 1;
				}
				if ($perline == 0)
				{
					$radiobits .= &#039;<tr>&#039;;
				}
				eval(&#039;$radiobits .= "&#039; . fetch_template(&#039;userfield_radio_option&#039;) . &#039;";&#039;);
				$perline++;
				if ($profilefield[&#039;perline&#039;] > 0 AND $perline >= $profilefield[&#039;perline&#039;])
				{
					$radiobits .= &#039;</tr>&#039;;
					$perline = 0;
					$unclosedtr = false;
				}
			}
			if ($unclosedtr)
			{
				$radiobits .= &#039;</tr>&#039;;
			}
			if ($profilefield[&#039;optional&#039;])
			{
				if (!$foundfield AND $vbulletin->userinfo["$profilefieldname"])
				{
					$optional = htmlspecialchars_uni($vbulletin->userinfo["$profilefieldname"]);
				}
				eval(&#039;$optionalfield = "&#039; . fetch_template(&#039;userfield_optional_input&#039;) . &#039;";&#039;);
			}
			eval(&#039;$custom_field_holder = "&#039; . fetch_template(&#039;userfield_radio&#039;) . &#039;";&#039;);
		}
		else if ($profilefield[&#039;type&#039;] == &#039;checkbox&#039;)
		{
			$data = vb_unserialize($profilefield[&#039;data&#039;]);
			$radiobits = &#039;&#039;;
			$perline = 0;
			$unclosedtr = true;
			foreach ($data AS $key => $val)
			{
				if ($vbulletin->userinfo["$profilefieldname"] & pow(2,$key))
				{
					$checked = &#039;checked="checked"&#039;;
				}
				else
				{
					$checked = &#039;&#039;;
				}
				$key++;
				if ($perline == 0)
				{
					$radiobits .= &#039;<tr>&#039;;
				}
				eval(&#039;$radiobits .= "&#039; . fetch_template(&#039;userfield_checkbox_option&#039;) . &#039;";&#039;);
				$perline++;
				if ($profilefield[&#039;perline&#039;] > 0 AND $perline >= $profilefield[&#039;perline&#039;])
				{
					$radiobits .= &#039;</tr>&#039;;
					$perline = 0;
					$unclosedtr = false;
				}
			}
			if ($unclosedtr)
			{
				$radiobits .= &#039;</tr>&#039;;
			}
			eval(&#039;$custom_field_holder = "&#039; . fetch_template(&#039;userfield_radio&#039;) . &#039;";&#039;);
		}
		else if ($profilefield[&#039;type&#039;] == &#039;select_multiple&#039;)
		{
			$data = vb_unserialize($profilefield[&#039;data&#039;]);
			$selectbits = &#039;&#039;;
			$selected = &#039;&#039;;

			if ($profilefield[&#039;height&#039;] == 0)
			{
				$profilefield[&#039;height&#039;] = count($data);
			}

			foreach ($data AS $key => $val)
			{
				if ($vbulletin->userinfo["$profilefieldname"] & pow(2, $key))
				{
					$selected = &#039;selected="selected"&#039;;
				}
				else
				{
					$selected = &#039;&#039;;
				}
				$key++;
				eval(&#039;$selectbits .= "&#039; . fetch_template(&#039;userfield_select_option&#039;) . &#039;";&#039;);
			}
			eval(&#039;$custom_field_holder = "&#039; . fetch_template(&#039;userfield_select_multiple&#039;) . &#039;";&#039;);
		}

		if ($profilefield[&#039;required&#039;] == 2)
		{
			// not required to be filled in but still show
			$profile_variable =& $customfields_other;
		}
		else // required to be filled in
		{
			if ($profilefield[&#039;form&#039;])
			{
				$profile_variable =& $customfields_option;
			}
			else
			{
				$profile_variable =& $customfields_profile;
			}
		}

		eval(&#039;$profile_variable .= "&#039; . fetch_template(&#039;userfield_wrapper&#039;) . &#039;";&#039;);
	}

	if (!$vbulletin->GPC[&#039;who&#039;])
	{
		$vbulletin->GPC[&#039;who&#039;] = iif($vbulletin->GPC[&#039;coppauser&#039;], &#039;coppa&#039;, &#039;adult&#039;);
	}

	$show[&#039;coppa&#039;] = $usecoppa = ($vbulletin->GPC[&#039;who&#039;] == &#039;adult&#039; OR !$vbulletin->options[&#039;usecoppa&#039;]) ? false : true;
	$show[&#039;customfields_profile&#039;] = ($customfields_profile OR $show[&#039;birthday&#039;]) ? true : false;
	$show[&#039;customfields_option&#039;] = ($customfields_option) ? true : false;
	$show[&#039;customfields_other&#039;] = ($customfields_other) ? true : false;
	$show[&#039;email&#039;] = ($vbulletin->options[&#039;enableemail&#039;] AND $vbulletin->options[&#039;displayemails&#039;]) ? true : false;

	$vbulletin->input->clean_array_gpc(&#039;p&#039;, array(
		&#039;timezoneoffset&#039; => TYPE_NUM
	));

	// where do we send in timezoneoffset?
	if ($vbulletin->GPC[&#039;timezoneoffset&#039;])
	{
		$timezonesel = $vbulletin->GPC[&#039;timezoneoffset&#039;];
	}
	else
	{
		$timezonesel = $vbulletin->options[&#039;timeoffset&#039;];
	}

	require_once(DIR . &#039;/includes/functions_misc.php&#039;);
	$timezoneoptions = &#039;&#039;;
	foreach (fetch_timezone() AS $optionvalue => $timezonephrase)
	{
		$optiontitle = $vbphrase["$timezonephrase"];
		$optionselected = iif($optionvalue == $timezonesel, &#039;selected="selected"&#039;, &#039;&#039;);
		eval(&#039;$timezoneoptions .= "&#039; . fetch_template(&#039;option&#039;) . &#039;";&#039;);
	}
	eval(&#039;$timezoneoptions = "&#039; . fetch_template(&#039;modifyoptions_timezone&#039;) . &#039;";&#039;);

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

	eval(&#039;print_output("&#039; . fetch_template(&#039;register&#039;) . &#039;");&#039;);
}

// ############################### start activate form ###############################
if ($vbulletin->GPC[&#039;a&#039;] == &#039;ver&#039;)
{
	// get username and password
	if (!$vbulletin->userinfo[&#039;userid&#039;])
	{
		$vbulletin->userinfo[&#039;username&#039;] = &#039;&#039;;
	}

	if ($permissions[&#039;forumpermissions&#039;] & $vbulletin->bf_ugp_forumpermissions[&#039;canview&#039;])
	{
		$navbits = construct_navbits(array(&#039;&#039; => $vbphrase[&#039;activate_your_account&#039;]));
		eval(&#039;$navbar = "&#039; . fetch_template(&#039;navbar&#039;) . &#039;";&#039;);
	}
	else
	{
		$navbar = &#039;&#039;;
	}

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

	eval(&#039;print_output("&#039; . fetch_template(&#039;activateform&#039;) . &#039;");&#039;);
}

// ############################### start activate ###############################
if ($_REQUEST[&#039;do&#039;] == &#039;activate&#039;)
{
	$vbulletin->input->clean_array_gpc(&#039;r&#039;, array(
		&#039;username&#039;		=> TYPE_NOHTML,
		&#039;activateid&#039;	=> TYPE_STR,

		// These three are cleaned so that they will exist and not be overwritten in the next step

		&#039;u&#039;				=> TYPE_UINT,
		&#039;a&#039;				=> TYPE_NOHTML,
		&#039;i&#039;				=> TYPE_STR,
	));

	if ($userinfo = $db->query_first("SELECT userid FROM " . TABLE_PREFIX . "user WHERE username=&#039;" . $db->escape_string($vbulletin->GPC[&#039;username&#039;]) . "&#039;"))
	{
		$vbulletin->GPC[&#039;u&#039;] = $userinfo[&#039;userid&#039;];
		$vbulletin->GPC[&#039;a&#039;] = &#039;act&#039;;
		$vbulletin->GPC[&#039;i&#039;] = $vbulletin->GPC[&#039;activateid&#039;];
	}
	else
	{
		eval(standard_error(fetch_error(&#039;badlogin&#039;, $vbulletin->options[&#039;bburl&#039;], $vbulletin->session->vars[&#039;sessionurl&#039;], $strikes)));
	}
}

if ($vbulletin->GPC[&#039;a&#039;] == &#039;act&#039;)
{
	$vbulletin->input->clean_array_gpc(&#039;r&#039;, array(
		&#039;u&#039;		=> TYPE_UINT,
		&#039;i&#039;		=> TYPE_STR,
	));

	$userinfo = verify_id(&#039;user&#039;, $vbulletin->GPC[&#039;u&#039;], 1, 1);

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

	if ($userinfo[&#039;usergroupid&#039;] == 3)
	{
		// check valid activation id
		$user = $db->query_first("
			SELECT activationid, usergroupid, emailchange
			FROM " . TABLE_PREFIX . "useractivation
			WHERE activationid = &#039;" . $db->escape_string($vbulletin->GPC[&#039;i&#039;]) . "&#039;
				AND userid = $userinfo[userid]
				AND type = 0
		");
		if (!$user OR $vbulletin->GPC[&#039;i&#039;] != $user[&#039;activationid&#039;])
		{
			// send email again
			eval(standard_error(fetch_error(&#039;invalidactivateid&#039;, $vbulletin->session->vars[&#039;sessionurl&#039;], $vbulletin->options[&#039;contactuslink&#039;])));
		}

		// delete activationid
		$db->query_write("DELETE FROM " . TABLE_PREFIX . "useractivation WHERE userid=$userinfo[userid] AND type=0");

		/*
		This shouldn&#039;t be needed any more since we handle this during registration
		if ($userinfo[&#039;coppauser&#039;] OR ($vbulletin->options[&#039;moderatenewmembers&#039;] AND !$userinfo[&#039;posts&#039;]))
		{
			// put user in moderated group
			$user[&#039;usergroupid&#039;] = 4;
		}*/

		if (empty($user[&#039;usergroupid&#039;]))
		{
			$user[&#039;usergroupid&#039;] = 2; // sanity check
		}

		// ### DO THE UG/TITLE UPDATE ###

		$getusergroupid = iif($userinfo[&#039;displaygroupid&#039;] != $userinfo[&#039;usergroupid&#039;], $userinfo[&#039;displaygroupid&#039;], $user[&#039;usergroupid&#039;]);

		$user_usergroup =& $vbulletin->usergroupcache["$user[usergroupid]"];
		$display_usergroup =& $vbulletin->usergroupcache["$getusergroupid"];

		// init user data manager
		$userdata = datamanager_init(&#039;User&#039;, $vbulletin, ERRTYPE_STANDARD);
		$userdata->set_existing($userinfo);
		$userdata->set(&#039;usergroupid&#039;, $user[&#039;usergroupid&#039;]);
		$userdata->set_usertitle(
			$user[&#039;customtitle&#039;] ? $user[&#039;usertitle&#039;] : &#039;&#039;,
			false,
			$display_usergroup,
			($user_usergroup[&#039;genericpermissions&#039;] & $vbulletin->bf_ugp_genericpermissions[&#039;canusecustomtitle&#039;]) ? true : false,
			($user_usergroup[&#039;genericpermissions&#039;] & $vbulletin->bf_ugp_genericpermissions[&#039;cancontrolpanel&#039;]) ? true : false
		);

		require_once(DIR . &#039;/includes/functions_ranks.php&#039;);
		if ($user[&#039;userid&#039;] == $vbulletin->userinfo[&#039;userid&#039;])
		{
			$vbulletin->userinfo[&#039;usergroupid&#039;] = $user[&#039;usergroupid&#039;];
			$vbulletin->userinfo[&#039;displaygroupid&#039;] = $user[&#039;usergroupid&#039;];
		}

		// see 3.6.x bug #176
		//$userinfo[&#039;usergroupid&#039;] = $user[&#039;usergroupid&#039;];

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

		if ($userinfo[&#039;coppauser&#039;] OR ($vbulletin->options[&#039;moderatenewmembers&#039;] AND !$userinfo[&#039;posts&#039;]))
		{
			// put user in moderated group
			$userdata->save();
			eval(standard_error(fetch_error(&#039;moderateuser&#039;, $userinfo[&#039;username&#039;], $vbulletin->options[&#039;forumhome&#039;], $vbulletin->session->vars[&#039;sessionurl_q&#039;]), &#039;&#039;, false));
		}
		else
		{
			// activate account
			$userdata->save();

			$username = unhtmlspecialchars($userinfo[&#039;username&#039;]);
			if (!$user[&#039;emailchange&#039;])
			{
				if ($vbulletin->options[&#039;welcomemail&#039;])
				{
					eval(fetch_email_phrases(&#039;welcomemail&#039;));
					vbmail($userinfo[&#039;email&#039;], $subject, $message);
				}

				$userdata->send_welcomepm();
			}

			if ($user[&#039;emailchange&#039;])
			{
				eval(standard_error(fetch_error(&#039;emailchanged&#039;, htmlspecialchars_uni($userinfo[&#039;email&#039;])), &#039;&#039;, false));
			}
			else
			{
				eval(standard_error(fetch_error(&#039;registration_complete&#039;, $userinfo[&#039;username&#039;], $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 ($userinfo[&#039;usergroupid&#039;] == 4)
		{
			// In Moderation Queue
			eval(standard_error(fetch_error(&#039;activate_moderation&#039;), &#039;&#039;, false));
		}
		else
		{
			// Already activated
			eval(standard_error(fetch_error(&#039;activate_wrongusergroup&#039;)));
		}
	}

}

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