<?php
ini_set('display_errors',1);
error_reporting(E_ALL);

require('db_connect.php');
if(isset($_POST)){
	$response = $_POST;
	
	/* It is very important to calculate the hash using the returned value and compare it against the hash that was sent while payment request, to make sure the response is legitimate */
	$salt = SALT_KEY; /* put your salt provided by traknpay here */
	if(isset($salt) && !empty($salt)){
		$response['calculated_hash']=hashCalculate($salt, $response);
		$response['valid_hash'] = ($response['hash']==$response['calculated_hash'])?'Yes':'No';
	} else {
		$response['valid_hash']='Set your salt in return_page.php to do a hash check on receiving response from Traknpay';
	}
}

function hashCalculate($salt,$input){
	/* Remove hash key if it is present */
	unset($input['hash']);
	/*Sort the array before hashing*/
	ksort($input);
	
	/*first value of hash data will be salt*/
	$hash_data = $salt;
	
	/*Create a | (pipe) separated string of all the $input values which are available in $hash_columns*/
	foreach ($input as $key=>$value) {
		if (strlen($value) > 0) {
			$hash_data .= '|' . $value;
		}
	}

	$hash = null;
	if (strlen($hash_data) > 0) {
		$hash = strtoupper(hash("sha512", $hash_data));
	}
		
	return $hash;
}

$id= $response["udf1"];
$userid= $response["udf2"];
$transaction_id= $response["transaction_id"];
$payment_mode= $response["payment_mode"];
$payment_channel= $response["payment_channel"];
$payment_datetime= $response["payment_datetime"];
$response_message= $response["response_message"];

if($response_message=="Transaction successful")
{
    mysqli_query($conn,"UPDATE tbl_userregistration_ug2 SET transaction_id='$transaction_id',  payment_mode='$payment_mode', payment_channel='$payment_channel',payment_datetime='$payment_datetime',response_message='$response_message',status=1,payment_redirectid='' WHERE id='$id' AND userid='$userid'");
    mysqli_query($conn,"UPDATE tbl_admission_ug2 SET status=1 WHERE regid='$id' AND userid='$userid'");
    
}

$sql="select * from tbl_userregistration_ug2 where id='$id' AND userid='$userid'";
$results=mysqli_query($conn,$sql);
$record = mysqli_fetch_assoc($results);

if($response_message=="Transaction successful")
{
    //if($record["course"]=="IA"){
        $chkTable="ia_unique_ug2";
    //} elseif($record["course"]=="ICOM"){
    //    $chkTable="icm_unique_reg";
    //} elseif($record["course"]=="ISC"){
    //    $chkTable="isc_unique_reg";
    //}
    
    $chkUniqExists= mysqli_query($conn,"SELECT * FROM ".$chkTable." WHERE user_id='$userid'");
    if(mysqli_num_rows($chkUniqExists) > 0){
        
    } else {
        mysqli_query($conn,"INSERT INTO ".$chkTable." (user_id) values ('$userid')");
    }
}
?>
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"><style type="text/css">
<!--
.style2 {
	font-size: 11px;
	font-family: cambria;
}
.style3 {font-family: cambria}
.style8 {	font-family: CAMbria;
	font-weight: bold;
	font-size: 24px;
	color: #000000;
}
.style4 {	font-family: mangal;
	font-size: 24px;
	font-weight: bold;
	color: #000000;
}
.style7 {font-weight: bold; font-family: CAMbria;}
.style9 {	font-family: CAMbria;
	font-size: 12px;
	font-weight: bold;
}

