<?php
require("header.php")
?>
<style>
  .btn-group>.btn:not(:last-child):not(.dropdown-toggle) {
    background: black;
  }

  .btn-group>.btn-group:not(:first-child)>.btn {
    background: black;
  }

  .page-item.active .page-link {
    background: black;
  }

  .dt-button-collection .dropdown-menu .buttons-columnVisibility {
    background-color: black;
  }
</style>

<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <div class="container-fluid">
      <div class="row mb-2">
        <div class="col-sm-6">
          <!-- <h1>Payment Setting</h1> -->
        </div>
        <div class="col-sm-6">

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

  <!-- Main content -->
  <section class="content">
    <div class="container-fluid">
      <div class="row">

        <div class="col-md-12">

          <!-- general form elements -->

          <div class="card card-secondary">
            <div class="card-header" style="background-color: black;">
              <h3 class="card-title">Add USDT Details</h3>
              <ol class="breadcrumb float-sm-right" style="background-color: black;">
                <li class="breadcrumb-item">Payment Setting</li>
                <li class="breadcrumb-item active">Payment Setting</li>
              </ol>
            </div>
            <!-- /.card-header -->
            <div class="card-body">


              <form class="form-horizontal" action="usdt_payment_code.php" method="post" enctype="multipart/form-data">

                <div class="form-group row">
                  <label for="inputName" class="col-sm-2 col-form-label">USDT Type<span style="color:red; font-size:18px;">*</span> :</label>
                  <div class="col-sm-10">
                    <select class="form-control" name="usdt_type">
                      <!-- <option value="UPI">UPI Qr</option> -->
                      <option value="Bitcoin">Bitcoin</option>
                      <option value="Trther">Trther</option>
                      <!-- Add more options as needed -->
                    </select>

                  </div>
                </div>


                <div class="form-group row">
                  <label for="inputName" class="col-sm-2 col-form-label">Payment Qr<span style="color:red; font-size:18px;">*</span>: </label>
                  <div class="col-sm-10">
                    <div class="input-group">
                      <div class="custom-file">
                        <input type="file" class="custom-file-input" name="usdt_qr" accept="img/*" id="exampleInputFile" required>
                        <label class="custom-file-label" for="exampleInputFile" id="fileLabel">Choose file </label>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="form-group row">
                  <label for="inputName" class="col-sm-2 col-form-label">Wallet Address <span style="color:red; font-size:18px;">*</span>: </label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="wallet_address" placeholder="Enter wallet Address!">

                  </div>
                </div>
                <div class="form-group row">
                  <label for="inputName" class="col-sm-2 col-form-label">Network<span style="color:red; font-size:18px;">*</span>: </label>
                  <div class="col-sm-10">
                    <input type="text" class="form-control" name="network" placeholder="Enter Network!">

                  </div>
                </div>


                <div class="form-group row offset-sm-2">
                  <div class="offset-sm-0 col-sm-3">
                    <button type="submit" class="btn btn-dark" name="submit" style="width:100%;margin-top: 16%; background:black">Submit</button>
                  </div>

                </div>

              </form>


            </div><!-- /.card-body -->
          </div>


        </div>
        <!-- /.card -->


      </div>

    </div>

    <!-- /.row -->

    <!-- /.container-fluid -->
  </section>
  <section class="content">
    <div class="container-fluid">
      <div class="row">

        <div class="col-md-12">

          <!-- general form elements -->

          <div class="card card-secondary">
            <div class="card-header" style="background-color: black;">
              <h3 class="card-title">View Bank Details</h3>
              <ol class="breadcrumb float-sm-right" style="background-color: black;">
                <li class="breadcrumb-item">Setting</li>
                <li class="breadcrumb-item active">Payment Setting</li>
              </ol>
            </div>
            <!-- /.card-header -->
            <div class="card-body">

              <table id="example1" class="table table-bordered table-striped">
                <thead>
                  <tr>
                    <th>Date</th>
                    <th>USDT Type</th>
                    <th>Payment Qr</th>
                    <th>Wallet Address</th>
                    <th>Network</th>
                    <th>Edit</th>

                  </tr>
                </thead>
                <tbody>
                  <?php
                  include('connection.php');
                  $uname = $_SESSION['username'];
                  $sql = "SELECT * FROM usdt_payment WHERE added_by='$uname' ORDER BY date_time ";
                  $res = mysqli_query($conn, $sql);
                  while ($row = mysqli_fetch_assoc($res)) {

                  ?>

                    <tr>
                      <td><?php echo $row['date_time'];  ?></td>
                      <td><?php echo $row['usdt_type'];  ?></td>
                      <td><img src="img/<?php echo $row['usdt_qr'];  ?>" height="50%" width="50%"></td>
                      <td><?php echo $row['wallet_address'];  ?></td>
                      <td><?php echo $row['network'];  ?></td>
                      <td>
                        <button type="button" class="btn btn-link" style="color:blue;font-weight:600;" data-toggle="modal" data-target="#exampleModalCenter_<?php echo $row['id']; ?>">
                          <i class="fa fa-pencil-square-o" aria-hidden="true"></i>
                      </td>
                    </tr>

                  <?php
                  }
                  ?>
                  <!-- Modal -->
                  <?php
                  $sql = "SELECT * FROM usdt_payment";
                  $res = mysqli_query($conn, $sql);

                  while ($row = mysqli_fetch_array($res)) {
                  ?>
                    <div class="modal fade" id="exampleModalCenter_<?php echo $row['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
                      <div class="modal-dialog modal-dialog-centered" role="document">
                        <div class="modal-content">
                          <div class="modal-header" style="background-color: black;">
                            <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                              <span aria-hidden="true">&times;</span>
                            </button>
                          </div>
                          <div class="modal-body">
                            <form action="usdt_payment_update.php" method="post" enctype="multipart/form-data">

                              <div class="form-group row">
                                <label for="inputName" class="col-sm-4 col-form-label">Payment Qr<span style="color:red; font-size:18px;">*</span>: </label>
                                <div class="col-sm-8">
                                  <div class="input-group">
                                    <div class="custom-file">
                                      <input type="hidden" class="form-control" maxlength="20" name="id" value="<?php echo $row['id'];  ?>" placeholder="Enter account holder name!">
                                      <input type="file" class="custom-file-input" name="usdt_qr" id="exampleInputFile" value="<?php echo $row['usdt_qr'];  ?>">
                                      <label class="custom-file-label" for="exampleInputFile" id="fileLabel"><?php echo $row['usdt_qr'];  ?></label>
                                    </div>
                                  </div>
                                </div>
                              </div>
                              <div class="form-group row">
                                <label for="inputName" class="col-sm-4 col-form-label">Wallet Address <span style="color:red; font-size:18px;">*</span>: </label>
                                <div class="col-sm-8">
                                  <input type="text" class="form-control" name="wallet_address" value="<?php echo $row['wallet_address'];  ?>" placeholder="Enter wallet Address!">

                                </div>
                              </div>
                              <div class="form-group row">
                                <label for="inputName" class="col-sm-4 col-form-label">Network<span style="color:red; font-size:18px;">*</span>: </label>
                                <div class="col-sm-8">
                                  <input type="text" class="form-control" name="network" value="<?php echo $row['network'];  ?>" placeholder="Enter Network!">

                                </div>
                              </div>



                              <div class="form-group row offset-sm-2">
                                <div class="offset-sm-0 col-sm-3">
                                  <button type="submit" class="btn btn-dark" name="update" style="width:100%;margin-top: 16%; background:black;">Submit</button>
                                </div>

                              </div>

                            </form>



                          </div>

                        </div>
                      </div>
                    </div>
                  <?php } ?>
                  <!-- modal end -->
                </tbody>

              </table>

            </div><!-- /.card-body -->
          </div>


        </div>
        <!-- /.card -->


      </div>

    </div>

    <!-- /.row -->

    <!-- /.container-fluid -->
  </section>
  <!-- /.content -->
