<?php

include("includes/header.php"); 
include("includes/sidebar.php"); 

$currency = "NGN";

$details = $db_handle->runBaseQuery("SELECT * FROM bank_details");
 $msg =  "";

if(isset($_POST['fund'])){
    if (!isset($_POST['csrf_token']) || !$csrf->validateToken($_POST['csrf_token'])) {
        die("CSRF token validation failed!");
    }
    $amount = $db_handle->sanitize($_POST['amount']);
   
    
}

if(isset($_POST['upload'])){
    
    if (!isset($_POST['csrf_token']) || !$csrf->validateToken($_POST['csrf_token'])) {
        die("CSRF token validation failed!");
    }
$proof = $_FILES['file']['name'];


$mode = "BANK TRANSFER";

    $folder = "../proofs/".$proof;
    $temp = $_FILES['file']['tmp_name'];
   
    $date = date("Y-m-d h:i:sa");
    $amount = $db_handle->sanitize($_POST['amount']);
    
    $status = 0;
   
    if (move_uploaded_file($temp, $folder)){

    
    $insert = $db_handle->insertRecord("insert into account_funding(userID,amount,proof,date,status) VALUES(?,?,?,?,?)","iissi",array($id,$amount,$proof,$date,$status));

    if($insert){
        
        $email_message = '<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Deposit Confirmation - Ovoh Initiative</title>
  <style>
    body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      background-color: #f9f9f9;
      margin: 0;
      padding: 0;
    }
    .container {
      max-width: 600px;
      margin: 20px auto;
      background: #ffffff;
      padding: 20px;
      border-radius: 6px;
      border: 1px solid #e0e0e0;
      color: #333333;
    }
    .logo {
      text-align: center;
      margin-bottom: 15px;
    }
    .logo img {
      max-width: 180px;
      height: auto;
    }
    h2 {
      color: #2c3e50;
      text-align: center;
    }
    p {
      line-height: 1.5;
    }
    .details {
      background: #f4f4f4;
      padding: 10px;
      border-radius: 4px;
      margin: 15px 0;
      font-size: 14px;
    }
    .footer {
      font-size: 12px;
      color: #999999;
      text-align: center;
      margin-top: 20px;
    }
  </style>
</head>
<body>
  <div class="container">
    <div class="logo">
      <img src="https://app.ovohinitiative.com//asset/images/logo.png" alt="Ovoh Initiative Logo">
    </div>
    <h2>Savings Request Received</h2>
    <p>Hi '.$fname." ".$surname.',</p>
    <p>We are pleased to inform that your deposit request has been successfully received and your account will be credited immediately we verify your deposit.</p>
    
    <div class="details">
      <p><strong>Amount:</strong> ₦'.number_format($amount).'</p>
      <p><strong>Date:</strong> '.$date.'</p>
      
    </div>

    <p>You can view your updated balance and transaction history by logging into your dashboard:</p>
    <p><a href="https://app.ovohinitiative.com/user/dashboard" style="color: #2c3e50;">https://app.ovohinitiative.com/user/dashboard</a></p>

    <p>If you did not authorize this transaction or if you have any questions, please contact our support team immediately:</p>
    <p>Email: <a href="mailto:support@ovohinitiative.com">support@ovohinitiative.com</a></p>

    <div class="footer">
      <p>This is an automated message. Please do not reply directly to this email.</p>
      <p>Ovoh Initiative | Warri, Delta State, Nigeria.</p>
    </div>
  </div>
</body>
</html>
';

$subject = "Deposit Request Received";

//$db_handle->send_mail($email,$email_message,$subject);
        
        
     $msg =  "<div class='alert alert-danger mx-auto'>
    
    <strong>Payment proof uploaded successfully. You will be notified after deposit has been confirmed.</strong>
  </div>";
}
}

}
 ?>
 <style>
#alertcb {
display: none;
  background: #4ade80;
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  margin-left: 8px;
  font-size: 0.9rem;
  animation: fadeInOut 1.5s ease;
}

