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

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

      if (deleteData('tt_page', 'id', $id_for_delete)){
        header("Location:page.php");
        exit;
      }else {
        $tt_alert = ttAlert('danger', 'Something went wrong to delete Page !');
      }

  }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="page-new.php" class="btn btn-primary btn-sm"><i class="bi bi-node-plus"></i> New Page </a>
    </div>
  </div>
  <?php     echo $tt_alert ?? ''; ?>

  <section class="section mt-4">
    <div class="bg-white rounded-2 ">
      <table  class="tt_datatable" style="width:100%">
        <thead>
            <tr>
                <th>Title</th>
                <th class="text-end">Action</th>
            </tr>
        </thead>
        <tbody>
        <?php
        $tt_web_page = showAllttdata("tt_page", " ORDER BY  id  DESC ");
        if (!empty($tt_web_page)) {
          foreach ($tt_web_page as $the_page) {
            ?>
            <tr>
                <td>
                  <a target="_blank" href="<?php echo $site_domain . $the_page['page_url'] ?>/"><?php echo $the_page['page_title'] ?></a>
                  <?php
                  if ($the_page['page_status'] == 'draft') {
                    ?>
                    <small class="badge bg-primary fw-normal ms-3">Draft</span>
                    <?php
                  }else {
                    ?>
                    <span class="badge bg-success fw-normal ms-3">Published</span>
                    <?php
                  }
                  ?>
                </td>
                <td class="text-end action-btn">
                  <a class="bg-primary" href="page-edit.php?page_id=<?php echo $the_page['id'] ?>"><i class="bi bi-pencil"></i></a>
                  <a class="bg-danger" data-bs-toggle="modal" data-bs-target="#delete_pop<?php echo $the_page['id'] ?>" href="#"><i class="bi bi-trash3"></i></a>
                </td>
            </tr>
            <?php
            ttPopaction('delete_pop'.$the_page['id'],'page.php?delid='.$the_page['id']);
          }
        }
        ?>
        </tbody>
      </table>
    </div>
  </section>
</main>
<?php require_once('inc/footer.php'); ?>
