<?php include_once('header.php'); ?>

<div class="container">
  <div class="card-deck mb-3">
    <div class="d-flex justify-content-between flex-wrap flex-md-nowrap mt-3 align-items-center pb-2 mb-3 border-bottom" style="width: 100%;">
      <h1 class="h2">Inquiry Details</h1>
      <div class="btn-toolbar mb-2 mb-md-0">
        <div class="btn-group mr-2">
          <a class="btn btn-sm btn-outline-secondary" href="inquiries.php">Inquiries</a>
        </div>
      </div>
    </div>
    <div class="table-responsive">
      <?php
      $id = '';
      if (isset($_GET['id'])) {
        $id = $_GET['id'];
      }
      $row = $con->getRows('inquiries', array('where' => 'link="' . $id . '"', 'return_type' => 'single'));
      $date  = strtotime($row['date']);
      $date = date('d M, Y(H:i:s)', $date);
      ?>
      <div id="error"></div>
      <table class="table table-striped table-bordered table-sm">
        <tr>
          <th>Name</th>
          <td><?= $row['name'] ?></td>
        </tr>
        <tr>
          <th>Email</th>
          <td><?= $row['email'] ?></td>
        </tr>
        <tr>
          <th>Phone</th>
          <td><?= $row['phone'] ?></td>
        </tr>
        <tr>
          <th>Date Posted</th>
          <td><?= $date ?></td>
        </tr>
        <tr>
          <th>Subject</th>
          <td><?= $row['subject'] ?></td>
        </tr>
        <tr>
          <th>Message</th>
          <td><?= $row['message'] ?></td>
        </tr>
        <tr>
          <th></th>
          <td rowspan="2">
            <button class="btn btn-outline-danger btn_delete" name="delete_btn" data-id3="<?php echo $row["link"]; ?>" style="float: right;"><i class="icon icon-trash"></i> Delete This Message</button>
          </td>
        </tr>
      </table>
    </div>
  </div>

</div>


<!-- Bootstrap core JavaScript
    ================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script>
  window.jQuery || document.write('<script src="../../js/vendor/jquery-slim.min.js"><\/script>')
</script>
<script src="../../js/vendor/popper.min.js"></script>
<script src="../../js/bootstrap.min.js"></script>
<script src="../../js/vendor/holder.min.js"></script>
<script type="text/javascript" src="../../js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="../../js/validation.min.js"></script>
<script src="../../js/tables/jquery.dataTables.js"></script>
<script src="../../js/tables/dataTables.bootstrap4.js"></script>

<!--  summernote JS
        ============================================ -->
<script src="../../js/summernote/summernote-updated.min.js"></script>
<script src="../../js/summernote/summernote-active.js"></script>

<script>
  //delete vacancy details details
  $(document).on('click', '.btn_delete', function() {
    var id = $(this).data("id3");
    var delete_inquiry = "delete_inquiry";

    if (confirm("Are you sure you want to remove this inquiry/query?")) {
      $.ajax({
        url: "sql_statements.php",
        method: "POST",
        data: {
          id: id,
          delete_inquiry: delete_inquiry
        },
        dataType: "text",
        success: function(data) {
          //alert(data);
          if (data == 1) {
            $("#error").fadeIn(1000, function() {
              $("#error").html('<div class="alert alert-success"> <button type="button" class="close" data-dismiss="alert">×</button><span class="icon icon-ok-circle"></span>&nbsp; A message has been removed!</div>');
            });
            $("#error").delay(6000).fadeOut(function() {});
            setTimeout(' window.location.href = "inquiries.php"; ', 6000);
          }
          fetchData();
        }
      });
    }
  });
</script>
</body>

</html>