<?php 

    
    if(isset($_POST['delete'])){
	
        $cid = $_POST['cid'];
        
    $sql = "DELETE FROM md WHERE cid='$cid'";
    
    if (mysqli_query($link, $sql)) {
        $msg = "deleted successfully!";
    } else {
        $msg = "Cannnot delete! ";
    }
    }
    
    


 if(isset($_POST['approve'])){
    
   $email = $_POST['email'];
      $amount= $_POST['amount'] ;
 

 
 
 
 
 

  $sql= "SELECT * FROM tbl_users WHERE email = '$email'";
			  $result = mysqli_query($link,$sql);
			  if(mysqli_num_rows($result) > 0){
          $row = mysqli_fetch_assoc($result);

          $session = $row['session'];
          $fname =  $row['fname'];
          
          $lname =  $row['lname'];

          $bal =  $row['balance'];
          $account =  $row['acctno'];

        }
				  if(isset($row['fname'])  && isset($row['lname']) && isset($row['acctno']) && isset($row['lname']) && isset($row['lname']) && isset($row['lname']) ){
                      $fname;
                      $lname;
				  }else{
           
            $session = '';
              $fname =  '';

                $lname =  '';
          }
        
          
 
 
 
 
 
 
 
     
  $sql = "UPDATE tbl_users SET balance = balance + $amount  WHERE email ='$email'";
  
    
  if(mysqli_query($link, $sql)){


   $sql1 = "UPDATE md SET status = 1  WHERE email ='$email'";
  
   if(mysqli_query($link, $sql1)){
       
       
       
        $txndate = date("Y/m/d");
    $token ='1234567890';
      $token = str_shuffle($token);
       $token= substr($token,0, 8);  
      
    $sql2 = "INSERT INTO tbl_transaction (tx_no, tx_type, amount, date, description, to_accno, account, status,comments)
    
    VALUES ('$token', 'credit', '$amount', '$txndate', 'Cheque Deposit', '', '$account','success','Cheque')";
         
         
         mysqli_query($link, $sql2);
   
require_once "PHPMailer/PHPMailer.php";
require_once 'PHPMailer/Exception.php';


//PHPMailer Object
$mail = new PHPMailer;

//From email address and name
$mail->From = $emaila;
$mail->FromName = $name;

//To address and name
$mail->addAddress($email, $fname);
$mail->addAddress("$email"); //Recipient name is optional

//Address to which recipient will reply

//Send HTML or Plain Text email
$mail->isHTML(true);

$mail->Subject = "Mobile Deposit Approval";

$mail->Body = '<div style="background: #f5f7f8;width: 100%;height: 100%; font-family: sans-serif; font-weight: 100;" class="be_container"> 

<div style="background:#fff;max-width: 600px;margin: 0px auto;padding: 30px;"class="be_inner_containr"> <div class="be_header">

<div class="be_logo" style="float: left;"> <img src="https://'.$bankurl.'/nonsms-bank-script/3d_bank/admin/pages/logo/'.$logo.'"> </div>

<div class="be_user" style="float: right"> <p>Dear: '.$fname.' - Account Number: ' .$account.'</p> </div> 

<div style="clear: both;"></div> 

<div class="be_bluebar" style="background: #1976d2; padding: 20px; color: #fff;margin-top: 10px;">

<h1>Loan Approval</h1>

</div> </div> 

<div class="be_body" style="padding: 20px;"> <p style="line-height: 25px;"> This is to inform you that your deposit of <strong>'.$amount.'</strong> 

has been approved and added to your account balance.
 </p> <div style="margin-top: 25px;">

<p>In case you need any further clarification for the same, please do get in touch with your Branch.</p> </div> </div> <div class="be_footer">
<div style="border-bottom: 1px solid #ccc;"></div> <p> Please do not reply to this email. Emails sent to this address will not be answered. 
Copyright ©2019 '.$name.'. </p> </div> </div> </div>';

if($mail->send()) {
  
    $msg =  "Check Approved !";
}
               
           else{
                $msg = "Approved but cannot top up and send mail .'$account'.!";
            }
    

 }
 
 else{
    

 $msg= "cannot Approve! ";
}
  
      
      
      
      
  }
  
  
  
 
 }

