<?php
/**
 * la.plume Micro CMS
 * ==================
 * COPYRIGHT Patrick Taylor http://www.mini-print.com/
 */

include ('inc/settings.php');

if (isset($_POST['submit'])) {

	if (!eregi ("^[[:alpha:].' -]{4,}$", stripslashes(trim($_POST['name'])))) {
		$problem = TRUE;
		$response0 = "You didn't enter your name.<br>";
	}

	$email = stripslashes(trim($_POST['email']));
	if ((strlen($email) < 5) || (!filter_var($email, FILTER_VALIDATE_EMAIL))) {
		$problem = TRUE;
		$response1 = "You didn't enter a valid email address.<br>";
	}

	if (strlen($_POST['comment']) < 1) {
		$problem = TRUE;
		$response2 = "You didn't specify your comment.<br>";
	}

	$name = stripslashes($_POST['name']);
	$message = stripslashes($_POST['comment']);

	if (!$problem) {
		$response1 = '';
		$comment = '';
		$ip = $_SERVER['REMOTE_ADDR'];
		$subject = 'Message from ' . $email;
		$website = LOCATION;
		$body = "Sent by {$name} [ {$email} ]\n\n{$website}\n\n{$message}\n\nIP: $ip";
		$body = wordwrap($body, 70);
		mail (EMAIL, $subject, $body) or print "Not sent.";
		$response0 = 'Your comment has been received, thank you.';
	} else {
		$content = ($_POST['comment']);
		$response3 = 'Please try again.';
	}
}

?>
<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact</title>
<link rel="stylesheet" media="only screen and (min-width: 661px), only screen and (min-device-width: 661px)" href="<?php echo LOCATION; ?>cms/inc/stylesheet.css" type="text/css">
<link rel="stylesheet" media="only screen and (max-width: 660px), only screen and (max-device-width: 660px)" href="<?php echo LOCATION; ?>cms/inc/mobile.css">

</head>

<body>
<div id="wrap">
	<div id="content">

<p id="banner"><?php echo BANNER_TEXT; ?></p>

<h1>Cont<i>act</i></h1>

<?php $message = CONTACT_TEXT; ?>
<p><?php echo stripslashes($message); ?></p>

<h2>Contact form</h2>
<?php

if (isset($_POST['submit'])) {
	echo '		<div class="response">';
	echo "\n\n";
	echo '<p>';
	echo $response0;
	echo $response1;
	echo $response2;
	echo $response3;
	echo '</p>';
	echo "\n\n";
	echo '		</div>';
	echo "\n";
}

?>

<form method="post" id="contactform" action="">

<p><input type="text" name="name" id="name" class="fixedwidth" size="22" value="<?php if (isset($_POST['submit'])) echo strip_tags($_POST['name']); ?>" maxlength="60" tabindex="1"><label for="name">Your name</label></p>

<p><input type="text" name="email" id="email" class="fixedwidth" size="22" value="<?php if (isset($_POST['submit'])) echo strip_tags($_POST['email']); ?>" maxlength="150" tabindex="2"><label for="email">Your email</label></p>

<p><textarea name="comment" id="comment" rows="8" cols="68"><?php if (isset($_POST['submit'])) echo strip_tags($content); ?></textarea></p>

<input type="submit" name="submit" class="submit" value="Submit">

</form>

<p><i>&#151;<?php echo SHORT_NAME; ?>&#151;</i></p>

	</div>

<?php include('inc/menu.php'); ?>
<?php include('inc/footer.php'); ?>
<?php include ('inc/tracking.php'); ?>

</div>

</body>
</html>