body {
	margin-top: 0px;
}
.style12 {	font-size: 13px;
	font-weight: bold;
	color: #003333;
	font-family: CAMbria;
}
.style20 {font-family: CAMbria; font-size: 13px; }
.style30 {font-family: CAMbria; font-size: 13px; }
.style30 {font-family: CAMbria; font-size: 13px; }
.style32 {font-family: CAMbria; font-size: 13px; }
.style32 {font-family: CAMbria; font-size: 13px; }
.style33 {font-size: 13px;
	font-weight: bold;
	color: #003333;
	font-family: CAMbria;
}
.style33 {	font-size: 13px;
	font-weight: bold;
	color: #003333;
	font-family: CAMbria;
}
.style34 {font-family: CAMbria; font-size: 13px; }
.style34 {font-family: CAMbria; font-size: 13px; }
.style35 {font-size: 12px;
	font-weight: bold;
	color: #003333;
	font-family: CAMbria;
}
.style35 {font-size: 12px;
	font-weight: bold;
	color: #003333;
	font-family: CAMbria;
}
.style36 {font-family: CAMbria; font-size: 12px; }
.style36 {font-family: CAMbria; font-size: 12px; }
.style37 {font-family: CAMbria; font-size: 12px; }
.style37 {font-family: CAMbria; font-size: 12px; }
.style38 {font-family: mangal}
.style38 {font-family: mangal}
.style39 {font-size: 12px;
	font-weight: bold;
	color: #003333;
	font-family: CAMbria;
}
.style39 {font-size: 12px;
	font-weight: bold;
	color: #003333;
	font-family: CAMbria;
}
.style40 {font-family: CAMbria; font-size: 13px; }
.style40 {font-family: CAMbria; font-size: 13px; }
.style41 {font-family: mangal}
.style41 {font-family: mangal}
.style43 {font-family: CAMbria; font-size: 13px; }
.style43 {font-family: CAMbria; font-size: 13px; }
.style44 {
	font-size: 14px;
	font-weight: bold;
	font-family: cambria;
	color: #FFFFFF;
}
.style45 {
	font-family: cambria;
	font-size: 12px;
}
.print_btn{
    font: bold 14px Arial;
    text-decoration: none;
    background-color: #0095ff;
    color: #fff;
    padding: 4px 6px 4px 6px;
    border-top: 1px solid #0095ff;
    border-right: 1px solid #333333;
    border-bottom: 1px solid #333333;
    border-left: 1px solid #0095ff;
}
-->
</style>
    <style type="text/css">
    <!--
        #success_message { border: 1px solid #000; width: 550px; text-align: left; padding: 10px 7px; background: #33ff33; color: #000; font-weight; bold; font-size: 1.2em; border-radius: 4px; -moz-border-radius: 4px; -webkit-border-radius: 4px; }
        fieldset { width: 90%; }
        legend { font-size: 24px; }
        .note { font-size: 18px; }
    -->
    </style>
    <style type="text/css">
        input[type=text], textarea,select
        {
            border: 1px solid #ccc;
        }
        input[type=text]:focus, textarea:focus , select:focus
        {
            background-color: #95FF95;
            border: 1px solid #ccc;
        }
    </style>

<script src="online_adm_frm.php_files/jquery-1.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>H.D.Jain College, Ara, Bhojpur,Bihar</title>
<style type="text/css">
<!--
body {
	margin-top: 0px;
	background-color: #FFF8E8;
}
.style3 {
	font-family: CAMbria;
	font-weight: bold;
	font-size: 24px;
	color: #000000;
}
.style7 {font-weight: bold; font-family: CAMbria;}
.style9 {
	font-family: CAMbria;
	font-size: 12px;
	font-weight: bold;
}
.style12 {
	font-size: 13px;
	font-weight: bold;
	color: #003333;
	font-family: CAMbria;
}
.style20 {font-family: CAMbria; font-size: 13px; }
.style24 {
	font-family: CAMbria;
	font-size: 14px;
	font-weight: bold;
	color: #FF0000;
}
.style25 {font-family: CAMbria}
.style27 {font-size: 13px}
.style29 {	font-family: mangal;
	font-size: 24px;
	font-weight: bold;
	color: #000000;
}
.style46 {
	color: #EE0000;
	font-weight: bold;
}
p.MsoNoSpacing
	{mso-style-parent:"";
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";
	margin-left:0in; margin-right:0in; margin-top:0in}
-->
</style>

<body style="background-color: #AAD5FF">

<form name="frm_admission" action="" method="post" enctype="multipart/form-data">
<div align="center">
  <input name="do" value="contact" type="hidden">

