<?php
    session_start();
    if( !isset($_SESSION['chap']) ){
        header("Location:../index.html#login-area");
        exit();
    }
    else{
        $chap = $_SESSION['chap'];
        include "../connect/db.php";
        $sql = mysqli_query($mysqli,"SELECT * FROM users WHERE email = '$chap' ");
        $row = mysqli_fetch_assoc($sql);
        if( $row['status'] == "suspended" ){header("Location:account.php"); exit();}
        else if( $row['status'] == "terminated" ){header("Location:terminate.php"); exit();}
    }




       if($row['kyc_status'] == "pending" || $row['kyc_status'] == "review" )


{
   header("Location:kyc.php");
   exit();


}
    if($row['code_level'] != "nothing"){

if($row['lock_status'] == "active" )


{
   header("Location:auth.php");
   exit();


}
else{
    
}



}
else{
    
}



?>
<!DOCTYPE html>
<html lang="en-US" class="js">
  <head>
    <meta charset="utf-8" />
    <meta name="author" content="Smart" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <meta
      name="description"
      content="Aspire Securities is a trademark of Aspire Financial Corporation. Aspire Securities is a trade name for the corporate and investment banking services of Aspire Financial Corporation and its subsidiaries. All rights reserved. Securities and strategic advisory services are provided by Aspire Securities, Inc., member FINRA, link opens in new tab and SIPC, link opens in new tab. Lending, financial risk management, and treasury management and payment services are offered by Aspire Bank. Deposit products are offered by Aspire Bank." />
    <!-- Fav Icon  -->
    <link rel="shortcut icon" href="../images/favicon.png" />
    <!-- Page Title  -->
    <title><?=$row['firstname']?> <?=$row['middlename']?> <?=$row['lastname']?> | <?= htmlspecialchars(getSetting('site_name', 'Deutsche Bank Holdings Delaware')) ?> Online banking</title>
    <!-- StyleSheets  -->
    <link rel="stylesheet" href="../scss/sweetalert.css" />
    <link rel="stylesheet" href="assets/css/dashlite.css?ver=2.4.0" />
    <link
      id="skin-default"
      rel="stylesheet"
      href="assets/css/theme.css?ver=2.4.0" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
    <link href="../css/toastr.css" rel="stylesheet" />
  </head>
  <link
    rel="stylesheet"
    href="https://www.jqueryscript.net/demo/jQuery-International-Telephone-Input-With-Flags-Dial-Codes/build/css/intlTelInput.css" />
  <script type="text/javascript">
    function googleTranslateElementInit() {
      new google.translate.TranslateElement(
        {
          pageLanguage: "en",
          layout: google.translate.TranslateElement.InlineLayout.SIMPLE,
        },
        "google_translate_element"
      );
    }
  </script>
  <script
    type="text/javascript"
    src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
  <style>
    .goog-te-gadget-simple {
      border: none;
    }
    .goog-te-gadget-simple a {
      color: #000;
    }
  </style>
  <body class="nk-body npc-crypto bg-white has-sidebar">
    <div class="nk-app-root">
      <!-- main @s -->
      <div class="nk-main">
        <!-- sidebar @s -->
        <div class="nk-sidebar nk-sidebar-fixed" data-content="sidebarMenu">
          <div
            class="nk-sidebar-element nk-sidebar-head"
            style="border-bottom: solid #fe473a">
            <div class="nk-sidebar-brand">
              <a href="dashboard" class="logo-link nk-sidebar-logo">
                <img
                  class="logo-light logo-img"
                  src="../logo.png"
                  srcset="../logo.png 2x"
                  alt="logo" />
                <img
                  class="logo-dark logo-img"
                  src="../logo.png"
                  srcset="../logo.png 2x"
                  alt="logo-dark" />
              </a>
            </div>
            <div class="nk-menu-trigger mr-n2">
              <a
                href="#"
                class="nk-nav-toggle nk-quick-nav-icon d-xl-none"
                data-target="sidebarMenu"
                ><em class="icon ni ni-arrow-left"></em
              ></a>
            </div>
          </div>
          <!-- .nk-sidebar-element -->











          <?php include 'includes/sidebar.php';  ?>













          <div class="nk-content nk-content-fluid">
            <div class="container-xl wide-lg">
              <div class="nk-content-body">
                <div class="nk-block-head">
                  <div class="nk-block-between-md g-4 card-bordered">
                    <div class="nk-block-head-content">
                      <h4 class="nk-block-title">Transfer Funds</h4>
                      <p class="nk-block-des">Send money to another account.</p>
                    </div>
                    <div class="nk-block-head-content">
                      <ul class="nk-block-tools gx-3">
                        <li>
                          <a href="wire?transaction_session=04f99e51b0bd92959a9f5f5935504b8690f661446488ed57408457cbf52904e7" class="btn btn-outline-primary"><span>Cross-border transfer</span><em class="icon ni ni-wallet-out"></em></a>
                        </li>
                      </ul>
                    </div>
                  </div>
                </div>

                <?php if (!empty($row['transfer_limit']) && $row['transfer_limit'] == 1): ?>
                <!-- Transfer Limited Modal -->
                <div class="modal fade show" id="limitModal" tabindex="-1" style="display:block;background:rgba(0,0,0,0.5);" aria-modal="true">
                  <div class="modal-dialog modal-dialog-centered">
                    <div class="modal-content text-center p-4">
                      <div style="font-size:3rem;color:#f4bd0e;margin-bottom:16px;"><em class="icon ni ni-alert-fill"></em></div>
                      <h5 class="mb-3">Transfer Restricted</h5>
                      <p class="sub-text mb-3"><?= htmlspecialchars($row['limit_message'] ?: 'Your account has a transfer restriction. Please contact customer care for assistance.') ?></p>
                      <div>
                        <a href="contact" class="btn btn-primary">Contact Support</a>
                        <a href="dashboard" class="btn btn-outline-primary ml-2">Back to Dashboard</a>
                      </div>
                    </div>
                  </div>
                </div>
                <script>document.body.style.overflow='hidden';</script>
                <?php else: ?>
                <div class="buysell wide-xs m-auto">
                  <div class="buysell-title text-center">
                    <h5 class="title"><?= htmlspecialchars(getSetting('site_name', 'Deutsche Bank Holdings Delaware')) ?> Online Banking Transfer</h5>
                  </div>
                    <!-- .buysell-title -->
                    <div class="buysell-block">
                      <form action="#" method="post" class="buysell-form"><?= csrf_field() ?>
                       <div class="buysell-field form-group">
    <div class="form-label-group">
        <label class="form-label">Select Account</label>
    </div>
    <input type="hidden" value="checking" name="bs-currency" id="buysell-choose-currency" />

    <div class="dropdown buysell-cc-dropdown">
        <!-- Chosen Indicator -->
        <a href="#" class="buysell-cc-choosen dropdown-indicator" data-toggle="dropdown">
            <div class="coin-item" id="chosen-account">
                <div class="coin-icon">
                    <em class="icon ni ni-wallet"></em>
                </div>
                <div class="coin-info">
                    <span class="coin-name">Checking Account (<?=currencySymbol($row['usercurrency'])?>)</span>
                    <span class="coin-text">Available Balance: <?=formatCurrency($row['checking_balance'], $row['usercurrency'])?></span>
                </div>
            </div>
        </a>

        <!-- Dropdown Menu -->
        <div class="dropdown-menu dropdown-menu-auto dropdown-menu-mxh">
            <ul class="buysell-cc-list">
                <!-- Checking Account -->
                <li class="buysell-cc-item selected">
                    <a href="#" class="buysell-cc-opt" data-currency="checking"
                       data-name="Checking Account (<?=$row['usercurrency']?>)" 
                       data-balance="<?=$row['usercurrency']?> <?=number_format($row['checking_balance'],2)?>" 
                       data-icon="ni ni-wallet">
                        <div class="coin-item coin-checking">
                            <div class="coin-icon">
                                <em class="icon ni ni-wallet"></em>
                            </div>
                            <div class="coin-info">
                                <span class="coin-name">Checking Account (<?=currencySymbol($row['usercurrency'])?>)</span>
                                <span class="coin-text">Available Balance: <?=formatCurrency($row['checking_balance'], $row['usercurrency'])?></span>
                            </div>
                        </div>
                    </a>
                </li>

                <!-- BSL Balance Account -->
                <li class="buysell-cc-item">
                    <a href="#" class="buysell-cc-opt" data-currency="bsl"
                       data-name="BSL Balance (<?=$row['usercurrency']?>)" 
                       data-balance="<?=$row['usercurrency']?> <?=number_format($row['bsl_balance'],2)?>" 
                       data-icon="ni ni-wallet">
                        <div class="coin-item coin-bsl">
                            <div class="coin-icon">
                                <em class="icon ni ni-wallet"></em>
                            </div>
                            <div class="coin-info">
                                <span class="coin-name">BSL Balance (<?=currencySymbol($row['usercurrency'])?>)</span>
                                <span class="coin-text">Available Balance: <?=formatCurrency($row['bsl_balance'], $row['usercurrency'])?></span>
                            </div>
                        </div>
                    </a>
                </li>
            </ul>
        </div> <!-- .dropdown-menu -->
    </div> <!-- .dropdown -->
