<html>
<head>
<title>Non-Seamless-kit</title>
</head>
<body>
<center>

<?php include('Crypto.php')?>
<?php 

	error_reporting(0);
	$servername = "localhost";
	$username = "adclubuser";
	$password = "W;yCg0H0k4z5";
	$dbname = "adclubmadras";

	// Create connection
	$conn = mysqli_connect($servername, $username, $password, $dbname);
	// Check connection
	if(!$conn){
	    die("Connection failed: " . mysqli_connect_error());
	}
	//print_r($_POST);die();
	$merchant_param1 = $_POST["merchant_param1"];
	if($merchant_param1 == "maddysregistration"){
		$registrationID = $_POST["order_id"];
		$sql = "select * from `wp_maddys_registration` where `registrationID` =  '$registrationID'";
		$query = mysqli_query($conn, $sql);
		if(mysqli_num_rows($query) > 0)
		{
			while($fetch = mysqli_fetch_assoc($query))
			{
				$reqID = $fetch['registrationID'];
				$price = $fetch['payableAmount'];
				$tID = time();
				$billing_email = $fetch['companyEmail'];
				$billing_name = $fetch['companyContactPerson'];
				$billing_address = $fetch['companyAddress'];
				$billing_tel = $fetch['companyTelephone'];
			}
		}
	}elseif($merchant_param1 == "maddysentryticket"){
		$entryID = $_POST["order_id"];
		$sql = "select * from `wp_maddys_entry_ticket` where `entryID` =  '$entryID'";
		$query = mysqli_query($conn, $sql);
		if(mysqli_num_rows($query) > 0)
		{
			while($fetch = mysqli_fetch_assoc($query))
			{
				$reqID = $fetch['entryID'];
				$price = $fetch['payableAmount'];
				$tID = time();
				$billing_email = $fetch['emailAddress'];
				$billing_name = $fetch['fullName'];
				$billing_address = "";
				$billing_tel = $fetch['contactNumber'];
			}
		}
	}elseif($merchant_param1 == "Maddys2018Entry"){
		$entryID = $_POST["order_id"];
		$sql = "select * from `wp_maddys_2018_step2` where `entryID` =  '$entryID'";
		$query = mysqli_query($conn, $sql);
		if(mysqli_num_rows($query) > 0)
		{
			while($fetch = mysqli_fetch_assoc($query))
			{
				$reqID = $fetch['entryID'];
				$price = $fetch['payableAmount'];
				$tID = time();
				$billing_email = $fetch['email'];
				$billing_name = $fetch['name'];
				$billing_address = $fetch['address'];
				$billing_tel = $fetch['contactNo'];
			}
		}
	}elseif($merchant_param1 == "course"){
		$orderID = $_POST["orderID"];
		$sql = "select * from `wp_course_application` where `unique_id` =  '$orderID'";
		$query = mysqli_query($conn, $sql);
		if(mysqli_num_rows($query) > 0)
		{
			while($fetch = mysqli_fetch_assoc($query))
			{
				$reqID = $fetch['unique_id'];
				$price = $fetch['courseFee'];
				$tID = time();
				$billing_email = $fetch['emailid'];
				$billing_name = $fetch['name'];
				$billing_address = $fetch['address1'];
				$billing_tel = $fetch['mobile'];
			}
		}
	}else{
		$orderID = $_POST["orderID"];
		$sql = "select * from `wp_members` where `unique_id` =  '$orderID'";
		$query = mysqli_query($conn, $sql);
		if(mysqli_num_rows($query) > 0)
		{
			while($fetch = mysqli_fetch_assoc($query))
			{
				$reqID = $fetch['unique_id'];
				$price = $fetch['price'];
				$tID = time();
				$billing_email = $fetch['email'];
				$billing_name = $fetch['con_person'];
				$billing_address = $fetch['address1'];
				$billing_tel = $fetch['mobile'];
			}
		}
	}
	$importantData = "merchant_id=107811&tid=".$tID."&order_id=".$reqID."&amount=".$price."&currency=INR&redirect_url=http://adclubmadras.com/ccavenue/ccavResponseHandler.php&cancel_url=http://adclubmadras.com/ccavenue/ccavResponseHandler.php&language=EN&billing_email=".$billing_email."&billing_name=".$billing_name."&billing_address=".$billing_address."&billing_tel=".$billing_tel;
	$merchant_data = '';
	$working_key = '5EDD35AF4A89BF071C4374A9A9BD6743';//Shared by CCAVENUES
	$access_code = 'AVNV66DH71CC11VNCC';//Shared by CCAVENUES
	
	foreach ($_POST as $key => $value){
		$merchant_data .= $key.'='.$value.'&';
	}
	$merchant_data .= $importantData;
	$encrypted_data = encrypt($merchant_data,$working_key); // Method for encrypting the data.
?>
<form method="post" name="redirect" action="https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction"> 
<?php
	echo "<input type=hidden name=encRequest value=$encrypted_data>";
	echo "<input type=hidden name=access_code value=$access_code>";
?>
</form>
</center>
<script language='javascript'>document.redirect.submit();</script>
</body>
</html>

