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

$session = $_REQUEST['session'];
$class = $_REQUEST['class'];
$idno = $_REQUEST['idno'];

$status = 0;
$examTerms = array();

//$resPattern = $db->getVal("select result_pattern from tbl_info where id = '1'");

//$examRes = $db->getRows("select id,term_name,term_type from exam_term_result where status = '1' AND term_type = '$resPattern'");

$examRes = $db->getRows("select id,name AS term_name, 0 AS term_type from examname where app_visibilty = '1'");

if (count($examRes) > 0){
    $status = 1;
    $examTerms = $examRes;
}

$classMessage = $db->getVal("SELECT message FROM result_message WHERE class = '$class' AND session = '$session'");
if (!$classMessage || $classMessage == ''){
    $classMessage = "Result";
}

$termArray = array("Select Term");

$termsList = $db->getRows("SELECT DISTINCT(term) FROM term_permission WHERE result_view = '1' AND session = '$session' ORDER BY id ASC ");
foreach ($termsList as $item) {
    $termArray[] = $item['term'];
}

if (in_array('Term2', $termArray)){
    $termArray[] = "Final";
}

echo json_encode(array("status" => $status, "data" => $examTerms, "class_msg"=>$classMessage, "term_list"=> $termArray));