<?php
include("connection.php");
include("header.php");
?>
<div class="main-content">
    <div class="page-content">
        <div class="container-fluid">
            <!-- start page title -->
            <div class="row">
                <div class="col-12">
                    <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                        <h4 class="mb-sm-0 font-size-18">View career</h4>
                    </div>
                </div>
            </div>
            <!-- end page title -->

            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="row mb-2">
                                <div class="col-sm-6 mt-3">
                                    <div class="search-box me-2 d-inline-block">
                                        <div class="position-relative">
                                            <input type="text" class="form-control" autocomplete="off" id="searchInput" onkeyup="searchTable()" placeholder="Search...">
                                            <i class="bx bx-search-alt search-icon"></i>
                                        </div>
                                    </div>

                                </div>
                                <!-- <div class="col-sm-6 mt-3">
                                    <div class="text-sm-end">
                                        <a href="addmeta_tag.php"> <button type="button" data-bs-toggle="modal" data-bs-target="#newContactModal" class="btn btn-success btn-rounded waves-effect waves-light addContact-modal mb-2">
                                                <i class="mdi mdi-plus me-1"></i> New Contact
                                            </button></a>
                                    </div>
                                </div> -->
                                <!-- end col-->
                            </div>
                            <!-- end row -->
                            <div class="table-responsive">
                                <table class="table align-middle table-nowrap table-hover dt-responsive nowrap w-100" id="userList-table">
                                    <thead class="table-light">
                                        <tr>
                                            <th scope="col">S.no</th>
                                            <th scope="col">Name</th>
                                            <th scope="col">Email</th>
                                            <th scope="col">Phone</th>
                                            <th scope="col">Gender</th>
                                            <th scope="col">Job Title</th>
                                            <th scope="col">Working</th>
                                            <th scope="col">Resume</th>
                                            <th scope="col" style="width: 200px">Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php

                                        $i = 0;
                                        $qry = mysqli_query($con, "SELECT * FROM job_applications ORDER BY id DESC");
                                        while ($row = mysqli_fetch_assoc($qry)) {
                                            $i++;
                                        ?>
                                            <tr>
                                                <td><?= $i ?></td>
                                                <td><?= htmlspecialchars($row['name']) ?></td>
                                                <td><?= htmlspecialchars($row['email']) ?></td>
                                                <td><?= htmlspecialchars($row['phone']) ?></td>
                                                <td><?= htmlspecialchars($row['gender']) ?></td>
                                                <td><?= htmlspecialchars($row['job_title']) ?></td>
                                                <td><?= htmlspecialchars($row['working_style']) ?></td>
                                                <td>
                                                    <?php
                                                    $ext = pathinfo($row['resume'], PATHINFO_EXTENSION);
                                                    $filePath = "./assets/images/team/" . $row['resume'];
                                                    if (in_array($ext, ['jpg', 'jpeg', 'png', 'gif'])) {
                                                        echo "<img src='$filePath' width='100' height='100'>";
                                                    } elseif ($ext === 'pdf') {
                                                        echo "<a href='$filePath' target='_blank'>View PDF</a>";
                                                    } elseif (in_array($ext, ['doc', 'docx'])) {
                                                        echo "<a href='$filePath' target='_blank'>View Document</a>";
                                                    } else {
                                                        echo "Unsupported file";
                                                    }
                                                    ?>
                                                </td>




                                                <td>
                                                    <a onclick="return confirm('Are you sure you want to delete this record?')" href="deletecareer.php?id=<?php echo $row['id'] ?>">
                                                        <button type="button" class="btn btn-danger btn-rounded waves-effect waves-light mb-2">
                                                            <i class="fas fa-trash"></i> Delete
                                                        </button>
                                                    </a>
                                                </td>
                                            </tr>
                                        <?php
                                        }
                                        ?>
                                    </tbody>


                                </table>
                                <!-- end table -->
                            </div>
                            <!-- end table responsive -->
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- container-fluid -->
    </div>
    <!-- End Page-content -->




    <?php
    include("footer.php");
    ?>
</div>