<?php
  session_start(); // start a session
?>
<html>
<head>
	<title>Virtual Alien / Old Nick / Nick Peterson :: Contact</title>
	<meta charset="utf-8" />
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<meta http-equiv="Description" content="Virtual Alien, Contact" />
  <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  <meta http-equiv="imagetoolbar" content="no" />
	<meta name="HandheldFriendly" content="true" />
  <link rel="stylesheet" type="text/css" href="css/vainset.css" title="master" />
	<meta name="Keywords" content="Nick Peterson, Virtual Alien, music, film, 80s, 90s, 00s, rock, pop, punk, male, singer, songwriter, film director, performer, writer, speed of light, writing on the wall, Est, In and Out of Planet Earth, E.S.T., Burning from the Inside, War of Love, Old Nick, King of the World, Map of the Universe, Digital Broadcast, #NickPeterson, #VirtualAlien, The Y2K File, #OldNick, Closer to the Sun, Old Nick, #Est, Red by James Hogan, V.A." />
	<meta name="Description" content="The official web presence of singer, songwriter, composer, writer and film director Nick Peterson AKA V.A. Virtual Alien..." />
</head>

<body>

<?php
	if (isset($_POST['submit'])) {
		$error = "";

		if (!empty($_POST['name'])) {
			$name = $_POST['name'];
		} else {
			$error .= "You didn't type in your name. <br />";
		}

		if (!empty($_POST['email'])) {
			$email = $_POST['email'];
			if (!preg_match("/^[_a-z0-9]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)) {
				$error .= "The e-mail address you entered is not valid. <br/>";
			}
		} else {
			$error .= "You didn't type in an e-mail address. <br />";
		}

		if (!empty($_POST['message'])) {
			$message = $_POST['message'];
		} else {
			$error .= "You didn't type in a message. <br />";
		}

		if(($_POST['code']) == $_SESSION['code']) {
			$code = $_POST['code'];
		} else {
			$error .= "The captcha code you entered does not match. Please try again. <br />";
		}

		if (empty($error)) {
			$headers[] = 'From: noreply@virtualalien.net';
			$headers[] = 'Reply-To: '. $name .' <'. $email .'>';
			//$headers[] = 'Cc: ';
			$to = "webmaster@virtualalien.net";
			$subject = 'VirtualAlien.net _ Contact';
			$content = $name . "(". $email .") has sent you a message: \n" . $message;
			$success = "<h3>Thank you! Your message has been sent!</h3>";

			mail($to, $subject, $content, implode("\r\n", $headers));
		}
	}
?>

			<article id="contact" class="panel normtext" style="width:80%; margin:0 auto; padding:20px">
				<span class="pagehead">Contact VA</span><br />
				<br />
				<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
					<div class="va_cf">
						<input type="text" name="name" placeholder="Name" <?php if ($_POST['name']) { echo ' value="'. $_POST['name'] .'"'; } ?>/>
						<input type="text" name="email" placeholder="Email" <?php if ($_POST['email']) { echo ' value="'. $_POST['email'] .'"'; } ?>/><br />
					</div>
					<br />
					<div class="va_cf va_fullwidth">
						<textarea name="message" placeholder="Message" rows="8" cols="30"><?php if ($_POST['message']) { echo $_POST['message']; } ?></textarea>
					</div>
					<br />
					<div class="va_cf">
						<label class="captcha"><img src="captcha.php" style="vertical-align: middle;"></label><input type="text" name="code" placeholder="Enter the digits" />
					</div>
					<br />
					<div class="va_cf">
						<input type="submit" name="submit" value="Send Message" />
					</div>
<?php
if (!empty($error)) {
	echo '<div class="va_cf error"><strong><h3>Your message was NOT sent.</strong> The following error(s) returned:<br/>' . $error . '</div>';
} elseif (!empty($success)) {
	echo '<div class="va_cf success"><span class="icon fa-tick"></span><strong>'. $success .'</strong></div>';
} else {
	echo '<!-- Submitted.';
	var_dump($_POST);
	echo "\nOther Vars:\n";
	echo 'error: '. $error ."\nsuccess: ". $success ."\n_SESSION['code']: ". $_SESSION['code'] ."\n";
	echo ' -->';
}
?>
				</form>
			</article>

		<!--  Scripts  --
	<script src="/js/jquery.min.js"></script>
	<script src="/js/skel.min.js"></script>
	<script src="/js/skel-layout.min.js"></script>
	<script src="/js/skel-viewport.min.js"></script>
	<script src="/js/util.js"></script>
	<script src="/js/main.js"></script-->
</body>
</html>
