<?php
include('config.php');
session_start();
$my_campus = $_SESSION['campus'];

if($_SERVER["REQUEST_METHOD"] == "POST")
{   
    $topic = $_POST["topic"];
    $title = $_POST["title"];
    $instructions = $_POST["instructions"];
    $link = $_POST["link"];
    $due_date = $_POST['due_date'];
    $converted_due_date = date("m-d-Y", strtotime($due_date));
    $due_time = $_POST["due_time"];
    $converted_due_time = date("h:i A", strtotime($due_time));

    if($converted_due_date == "01-01-1970" || $converted_due_date == "" || $converted_due_time == "12:00 AM" || $converted_due_time == ""){
        $converted_due_date = "None";
        $converted_due_time = "None";
    }
    if($instructions == ""){
        $instructions = "None";
    }

    // Get the current time adn date
    date_default_timezone_set('Asia/Manila');
    $date = date("m-d-Y");
    $time = date("h:i A");
    
    $sql = "INSERT INTO evaluations (`Topic`, `Instructions`, `Link`, `Due_Date`, `Due_Time`, `Date_Posted`, `Time_Posted`, `Campus`) VALUES ('$topic', '$instructions', '$link', '$converted_due_date', '$converted_due_time', '$date', '$time', '$my_campus')";
    if (mysqli_query($db, $sql)){
        echo '<script>alert("Evaluation was posted successfully!");</script>';
        echo '<script>document.location = "evaluations.php"</script>';
    }else{
        echo mysqli_error($db);
    }
    
}
?>