<?php include("../include/config.php"); 

//send mail to Admin

$tokenx = mysqli_real_escape_string($conn, $_REQUEST['token']);
$ref= mysqli_real_escape_string($conn, $_REQUEST['ref']); 
date_default_timezone_set("America/New_York");
$date= date("Y-m-d");
$time= date("h:i");

$sele = mysqli_fetch_array(mysqli_query($conn, "SELECT username, plan, payment, amount, wallet, status FROM deposits WHERE ref = '$ref'" ));
$username = $sele[0];
$plan = $sele[1];
$payment = $sele[2];
$amount = $sele[3];
$wallet = $sele[4];
$status = $sele[5];

// $query = mysqli_query($conn, "SELECT * FROM users WHERE username = '$username'");
// 	$row = mysqli_fetch_assoc($query);
// 	$user_id = $row["id"];
	
	
// if (isset($_REQUEST['token'])) {



if ($tokenx == "76jh45"){
$status= "Successful";
$upd = "UPDATE deposits SET status='$status' WHERE ref ='$ref'";
$query= mysqli_query($conn, $upd);

$updd = "UPDATE trade_history SET status='$status' WHERE trade_id ='$ref'";
$query0= mysqli_query($conn, $updd);

$query2 = mysqli_query($conn, "SELECT * FROM users WHERE username = '$username'");
$row = mysqli_fetch_assoc($query2);
$account_deposit = $row["account_deposit"];
$account_balance = $row["account_balance"];
$email = $row["email"];
$user_id = $row["id"];

$query1 = mysqli_query($conn, "INSERT INTO transfer values('', '$user_id', '$ref', '$date', '$time', '$amount', '$status')");

$new_account_deposit = (($account_deposit*1) + ($amount));
$new_account_balance = (($account_balance*1) + ($amount));


$query3 = mysqli_query($conn, "UPDATE users SET account_balance = '$new_account_balance', account_deposit = '$new_account_deposit', last_deposit = '$amount', account_type = '$plan' WHERE id = '$user_id'");

                    
if ($query3) {

//send mail to buyer
$to = $email;

$message= '

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      <title>'.$site_name.'</title>
      <link href="'.$site_logo.'" rel="icon">
      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        
        <style>
#customers {
  font-family: Arial, Helvetica, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

#customers td, #customers th {
  border: 1px solid #ddd;
  padding: 8px;
}

#customers tr:nth-child(even){background-color: #f2f2f2;}

#customers tr:hover {background-color: #ddd;}

#customers th {
  padding-top: 12px;
  padding-bottom: 12px;
  text-align: left;
  background-color: #04AA6D;
  color: white;
}

.buttonxxx {
  background-color: #4CAF50;
  border: none;
  color: white;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 4px 2px;
  cursor: pointer;
}

.btn {
  background-color: DodgerBlue;
  border: none;
  color: white;
  padding: 12px 30px;
  cursor: pointer;
  font-size: 20px;
}

/* Darker background on mouse-over */
.btn:hover {
  background-color: RoyalBlue;
}
</style>
    </head>
    <body>
    <center> <h3 style="color:green">Investment Approved</h3> </center>
    <div>
     
      <center><img style="width:32%;height:32%;border-radius:1px;" src="'.$site_logo.'"></center>
     <br>
     
     
      <p>Dear <b>'.$username.'</b>, </p>
       
       
       
     
  <div class="container">
  <p>Your Payment made for the plan of <b>'.$plan.'</b> has been APPROVED. 
  
 <p> and your account has been credited with <b>$'.$amount.'</b>. Your total investment amount is <b>$'.$new_account_deposit.'</b></p>
      <br>
       
      <p>
       <center><b style="color:green"> We appreciate and Thank You For Your Payment!</b>
         <br>
         '.$site_url2.'<center>
      </p>
         

         
         <p style="font-size:10px;">
          <span style="font-weight:bold; font-size:10px;">Legal</span>

This email message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please delete it from your computer. '.$site_name.', does not accept responsibility for changes made to this message after it was sent. Whilst all reasonable care has been taken to avoid the transmission of viruses, it is the responsibility of the recipient to ensure that onward transmission, opening or use of this message and any attachments will not adversely affect its systems or data. No responsibility is acepted by '.$site_name.' in this regard and the recipient should carry out such virus and othr checks as it considers appropriate.


         </p>
            
          
       
    </div>
    </body>
    </html>';
          
$subject = "Payment Approved";
 // To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';

// Additional headers
$headers[] = 'From: '.$site_name.' <'.$site_email2.'>' . "\r\n";


mail($to, $subject, $message,  implode("\r\n", $headers));
    
 echo  "<h3>Payment Has Been Approved By You. Confirmation Mail has been been sent to client. $username</h3>"; 
}else {
	

$msg= "Failed To Delete";
}    


}else {
	

$msg= "Access Denied";
}       

echo $msg;

?>