<?php
@session_start();
include "control/activity.php";

 $dd = new activity();
 $loginStatus = $_SESSION['loginDetails'];


  if($loginStatus == null){
    echo "<script>window.open('login.php','_self')</script>";
  }



  $table = "admin_calculation";
  $condition = null;
  $getAdminDetails = $dd->single($table,$condition);
  
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title><?= $getAdminDetails['title']; ?> </title>
</head>
<body>

    <div class="main" id="main">
		  <?php include "menu.php"; ?>
    <div class="right"> 
  <div class="tab-content">


   <?php include "headermenu.php"; ?>


        <!-- Overview -->
         <div id="overview" class="tab-pane active"  >
                <div class="content" >
                  
               <div class="content-wrapper">
                 <div class="container-fluid">

                      <!--======================================================  Content  ====================================================-->                                            
                          <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                              <a href="dashboard.php">Funds Transfer..!!</a>
                            </li>
                          </ol>

                          <div class="row">
                              <div class="col-xl-4 col-sm-4 mb-4">
                                 <table class="table table-bordered">
                                    <form method="post">
                                    <tr>
                                        <th>Mobile Number : <input name="email" id="emailId" onkeyup="getSponcerData()" class="form-control"/></th>
                                    </tr>
                                    <tr>
                                        <th>Join Date : <input id="memname" disabled class="form-control"/></th>
                                    </tr>
                                    <tr>
                                        <th>Transfer Amount : <input name="amount" class="form-control"/></th>
                                    </tr>
                                    <tr>
                                        <th>Confirm Amount : <input name="camount" class="form-control"/></th>
                                    </tr>
                                    <tr>
                                        <th>Remark : <input name="remark" class="form-control" /></th>
                                    </tr>
                                    <tr>
                                        <td><button id="buttonData" name="transferNow" class="btn btn-success fa fa-transfer">TRANSFER FUNDS</button></td>
                                    </tr>
                                    </form>
                                 </table>
                              </div>
                          </div>
  
                           
      <!--============  FIN DE L'AJOUT  ===============-->
      
      
      
     
      </div>
      <!-- /.container-fluid-->
       </div>  <!-- /content-wrapper-->


                </div>
                </div>
             </div><!--Right panel-->
</div><!--Main-->


</body>
</html>

<script>
    document.getElementById("buttonData").disabled = true;
    function getSponcerData()
    {
        var sponserEmail = document.getElementById('emailId').value;
        if(sponserEmail.length >= 3){
        const xhttp = new XMLHttpRequest();
        xhttp.onload = function() {
            var demo_show = this.responseText;
            const exData = JSON.parse(demo_show);
            if(exData.status == 'success'){
                var name = exData.name;
                document.getElementById("buttonData").disabled = false;
                document.getElementById('memname').value = name;
            }
            else{
                document.getElementById("buttonData").disabled = true;
            }
            
        }
        xhttp.open("GET", "getmemberDetails.php?sponcer="+sponserEmail);
        xhttp.send(); 
      }
    }
</script>



<?php include "style.php" ?>

<?php
 if(isset($_POST['transferNow']))
 {
    $email = $_REQUEST['email'];
    $amount = $_REQUEST['amount'];
    $camount = $_REQUEST['camount'];
    $remark = $_REQUEST['remark'];

    if($amount == $camount){
        $table = "userdetails";
        $value = "wallet=wallet+$amount";
        $condition = " mobile='$email'";
        $result = $dd->updateData($table,$value,$condition);
        if($result){
            $date = date("H:i d/m/Y");
            $txnNumber = date("hisdmY").mt_rand(11,99);
            $table = "funds_request";
            $value = "(`userKey_id`, `request_date`, `request_type`, `amount`, `refrence_number`, `funds_status`,`avl_balance`,`remark`) 
            SELECT userKey,'$date','INR','$amount','$txnNumber','success',wallet,'$remark' FROM userdetails WHERE mobile='$email'";
            $result = $dd->insertData($table,$value);
            if($result){
                echo "<script>alert('Transfer successfull..!!'),window.open('?','_self')</script>";
            }
        }
    }
    else{
      echo "<script>alert('Sorry Confirm amount not match..!!')</script>";
    }


 }

?>