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

    $categories = mysqli_query($conf,"SELECT * FROM categories");
    $materials = mysqli_query($conf, "SELECT * FROM material");

?>
<div class="school-container">
    <h2>JETS MATERIALS NAMAGEMENT</h2>
    <p style="color:red">* only PDF files are allowed</p>
    <div class="add-school">
        <form method="POST" enctype="multipart/form-data">
            <input type="text" id="material" placeholder="Enter Material Name" name="material_name" required>
            <input type="file" placeholder="select file" name="material_file" accept=".pdf" required>
            <select id="categorySelect" name="category" required>
                <option value="" disabled selected>Select Category</option>
                <?php
                    while($cat = mysqli_fetch_array($categories))
                    {
                ?>
                <option value="<?php echo $cat["category_name"] ?>"><?php echo $cat["category_name"] ?></option>
                <?php
                    }
                ?>
            </select>
            <button  type="submit" name="add_material">Upload Document</button>
        </form>
    </div>
    <table id="schoolsTable">
        <thead>
            <tr>
                <th>Materal Name</th>
                <th>Category</th>
                <th>Posted By</th>
                <th>Posted Year</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            <!-- Dummy data -->
            <?php
                while($material = mysqli_fetch_array($materials))
                {
            ?>
            <tr>
                <td><a href="<?php echo $material["material_location"] ?>" style="text-decoration: none; color:black; text-align:center;"><img src="../images/icon.PNG" width="50"> <br> <?php echo $material["material_name"] ?></a></td>
                <td><?php echo $material["material_category"] ?></td>
                <td><?php echo $material["posted_by"] ?></td>
                <td><?php echo $material["post_date"] ?></td>
                <td>
                <button class="delete"><a  href="./deletions/delete_material.php?material_del=<?php echo $material["id"] ?>" onclick="return confirm('Are you sure you want delete this document?');" style="color:white; text-decoration:none;">Delete</a></button>
                </td>
            </tr>
            <?php
                }
            ?>
        </tbody>
    </table>
</div>
