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

$id = $_REQUEST['pid'];

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

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

$imageFileData = $db->getRows("SELECT name FROM practice_question_files WHERE paper_id='$id'");

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

$resFile = $db->delete("practice_question_files","where paper_id='".$id."' ");

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

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

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