<?php


session_start();
include("include/config.php");
include("include/functions/import.php");

if ($_REQUEST[code] != "")
{
	if (strlen($_REQUEST[code]) != "15")
	{
		$error = "$lang[520]";
	}
	else
	{
		$code = stripslashes($_REQUEST[code]);
		$query="SELECT * from members_verifycode WHERE code='".mysql_real_escape_string($code)."'";
		$result=$conn->execute($query);
		
		if($result->recordcount()>=1)
		{
			$userid = $result->fields['USERID'];
			
			$query="SELECT verified from members WHERE USERID='$userid'";
			$result=$conn->execute($query);
			$verified = $result->fields['verified'];
			
			if ($verified == "1")
			{
				$error = "$lang[521]";
			}
			else
			{
				$query="UPDATE members SET verified='1' WHERE USERID='$userid'";
				$result=$conn->execute($query);
				$showmessage = "Your e-mail address has successfully been confirmed.";
				
				if ($_SESSION[USERID] == $userid)
				{
					$_SESSION[VERIFIED] = "1";
				}
			}
		}
		else
		{
			$error = "$lang[522]";
		}
	}
}

$pagetitle = "$lang[523]";
STemplate::assign('pagetitle',$pagetitle);

STemplate::assign('showmessage',$showmessage);
STemplate::assign('error',$error);

//TEMPLATES BEGIN
STemplate::display('header.tpl');
STemplate::display('confirmemail.tpl');
STemplate::display('footer.tpl');
//TEMPLATES END
?>