<?php
ini_set("max_execution_time", "30000");
session_start();

if($_POST["vURL"] == ""){

	$vURL = "https://online.backgroundchecks.com/integration/bgcdirectpost.aspx";

}
if($_POST["$vUserName"] == ""){

	$vUserName="dollarint";

}
if($_POST["$vPassword"] == ""){

	$vPassword="MNo3#3";

}
if($_POST["$vAccount"] == ""){

	$vAccount="10013649";

}
if($_POST["$vFirstName"] == ""){

	$vFirstName="gertrude";

}
if($_POST["$vMiddleName"] == ""){

	$vMiddleName="x";

}
if($_POST["$vLastName"] == ""){

	$vLastName="harkenreadeo";

}
if($_POST["$vSSN"] == ""){

	$vSSN="255066112";

}
if($_POST["$vDD"] == ""){

	$vDD="8";

}
if($_POST["$vMM"] == ""){

	$vMM="12";

}
if($_POST["$vYYYY"] == ""){

	$vYYYY="1953";

}
if($_POST["$vStreet"] == ""){

	$vStreet="305 linden bv";

}
if($_POST["$vCity"] == ""){

	$vCity="atlanta";

}
if($_POST["$vState"] == ""){

	$vState="GA";

}
if($_POST["$vPostCode"] == ""){

	$vPostCode="30316";

}
if($_POST["$vPhone"] == ""){

	$vPhone="255066112";

}



function get_sub_string($from="", $to="", $string="")
	{
		$pos	= strpos($string, $from);
		if ($pos === false) {
			$return	= "";
		} else {
			$pos1	= strpos($string, $to);
			if ($pos1 === false) {
				$return	= "";
			} else {
				$return	= substr($string, $pos+strlen($from), $pos1-($pos+strlen($to)-1));
			}
		}
		return $return;
	}
	
