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

    $events = mysqli_query($conf,"SELECT * FROM notices ORDER BY notice_date DESC");
    $districts = mysqli_query($conf, "SELECT * FROM districts");

?>
<div class="school-container">
    <h2>MUCHINGA JETS NOTIFICATIONS</h2>
    <div class="add-school">
        <form method="POST">
            <input type="text" id="event" placeholder="Enter Notification Heading" name="notice" required>
            <select id="categorySelect" name="district" required>
                <option value="" disabled selected>Select District</option>
                <?php
                    while($dist = mysqli_fetch_array($districts))
                    {
                ?>
                <option value="<?php echo $dist["district_name"] ?>"><?php echo $dist["district_name"] ?></option>
                <?php
                    }
                ?>
            </select>
            <br>
            <br>
            <textarea name="article" required placeholder="write notification" style="width:620px; height: 50px;"></textarea>
            <br>
            <button  type="submit" name="add_notice">Send Notifications</button>
        </form>
    </div>
    <table id="schoolsTable">
        <thead>
            <tr>
                <th>Notice Header</th>
                <th>Receipient</th>
                <th>Notice Content</th>
                <th>Date</th>
                <th>Action</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>
                <td>
                <button class="delete"><a  href="./deletions/delete_notice.php?notice_del=<?php echo $evt["id"] ?>" onclick="return confirm('Are you sure you want delete this notice?');" style="color:white; text-decoration:none;">Delete</a></button>
                </td>
            </tr>
            <?php
                }
            ?>
        </tbody>
    </table>
</div>
