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

$qid = $_REQUEST['qid'];

$status = 0;
$msg = 'Unable to delete file. Please Try Again..!';

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

$resQues = $db->delete("practice_questions","where id='".$qid."'");

if ($resQues != ""){
    $status = 1;
    $msg = 'File deleted Successfully';

    $queFiles = $db->getRows("SELECT name FROM practice_question_files WHERE question_id='$qid'");

    foreach ($queFiles as $fileName) {
        unlink("../../uploads/practice/" . $fileName['name']);
    }

    $db->delete("practice_question_files","where question_id='".$qid."'");

}

echo json_encode(array('status' => $status, 'msg' => $msg));