<?php require_once('../../setup.php'); ?>
<?php
session_start();
ob_start();
if (!isset($_SESSION['hash'])) {
  header("Location: login");
  exit();
} else {
  $hash = $_SESSION['hash'];
}
?>
<!DOCTYPE html>
<html lang="en">

<head>

  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">

  <title><?= $main_name; ?></title>

  <!-- Custom fonts for this template-->
  <link rel="shortcut icon" href="../../assets/images/logo.png" />
  <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">

  <!-- Custom styles for this template -->
  <link href="css/sb-admin-2.min.css" rel="stylesheet">

  <!-- Custom styles for this page -->
  <link href="vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">

</head>

<body id="page-top">

  <!-- Page Wrapper -->
  <div id="wrapper">

    <!-- Sidebar -->
    <?php include('admin_nav.php'); ?>
    <!-- End of Sidebar -->

    <!-- Content Wrapper -->
    <div id="content-wrapper" class="d-flex flex-column">

      <!-- Main Content -->
      <div id="content">

        <!-- Topbar -->
        <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">&nbsp;</nav>
        <!-- End of Topbar -->

        <!-- Begin Page Content -->
        <div class="container-fluid">

          <!-- Page Heading -->
          <h1 class="h3 mb-1 text-primary"><i class="fa fa-user"></i> Edit User Withdrawal</h1>
          <p class="mb-4">You can edit user withdrawal by changing the form below.</p>

          <!-- Content Row -->
          <div class="row">

            <!-- Border Left Utilities -->
            <div class="col-lg-6">
              <div class="card mb-4 py-3 border-left-primary">
                <div class="card-body">
                  <?php
                  require_once("../conn.php");

                  if (isset($_GET['e'])) {
                    $track_id = $_GET['e'];
                    $sql3 = "SELECT * FROM transactions WHERE id=$track_id";
                    $result3 = $dbconfig->query($sql3);

                    if ($result3->num_rows > 0) {
                      // output data of each row
                      while ($row3 = $result3->fetch_assoc()) {
                        $dbid = $row3['id'];
                        $dbamount = $row3['amount'];
                        $dbdate = $row3['date'];
                        $dbstatus = $row3['status'];
                      }
                    }
                  } else {
                    header("Location: florence");
                  }
                  ?>
                  <?php
                  require_once("../conn.php");
                  if (isset($_POST['update_profile'])) {
                    $dbid = $_POST['id'];
                    $amount = $_POST['amount'];
                    $date = $_POST['date'];
                    $status = $_POST['status'];


                    $sql = "UPDATE transactions SET
                      amount = '$amount',
                      date = '$date',
                      status = '$status'
                    WHERE id = $dbid";

                    if ($dbconfig->query($sql) === TRUE) {
                      header("Refresh: 2; url=admin_withdrawal");
                      echo '<div align="center" class="alert alert-success"><i class="fa fa-check"></i>&nbsp;&nbsp;<b>Transaction</b> was updated successfully...</div>';
                    }
                  }
                  ?>
                  <form action="" method="POST">
                    <div class="form-group">
                      <label for="email">Amount:</label>
                      <input type="hidden" class="form-control" name="id" value="<?php echo $dbid; ?>" required>
                      <input type="text" class="form-control" name="amount" value="<?php echo $dbamount; ?>" maxlength="20" required>
                    </div>
                    <div class="form-group">
                      <label for="email">Date:</label>
                      <input type="text" class="form-control" name="date" value="<?php echo $dbdate; ?>" required>
                    </div>
                    <div class="form-group">
                      <label for="email">Status</label>
                      <select class="form-control" name="status" required>
                        <option value="<?php echo $dbstatus; ?>"><?php echo $dbstatus; ?></option>
                        <option value="pending">pending</option>
                        <option value="canceled">canceled</option>
                        <option value="approved">approved</option>
                      </select>
                    </div>
                    <button type="submit" name="update_profile" class="btn btn-primary">Update Profile</button>
                  </form>
                </div>
              </div>
            </div>

          </div>

        </div>
        <!-- /.container-fluid -->

      </div>
      <!-- End of Main Content -->

    </div>
    <!-- End of Content Wrapper -->

  </div>
  <!-- End of Page Wrapper -->

  <!-- Scroll to Top Button-->
  <a class="scroll-to-top rounded" href="#page-top">
    <i class="fas fa-angle-up"></i>
  </a>

  <!-- Bootstrap core JavaScript-->
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

  <!-- Core plugin JavaScript-->
  <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

  <!-- Custom scripts for all pages-->
  <script src="js/sb-admin-2.min.js"></script>

  <!-- Page level plugins -->
  <script src="vendor/datatables/jquery.dataTables.min.js"></script>
  <script src="vendor/datatables/dataTables.bootstrap4.min.js"></script>

  <!-- Page level custom scripts -->
  <script src="js/demo/datatables-demo.js"></script>

</body>

</html>