<table align="center" bgcolor="#000000" border="0" cellpadding="0" cellspacing="1" width="70%">
  <tbody><tr>
    <td bgcolor="#FFFFCC"><table bgcolor="#666666" border="0" cellpadding="0" cellspacing="1" width="100%">
      <tbody><tr>
        <td align="center" height="60" valign="top" width="100%">
		<img border="0" src="images/hd1.jpg" width="988" height="136"></td>
      </tr>
    </tbody></table></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#000000"><span class="style44">TRANSACTION DETAIL OF REGISTRATION 
	</span></td>
  </tr>
  <tr>
    <td align="center" bgcolor="#EEEEEE">
    <table style="padding-top: 10px;" bgcolor="#EEEEEE" border="0" cellpadding="0" cellspacing="0" width="98%">
      <tbody><tr>
        <td align="center"><table border="0" cellpadding="0" cellspacing="0" width="100%">
            <tbody>
            <tr>
            <td>
              <p>Hi, <strong><?php echo $record["name"]; ?></strong></p>
              <?php if($record["response_message"]=="Transaction successful" && $record["status"]==1){ ?>
              <p>You have successfully paid Rs. <?php echo $record["payable_amount"];  ?>.</p>
          	  <?php } else {
          	  	?>
          	  	<p>Your transaction is not successfully completed.</p>
          	  	<?php
          	  } ?>

            </td>              
            </tr>
              <tr>
              <td align="center" height="25" valign="top"><table border="0" cellpadding="0" cellspacing="1" width="100%">
                <tbody><tr>
                  <td colspan="2" align="left" height="20">
					<strong class="style9">TRANSACTION DETAIL OF REGISTRATION</strong> : </td>
                  </tr>
                <tr>
                  <td height="25" width="2%">&nbsp;</td>
                  <td width="98%"><table bgcolor="#000000" border="1" cellpadding="0" cellspacing="1" width="100%">
                    <tbody><tr>
                      <td class="style35" align="center" bgcolor="#FFFFFF" height="25" valign="top">
						<font size="2">TRANSACTION ID<span class="style26"></span><br>
						</font></td>
						<td class="style35" align="center" bgcolor="#FFFFFF" height="25" valign="top">
						<font size="2">PAYMENT MODE<span class="style26"></span><br>
						</font></td>
						<td class="style35" align="center" bgcolor="#FFFFFF" height="25" valign="top">
						<font size="2">PAYMENT CHANNEL<span class="style26"></span><br>
						</font></td>
						<td class="style35" align="center" bgcolor="#FFFFFF" height="25" valign="top">
						<font size="2">PAYMENT DATETIME<span class="style26"></span><br>
						</font></td>
						<td class="style35" align="center" bgcolor="#FFFFFF" height="25" valign="top">
						<font size="2">PAYMENT STATUS<span class="style26"></span><br>
						</font></td>
                    </tr>
                    <tr>
                      <td class="style33" align="center" bgcolor="#FFFFFF" height="25" valign="top">
						<font size="2">&nbsp;<?php echo $transaction_id; ?></font></td>
						<td class="style33" align="center" bgcolor="#FFFFFF" height="25" valign="top">
						<font size="2">&nbsp;<?php echo $payment_mode; ?></font></td>
						<td class="style33" align="center" bgcolor="#FFFFFF" height="25" valign="top">
						<font size="2">&nbsp;<?php echo $payment_channel; ?></font></td>
						<td class="style33" align="center" bgcolor="#FFFFFF" height="25" valign="top">
						<font size="2">&nbsp;<?php echo $payment_datetime; ?></font></td>
						<td class="style33" align="center" bgcolor="#FFFFFF" height="25" valign="top">
						<font size="2">&nbsp;<?php echo $response_message; ?></font></td>
                    </tr>

                  </tbody></table></td>
                </tr>
              </tbody></table></td>
              </tr>
          </tbody></table></td>
      </tr>      
   </tbody></table>
   </td>
  </tr>
  

  <tr>
    <td bgcolor="#EEEEEE">
	<table border="0" cellpadding="0" cellspacing="0" width="100%" height="29">
      <tbody><tr>
        <td align="center" bgcolor="#000000" height="29"><a href="receipt.php?id=<?php echo base64_encode($id); ?>" class="print_btn">Print Receipt Detail</a></td>
      </tr>
    </tbody></table></td>
  </tr>

<!--  <tr>
    <td align="center" bgcolor="#FFFFFF">&nbsp;
      <!--onclick="return CheckMe();"</td>
  </tr>-->
  </tbody></table>
  </div></form>
  
</body></html>

