
        <?php include 'include/navbar.php';?>
        <?php include 'include/sidebar.php';?>
     
            <div id="layoutSidenav_content">
                <main>
                    <div class="container-fluid px-4">
                        <h1 class="mt-4">Dashboard</h1>
                        <ol class="breadcrumb mb-4">
                            <li class="breadcrumb-item active">Manage Visa</li>
                        </ol>

                        <div class=" mt-4">

<table class="table table-bordered example">
  <thead>
    <tr>
      <th>#</th>
      <th>Title</th>
      <th>Country</th>
      <th>Short Detail</th>
      <th>Visa Type</th>
      <th>Sub Visa Type</th>
      <th>Apply Link</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    <?php
    $visas = mysqli_query($conn, "
      SELECT visas.*, 
             countries.country_name, 
             visa_types.visa_type AS visa_type_name, 
             sub_visa_types.sub_visa_type AS sub_visa_type_name
      FROM visas
      JOIN countries ON visas.country_id = countries.id
      LEFT JOIN visa_types ON visas.visa_type = visa_types.id
      LEFT JOIN sub_visa_types ON visas.sub_visa_type = sub_visa_types.id
      ORDER BY visas.id DESC
    ");
    $i = 1;
    while ($row = mysqli_fetch_assoc($visas)):
    ?>
      <tr>
        <td><?= $i++; ?></td>
        <td><?= htmlspecialchars($row['title']); ?></td>
        <td><?= htmlspecialchars($row['country_name']); ?></td>
        <td><?= htmlspecialchars(substr($row['short_detail'], 0, 60)); ?>...</td>
        <td><?= htmlspecialchars($row['visa_type_name']); ?></td>
        <td><?= htmlspecialchars($row['sub_visa_type_name']); ?></td>
        <td><a href="<?= htmlspecialchars($row['apply_link']); ?>" target="_blank">Apply</a></td>
        <td>
          <a href="edit-visa.php?id=<?= $row['id']; ?>" class="btn btn-sm btn-warning">Edit</a>
          <a href="?id=<?= $row['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Delete this visa?')">Delete</a>
        </td>
      </tr>
    <?php endwhile; ?>
  </tbody>
</table>

<?php
if (isset($_GET['id'])) {
    $id = intval($_GET['id']);
    $delete = "DELETE FROM visas WHERE id = $id";
    if (mysqli_query($conn, $delete)) {
        header("Location: manage-visa.php");
        exit;
    } else {
        echo "Failed to delete job.";
    }
}

?>

 
                    </div>
                </main>
                <?php include "include/footer.php";?>
            </div>
        </div>
<!-- JS TextEditor -->
<script src="//cdn.ckeditor.com/4.13.1/standard/ckeditor.js"></script>
         <script>
        CKEDITOR.replace('arContent');
    </script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
        <script src="js/scripts.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js" crossorigin="anonymous"></script>
        <script src="assets/demo/chart-area-demo.js"></script>
        <script src="assets/demo/chart-bar-demo.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/simple-datatables@latest" crossorigin="anonymous"></script>
        <script src="js/datatables-simple-demo.js"></script>
    </body>
</html>
