index-test.php
[php]<?php
--------------------------------------------------------------
--------------------------------------------------------------
switch ($_SERVER[‘HTTP_HOST’]) {
case ‘www.absenteehomeowners.com’:
case ‘absenteehomeowners.com’:
default:
include_once($_SERVER[‘DOCUMENT_ROOT’] . ‘/etc/absenteehomeowners.php’);
break;
case ‘absenteehomeowners.stoutstreet.com’:
include_once($_SERVER[‘DOCUMENT_ROOT’] . ‘/dev/absenteehomeowners/etc/absenteehomeowners.php’);
break;
}
page_open(’’);
$dbg = new debug (SITE_PATH . ‘/debug/admin_index.txt’,DEBUG_FROM,DEBUG_TO);
$dbg->set_show (“File”);
$template = ‘arrival/index-test.tpl’;
$arrivalon=“id=‘on’”;
$navfix=‘550’;
$notification=new Notification();
SiteCookie::extract(“absenteehomeowners_arrival”);
if ((isset($_COOKIE[‘last_name’])) && ($_COOKIE[‘last_name’] != ‘’)) {
$last_name = $_COOKIE[‘last_name’];
}
if ((isset($_COOKIE[‘address’])) && ($_COOKIE[‘address’] != ‘’)) {
$address = $_COOKIE[‘address’];
}
if ((isset($_COOKIE[‘housekeeping’])) && ($_COOKIE[‘housekeeping’] != ‘’)) {
switch ($_COOKIE[‘housekeeping’]) {
case ‘no’:
default:
$tpl->set_var(‘no_select’, ‘checked’);
break;
case ‘prior’:
$tpl->set_var(‘prior_select’, ‘checked’);
break;
case ‘after’:
$tpl->set_var(‘after_select’, ‘checked’);
break;
case ‘both’:
$tpl->set_var(‘both_select’, ‘checked’);
break;
}
}
if ((isset($_COOKIE[‘special’])) && ($_COOKIE[‘special’] != ‘’)) {
$tellus = $_COOKIE[‘special’];
}
//begin form submit
while ( is_array($HTTP_POST_VARS) && list($key, $val) = each($HTTP_POST_VARS)) {
$send_mail = true;
$spam_score = 0;
$reason = ‘’;
switch ($key) {
case “notification_submit”:
$notification->handlePostVars();
$validator=new Validator();
$last_name = $validator->strip_metas($_POST[‘last_name’]);
$email_address = $validator->strip_metas($_POST[‘email_address’]);
$address = $validator->strip_metas($_POST[‘address’]);
$arrival = $_POST[‘arrival’];
$departure = $_POST[‘departure’];
$housekeeping = $_POST[‘housekeeping’];
$tellus = $validator->strip_metas($_POST[‘tellus’]);
$remember = $_POST[‘remember’];
$notification->setIPAddress($_SERVER[‘REMOTE_ADDR’]);
if (! ($last_name) || ($last_name == ‘’)) {
$error_msg .= ’
- Missing last name.’;
$last_name_req = ‘notification_req_failed’;
}
if ( (! ($address)) || ($address == ‘’)) {
$error_msg .= ’
- Missing address.’;
$address_req = ‘notification_req_failed’;
}
if ( (! ($housekeeping)) || ($housekeeping == ‘’)) {
$error_msg .= ’
- Missing housekeeping selection.’;
$housekeeping_req = ‘notification_req_failed’;
}
if ( (! ($arrival)) || ($arrival == ‘’)) {
$error_msg .= ’
- Missing arrival date.’;
$arrival_req = ‘notification_req_failed’;
}
else {
if((substr_count($arrival,DATE_SEPARATOR))<>2){
$error_msg .= ’
- Invalid arrival date – please use ’ . DATE_SEPARATOR;
$arrival_req = ‘notification_req_failed’;
} elseif (!preg_match(’/^\d{1,2}/\d{1,2}/\d{4}$/’, $arrival)) {
$error_msg .= ’
- Invalid arrival date – please use ’ . DATE_FORMAT;
$arrival_req = ‘notification_req_failed’;
} else {
$arr=split(DATE_SEPARATOR,$arrival); // splitting the array
$mm=$arr[0]; // first element of the array is month
$mmresult=ereg("^[0-9]+$",$mm,$trashed);
if (!($mmresult)) {
$error_msg .= ’
- Invalid arrival month.’;
$arrival_req = ‘notification_req_failed’;
}
$dd=$arr[1]; // second element is date
$ddresult=ereg("^[0-9]+$",$dd,$trashed);
if (!($ddresult)) {
$error_msg .= ’
- Invalid arrival day.’;
$arrival_req = ‘notification_req_failed’;
}
$yy=$arr[2]; // third element is year
$yyresult=ereg("^[0-9]+$",$yy,$trashed);
if (!($yyresult)) {
$error_msg .= ’
- Invalid arrival year.’;
$arrival_req = ‘notification_req_failed’;
}
If(!checkdate($mm,$dd,$yy)){
$error_msg .= ’
- Invalid arrival date.’;
$arrival_req = ‘notification_req_failed’;
} else {
$checkdate = dateDiff(DATE_SEPARATOR,$arrival,CURRENT_DATE);
//echo intval($checkdate);
If ( (intval($checkdate) < intval(CURRENT_DAY_SOONEST)) ) {
$error_msg .= ’
- Arrival date must be at least ’ . CURRENT_DAY_SOONEST. ’ days from today. ‘;//You have a difference of ’ . $checkdate;
//$error_msg .= ’
- Arrival date must be no more than’ . CURRENT_DAY_SOONEST. ’ days from today. checkdate date_diff(’ .$arrival .’,’. CURRENT_DATE. ‘) ’ . $checkdate;
$arrival_req = ‘notification_req_failed’;
}
If ($checkdate > CURRENT_DAY_LATEST) {
$error_msg .= ’
- Arrival date must be no more than ’ . CURRENT_DAY_LATEST. ’ days from today. ‘;//You have a difference of ’ . $checkdate;
//$error_msg .= ’
- Arrival date must be no more than ’ . CURRENT_DAY_LATEST. ’ days from today. checkdate date_diff(’ .$arrival .’,’. CURRENT_DATE. ‘) ’ . $checkdate;
$arrival_req = ‘notification_req_failed’;
}
}
}
}
if ( (! ($departure)) || ($departure == ‘’)) {
$error_msg .= ’
- Missing departure date.’;
$departure_req = ‘notification_req_failed’;
}
else {
if((substr_count($departure,DATE_SEPARATOR))<>2){
$error_msg .= ’
- Invalid departure date – please use ’ . DATE_SEPARATOR;
$departure_req = ‘notification_req_failed’;
} elseif (!preg_match(’/^\d{1,2}/\d{1,2}/\d{4}$/’, $departure)) {
$error_msg .= ’
- Invalid departure date – please use ’ . DATE_FORMAT;
$arrival_req = ‘notification_req_failed’;
} else {
$arr=split(DATE_SEPARATOR,$departure); // splitting the array
$mm=$arr[0]; // first element of the array is month
$mmresult=ereg("^[0-9]+$",$mm,$trashed);
if (!($mmresult)) {
$error_msg .= ’
- Invalid departure month.’;
$departure_req = ‘notification_req_failed’;
}
$dd=$arr[1]; // second element is date
$ddresult=ereg("^[0-9]+$",$dd,$trashed);
if (!($ddresult)) {
$error_msg .= ’
- Invalid departure day.’;
$departure_req = ‘notification_req_failed’;
}
$yy=$arr[2]; // third element is year
$yyresult=ereg("^[0-9]+$",$yy,$trashed);
if (!($yyresult)) {
$error_msg .= ’
- Invalid departure year.’;
$departure_req = ‘notification_req_failed’;
}
If(!checkdate($mm,$dd,$yy)){
$error_msg .= ’
- Invalid departure date.’;
$departure_req = ‘notification_req_failed’;
} else {
$checkdate = dateDiff(DATE_SEPARATOR,$departure,$arrival);
If ($checkdate < 0) {
$error_msg .= ’
- Departure date must be later than arrival date. ‘;//checkdate date_diff(’ .$departure .’,’. $arrival. ‘) ’ . $checkdate;
//$error_msg .= ’
- Departure date must be later than arrival date. checkdate date_diff(’ .$departure .’,’. $arrival. ‘) ’ . $checkdate;
$departure_req = ‘notification_req_failed’;
} else {
If ($checkdate > DEPARTURE_LATEST) {
$error_msg .= ’
- Departure date must be no more than ’ . DEPARTURE_LATEST. ’ days from arrival. ‘;//You have a difference of ’ . $checkdate;
//$error_msg .= ’
- Departure date must be no more than ’ . DEPARTURE_LATEST. ’ days from departure. checkdate date_diff(’ .$departure .’,’. CURRENT_DATE. ') ’ . $checkdate;
$departure_req = ‘notification_req_failed’;
}
}
}
}
}
if (isset ($error_msg)) {
$display_error_msg = '<p id="error">There was an error submitting your form. ';
$display_error_msg .= 'Please correct the errors below and resubmit.<span id="errormsg">' . $error_msg . '</span></p>';
break;
}
if (isset($remember) && ($remember == 'y')) {
// Create a local object
$SiteCookie=new SiteCookie("absenteehomeowners_arrival");
// Add the variables to be saved in the cookie
$SiteCookie->put("last_name",$last_name);
$SiteCookie->put("address",$address);
$SiteCookie->put("housekeeping",$housekeeping);
$SiteCookie->put("special",$tellus);
$SiteCookie->put("email_address",$email_address);
$SiteCookie->put("time",time());
// Set the cookie
$SiteCookie->set();
} else {
$SiteCookie=new SiteCookie("absenteehomeowners_arrival", time()-86400);
// Clear all values
$SiteCookie->clear();
// Set the cookie
$SiteCookie->set();
}
if ($send_mail == true && ($spam_score < 2)) { //
$notification_ret_val = $notification->sendInfo($spam_score,$reason);
if (!$notification_ret_val || ($notification->getErrorMessage())) {
$error_msg .= $notification->getErrorMessage();
$dbg->report ("\n\n notification->getErrorMessage: ", __LINE__, __FILE__, "", $notification->getErrorMessage());
$subject .= ' sendInfo() ERROR';
$body = $error_msg . "\nView the debug log here:\n";
$body = '<a href="http://' .$GLOBALS[HTTP_HOST] . '/debug/notification.php.txt">http://' . $GLOBALS[HTTP_HOST] . '/debug/notification.php.txt</a>';
$debug_ret_val=mail(SUBMIT_TO,$subject,$body,HEADERS);
break;
} else {
//echo 'WILL SEND spam_score=' . $spam_score;
//echo '<br />reason = ' . $reason;
$page='thanks';
}
} else {
//echo 'WILL <strong>NOT</strong> SEND spam_score=' . $spam_score;
//echo '<br />reason = ' . $reason;
$page='thanks';
}
break;
default:
break;
}
} //end form submit
$tpl->set_var(‘last_name’, $last_name);
$tpl->set_var(‘email_address’, $email_address);
$tpl->set_var(‘address’, $address);
$tpl->set_var(‘arrival’, $arrival);
$tpl->set_var(‘departure’, $departure);
$tpl->set_var(‘housekeeping’, $housekeeping);
$tpl->set_var(‘tellus’, $tellus);
$tpl->set_var(‘last_name_req’, $last_name_req);
$tpl->set_var(‘email_address’, $email_address);
$tpl->set_var(‘address_req’, $address_req);
$tpl->set_var(‘arrival_req’, $arrival_req);
$tpl->set_var(‘departure_req’, $departure_req);
$tpl->set_var(‘housekeeping_req’, $housekeeping_req);
if (isset($_POST[‘housekeeping’])) {
$housekeeping = $_POST[‘housekeeping’];
switch ($housekeeping) {
case ‘no’:
default:
$tpl->set_var(‘no_select’, ‘checked’);
break;
case ‘prior’:
$tpl->set_var(‘prior_select’, ‘checked’);
break;
case ‘after’:
$tpl->set_var(‘after_select’, ‘checked’);
break;
case ‘both’:
$tpl->set_var(‘both_select’, ‘checked’);
break;
}
}
if (isset($page)) {
switch ($page) {
case ‘thanks’:
default:
header(“Location: thanks.php”);
break;
}
}
if (isset ($error_msg)) {
$tpl->set_var(ERROR_MSG, $display_error_msg);
}
set_header($header_template);
set_nav($nav_template);
set_body(SITE_NAME . ‘.tpl’,$template,SITE_TITLE);
set_footer($footer_template);
$tpl->set_var(‘arrivalon’, $arrivalon);
$tpl->set_var(‘navfix’, $navfix);
$tpl->parse(‘HEADER’, ‘header’);
$tpl->parse(‘NAV’, ‘nav’);
$tpl->parse(‘BODY’, ‘body’);
$tpl->parse(‘FOOTER’, ‘footer’);
$tpl->parse(‘MAIN’, ‘wrapper’);
$tpl->p(‘MAIN’);
page_close();
?>[/php]