<?php
$start_time = date("c");
set_time_limit(180000);
//include("/home/phil/uploads/database.php");
// Connect to the Database
//$con_ptr = mysql_connect('db-02-03.tmnplc.com:3306','campaigns_web','pH4q.fQB23!');
//$con_ptr = connect_sym_live();
//$con_ptr = connect_sbm();
// Connect to the Database
$con_ptr = mysql_connect("db-08-02.tmnplc.com", "keila_web","Zircon500");
//$con_ptr = mysql_connect("db-08-01.tmnplc.com", "mailman","6Zyj8xj7");
// database
//$db = "mailman"; // testing
$db = "surveycentral"; // live
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$user_tbl = $db.".Users";
$mobile_tbl = $db.".MobileData";
$landline_tbl = $db.".LandLineData";
// data8 login details
$d8username = "tmngroup_data8";
$d8password = "AxUcmOkj12";
if($_POST)
{
foreach($_POST as $key => $value)
{
// for form debugging
//echo $key." --- ".$value."<br>";
$$key = $value;
}
}
if($_GET)
{
foreach($_GET as $key => $value)
{
// for form debugging
//echo $key." --- ".$value."<br>";
$$key = $value;
}
}
error_reporting(E_ALL);
$logdir = "/var/www/purelead/log_files/external_feed_log/";
$time = date("c");
function MobileIsValid($telephone, $d8username, $d8password)
{
global $mobile_tbl, $con_ptr;
// first we check to see if we've already searched for this number in the 3 months so we don't cane our credits
$three_months_ago = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m")-3, date("d"), date("Y")));
$sql = "SELECT * FROM ".$mobile_tbl." WHERE Number = '".$telephone."' AND dos > '".$three_months_ago."'";
//echo $sql;
$res = mysql_query($sql, $con_ptr);
$numrows = mysql_num_rows($res);
if($numrows > 0)
{
$row = mysql_fetch_array($res);
if($row['Result'] == 'Success')
{
return true;
} else
{
return false;
}
}
$params = array(
"username" => $d8username,
"password" => $d8password,
"number" => $telephone,
"options" => $options
);
$client = new SoapClient("http://webservices.data-8.co.uk/MobileValidation.asmx?WSDL");
if($numrows == 0)
{
$result = $client->IsValid($params);
}
//print_r($result);
if ($result->IsValidResult->Result != "Success")
{
return false;
}
else
{
return true;
}
}
// logs the reuslts
function logResults($values, $logfile){
global $logdir, $time;
// count the values
$num_vals = count($values);
// open the log file
$resfile = fopen($logdir.$logfile, "a");
//write data to the log file
foreach($values as $key => $value){
$value = str_replace("'", "", $value);
$value = trim($value, "\n\r");
$value = regx_replace("\r", " ", $value);
$value = regx_replace("\n", " ", $value);
fwrite($resfile, $key." --> ".$value);
fwrite($resfile, ",");
}
fwrite($resfile, $time);
fwrite($resfile, "\n");
// close the log file
fclose($resfile);
}
function LineIsValid($telephone, $d8username, $d8password)
{
global $landline_tbl, $con_ptr;
// first we check to see if we've already searched for this number in the 3 months so we don't cane our credits
$three_months_ago = date("Y-m-d H:i:s", mktime(date("H"), date("i"), date("s"), date("m")-3, date("d"), date("Y")));
$sql = "SELECT * FROM ".$landline_tbl." WHERE Number = '".$telephone."' AND dos > '".$three_months_ago."'";
$res = mysql_query($sql, $con_ptr);
$numrows = mysql_num_rows($res);
if($numrows > 0)
{
$row = mysql_fetch_array($res);
if($row['Result'] == 'Valid')
{
return true;
} else
{
return false;
}
}
$params = array(
"username" => $d8username,
"password" => $d8password,
"number" => $telephone,
"options" => $options
);
//$client = new SoapClient("http://webservices.data-8.co.uk/TelephoneValidation.asmx?WSDL");
$client = new SoapClient("http://webservices.data-8.co.uk/TelephoneLineValidation.asmx?WSDL");
$result = $client->IsValidAdvanced($params);
//logResults($result, date("c"), "LandLineCheck.log", $telephone);
if ($result->IsValidAdvancedResult->Result != "Valid")
{
return false;
}
else
{
return true;
}
}
function checkNumber($telephone)
{
global $d8username, $d8password;
// now do the data8 check
$match = "/^07[0-9]{9,10}/";
if(preg_match($match, $telephone))
{
// then it's a mobile
if(MobileIsValid($telephone, $d8username, $d8password) != true)
{
$errordata['telephone'] = "You haven\'t provided us with a valid UK telephone number";
$error = 15;
return false;
}
} else
{
// then it's a landline
if(LineIsValid($telephone, $d8username, $d8password) != true)
{
$errordata['telephone'] = "You haven\'t provided us with a valid UK telephone number";
$error = 16;
return false;
}
}
return true;
}
// Call the checkNumber function
if (checkNumber($_POST['telephone']) == false)
{
echo'false - number provided is false';
die;
}
else
//Call mobile function
if (MobileIsValid(($_POST['telephone']), $d8username, $d8password) == false)
{
echo'false - number provided is false';
die;
}
else
//Call landline function
if (LineIsValid(($_POST['telephone']), $d8username, $d8password) == false)
{
echo'false - number provided is false';
die;
}
else
// todays date
$today = date("Ymd");
// Call the getAge function
if (isset($_POST['birth_date']))
{
$age = getAge($birth_date);
}
//Or fail
else echo'false - no dob provided';
{
}
function getAge($birth_date){
list($year, $month, $day) = explode("-", $birth_date);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($day_diff < 0)
{
$month_diff--;
}
if ($month_diff < 0)
{
$year_diff--;
}
return $year_diff;
}
$curl = curl_init();
if ( !$curl )
{
print "Failed to initalise cURL object\n";
} else {
$url = "https://v3.lolagrove.com/data.ashx?id=7941.1674&paid_creditors_six_months=Yes&email=".urlencode($email)."&firstname=".urlencode($firstname)."&lastname=".($lastname)."&address1=".urlencode($address1)."&towncity=".urlencode($towncity)."&postcode=".urlencode($postcode)."&telephone=".urlencode($telephone)."&age=".urlencode($age)."&debt_amount=".urlencode($debt_amount)."&debt_with=".urlencode($debt_with)."&disposable_income=".urlencode($disposable_income)."&iva_bankruptcy=".urlencode($iva_bankruptcy)."&securekey=6e5af886-22e5-4f04-b97b-946539aa70f1";
$curl_opts = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_FAILONERROR => true,
);
if ( !curl_setopt_array( $curl, $curl_opts ) )
{
print "Unable to set properties on CURL object\n";
} else
{
$response = curl_exec( $curl );
$responseCode = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
if ( is_bool( $response ) && $response == false )
{
// Failed to make HTTP request to tracking URL
echo 'Error from CURL in livefeed: "', curl_error( $curl ), '" ', var_export( curl_getinfo( $curl ), TRUE );
} else if ( ! ( $responseCode >= 200 && $responseCode <= 299 ) )
{
// We got an HTTP response, but it was not successful
print "Error: Tracking URL returned HTTP $responseCode\n";
} else {
// All good
print "Success, response was:\n";
echo var_export( $response ), "\n";
}
}
}
curl_close( $curl );
// log the values
$values[] = $response;
$values[] = $responseCode;
$values[] = $url;
logResults($values, 'Madison_financial');
//}
preferences:
61.82 ms | 402 KiB | 5 Q