<?php include 'includes/header.php'; ?>
<?php include 'includes/sidebar.php'; ?>
<?php require 'includes/db_connect.php'; ?>

<div class="container mt-4">
    <h4 class="text-orange">Staff Work Reports</h4>

    <table class="table table-bordered table-striped mt-3">
        <thead class="bg-orange text-white">
            <tr>
                <th>#</th>
                <th>Staff Name</th>
                <th>Report Title</th>
                <th>Report Content</th>
                <th>Date Submitted</th>
            </tr>
        </thead>
        <tbody>
            <?php
            $reports = $conn->query("SELECT reports.*, staff.fullname 
                                     FROM reports 
                                     JOIN staff ON reports.staff_id = staff.id 
                                     ORDER BY reports.id DESC");
            if ($reports->num_rows > 0) {
                $sn = 1;
                while ($row = $reports->fetch_assoc()) {
                    echo "
                    <tr>
                        <td>{$sn}</td>
                        <td>{$row['fullname']}</td>
                        <td>{$row['title']}</td>
                        <td>{$row['content']}</td>
                        <td>{$row['submitted_at']}</td>
                    </tr>";
                    $sn++;
                }
            } else {
                echo "<tr><td colspan='5' class='text-center'>No Reports Found</td></tr>";
            }
            ?>
        </tbody>
    </table>
</div>

<?php include 'includes/footer.php'; ?>