@keyframes fadeInOut {
  0% { opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { opacity: 0; }
}
</style>
 
 <div class="main-content app-content">
<div class="container">
                            
                            <!--Modal: order-modal-->
                           
                                <h5 class="text-uppercase">
    </h5>
    <div class="row settings mt-3">
       
       
        <div class="col-xl-12">
            <div id="settingmenuContent">
                
                                <div id="editprofile">
                    <div class="row mb-5">
                        <div class="col-12">
                            <div class="card border-0 box-shadow">
                                <div class="card-body pb-0">
                                    <div class="d-flex align-items-center mb-3">
                                        <h5 class="text-uppercase">Make Payment</h5>
                                    </div>
                                    
                                     <?php echo $msg; ?>
                                     
                                    <p id="alertcb"></p>
                                    <p>Please make the payment of <b>NGN<?php echo number_format($amount); ?> </b>to any of the account details below.  Always verify and confirm you copied the account number correctly.</p>
                                   
                                    <?php
                                    if($details){
                                        $i = 1;
                                    foreach($details as $detail){
                                       
                                        echo '<div>
                                        <h5>BANK NAME: '.$detail['bank_name'].'</h5>
                                    <p>ACCOUNT NUMBER: <span id="acc_no'.$i.'">'.$detail['acc_no'].'</span> <span><i class="ri-file-copy-line" style="font-size: 24px" onclick="copyToClipboard(\'#acc_no'.$i.'\');cpb()"></i></span></p>
                                    <p>ACCOUNT NAME: '.$detail['acc_name'].'</p>
                                   
                                    </div>';
                                    $i++;
                                    }
                                    }
                                    
                                    ?>
                                    
                        
                                </div>
                            </div>
                        </div>
                        
                        
                        
                        
                         <div class="col-12">
                            <div class="card border-0 box-shadow">
                                <div class="card-body pb-0">
                                    <div class="d-flex align-items-center mb-3">
                                        <h5 class="text-uppercase">Upload Payment Proof after payment.</h5>
                                    </div>
                                    
                                    
                        <form method="POST" action="" enctype="multipart/form-data">
                                         <?php echo $csrf->csrfInput(); ?>  
                                         
                                         
                                        
                                         
                                         <div class="row">
                                            <div class="form-group col-sm-12">
                                                <label class="form-label">Amount<span
                                                        class="text-danger"> * </span></label>
                                                <input type="number" class="form-control" name="amount" id="amount"
                                                    value="<?php echo $amount; ?>"
                                                    placeholder="Amount" required>

                                            </div>
                                            
                                            <div class="form-group col-sm-12">
                                                <label class="form-label">Screenshot/Proof Of Payment<span
                                                        class="text-danger"> * </span></label>
                                                <input type="file" class="form-control" name="file" id="proof"
                                                    value=""
                                                    placeholder="" required>

                                            </div>
                                                                                        
                                                
                                                                                        <div class="form-group text-end">
                                                                                            <br>
                                                <button
                                                    class="btn btn-red modern-btn"
                                                     type="submit" name="upload"  >Upload</button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        
                        
                        
                    </div>
                </div>
                

                          
                    </div>
                  
                               

            </div>
        </div>
    </div>
    
    
                        </div>
                    </div>
                </div>
  <?php

include("includes/footer.php"); 

?>

 <script type="text/javascript">function copyToClipboard(element) {
                var $temp = $("<input>");
                $("body").append($temp);
                $temp.val($(element).text()).select();
                document.execCommand("copy");
                $temp.remove();
            }

            function cpb() {
                document.getElementById('alertcb').innerHTML= "Account Number Copied Successfully!!!";
                document.getElementById('alertcb').style.display = "inline-block";
                var stime = setTimeout(alertf, 1300);
                function alertf() {
                    //document.getElementById('alertcb').innerHTML= ""; 
                     document.getElementById('alertcb').style.display = "none";
                }  
            }
            
            </script>


 
 