<?
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value)
{
	$value = urlencode(stripslashes($value));
	$req .= '&' . $key . '=' . $value;
}
$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 ('www.paypal.com', 80, $errno, $errstr, 30);
$payment_status = $_POST['payment_status'];
$amount = $_POST['mc_gross'];
$pay_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];

$scustom = explode('##',$_POST['custom']);

$trn_id=$scustom[0];
$typeofpay=$scustom[1];
$user_id=$scustom[2];
$plan_id=$scustom[3];
$recycle=$scustom[4];

if (!$fp)
{
	$error_output = $errstr . ' (' . $errno . ')';
}
else
{
	fputs ($fp, $header . $req);
	while (!feof($fp))
	{
		$res = fgets ($fp, 1024);
		if (strcmp ($res, "VERIFIED") == 0)
		{
$checkpay="yes";

		}
	}
	fclose ($fp);
}

if($checkpay=="yes")
{
require '../include/databaseinfo.php';
	$sql=mysql_connect($dbhost,$dbuser,$dbpass);
 	if(!$sql) {
		echo "<h1>Unable to Establish Connection to the Server</h1><hr noshade size=2 color=#000000>";
		exit();
	}
	$db_sel=mysql_select_db($dbname,$sql);
	if(!$db_sel) {
		echo "<h1>Unable to Connect to the Database</h1><hr noshade size=2 color=#000000>";
		exit();
	}
if($typeofpay=="shopcheck"){
$trans_date=date('Y-m-d');	
$insert_query="insert into usertransaction(trans_amount,itemid,user_id,trans_batchnumber,trans_date, trans_details, txn_id, type, currency, typeofpay, service) values($amount,'$plan_id','$user_id','$trn_id','$trans_date', 'Bid Purchase', '$txn_id', 'Debit', '$pay_currency', '$typeofpay', '$plan_id')";	
$insert_result=mysql_query($insert_query);
	
$plan_select_query="select * from plan where plan_id='$plan_id'";
$plan_select_result=mysql_query($plan_select_query);
$plan_select_row=mysql_fetch_array($plan_select_result);
$items=$plan_select_row['items'];

$query="update member_details set bid_num=bid_num+$items where user_id='$user_id'";
mysql_query($query);
}
if($typeofpay=="buy_pay"){
$trans_date=date('Y-m-d');	
$productid="$plan_id";
		     $up_sql="update auction_details set status='Sold' where productid=$productid";	
			mysql_query($up_sql);
		  
			$insert_query="insert into usertransaction(trans_amount,itemid,user_id,trans_batchnumber,trans_date, trans_details, seller_id, txn_id, type, currency, typeofpay, service) values($amount,'$productid','$user_id','$trn_id','$trans_date', 'Payment','$seller_id', '$txn_id', 'Debit', '$pay_currency', '$typeofpay', 'OTHER')";	
			$insert_result=mysql_query($insert_query);
}
}
?>