<?php
include("../../db.php");
header('Content-Type: application/json');

$class   = $_GET['class'];
$section = $_GET['section'];
$sub_id  = $_GET['sub_id'];
$term_id = $_GET['term_id'];
$session = $_GET['session'];

$secWhere = "";
if ($section != ''){
    $secWhere = "AND section = '$section'";
}

$status = 1;

$omrPaperArray = new stdClass();
$omrPaper = $db->getRow("SELECT * from omr_paper WHERE class = '$class' $secWhere AND subject = '$sub_id' AND exam = '$term_id' AND session = '$session' ");
if ($omrPaper && count($omrPaper) > 0){
    $omrQuestions = $db->getRows("SELECT id,question,answer,mark FROM omr_question WHERE paper = '$omrPaper[id]' AND session = '$session' ORDER BY question ASC");

    if (count($omrQuestions) == 0){
        $status = 0;
    }

    $omrPaper['question_count'] = count($omrQuestions);
    $omrPaper['paper_mark'] = count($omrQuestions);
    $omrPaper['questions'] = $omrQuestions;

    $omrPaperArray = $omrPaper;
}else{
    $status = 0;
}

echo json_encode(array("status" => $status, "data" => $omrPaperArray));