<?php
/*
script: contact.php
purpose: display and process the contact page form for users to contact you.
copyright: copyright 2004 Php Image Host. All Rights Reserved. You may modify this file for use on your
					site running a licenced copy of the Php Image Host scripts.
					You must not distribute this file or derivations of it.
Nullified By CrAcKlOvE

*/

// include configuration / initialization stuff

require_once(dirname(__FILE__).'/includes/config.inc.php');

// init variables

$name = $ace->getstr('name', $_POST, $user != 0 ? $user->name : '');
$email = $ace->getstr('email', $_POST, $user != 0 ? $user->email : '');
$subject = $ace->getstr('subject', $_POST);
$message = $ace->getstr('message', $_POST);
$errors = '';
$submitted = false;

// process contact form submission and send an email if successful

if( $ace->getstr('submit', $_POST) ){
	if( $email == '' || !$ace->validateemail($email) ){
		$errors .= '<br />You must enter your email address.';
	}
	if( $name == '' ) $errors.='<br />You must enter your name.';
	if( $subject == '' ) $errors.='<br />You must enter a subject.';
	if( strlen($message) < 10 ) $errors.='<br />You must enter your message.';
	if( $errors == '' ){
		$to = $config->admin_email;
		$headers = "From: $email\r\nReply-To: $email\r\nErrors-To: $to\r\nReturn-Path: $to";
		$ip = isset($_SERVER['X_FORWARDED_FOR']) ? $_SERVER['X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
		$message = 'Submission from '.$config->sitename.' contact form sent by '.$name.' ('.$ip.') on '.date('l jS F Y @ H:i')."\n\n".$message;
		@mail($to, $subject, $message, $headers);
		$submitted = true;
	}
}

// include the site header

require_once(dirname(__FILE__).'/header.php');

if( !$submitted ){

	// if the form hasn't been successfully submitted, display the contact page
	// message (editable in the page content area of the site admin area)

	$pagecontent->display('Contact');

	// display any errors with the form submission

	if( $errors != '' ){
?>
<div class="errors">Please correct the following errors:<br />
<?php echo $errors;?>
</div>
<?php
	}

	// display the contact form.

?>
<form action="<?php echo $_SERVER['SCRIPT_NAME'];?>" method="post">
<div class="contactform">
<table class="contacttable" cellspacing="0" cellpadding="0" border="0">
<tr>
	<td class="contactlabel">Your Name:</td>
	<td class="contactfield"><input class="contactinput" type="text" name="name" value="<?php echo htmlspecialchars($name);?>" /></td>
</tr>
<tr>
	<td class="contactlabel">Your Email:</td>
	<td class="contactfield"><input class="contactinput" type="text" name="email" value="<?php echo htmlspecialchars($email);?>" /></td>
</tr>
<tr>
	<td class="contactlabel">Subject:</td>
	<td class="contactfield"><input class="contactinput" type="text" name="subject" value="<?php echo htmlspecialchars($subject);?>" /></td>
</tr>
<tr>
	<td class="contactlabel" style="vertical-align: top">Message:</td>
	<td class="contactfield"><textarea class="contactmessage" name="message"><?php echo htmlspecialchars($message);?></textarea></td>
</tr>
<tr>
	<td class="contactlabel">&nbsp;</td>
	<td class="contactfield"><input type="submit" name="submit" value="Submit Message" /></td>
</tr>
</table>
</div>
</form>
<?php

}else{

	// the form has been submitted. Display some kind of "thanks for contacting us" message.

	$pagecontent->display('Contact Submitted');

}

// include the site footer.

require_once(dirname(__FILE__).'/footer.php');

?>
