<?php
include("../../db.php");
error_reporting(E_ALL);
header("Access-Control-Allow-Origin: * ");

$file_name = $_REQUEST['file_name'];
$file_type = $_REQUEST['file_type'];

if ($file_name == null || $file_name == "" || $file_type == null || $file_type == "") {
    echo json_encode(array('status' => 0, 'msg' => 'file name is needed'));
    return;
}

$resFile = $db->delete("assignment_files","where name='".$file_name."' ");

$folder = getPath($file_type);

if($folder != ""){
unlink("../../uploads/$folder/" . $file_name);   
}

if ($resFile != "") {
    echo json_encode(array('status' => 1, 'msg' => 'File deleted Successfully', "file_name"=>$file_name));

} else {
    echo json_encode(array('status' => 0, 'msg' => 'Unable to delete file. Please Try Again..!'));
}

function getPath($type)
{

    switch ($type) {
        case "key_terms": return "keyterms";

        case "mind_map": return "mindmap";

        case "key_notes": return "keynotes";

        case "practical_projects": return "practicalprojects";

        default: return "";
    }
}