<?PHP
######################################################
# #
# Forms To Go 4.0.3 #
# http://www.bebosoft.com/ #
# #
######################################################



define('kOptional', true);
define('kMandatory', false);

define('kStringRangeFrom', 1);
define('kStringRangeTo', 2);
define('kStringRangeBetween', 3);

define('kYes', 'yes');
define('kNo', 'no');

define('kNumberRangeFrom', 1);
define('kNumberRangeTo', 2);
define('kNumberRangeBetween', 3);




error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);

function DoStripSlashes($fieldValue) {
if ( get_magic_quotes_gpc() ) {
if (is_array($fieldValue) ) {
return array_map('DoStripSlashes', $fieldValue);
} else {
return stripslashes($fieldValue);
}
} else {
return $fieldValue;
}
}

function FilterCChars($theString) {
return preg_replace('/[\x00-\x1F]/', '', $theString);
}

function ProcessPHPFile($PHPFile) {
ob_start();
require $PHPFile;
return ob_get_clean();
}

function CheckString($value, $low, $high, $mode, $limitAlpha, $limitNumbers, $limitEmptySpaces, $limitExtraChars, $optional) {
if ($limitAlpha == kYes) {
$regExp = 'A-Za-z';
}

if ($limitNumbers == kYes) {
$regExp .= '0-9';
}

if ($limitEmptySpaces == kYes) {
$regExp .= ' ';
}

if (strlen($limitExtraChars) > 0) {

$search = array('\\', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|');
$replace = array('\\\\', '\[', '\]', '\-', '\$', '\.', '\*', '\(', '\)', '\?', '\+', '\^', '\{', '\}', '\|');

$regExp .= str_replace($search, $replace, $limitExtraChars);

}

if ( (strlen($regExp) > 0) && (strlen($value) > 0) ){
if (preg_match('/[^' . $regExp . ']/', $value)) {
return false;
}
}

if ( (strlen($value) == 0) && ($optional === kOptional) ) {
return true;
} elseif ( (strlen($value) >= $low) && ($mode == kStringRangeFrom) ) {
return true;
} elseif ( (strlen($value) <= $high) && ($mode == kStringRangeTo) ) {
return true;
} elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == kStringRangeBetween) ) {
return true;
} else {
return false;
}

}


function CheckNumeric($value, $low, $high, $mode, $optional) {
if ( (strlen($value) == 0) && ($optional === kOptional) ) {
return true;
} elseif (!is_numeric($value)) {
return false;
} elseif ( ($value >= $low) && ($mode == kNumberRangeFrom) ) {
return true;
} elseif ( ($value <= $high) && ($mode == kNumberRangeTo) ) {
return true;
} elseif ( ($value >= $low) && ($value <= $high) && ($mode == kNumberRangeBetween) ) {
return true;
} else {
return false;
}
}


function CheckEmail($email, $optional) {
if ( (strlen($email) == 0) && ($optional === kOptional) ) {
return true;
} elseif ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email) ) {
return true;
} else {
return false;
}
}



if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}

$FTGname = DoStripSlashes( $_REQUEST['name'] );
$FTGemail = DoStripSlashes( $_REQUEST['email'] );
$FTGcompany = DoStripSlashes( $_REQUEST['company'] );
$FTGaddress = DoStripSlashes( $_REQUEST['address'] );
$FTGaddress1 = DoStripSlashes( $_REQUEST['address1'] );
$FTGcity = DoStripSlashes( $_REQUEST['city'] );
$FTGstate = DoStripSlashes( $_REQUEST['state'] );
$FTGzip = DoStripSlashes( $_REQUEST['zip'] );
$FTGphone = DoStripSlashes( $_REQUEST['phone'] );
$FTGcomment = DoStripSlashes( $_REQUEST['comment'] );
$FTGsubmit = DoStripSlashes( $_REQUEST['submit'] );


# Fields Validations

$validationFailed = false;
if (!CheckString($FTGname, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$FTGErrorMessage['name'] = 'Please enter your name';
$validationFailed = true;
}

if (!CheckEmail($FTGemail, kMandatory)) {
$FTGErrorMessage['email'] = 'Please enter a correct email address';
$validationFailed = true;
}

if (!CheckNumeric($FTGzip, 500, 99499, kNumberRangeBetween, kMandatory)) {
$FTGErrorMessage['zip'] = 'Please enter a valid 5 digit zip code';
$validationFailed = true;
}



# Embed error page and dump it to the browser

if ($validationFailed === true) {

$fileErrorPage = 'error.html';

if (file_exists($fileErrorPage) === false) {
echo '<html><head><title>Error</title></head><body>The error page: <b>' . $fileErrorPage. '</b> cannot be found on the server.</body></html>';
exit;
}

$errorPage = ProcessPHPFile($fileErrorPage);

$errorList = implode("<br />\n", $FTGErrorMessage);
$errorPage = str_replace('<!--VALIDATIONERROR-->', $errorList, $errorPage);

$errorPage = str_replace('<!--FIELDVALUE:name-->', $FTGname, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:email-->', $FTGemail, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:company-->', $FTGcompany, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:address-->', $FTGaddress, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:address1-->', $FTGaddress1, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:city-->', $FTGcity, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:state-->', $FTGstate, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:zip-->', $FTGzip, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:phone-->', $FTGphone, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:comment-->', $FTGcomment, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:submit-->', $FTGsubmit, $errorPage);
$errorPage = str_replace('<!--ERRORMSG:name-->', $FTGErrorMessage['name'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:email-->', $FTGErrorMessage['email'], $errorPage);
$errorPage = str_replace('<!--ERRORMSG:zip-->', $FTGErrorMessage['zip'], $errorPage);


echo $errorPage;
exit;

}
# Email to Form Owner

$emailSubject = FilterCChars("Request for resume and headshot");

$emailBody = "name : $FTGname\n"
. "email : $FTGemail\n"
. "company : $FTGcompany\n"
. "address : $FTGaddress\n"
. "address1 : $FTGaddress1\n"
. "city : $FTGcity\n"
. "state : $FTGstate\n"
. "zip : $FTGzip\n"
. "phone : $FTGphone\n"
. "comment : $FTGcomment\n"
. "submit : $FTGsubmit\n"
. "";
$emailTo = 'Steve <steveb@dvmediapro.com>,Chuck <chuckp@dvmediapro.com>';

$emailFrom = FilterCChars("$FTGemail");

$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: 7bit\n";

mail($emailTo, $emailSubject, $emailBody, $emailHeader);


# Redirect user to success page

header("Location: success.html");
exit;
?>