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

    include "../backend/connection.php";
    $configure = new DefaultDatabase();
    $conf = $configure->connect();

    //fetch school detailss
    $details = mysqli_query($conf,"SELECT * FROM school_admin WHERE username = '".$_SESSION["school_admin"]."'");
    $det = mysqli_fetch_array($details);
    $broadcast = "All";

    $events = mysqli_query($conf,"SELECT * FROM notices WHERE receipient = '".$det["district"]."' OR receipient = '".$broadcast."' ORDER BY notice_date DESC");
    $districts = mysqli_query($conf, "SELECT * FROM districts");

?>
<div class="school-container">
    <h2>NOTIFICATIONS <ion-icon name="megaphone-outline"></ion-icon></h2>

    <table id="schoolsTable">
        <thead>
            <tr>
                <th>Notice Header</th>
                <th>Receipient</th>
                <th>Notice Content</th>
                <th>Date</th>
            </tr>
        </thead>
        <tbody>
            <!-- Dummy data -->
            <?php
                while($evt = mysqli_fetch_array($events))
                {
            ?>
            <tr>
                <td> <?php echo $evt["notice_header"] ?></td>
                <td><?php echo $evt["receipient"] ?></td>
                <td><?php echo $evt["notice_content"] ?></td>
                <td><?php echo $evt["notice_date"] ?></td>
            </tr>
            <?php
                }
            ?>
        </tbody>
    </table>
</div>
