<?
	// PHP 4.1

	// read the post from PayPal system and add 'cmd'
	$req = 'cmd=_notify-validate';

	foreach ($_POST as $key => $value) {
		$value = urlencode(stripslashes($value));
		$req .= "&$key=$value";
	}

	// post back to PayPal system to validate
	$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
	$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
	$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
	$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

	if (!$fp) {
		echo "HTTP failed. Please check with system administrator.";
	}else {
		if (strpos($_REQUEST['invoice'], 'SINCE') !== false){
			include("settings.php");
		}else{
			include("../WCCM/settings.php");
		}
		if ($_REQUEST['payment_status']=="Completed"){
            $update = array(
                "registrant_paid" => "PAID",
                "sPayPalTranx" => $_REQUEST['txn_id']
            );
            $bind = array(
                ":search1" => $_REQUEST['invoice']
            );
            $db->update("tbl_registrant", $update, "paypal_invoice = :search1", $bind); 
		}
	}
	fclose ($fp);
?>