<?php
include('includes/header.php');
include('includes/navbar.php');
?>

<div class="container-fluid">
  <?php
  if (isset($_POST['update'])) {
      $btc_wallet = $_POST['btc_wallet'];
      $eth_wallet = $_POST['eth_wallet'];
      $ltc_wallet = $_POST['ltc_wallet'];
      $usdt_wallet = $_POST['usdt_wallet'];

      $update_wallet = "UPDATE dmethod SET btc = '$btc_wallet', eth = '$eth_wallet', ltc = '$ltc_wallet', usdt = '$usdt_wallet' WHERE id = 1";
      if ($connection->query($update_wallet)===TRUE) {
          $error = "update_success";
          }else {
            $error = "error";
          }
  }
   ?>
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">Update Website Wallet Address </h6>
        </div>
        <div class="card-body">

          <br>
          <form class="" action="" method="post" enctype="multipart/form-data">
            <div class="form-group">
              <label>BTC Wallet Address</label>
              <input type="text" name="btc_wallet" value="<?php echo $btc_wallet ?>" class="form-control">
              <br>

              <label>ETH Wallet Address</label>
              <input type="text" name="eth_wallet" value="<?php echo $eth_wallet ?>" class="form-control">
              <br>

              <label>LTC Wallet Address</label>
              <input type="text" name="ltc_wallet" value="<?php echo $ltc_wallet ?>" class="form-control">
              <br>

              <label>USDT Wallet Address</label>
              <input type="text" name="usdt_wallet" value="<?php echo $usdt_wallet ?>" class="form-control">
              <br>

              <br>
              <button type="submit" name="update" class="btn btn-primary">Update Wallet</button>
            </div>
          </form>
        </div>
    </div>
</div>


</div>

<p id="error" style='display: none'><?php echo $error?></p>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script>
    var error = document.getElementById('error');

    if (error.textContent == "update_success") {
        swal("SUCCESS!", "Website Wallets Updated Successfully", "success");
        setTimeout(() => {
            window.location.href = ''
        }, 2000);

    }else if (error.textContent == "error") {
        swal("ERROR!", "Sorry an error occurred. Please try again later", "warning");

    }

</script>
<?php
include('includes/scripts.php');
include('includes/footer.php');
?>
