<?PHP
/********************************************************************************+\
** -+- LeetWEB Last Edition ~ The way to run a private server
*+*******************************************************************************
** -+- Copyright (C) 2011 Nilz. All rechten worden voorbehouden
** -+- http://www.leethotel.com
**
** -+- Parts Copyright (C) 2011 Joopie. All rechten worden voorbehouden
** -+- http://www.jospiek.nl
\+*******************************************************************************/
include("Includes/Global.php");

$pagename = "Register";

	if(session_is_registered(username))
	{
		Redirect("".$path."/me.php");
	}

	if(isset($_POST['register_ok']))
	{
		$username = Filter($_POST['username']);
		$password = LeetHash($_POST['password']);
		$password2 = LeetHash($_POST['passwordA']);
		$email = Filter($_POST['email']);
		$myIp = $_SERVER['REMOTE_ADDR'];

	if(empty($username) || empty($password) || empty($email))
	{
		$errors = 'To register you have to complete all fields!';
	}
	
	else if(strlen($username) <= 0)
	{
		$errors = 'Choose your username';
	}

	else if(strlen($password) <= 5)
	{
		$errors = 'The password you selected is too short.';
	}

	else if(strlen($password2) <= 5)
	{
		$errors = 'Password is different. Try again';
	}

	else if(strlen($username) >= 32)
	{
		$errors = 'Sorry, this name is too long';
	}

	else if(strlen($password) >= 50)
	{
		$errors = 'The password you selected is too long.';
	}

	else if(strlen($password2) >= 50)
	{
		$errors = 'Password is different. Try again';
	}

	else if(strlen($email) <= 6)
	{
		$errors = 'Please enter a valid email address.';
	}

	else if($users->UserExists($username))
	{
		$errors = 'The name you chose already exists Think different.';
	}

	else if(!$users->ValidEmail($email))
	{
		$errors = 'Please enter a valid email address';
	}

	else if(!$users->HasValidName($username))
	{
		$errors = 'This name is already in use or is not allowed. Try again';
	}

	else if(!$users->HasValidChar($username))
	{
		$errors = 'This name is already in use or is not allowed. Try again';
	}

	else if($users->EmailInUse($email))
	{
		$errors = 'This email address is already in use. Try again!';
	}

	else if($password != $password2)
	{
		$errors = 'Password is different. Try again';
	}

	else if($users->Limitof3($myIp))
	{
		$errors = 'Unfortunately, you have already created more than 3 users';
	}
	
	if(isset($errors))
	{
		$showMessage = '<div class="errorbox"><font color=white>';
		$showMessage .= $errors;
		$showMessage .= '</font></div>';
	}	

	if(!isset($errors))
	{
		$users->AddMember($username,$password,$email,$myIp, $sitename);
	
		$_SESSION['username'] = $username;
		$_SESSION['password'] = $password;
	
		header("Location: ".$path."/me.php");
		exit;
	}
}
?>
<!doctype html>
<html>
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
		<title><?PHP echo $shortname; ?>: <?PHP echo $pagename; ?></title>
		
		<link href="<?PHP echo $path; ?>/Web/style/global.css" type="text/css" rel="stylesheet">
		<link href="<?PHP echo $path; ?>/Web/style/login.css" type="text/css" rel="stylesheet">
		<link rel="icon" type="image/x-icon" href="<?PHP echo $path; ?>/Web/logo.ico" />
	</head>
	<body>
		<div class="begin static center">
			<div class="top">
				<div class="logo"><a href="/"><img src="<?PHP echo $path; ?>/Web/leet.png" alt=""></a></div>
				
				<div class="balk">
					
					<ul>
						<li class="title">Welcome to <?PHP echo $sitename; ?>!</li>
						<li class="menuitem" onclick="location.href = '<?PHP echo $path; ?>';"><p class="icon ihome"></p>Log in</li>
					</ul>
					
				</div>
			</div>
			
			<div class="page">
				<div class="box registreer">
					<div class="title">Register</div>
					<div class="content">
<?PHP
if(isset($showMessage))
{
	echo $showMessage;
}
?>
						
						<form actio<?PHP echo Filter($_SERVER['PHP_SELF']); ?>n="" method="post">
							
							<p class="input"><label>Username:</label><br>
							<input type="text" name="username" value="">
							<i>You can name these symbols <b> -=?!:.</b></i></p>
							<p class="input"><label>Email address:</label><br>
							<input type="text" name="email" value="">
							<i>Please enter a <b>valid</b> email address!</i></p>
							
							<p class="input"><label>Password</label><br>
							<input type="password" name="password" autocomplete="off" value="">
							<i>Your password must be <b>6 characters</b> long.</i></p>
							<p class="input"><label>Password again:</label><br>
							<input type="password" name="passwordA" autocomplete="off" value="">
							<i>Your password again.</i></p>
							
							<p><input type="submit" name="register_ok" value="Register"></p>
						</form>
						<br style="clear: both;">
					</div>
				</div>
			</div>
		</div>
		
		<div class="copyright static center">
		<?PHP include("Includes/Footer.php"); ?>
		</div>
	</body>
</html>