<?php
include('config.php');
if($_SERVER["REQUEST_METHOD"] == "POST")
{   
    $ID = $_POST["ID"];
    $code = $_POST["code"];
    $filename = $_POST["my_uploaded_file"];

    // Get the current time adn date
    date_default_timezone_set('Asia/Manila');
    $date = date("m/d/Y");
    $time = date("h:i A");   

    $sql = "UPDATE tasks SET `File_Link`='', `File_Status`='unsubmitted', `Date_Submitted`='$date', `Time`='$time', Notif_Status='none' WHERE `Code`='$code'";
    if (mysqli_query($db, $sql)){
        if(unlink('../submitted_files/'.$filename.'')) {
            echo '<script>alert("Unsubmitted successfully!");</script>';
            echo '<script>document.location = "view_assignment.php?ID='.$ID.'"</script>';
        } else {
            echo '<script>alert("Unsubmitted successfully, but the file was failed to remove!");</script>';
            echo '<script>document.location = "view_assignment.php?ID='.$ID.'"</script>';
        }
    }
    else{
        echo mysqli_error($db);
    }   
}
?>