<?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">Edit Blog</li>
            </ol>

            <div class="mt-4">
                <?php

// Fetch jobs
$query = "SELECT * FROM jobs ORDER BY id DESC";
$result = mysqli_query($conn, $query);
?>

<div>
  <table class="table table-bordered table-hover example">
    <thead>
      <tr>
        <th>ID</th>
        <th>Title</th>
        <th>Company</th>
        <th>Apply Url</th>
        <th>Salary</th>
        <th>Location</th>
        <th>Commitment</th>
        <th>Experience</th>
        <th>Gender</th>
        <th>Qualification</th>
        <th>Status</th>
        <th>Actions</th>
      </tr>
    </thead>
    <tbody>
      <?php while ($row = mysqli_fetch_assoc($result)): ?>
        <tr>
          <td><?= $row['id'] ?></td>
          <td><?= htmlspecialchars($row['job_title']) ?></td>
          <td><?= htmlspecialchars($row['company_name']) ?></td>
          <td><?= htmlspecialchars($row['apply_url']) ?></td>
          <td><?= htmlspecialchars($row['salary']) ?></td>
          <td><?= htmlspecialchars($row['location']) ?></td>
          <td><?= htmlspecialchars($row['commitment']) ?></td>
          <td><?= htmlspecialchars($row['experience']) ?></td>
          <td><?= htmlspecialchars($row['gender']) ?></td>
          <td><?= htmlspecialchars($row['qualification']) ?></td>
          <td>
            <?= $row['status'] == 1 ? "<span class='badge bg-success'>Active</span>" : "<span class='badge bg-secondary'>Inactive</span>" ?>
          </td>
          <td>
            <a href="edit_job.php?id=<?= $row['id'] ?>" class="btn btn-sm btn-primary">Edit</a>
            <a href="?id=<?= $row['id'] ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this job?')">Delete</a>
          </td>
        </tr>
      <?php endwhile; 




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


    </tbody>
  </table>
</div>

            </div>
        </div>
    </main>
    <?php include "include/footer.php"; ?>
</div>

<!-- CKEditor -->
<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>