</div>
<!-- for searching -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.16.9/xlsx.full.min.js"></script>
<script>
  const fileInput = document.getElementById('exampleInputFile');
  const fileLabel = document.getElementById('fileLabel');

  fileInput.addEventListener('change', function() {
    if (fileInput.files.length > 0) {
      fileLabel.innerText = fileInput.files[0].name;
    } else {
      fileLabel.innerText = 'Choose file (Choose an Excel file for filter)';
    }
  });
</script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<!-- Sweet Alert  start-->
<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 1) { ?>
  <script>
    Swal.fire(
      'Good job!',
      ' Added Successfully!!',
      'success'
    ).then(() => {
      window.location.href = "usdt_payment.php";
    });
  </script>
<?php } ?>

<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 2) { ?>
  <script>
    Swal.fire(
      'Oops...',
      'Something went wrong!!',
      'error'
    ).then(() => {
      window.location.href = "usdt_payment.php";
    });
  </script>
<?php } ?>

<?php if (isset($_REQUEST['msg']) && $_REQUEST['msg'] == 3) { ?>
  <script>
    Swal.fire(
      'Oops...',
      'Already Added This Bank Name',
      'error'
    ).then(() => {
      window.location.href = "usdt_payment.php";
    });
  </script>
<?php } ?>
<?php
require("footer.php")
?>