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

    //school registration
    if(isset($_POST["register_school"]))
    {
        $school_name = htmlspecialchars($_POST["school_name"]);
        $district = htmlspecialchars($_POST["district"]);

        $register = mysqli_query($conf,"INSERT INTO schools (school_name,district) VALUES ('".$school_name."','".$district."')");
        
    }
    //staff registration
    if(isset($_POST["register_staff"]))
    {
        $default_password = "jets1234";
        $first_name = htmlspecialchars($_POST["first_name"]);
        $last_name = htmlspecialchars($_POST["last_name"]);
        $phone = htmlspecialchars($_POST["phone"]);
        $school_name = htmlspecialchars($_POST["school"]);
        $district = htmlspecialchars($_POST["district"]);
        $password = md5($default_password);

        $register_staff = mysqli_query($conf,"INSERT INTO school_admin (first_name,last_name,phone,district,school,username,password) VALUES ('".$first_name."','".$last_name."','".$phone."','".$district."','".$school_name."','".$phone."','".$password."')");
        
    }
    //adjudicator registration
    if(isset($_POST["adjudicator_register"]))
    {
        $default_password = "jets1234";
        $first_name = htmlspecialchars($_POST["first_name"]);
        $last_name = htmlspecialchars($_POST["last_name"]);
        $phone = htmlspecialchars($_POST["phone"]);
        $category = htmlspecialchars($_POST["category"]);
        $district = htmlspecialchars($_POST["district"]);
        $password = md5($default_password);

        $register_adjudicator = mysqli_query($conf,"INSERT INTO adjudicator (first_name,last_name,phone,district,category,username,password) VALUES ('".$first_name."','".$last_name."','".$phone."','".$district."','".$category."','".$phone."','".$password."')");
        
    }
    //adding jets material
    if(isset($_POST["add_material"]))
    {
        $poster = "Regonal Admin";
        $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."'
        )");
    }
    //creating a post
    if(isset($_POST["add_post"]))
    {
        $event_name = htmlspecialchars($_POST["event_name"]);
        $district = htmlspecialchars($_POST["district"]);
        $blog = htmlspecialchars($_POST["article"]);

        $event_file = $_FILES["event_file"]["name"];
        $tempname = $_FILES["event_file"]["tmp_name"];
        $folder = "../news/".$event_file;

        move_uploaded_file($tempname,$folder);

        $insert_blog = mysqli_query($conf,"INSERT INTO events(event_name,event_image,event_blog,event_district) VALUES (
        '".$event_name."','".$folder."','".$blog."','".$district."'
        )");
    }
    //create a notification
    if(isset($_POST["add_notice"]))
    {
        $notice_name = htmlspecialchars($_POST["notice"]);
        $district = htmlspecialchars($_POST["district"]);
        $article = htmlspecialchars($_POST["article"]);

        $add_notice = mysqli_query($conf,"INSERT INTO notices (notice_header,receipient,notice_content) VALUES ('".$notice_name."','".$district."','".$article."')");
        
    }

?>