<?php
include("connect.php"); 
$response = array();
if(isset($_POST['admin_id']))
{
	$ver = $_POST['admin_id'];
	date_default_timezone_set('Asia/Calcutta');
    $scro = date("h:i:sa");
    $da  = date("Y-m-d");
    $scri =$da.' '.$scro;
	
	
	$month=$_POST["month"];
	$amount=$_POST["amount"];
	$txnid=$_POST["razorpay_payment_id"];
	$payment_plan=$_POST["payment_plan"];
	$payment_type=$_POST["payment_type"];
	
	$host= gethostname();
	$ip = gethostbyname($host);
	$mac_id=$ip;
	$time = microtime();
	$t = substr($time,-4);
	$abtxid ="BTTX".$ver."U".$t;
	
		$insert_transaction=mysqli_query($con,"INSERT INTO tbl_bt_transaction(bt_txn_id,transaction_date,transaction_time,admin_id,transaction_id,transaction_amount,txn_status,txn_type,plan_type,month,payment_mode)VALUES('$abtxid','$da','$scro','$ver','$txnid','$amount','Failure', 'Renew','$payment_plan','$month','$payment_type')");
	
	$fetchwpq=mysqli_query($con,"SELECT  * from tbl_admin_panel WHERE admin_id='$ver'");
    if($fetchwpq)
	{
		while($fetchrow=mysqli_fetch_assoc($fetchwpq))
		{
			extract($fetchrow);
			$flag=0;
			$uname=ucwords($admin_name);
			$email=$admin_email;
			$phoneuser=$admin_phone;
			$regtime=$next_renew_date;
			$date = strtotime($registration_datetime);
			$h=date('h', $date);
			date_default_timezone_set('Asia/Calcutta');
			$scro = date("h:i:sa");
			$da  = date("Y-m-d");
			$scri =$da.' '.$scro;
			$amount=$_POST["amount"];     
			$id=$admin_id;
	        include("sendmail-failure-renew.php");
			require '../../bthawk/PHPMailer-master/PHPMailerAutoload.php';
            $d_link="https://www.bthawk.appexperts.net/";
            $prod_name="BTC";
            $sendmail=new SendMail();
			$res = $sendmail->sendMailUser($email,$uname,$prod_name,$scri,$d_link,$amount,$phoneuser,$id,$payment_type);
			   $adminmail="btcover@appexperts.net";
			   
			$sd_link="https://www.bthawk.appexperts.net/";
                
            $sendmailadmin=new SendMail();
			$result_admin=$sendmailadmin->sendmailAdmin($adminmail,$email,$uname,$prod_name,$scri,$d_link,$phoneuser,$id,$payment_type);
			  
		} 
	}
	if($res==1 and $result_admin==1)
	{
		$response['success']='1';
		$response['message']="Mail send successfully";
	}
	else
	{
		$response['success']='0';
		$response['message']="Mail not send";
	}
}
else
{
	$response['success']='0';
	$response['details']="Required field missing";
}	
echo json_encode($response);

?>