<?php include('Crypto.php')?>
<?php
$ra=rand(10,1000000000);
 include('link/databaseconnection.php');
	    $date=date("Y-m-d");
        date_default_timezone_set("asia/kolkata");
        $time=date("h:i:sa");
	error_reporting(0);
	
		$workingKey='D2CDE288674EA1C8003BDDA97ACE0169';		//Working Key should be provided here.
	$encResponse=$_POST["encResp"];			//This is the response sent by the CCAvenue Server
	$rcvdString=decrypt($encResponse,$workingKey);		//Crypto Decryption used as per the specified working key.
	$order_status="";
	$decryptValues=explode('&', $rcvdString);
	$dataSize=sizeof($decryptValues);
	

	for($i = 0; $i < $dataSize; $i++) 
	{
		$information=explode('=',$decryptValues[$i]);
		if($i==3)	
			$order_status=$information[1];
	}
	$order_id='';$tracking_id='';$bank_ref_no='';
	$order_status='';$failure_message='';$payment_mode='';
	$card_name='';$status_code='';$status_message='';
	$currency='';$amount='';$billing_name='';
	$billing_address='';$billing_city='';$billing_state='';
	$billing_zip='';$billing_country='';$billing_tel='';
	$billing_email='';
	for($i = 0; $i < $dataSize; $i++) 
	{
			$information=explode('=',$decryptValues[$i]);
			if($i==0)	$order_id=$information[1];
			if($i==1)	$tracking_id=$information[1];
			if($i==2)	$bank_ref_no=$information[1];
			if($i==3)	$order_status=$information[1];
			if($i==4)	$failure_message=$information[1];
			if($i==5)	$payment_mode=$information[1];
			if($i==6)	$card_name=$information[1];
			if($i==7)	$status_code=$information[1];
			if($i==8)	$status_message=$information[1];
			if($i==9)	$currency=$information[1];
			if($i==10)	$amount=$information[1];
			if($i==11)	$billing_name=$information[1];
			if($i==12)	$billing_address=$information[1];
			if($i==13)	$billing_city=$information[1];
			if($i==14)	$billing_state=$information[1];
			if($i==15)	$billing_zip=$information[1];
			if($i==16)	$billing_country=$information[1];
			if($i==17)	$billing_tel=$information[1];
			if($i==18)	$billing_email=$information[1];
			
	}
$session='2022-2023';
	$sel="select * from payment_fees where order_id='$order_id' order by id desc";
	$res=mysqli_query($conn,$sel);
	if($row=mysqli_fetch_array($res,MYSQLI_BOTH))
	{
		$mob=$row['billing_tel'];
		$am=$row['amount'];
		$form_id=$row['form_id'];
		$up="update payment_fees set tracking_id='$tracking_id',bank_ref_no='$bank_ref_no',order_status='$order_status',payment_mode='$payment_mode',card_name='$card_name',status_code='$status_code' ,status_message='$status_message',currency='$currency',amount='$amount',date='$date',time='$time' where order_id='$order_id'";
		if(mysqli_query($conn,$up))
		{
			if($order_status=='Success')
			{
				
					$sel10="select * from registration2 where id='$form_id' order by id desc";
            	    $res10=mysqli_query($conn,$sel10);
	
                	$row10=mysqli_fetch_array($res10,MYSQLI_BOTH);
                	$class=$row10['class'];
                	$t=$row10['name'];
                	 $to = $billing_email;
         $subject = "SGNGOVT.  FEES ";
         
          $message = '<!DOCTYPE html>
 <html>
       <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       </head>

  <body style="margin:0px; padding:0px; background:#f7f7f7;">
  <div style="display:block; margin:auto; width:750px;background:#2C3E50; border-bottom: solid 2px #2C3E50;">
  <div style="display:block; width:750px; margin:auto;">
  <span style="color:#fff;padding:5px 10px;display:block;font-size:15px;">From: SGN. GOVT. P.G. COLLEGE </span>
  </div>

  </div>
  <div style="width:750px; margin: auto; background:#fff; min-height: 100px;">
  <div style="text-align: left;display: block;width: 500px;padding: 50px; padding-bottom:30px;font-size: 15px;color: #666; margin:auto;">
  <div style="color:inherit;display:block;width:100%;margin:10px 0;line-height:24px;font-size:13px;color:#333;font-weight:bold;text-transform: capitalize;">Hi,  '.$t. '</div>
  <div style="color:inherit;display:block;width:100%;margin:10px 0;line-height:24px;font-size:13px;color:#333;font-weight:bold">Form No.  :,&emsp; '.$form_id.'</div>
  <div style="color:inherit;display:block;width:100%;margin:10px 0;line-height:24px;font-size:13px;color:#333;font-weight:bold">Amount  : &emsp;'.$am.' </div>
  <div style="color:inherit;display:block;width:100%;margin:10px 0;line-height:24px"><span style="color:#111;font-weight:800;display:block;font-size:15px;"><span style="background-color:;color:black">आपका  एडमिशन  शुल्क  कॉलेज में जमा हो गया  है ,  फॉर्म  प्रिंट  करके  उसके साथ सभी  डॉक्यूमेंट का फोटोकॉपी जमा करें  |</span>
  </div>
  <div style="color:inherit;display:block;width:100%;margin:10px 0;line-height:24px">Thank you for visiting us..
  </div>
  </div>
  <div style="border-top:solid 1px #ddd; text-align:left;font-size:14px;color:#888;padding-top:5px;padding-bottom:2px;padding-left:10px;">&copy; sgngovtcollegemau.org</div>
  </div>
  </body>
  </html>';

         
         
         $header = "From:support@sgngovtcollegemau.org \r\n";
         $header .= "Cc: \r\n";
         $header .= "MIME-Version: 1.0\r\n";
         $header .= "Content-type: text/html\r\n";
         
         $retval = mail ($to,$subject,$message,$header);
                	 	echo "<script>alert('Your  Fees Successfully Paid ,Please Again Login');window.location.href='adm_process.php';</script>";
                	
                
			
			}
			else
			{
			      $to = $billing_email;
         $subject = "SGNGOVT.  FEES FAILED";
         
         
         $message .= 'Dear Student  ......'. $billing_name.   ' ......Your Admission Fees...'. $am.   'Rs.....  has Failed Please Re-paid Fees OR Contact College .  For any Query Contact 9457814757 Your Payment Order id ...'. $order_id.'..& .. Payment Status..'.$order_status ;
         
         $header = "From:support@sgngovtcollegemau.org \r\n";
         $header .= "Cc: \r\n";
         $header .= "MIME-Version: 1.0\r\n";
         $header .= "Content-type: text/html\r\n";
         
         $retval = mail ($to,$subject,$message,$header);
         
				echo "<script>alert('Your  Fees  Failed');window.location.href='slip.php?flag=$order_id';</script>";
			}
			
		}
	}
	else
	{
		$up="update payment_fees set tracking_id='$tracking_id',bank_ref_no='$bank_ref_no',order_status='$order_status',payment_mode='$payment_mode',card_name='$card_name',status_code='$status_code' ,status_message='$status_message',currency='$currency',amount='$amount',date='$date',time='$time' where order_id='$order_id'";
		if(mysqli_query($conn,$up))
		{
			echo "<script>alert('Your Registration Fees  Failed Please Try Again');window.location.href='adm_process.php';</script>";
		}
	}
	


	

	
		
	
?>
