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

$id = $_REQUEST['id'];

if ($id == null || $id == "") {
    echo json_encode(array('status' => 0, 'msg' => 'paper id is needed'));
    return;
}

$folderName = array("key_notes" => "keynotes", "practical_projects"=>"practicalprojects", "key_terms"=>"keyterms", "mind_map"=>"mindmap");

$resQue = $db->delete("assignment_new", "where id='" . $id . "'");

$imageFileData = $db->getRows("SELECT name,type FROM assignment_files WHERE assignment_id='$id'");

foreach ($imageFileData as $item) {

    $type   = $item['type'];
    $folder = $folderName[$type];

    unlink("../../uploads/$folder/" . $item['name']);
}

$flgUp = $db->delete("assignment_files", "where assignment_id='$id'");

if ($flgUp != "") {
    echo json_encode(array('status' => 1, 'msg' => 'Assignment deleted successfully'));

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