</div>

<script>
document.querySelectorAll(".buysell-cc-opt").forEach(opt => {
    opt.addEventListener("click", function(e) {
        e.preventDefault();

        // Remove selected from all items
        document.querySelectorAll(".buysell-cc-item").forEach(item => {
            item.classList.remove("selected");
        });

        // Add selected to clicked item
        this.closest(".buysell-cc-item").classList.add("selected");

        // Update hidden input
        let selectedCurrency = this.getAttribute("data-currency");
        document.getElementById("buysell-choose-currency").value = selectedCurrency;
        console.log(selectedCurrency);

        // Update chosen indicator
        let chosen = document.getElementById("chosen-account");
        let name = this.getAttribute("data-name");
        let balance = this.getAttribute("data-balance");
        let icon = this.getAttribute("data-icon");

        chosen.innerHTML = `
            <div class="coin-icon">
                <em class="icon ${icon}"></em>
            </div>
            <div class="coin-info">
                <span class="coin-name">${name}</span>
                <span class="coin-text">Available Balance: ${balance}</span>
            </div>
        `;
    });
});
</script>

                        <!-- .buysell-field -->
                        <div class="buysell-field form-group">
                          <div class="result"></div>
                          <div class="form-label-group">
                            <label class="form-label" for="buysell-amount"
                              >Amount to Transfer</label
                            >
                          </div>
                          <div class="form-control-group">
                            <input
                              type="number"
                              class="form-control form-control-lg form-control-number"
                              id="amount"
                              name="amount"
                              placeholder="2000" />
                            <div class="form-dropdown">
                              <div class="text"><?=currencySymbol($row['usercurrency'])?><span></span></div>
                            </div>
                          </div>
                          <div class="form-note-group">
                            <span class="buysell-min form-note-alt"
                              >Minimum: 5.00 <?=currencySymbol($row['usercurrency'])?></span
                            >
                            <span class="buysell-rate form-note-alt"
                              >1 <?=currencySymbol($row['usercurrency'])?> = 1 <?=currencySymbol($row['usercurrency'])?></span
                            >
                          </div>
                        </div>
                        <!-- .buysell-field -->
                        <div class="buysell-field form-group"></div>
                        <!-- .buysell-field -->
                        <div class="buysell-field form-action">
                          <button
                            type="submit"
                            class="btn btn-lg btn-block btn-primary stepOnenew"
                            id="btn1">
                            Continue to next step
                          </button>
                        </div>
                        <!-- .buysell-field -->
                        <div class="form-note text-base text-center">
                          Note: our transfer fee is included.
                        </div>
                      </form>
                      <script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script>
                    <script>
                      $(document).ready(function () {
    $('.stepOnenew').click(function (e) {


      Swal.showLoading();

        // Disable the button to prevent multiple clicks

        // Prevent the default form submission
        e.preventDefault();

        // Get the amount value
        var amount = $('#amount').val();

        selectedCurrency = document.getElementById("buysell-choose-currency").value ;




        if (amount < 5 ){
          Swal.fire({
                        icon: 'info',
                        title: 'Notice',
                        text: 'You can only transfer minimum of 5<?=$row['usercurrency']?>',
                        showConfirmButton: false,
                        timer: 2000
                    });
                    return;
        }
        else  if (amount > <?=$row['checking_balance']?> ){
          Swal.fire({
                        icon: 'info',
                        title: 'Notice',
                        text: 'Insufficient Funds',
                        showConfirmButton: false,
                        timer: 2000
                    });
                    return;
        }

        // Re-enable the button after handling the logic
        setTimeout(function() {
            document.getElementById("btn1").disabled = false;
            // Redirect after 3.2 seconds
            window.location = "transfer-page.php?amount=" + amount+"&account="+selectedCurrency;
        }, 3200);
    });
});
</script>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <?php endif; ?>

          <div class="nk-footer nk-footer-fluid">
            <div class="container-fluid">
              <div class="nk-footer-wrap">
                <div class="nk-footer-copyright">
                  &copy; <?php
echo date("Y");
?>  <?= htmlspecialchars(getSetting('site_name', 'Deutsche Bank Holdings Delaware')) ?>
                  <a href="#">All rights reserved.</a>
                </div>
                <div class="nk-footer-links">
                  <ul class="nav nav-sm">
                    <li class="nav-item">
                      <a class="nav-link" href="#">Terms</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" href="privacy">Privacy</a>
                    </li>
                    <li class="nav-item">
                      <a class="nav-link" href="contact">Help</a>
                    </li>
                  </ul>
                </div>
              </div>
            </div>
          </div>
          <!-- footer @e -->
        </div>
        <!-- wrap @e -->
      </div>
      <!-- main @e -->
    </div>
    <!-- app-root @e -->
    <!-- JavaScript -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="../js/country.js"></script>
    <script src="assets/js/bundle.js?ver=2.4.0"></script>
    <script src="assets/js/scripts.js?ver=2.4.0"></script>
    <script src="assets/js/charts/chart-crypto.js?ver=2.4.0"></script>
    <script src="../js/sweetalert.js"></script>
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/custom.js"></script>
    <script src="../js/toastr.js"></script>
  </body>
</html>
