<?php

include "connection.php";

$json = file_get_contents("php://input");
$data = json_decode($json, true);

$lesson = $data["lesson"];
$medium = $data["medium1"];
$quiz_number = $data["quiz_number"];

$value = [];
$response = [
    "status" => false,
    "message" => "",
    "data" => $value
];

if ($lesson == 0 || $lesson == null) {
    $response["message"] = "Please select lesson first.";
} else if ($medium == 0 || $medium == null) {
    $response["message"] = "Please select lesson language.";
} else if ($quiz_number == 0 || $quiz_number == null) {
    $response["message"] = "Please select quiz number.";
} else {

    $rows = 0;
    try {
       $rs = Database::search("SELECT * FROM `mcq` WHERE `lesson_id` = '".$lesson."' AND `medium_id` = '".$medium."' AND `question_number` = '".$quiz_number."' ");
        $rows = $rs->num_rows;

        if ($rows == 1) {
            $response["status"] = true;
            $value = $rs->fetch_assoc();
            $response["data"] = $value;
 
        } else {
            $response["status"] = false;
            $response["message"] = "MCQ Not Found";
        }

    } catch (Exception $e) {
        $response["message"] = "SQL Error: " . $e->getMessage();
    }
}

header("Content-Type: application/json");
echo json_encode($response);

?>
