<?php
    session_start();
    if(!isset($_SESSION["judge_admin"]))
    {
        header("location:./index.php");
    }

    include "../backend/connection.php";
    $configure = new DefaultDatabase();
    $conf = $configure->connect();
    //fetch judge detailss
    $details = mysqli_query($conf,"SELECT * FROM adjudicator WHERE username = '".$_SESSION["judge_admin"]."'");
    $det = mysqli_fetch_array($details);

    //default pupil status
    $status = 0;
    //fetch pupils details
    $pupils = mysqli_query($conf, "SELECT * FROM participants WHERE category = '".$det["category"]."' AND status < 3");
    //fetch result details
    $results = mysqli_query($conf, "SELECT * FROM participants WHERE category = '".$det["category"]."' AND status > 0");
?>
<div class="school-container">
    <h2>MANAGE PARTICIPANTS RESULTS</h2>
    <div class="add-school">
        <form method="POST">
            <select id="sectionSelect" name="participant" required>
                <option value="" disabled selected>Select Participant</option>
                <?php
                    while($pupil = mysqli_fetch_array($pupils))
                    {
                ?>
                <option value="<?php echo $pupil["id"]?>"><?php echo $pupil["first_name"]." ".$pupil["last_name"]; ?></option>
                <?php
                    }
                ?>
            </select>
            <input type="number" name="points" min="0" max="75" required>
            <button  type="submit" name="register_results">Add Results</button>
        </form>
    </div>
    <table id="results">
        <thead>
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>School</th>
                <th>Section</th>
                <th>Category</th>
                <th>Judges Attended</th>
                <th>Points</th>
            </tr>
        </thead>
        <tbody>
            <!-- Dummy data -->
            <?php
                while($pat = mysqli_fetch_array($results))
                {
            ?>
            <tr>
                <td><?php echo $pat["first_name"] ?></td>
                <td><?php echo $pat["last_name"] ?></td>
                <td><?php echo $pat["school"] ?></td>
                <td><?php echo $pat["grade_section"] ?></td>
                <td><?php echo $pat["category"] ?></td>
                <td><?php echo $pat["status"] ?></td>
                <td><?php echo $pat["points"] ?></td>
            </tr>
            <?php
                }
            ?>
        </tbody>
    </table>
</div>
