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

    $districts = mysqli_query($conf,"SELECT * FROM districts");
    $schools = mysqli_query($conf, "SELECT * FROM schools");
    $staff = mysqli_query($conf,"SELECT * FROM school_admin");

?>
<div class="school-container">
    <h2>MANAGE SCHOOL ADMINISTRATORS</h2>
    <div class="add-school">
        <form method="POST">
            <input type="text" placeholder="First Name" name="first_name" required>
            <input type="text" placeholder="Last Name" name="last_name" required>
            <input type="text" placeholder="phone" name="phone" required>
            <select id="districtSelect" 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>
            <select id="schoolSelect" name="school" required>
                <option value="" disabled selected>Select School</option>
                <?php
                    while($school = mysqli_fetch_array($schools))
                    {
                ?>
                <option value="<?php echo $school["school_name"] ?>"><?php echo $school["school_name"] ?></option>
                <?php
                    }
                ?>
            </select>
            <button  type="submit" name="register_staff">Add Staff</button>
        </form>
    </div>
    <table id="schoolsTable">
        <thead>
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>Phone Number</th>
                <th>School</th>
                <th>District</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <!-- Dummy data -->
            <?php
                while($staff_members = mysqli_fetch_array($staff))
                {
            ?>
            <tr>
                <td><?php echo $staff_members["first_name"] ?></td>
                <td><?php echo $staff_members["last_name"] ?></td>
                <td><?php echo $staff_members["phone"] ?></td>
                <td><?php echo $staff_members["school"] ?></td>
                <td><?php echo $staff_members["district"] ?></td>
                <td>
                <button class="delete"><a  href="./deletions/delete_staff.php?staff_del=<?php echo $staff_members["id"] ?>" onclick="return confirm('Are you sure you want to delete this School Administrator?');" style="color:white; text-decoration:none;">Delete</a></button>
                    
                </td>
            </tr>
            <?php
                }
            ?>
        </tbody>
    </table>
</div>