if(isset($_POST['btnGo']) && $_POST['btnGo']=='Check')
{

		$string		= "";
		$passed		= "NO";
		$msg		= "Invalid input parameters";
		$qtyFound	= 0;
		$qtyReturn	= 0;
		
		$vURL		= $_POST['vURL'];
		$vUserName	= $_POST['vUserName'];
		$vPassword	= $_POST['vPassword'];
		$vAccount	= $_POST['vAccount'];
		$firstName	= addslashes($_POST['vFirstName']);
		$middleName	= addslashes($_POST['vMiddleName']);
		$lastName	= addslashes($_POST['vLastName']);
		$suffixCode	= "";
		$ssn		= addslashes($_POST['vSSN']);
		$month		= addslashes($_POST['vMM']);
		$day		= addslashes($_POST['vDD']);
		$year		= addslashes($_POST['vYYYY']);
		$street		= addslashes($_POST['vStreet']);
		$city		= addslashes($_POST['vCity']);
		$state		= addslashes($_POST['vState']);
		$postalCode			= addslashes($_POST['vPostCode']);
		$telephoneNumber	= addslashes($_POST['vPhone']);

		$xmlrequest = '<?xml version="1.0" encoding="us-ascii" standalone="yes"?>
		<BGC>
		<login>
			<user>'.$vUserName.'</user>
			<password>'.$vPassword.'</password>
			<account>'.$vAccount.'</account>
		</login>
		<product>
			<USOneTrace>
				<order>
					<SSN>'.$ssn.'</SSN>
					<firstName>'.$firstName.'</firstName>
					<lastName>'.$lastName.'</lastName>
				</order>
			</USOneTrace>
		</product>
		</BGC>';
		
			//for testing
				//$_SESSION['test_before_file']='USOneTrace Request to Server'."\n\n".$xmlrequest;
				echo "===================================================================<br>";
				echo "USOneTrace Request to Server<br>";
				echo "===================================================================<br>";
				echo htmlentities($xmlrequest) ;
				echo "<br>===================================================================<br><br><br><br>";
			//teting end
		
		//separate the request URL and parameters into separate variables
		//initialize curl session $session = curl_init($request);
		$ch = curl_init();
		//set curl options to set to use https post point to url
		curl_setopt($ch, CURLOPT_URL, $vURL);
		curl_setopt($ch, CURLOPT_POST, TRUE);
		//specify which fields to post
		
		//for goddady server
		curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
		curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
		curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
		//curl_setopt ($ch, CURLOPT_PROXY,"http://64.202.165.130:3128");
		//for goddady server*/
		
		curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlrequest);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		//set authentication and security
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
		curl_setopt($ch, CURLOPT_TIMEOUT, CURL_TIMEOUT);
		//run the curl_exec to execute the post $response = curl_exec($session);
		$xml_report = curl_exec ($ch);
		//close curl resource and free up resources
		curl_close ($ch);
		
				echo "===================================================================<br>";
				echo "USOneTrace Response from Server<br>";
				echo "===================================================================<br>";
				echo htmlentities($xml_report) ;
				echo "<br>===================================================================<br><br><br><br>";

		$xml_report = preg_replace("/<form[^~]*<\/form>/","", $xml_report,1);
		$xml_report = preg_replace("/<script>[^~]*<\/script>/","", $xml_report,1);

		$xml	= get_sub_string("<response>", "</response>", $xml_report);
		if ($xml <> "") {
				$xml_report	= $xml;
		
			//for testing
				//$_SESSION['test_before_file_response']='USOneTrace Response from Server'."\n\n".$xml_report;
				$_SESSION['test_before_file_response']=$xml_report;
			//teting end

	    } else {
			$msg		= strip_tags(get_sub_string("<warnings>", "</warnings>", $xml_report));
			$msg		.= strip_tags(get_sub_string("<errors>", "</errors>", $xml_report));
			
			//for testing
				//$_SESSION['test_before_file_response'].='USOneTrace Error Response from Server'."\n\n".$msg;
				$_SESSION['test_before_file_response'].=$msg;
			//teting end
		}


		$array	= array();
		$arrRes	= array();
		$myarray= array();
		$array	= explode("<record>", $xml_report);

		foreach ($array as $key => $value) {
			$arrRes[]['fname']	= strtoupper(trim(get_sub_string("<firstName>", "</firstName>", $value)));
			$arrRes[]['mname']	= strtoupper(trim(get_sub_string("<middleName>", "</middleName>", $value)));
			$arrRes[]['lname']	= strtoupper(trim(get_sub_string("<lastName>", "</lastName>", $value)));
			$arrRes[]['age']	= strtoupper(trim(get_sub_string("<age>", "</age>", $value)));
		}

		if (!empty($arrRes)) {
			foreach ($arrRes as $key => $value) {
				if (($value['fname'] == strtoupper($firstName))
					AND ($value['mname'] == strtoupper($middleName))
					AND ($value['lname'] == strtoupper($lastName))
					AND ($value['age'] == get_age_from_date($year.$month.$day))) {
					$myarray	= $value;
				}
			}
		}

		//if (!empty($myarray)) {
			$xmlrequest = '<?xml version="1.0" encoding="us-ascii" standalone="yes"?>
			<BGC>
			<login>
				<user>'.$vUserName.'</user>
				<password>'.$vPassword.'</password>
				<account>'.$vAccount.'</account>
			</login>
			<product>
				<USOneSearch>
					<order>
						<firstName>'.$firstName.'</firstName>
						<middleName>'.$middleName.'</middleName>
						<lastName>'.$lastName.'</lastName>
						<DOB>
						  <month>'.$month.'</month>
						  <day>'.$day.'</day>
						  <year>'.$year.'</year>
						</DOB>
					</order>
				</USOneSearch>
			</product>
			</BGC>';
			
			//for testing
				//$_SESSION['test_before_file2']='USOneSearch Request to Server'."\n\n".$xmlrequest;
				echo "===================================================================<br>";
				echo "USOneSearch Request to Server<br>";
				echo "===================================================================<br>";
				echo htmlentities($xmlrequest) ;
				echo "<br>===================================================================<br><br><br><br>";
			//teting end
				
			//separate the request URL and parameters into separate variables
			//initialize curl session $session = curl_init($request);
			$ch = curl_init();
			//set curl options to set to use https post point to url
			curl_setopt($ch, CURLOPT_URL, $vURL);
			curl_setopt($ch, CURLOPT_POST, TRUE);
			//specify which fields to post
			
			curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlrequest);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
			
			//for goddady server
		curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
		curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
		curl_setopt ($ch, CURLOPT_PROXY,"http://proxy.shr.secureserver.net:3128");
		//curl_setopt ($ch, CURLOPT_PROXY,"http://64.202.165.130:3128");
		//for goddady server*/
		
			//set authentication and security
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
			curl_setopt($ch, CURLOPT_TIMEOUT, CURL_TIMEOUT);
			//run the curl_exec to execute the post $response = curl_exec($session);
			$xml_report = curl_exec ($ch);
			//close curl resource and free up resources
			curl_close ($ch);
			echo "===================================================================<br>";
			echo "USOneTrace Response from Server<br>";
			echo "===================================================================<br>";
			echo htmlentities($xml_report) ;
			echo "<br>===================================================================<br><br><br><br>";
			$xml_report = preg_replace("/<form[^~]*<\/form>/","", $xml_report,1);
			$xml_report = preg_replace("/<script>[^~]*<\/script>/","", $xml_report,1);

			$xml	= get_sub_string("<response>", "</response>", $xml_report);
			if ($xml <> "") {
				$xml_report	= $xml;
				//for testing
					//$_SESSION['test_before_file_response2']='USOneSearch Response from Server'."\n\n".$xml_report;
					$_SESSION['test_before_file_response2']=$xml_report;
				//teting end
			
			} else {
				$msg		= strip_tags(get_sub_string("<warnings>", "</warnings>", $xml_report));
				$msg		.= strip_tags(get_sub_string("<errors>", "</errors>", $xml_report));
				
				//for testing
					//$_SESSION['test_before_file_response2']='USOneSearch Response from Server'."\n\n".$xml_report;
					$_SESSION['test_before_file_response2']=$xml_report;
				//teting end
			
			}

			$qtyFound	= get_sub_string("qtyFound=\"", "\"", $xml_report);
			$qtyReturn	= get_sub_string("qtyReturned=\"", "\"", $xml_report);

			if ($qtyFound > 0 OR $qtyReturn > 0)
				$passed	= "NO";
			else
				$passed	= "YES";

		//}
	$msg='yes';

}//end if

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Testing  Background Check</title>
</head>
<body>
<table width="100%"  border="1" cellspacing="1" cellpadding="1">
  <tr>
    <td><b>Logic Applied</b></td>
  </tr>
  <tr>
    <td><i>Issue</i> : USOneSearch takes first name , last name and optional date of birth as parameters. So any query would return thousands of 
	results thereby making the background check meaningless </td>
  </tr>
  <tr>
    <td><i>Solution</i> : Do a USOneTrace using the ssn provided, compare the reponse values with the entered first name , second name and optional 
	date of birth and do a USOneSearch thereby making the background check meaningful</td>
  </tr>
   <tr>
    <td><i>Data Received for a test done on 2008-04-08 15:06:18 under testmode</i> : 

