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

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

?>
<div class="school-container">
    <h2>MUCHINGA JETS ACTIVITIES POSTS</h2>
    <p style="color:red">* only picture files are allowed</p>
    <div class="add-school">
        <form method="POST" enctype="multipart/form-data">
            <input type="text" id="event" placeholder="Enter Event Name" name="event_name" required>
            <input type="file" placeholder="select file" name="event_file" accept=".jpg,.png,.gif,jpeg" 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 news article" style="width:620px; height: 150px;"></textarea>
            <br>
            <button  type="submit" name="add_post">Upload News</button>
        </form>
    </div>
    <table id="schoolsTable">
        <thead>
            <tr>
                <th>Event Name</th>
                <th>District</th>
                <th>Event Date</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <!-- Dummy data -->
            <?php
                while($evt = mysqli_fetch_array($events))
                {
            ?>
            <tr>
                <td> <?php echo $evt["event_name"] ?></td>
                <td><?php echo $evt["event_district"] ?></td>
                <td><?php echo $evt["event_date"] ?></td>
                <td>
                <button class="delete"><a  href="./deletions/delete_post.php?post_del=<?php echo $evt["id"] ?>" onclick="return confirm('Are you sure you want delete this post?');" style="color:white; text-decoration:none;">Delete</a></button>
                </td>
            </tr>
            <?php
                }
            ?>
        </tbody>
    </table>
</div>
