<?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);

    //pupil registration
    if(isset($_POST["register_pupil"]))
    {
        $status = 0;
        $district = $det["district"];
        $school = $det["school"];
        $first_name = htmlspecialchars($_POST["first_name"]);
        $last_name = htmlspecialchars($_POST["last_name"]);
        $date = htmlspecialchars($_POST["date"]);
        $grade = htmlspecialchars($_POST["section"]);
        $category = htmlspecialchars($_POST["category"]);

        $register = mysqli_query($conf,"INSERT INTO participants (first_name,last_name,grade_section,date_of_birth,school,district,category,status)
         VALUES ('".$first_name."','".$last_name."','".$grade."','".$date."','".$school."','".$district."','".$category."','".$status."')");
        
    }
    //adding jets material
    if(isset($_POST["add_material"]))
    {
        $poster = $det["school"];
        $material_name = htmlspecialchars($_POST["material_name"]);
        $category = htmlspecialchars($_POST["category"]);

        $material_file = $_FILES["material_file"]["name"];
        $tempname = $_FILES["material_file"]["tmp_name"];
        $folder = "../documents/".$material_file;

        move_uploaded_file($tempname,$folder);

        $insert_data = mysqli_query($conf,"INSERT INTO material(material_name,material_category,material_location,posted_by) VALUES (
        '".$material_name."','".$category."','".$folder."','".$poster."'
        )");
    }
    //adding jets report
    if(isset($_POST["add_report"]))
    {
        $poster = $det["school"];
        $category = htmlspecialchars($_POST["category"]);
        $full_name = htmlspecialchars($_POST["pupil"]);
        $section = htmlspecialchars($_POST["level"]);

        $material_file = $_FILES["material_file"]["name"];
        $tempname = $_FILES["material_file"]["tmp_name"];
        $folder = "../reports/".$material_file;

        move_uploaded_file($tempname,$folder);

        $insert_data = mysqli_query($conf,"INSERT INTO reports(full_name,school,category,section_name,location) VALUES (
        '".$full_name."','".$poster."','".$category."','".$section."','".$folder."'
        )");
    }

?>