<?php

include "../db.php";

if(isset($_POST['skip_id'])){

  

    $update_skip = "UPDATE examination SET status =2 WHERE id='$_POST[skip_id]'";

    if(mysqli_query($con, $update_skip)){

        $data = "TRUE";

    }else{

        $data =  "FALSE";

    }

    echo $data;

}

if(isset($_POST['next_option'])){

    $update_next = "UPDATE examination SET status =1, chosen_option ='$_POST[next_option]'  WHERE id='$_POST[next_id]'";

    if(mysqli_query($con, $update_next)){

        $data = "TRUE";

    }else{

        $data =  "FALSE";

    }

    echo $data;

}

if(isset($_POST['submit_id'])){

    $SelectExam = "SELECT * FROM examination WHERE exam_ref = '$_POST[submit_id]'";

    $ExamRun = mysqli_query($con, $SelectExam);

    $marks = 0;

    $TotalMarks = 0;

    foreach($ExamRun as $ArrayData){

        $SelectQuestion = "SELECT * FROM question WHERE id = '$ArrayData[question_id]'";

        $QuestionRun = mysqli_query($con, $SelectQuestion);

        $QuestionRow = mysqli_fetch_assoc($QuestionRun);

        if($ArrayData['chosen_option']==$QuestionRow['correct_option']){

            $marks += $QuestionRow['marks'];

        }

        $TotalMarks += $QuestionRow['marks'];

    }

    $update_submit = "UPDATE mocktest_result SET total_marks ='$TotalMarks' , obtained_marks ='$marks' WHERE exam_ref='$_POST[submit_id]'";

    if(mysqli_query($con, $update_submit)){

        // session_start();

        // $_SESSION["Exam_ref"] = $_POST["submit_id"];

        // $data = json_encode(array('Exam_ref' => $_SESSION['Exam_ref']));

        $data = "TRUE";

    }else{

        $data =  "FALSE";

    }

    echo $data;

}

?>