<div class="modal fade" id="addadminprofile" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Change User Status</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>

      </div>
      <?php
          if (isset($_POST['submit'])) {
              $id = $_POST['id'];
              $status = $_POST['status'];

              if (empty($id) || empty($status)) {
                $error2 = "empty";
              }else {
                $sql = "UPDATE users SET status = '$status' WHERE user_id = '$id'";
                if ($connection->query($sql)===TRUE) {
                    $error2 = "status_success";
                }else {
                    $error2 = "error";
                  }
              }

          }

      ?>
      <form action="" method="POST">

        <div class="modal-body">

            <div class="form-group">
              <label for="">Select User </label>
              <select name="id" style='color: var(--text); text-align: left' required class="form-control">
                  <option value="">Select Account </option>
                  <?php
                      $sql = "SELECT * FROM users WHERE id != 1";
                      $result = $connection->query($sql);
                      while ($row = $result->fetch_assoc()) {
                          $db_name = $row['full_name'];
                          $db_id = $row['user_id'];
                          $db_email = $row['email'];
                          $db_status = $row['status'];
                  ?>
                  <option value="<?php echo $db_id?>"><?php echo $db_name?> (<?php echo $db_email?>) <?php echo $db_status ?></option>
                  <?php }?>
              </select>
            </div>

            <div class="form-group">
                <label for="">Select Status</label>
                <select name="status" required class="form-control">
                    <option value="">Select Account Status</option>
                    <option value="active">Active</option>
                    <option value="suspend">Suspend</option>
                    <option value="inactive">Inactive</option>
                </select>
            </div>

        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="submit" name="submit" class="btn btn-primary">Submit</button>
        </div>
      </form>

    </div>
  </div>
</div>


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

    if (error.textContent == "empty") {
      swal("EMPTY FIELD!", "Please select user and status", "warning");

    }else if (error.textContent == "status_success") {
      swal("Completed!", "User Status have been set as <?php echo $status ?>", "success");
        setTimeout(() => {
            window.location.href = 'users.php'
        }, 3000);
    }else if (error.textContent == "error") {
      swal("ERROR!", "Sorry!!!, Something went wrong, try later or contact support", "error");
    }

</script>
