<?PHP
######################################################
# #
# Forms To Go 3.2.1 #
# [URL unfurl="true"]http://www.bebosoft.com/[/URL] #
# #
######################################################
DEFINE('kOptional', true);
DEFINE('kMandatory', false);
DEFINE('kStringRangeFrom', 1);
DEFINE('kStringRangeTo', 2);
DEFINE('kStringRangeBetween', 3);
DEFINE('kYes', 'yes');
DEFINE('kNo', 'no');
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);
#----------
# Filter by Stop Words
function stopwords_check()
{
$specialchars = array('\\', '[', ']', '-', '$', '.', '*', '(', ')', '?', '+', '^', '{', '}', '|');
$escapedchars = array('\\\\', '\[', '\]', '\-', '\$', '\.', '\*', '\(', '\)', '\?', '\+', '\^', '\{', '\}', '\|');
$StopWordsFile = 'badwords.txt';
if (file_exists($StopWordsFile) === false) {
echo '<html><head><title>Error</title></head><body>The Stop Words file: <b>' . $StopWordsFile . '</b> cannot be found on the server.</body></html>';
exit;
}
$bannedstopwords = file($StopWordsFile);
foreach ($_POST as $fieldname => $fieldvalue) {
foreach ($bannedstopwords as $stopword_key => $stopword_value) {
$stopword_value = str_replace($specialchars, $escapedchars, $stopword_value);
$pattern = '/.*' . rtrim($stopword_value) . '.*/i';
if (is_array($fieldvalue)) {
$fieldvalue = implode(",", $fieldvalue);
}
if (get_magic_quotes_gpc()) {
$fieldvalue = stripslashes($fieldvalue);
}
if (preg_match($pattern, $fieldvalue)) {
header('Location: [URL unfurl="true"]http://www.calvaryaog.org.au/church/general/Banned.asp');[/URL]
exit;
}
}
}
}
#----------
# Filter by IP Address
function ipaddress_check($ClientIP)
{
$BannedIPsFile = 'IPAddresses.txt';
if (file_exists($BannedIPsFile) === false) {
echo '<html><head><title>Error</title></head><body>The banned IPs file: <b>' . $BannedIPsFile . '</b> cannot be found on the server.</body></html>';
exit;
}
$bannedips = file($BannedIPsFile);
foreach ($bannedips as $ip_key => $ip_value) {
if (rtrim($ip_value) == $ClientIP) {
header('Location: [URL unfurl="true"]http://www.calvaryaog.org.au/church/general/Banned.asp');[/URL]
exit;
}
}
}
function DoStripSlashes($FieldValue)
{
if ( get_magic_quotes_gpc() ) {
if (is_array($FieldValue) ) {
return array_map('DoStripSlashes', $FieldValue);
} else {
return stripslashes($FieldValue);
}
} else {
return $FieldValue;
}
}
#----------
# FilterCChars:
function FilterCChars($TheString)
{
return preg_replace('/[\x00-\x1F]/', '', $TheString);
}
#----------
# Validate: String
function check_string($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;
}
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ClientIP = $_SERVER['REMOTE_ADDR'];
}
stopwords_check();
ipaddress_check($ClientIP);
$FTGtitle = DoStripSlashes( $_REQUEST['title'] );
$FTGcategory = DoStripSlashes( $_REQUEST['category'] );
$FTGURL = DoStripSlashes( $_REQUEST['URL'] );
$FTGdescription = DoStripSlashes( $_REQUEST['description'] );
$FTGSubmit2 = DoStripSlashes( $_REQUEST['Submit2'] );
$FTGSubmit = DoStripSlashes( $_REQUEST['Submit'] );
# Fields Validations
$ValidationFailed = false;
if (!check_string($FTGtitle, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$ValidationFailed = true;
$FTGtitle_errmsg = 'Please enter a title';
$ErrorList .= $FTGtitle_errmsg . '<br/>';
}
if (!check_string($FTGURL, 1, 0, kStringRangeFrom, kNo, kNo, kNo, '', kMandatory)) {
$ValidationFailed = true;
$FTGURL_errmsg = 'Please enter the website address';
$ErrorList .= $FTGURL_errmsg . '<br/>';
}
# 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;
}
$FileHandle = fopen ($FileErrorPage, "r");
$ErrorPage = fread ($FileHandle, filesize($FileErrorPage));
fclose ($FileHandle);
$ErrorPage = str_replace('<!--VALIDATIONERROR-->', $ErrorList, $ErrorPage);
$ErrorPage = str_replace('<!--FIELDVALUE:title-->', $FTGtitle, $ErrorPage);
$ErrorPage = str_replace('<!--FIELDVALUE:category-->', $FTGcategory, $ErrorPage);
$ErrorPage = str_replace('<!--FIELDVALUE:URL-->', $FTGURL, $ErrorPage);
$ErrorPage = str_replace('<!--FIELDVALUE:description-->', $FTGdescription, $ErrorPage);
$ErrorPage = str_replace('<!--FIELDVALUE:Submit2-->', $FTGSubmit2, $ErrorPage);
$ErrorPage = str_replace('<!--FIELDVALUE:Submit-->', $FTGSubmit, $ErrorPage);
$ErrorPage = str_replace('<!--ERRORMSG:title-->', $FTGtitle_errmsg, $ErrorPage);
$ErrorPage = str_replace('<!--ERRORMSG:URL-->', $FTGURL_errmsg, $ErrorPage);
echo $ErrorPage;
exit;
}
# Email to Form Owner
$emailSubject = FilterCChars("BIBLE COLLEGE WEBSITE LINK");
$emailBody = chunk_split(base64_encode("<html>\n"
. "<head>\n"
. "<title>Web page error</title>\n"
. "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n"
. "<link href=\"[URL unfurl="true"]http://www.calvaryaog.org.au/css/CSS_Styles.css\"[/URL] rel=\"stylesheet\" type=\"text/css\">\n"
. "</head>\n"
. "\n"
. "<body>\n"
. "<table width=\"500\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\">\n"
. " <tr> \n"
. " <td colspan=\"2\"><img src=\"[URL unfurl="true"]http://www.calvaryaog.org.au/bible_college/images/ModuleLogo.png\"[/URL] width=\"552\" height=\"134\"></td>\n"
. " </tr>\n"
. " <tr> \n"
. " <td colspan=\"2\" class=\"normalTxt\">Some one has suggested a website link for the bible college. Details below. </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td width=\"137\" align=\"right\" valign=\"top\" class=\"normalTxtnobox\"><strong>Title: </strong></td>\n"
. " <td width=\"463\" valign=\"top\" class=\"normalTxtnobox\">$FTGtitle </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td height=\"1\" align=\"right\" valign=\"middle\" class=\"normalTxtnobox\"><strong>Category</strong></td>\n"
. " <td height=\"1\" align=\"left\" valign=\"middle\" class=\"normalTxtnobox\">$FTGcategory</td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td height=\"1\" align=\"right\" valign=\"middle\" class=\"normalTxtnobox\"><strong>URL</strong></td>\n"
. " <td height=\"1\" align=\"left\" valign=\"middle\" class=\"normalTxtnobox\">$FTGURL </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td height=\"1\" align=\"right\" valign=\"middle\" class=\"normalTxtnobox\"><strong>Description: </strong></td>\n"
. " <td height=\"1\" align=\"left\" valign=\"middle\" class=\"normalTxtnobox\">$FTGdescription </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td colspan=\"2\" align=\"right\" valign=\"middle\" class=\"normalTxtnobox\"><hr size=\"1\"></td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td align=\"right\" valign=\"top\" class=\"normalTxtnobox\">IP Address: </td>\n"
. " <td valign=\"top\" class=\"normalTxtnobox\">$ClientIP </td>\n"
. " </tr>\n"
. " <tr>\n"
. " <td align=\"right\" valign=\"top\" class=\"normalTxtnobox\">Date Sent: </td>\n"
. " <td valign=\"top\" class=\"normalTxtnobox\">" . date('d/m/y') . " </td>\n"
. " </tr>\n"
. "</table>\n"
. "</body>\n"
. "</html>\n"
. ""))
. "\n";
//$emailTo = + include ('emailaddress.php');
$emailTo = 'email@address.net.au';
$emailFrom = FilterCChars("weblink@biblecollege.com.au");
$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-Type: text/html; charset=\"ISO-8859-1\"\n"
. "Content-Transfer-Encoding: base64\n"
. "\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Embed success page and dump it to the browser
$FileSuccessPage = 'success.html';
if (file_exists($FileSuccessPage) === false) {
echo '<html><head><title>Error</title></head><body>The success page: <b> ' . $FileSuccessPage . '</b> cannot be found on the server.</body></html>';
exit;
}
$FileHandle = fopen ($FileSuccessPage, "r");
$SuccessPage = fread ($FileHandle, filesize($FileSuccessPage));
fclose ($FileHandle);
$SuccessPage = str_replace('<!--FIELDVALUE:title-->', $FTGtitle, $SuccessPage);
$SuccessPage = str_replace('<!--FIELDVALUE:category-->', $FTGcategory, $SuccessPage);
$SuccessPage = str_replace('<!--FIELDVALUE:URL-->', $FTGURL, $SuccessPage);
$SuccessPage = str_replace('<!--FIELDVALUE:description-->', $FTGdescription, $SuccessPage);
$SuccessPage = str_replace('<!--FIELDVALUE:Submit2-->', $FTGSubmit2, $SuccessPage);
$SuccessPage = str_replace('<!--FIELDVALUE:Submit-->', $FTGSubmit, $SuccessPage);
echo $SuccessPage;
exit;
?>