<?php
require_once('config.php');

// Delete Article
if (isset($_GET['delid'])) {
  if ($c_user_ud == 'active') {

    $id_for_delete = $_GET['delid'] ;
    if (deleteData('mahamudfutureit_photostories', 'id', $id_for_delete)) {
      header("Location:photo-stories.php");
      exit;
    }else {
      $tt_alert = ttAlert('danger', 'Something went wrong to delete Story !');
    }

  }else {
    $tt_alert = ttAlert('danger', 'You Cannot Delete This Page !');
  }

}



// Include Heaser File
require_once('inc/header.php');
?>
<main id="main" class="main ">
  <div class="row">
    <div class="col-6 align-items-center">
      <div class="pagetitle mb-0">
        <h1><?php echo $page_title ?></h1>
      </div>
    </div>
    <div class="col-6 text-end">
        <a href="photo-stories-new.php" class="btn btn-primary btn-sm"><i class="bi bi-node-plus"></i> New Story </a>
    </div>
  </div>
    <?php     echo $tt_alert ?? ''; ?>
  <section class="section mt-4">
    <div class="bg-white rounded-2">

      <table id="MahamudFutureITDTable" class="display" style="width:100%">
        <thead>
          <tr>
            <th>Title</th>
            <th class="text-center">Date</th>
            <th class="text-center">View</th>
            <th class="text-center">Author</th>
            <th class="text-center">Actions</th>
          </tr>
        </thead>
      </table>
      <script>
          $(document).ready(function () {
              $('#MahamudFutureITDTable').DataTable({
                  ajax: {
                      url: 'photo-stories-server.php',
                      type: 'POST',
                  },
                  columns: [
                      { data: 'ptitle' },
                      { data: 'pdate' },
                      { data: 'viewcount' },
                      { data: 'pauthor' },
                      { data: 'paction' },
                  ],
                  order: [],
                  responsive: true,
              });
          });
      </script>
    </div>
  </section>
</main>
<script>
  document.addEventListener("click", function(event) {
    // Check if the clicked element or its parent has the class 'actiion_to_delete'
    const target = event.target.closest(".actiion_to_delete");

    if (target) {
      event.preventDefault(); // Prevent default link behavior
      const url = target.getAttribute("data-href");

      if (confirm("Are you sure you want to delete this item?")) {
        window.location.href = url;
      }
    }
  });
</script>

<?php require_once('inc/footer.php'); ?>