Residential address confirmed, record indicates different consumer name at this address.Unit or apartment number is required for this address.Phone matches residential address.Residential addressNo high risk information found for this address.No high risk information found for this phone.SSN matches address only.

score : 669</td>
  </tr>
    <tr>
    <td>Click <a href="bc_test1.zip">here</a> to download the zip version of this test file to verify the codes</td>
  </tr>
</table>
<br><br><br><br>
<form action="" method="post">
<table width="100%"  border="0" cellspacing="1" cellpadding="5">
 <tr align="left">
    <td width="34%" colspan="2">
		<strong>Backgroung check URL</strong><br>
		Test mode : https://model.backgroundchecks.com/integration/bgcdirectpost.aspx<br>
		Live mode : https://online.backgroundchecks.com/integration/bgcdirectpost.aspx<br>	
	</td>
  </tr>
  <tr>
    <td align="right">Backgroung check URL</td>
    <td align="left"><input name="vURL" type="text" class="inputbox" value="<?php echo $vURL; ?>" size="80" maxlength="200"></td>
  </tr>
 <tr align="left">
    <td width="34%" colspan="2"><strong>Account Information</strong></td>
  </tr>
  <tr>
    <td align="right">User Name</td>
    <td align="left"><input name="vUserName" type="text" class="inputbox" value="<?php echo $vUserName; ?>" size="30" maxlength="100"></td>
  </tr>
  <tr>
    <td align="right">Password</td>
    <td align="left"><input name="vPassword" type="text" class="inputbox" value="<?php echo $vPassword; ?>" size="30" maxlength="100"></td>
  </tr>
  <tr>
    <td align="right">Account</td>
    <td align="left"><input name="vAccount" type="text" class="inputbox" value="<?php echo $vAccount; ?>" size="30" maxlength="100"></td>
  </tr>
  <tr align="left">
    <td colspan="2"><strong>User Information </strong></td>
    </tr>
  <tr>
    <td width="34%" align="right">First Name *</td>
    <td width="66%" align="left"><input name="vFirstName" type="text" class="inputbox" value="<?php echo $vFirstName; ?>" size="30" maxlength="200"></td>
  </tr>
  <tr>
    <td align="right">Middle Name</td>
    <td align="left"><input name="vMiddleName" type="text" class="inputbox" value="<?php echo $vMiddleName; ?>" size="30" maxlength="100"></td>
  </tr>
  <tr>
    <td align="right">Last Name</td>
    <td align="left"><input name="vLastName" type="text" class="inputbox"  value="<?php echo $vLastName; ?>" size="30" maxlength="200"></td>
  </tr>
  <tr>
    <td align="right">SSN *</td>
    <td align="left"><input name="vSSN" type="text" class="inputbox"  value="<?php echo $vSSN; ?>" size="30" maxlength="200"></td>
  </tr>
  <tr>
    <td align="right">DOB *</td>
    <td align="left">Day:
                                    <input name="vDD" type="text" class="inputbox" value="<?php echo $vDD; ?>" size="2" maxlength="2">
Month:
<input name="vMM" type="text" class="inputbox" value="<?php echo $vMM; ?>" size="2" maxlength="2">
Year:
<input name="vYYYY" type="text" class="inputbox" value="<?php echo $vYYYY; ?>" size="6" maxlength="4"></td>
  </tr>
  <tr>
    <td align="right">Street *</td>
    <td align="left"><input name="vStreet" type="text" class="inputbox" value="<?php echo $vStreet; ?>" size="30" maxlength="100"></td>
  </tr>
  <tr>
    <td align="right">City</td>
    <td align="left"><input name="vCity" type="text" class="inputbox" value="<?php echo $vCity; ?>" size="30" maxlength="100"></td>
  </tr>
  <tr>
    <td align="right">State *</td>
    <td align="left"><input name="vState" type="text" class="inputbox" value="<?php echo $vState; ?>" size="30" maxlength="100"></td>
  </tr>
  <tr>
    <td align="right">Postal Code *</td>
    <td align="left"><input name="vPostCode" type="text" class="inputbox" value="<?php echo $vPostCode; ?>" size="30" maxlength="100"></td>
  </tr>
  <tr>
    <td align="right">Telephone Number *</td>
    <td align="left"><input name="vPhone" type="text" class="inputbox" value="<?php echo $vPhone; ?>" size="30" maxlength="100"></td>
  </tr>
  <tr>
    <td align="right">&nbsp;</td>
    <td align="left"><input type="submit" name="btnGo" value="Check"></td>
  </tr>
</table>

</form>
</body>
</html>
