<?php
include("../../db.php");
//header("Access-Control-Allow-Origin: * ");
header('Content-Type: application/json');

$session = $_GET['session'];

$arr = $db->getRows("select class from class");
$arr_sec = $db->getRows("select name from section");

$jsonc = array();

// 	 $sqlsec = "select name from section";
// 	$result1=mysql_query($sqlsec);
//   while ($rowc=mysql_fetch_assoc($result1))
foreach ($arr_sec as $rowc) {
    $jsonc[] = $rowc['name'];
}

$sqlsec = $db->getRows("select name,total from examterm");

// 	$result_term = mysql_query($sqlsec);
//   while ($rowt = mysql_fetch_assoc($result_term))
foreach ($sqlsec as $rowt) {
    $jsond[] = array("exam_name" => $rowt['name'], "max_mark" => $rowt['total']);
}

$cri = $db->getRows("select * from criteria where session = '$session' and school_id='1' group by type, class");

// 	$result_criteria = mysql_query($cri);
//   while ($rowp = mysql_fetch_assoc($result_criteria))
foreach ($cri as $rowp) {
    $jsonp[] = $rowp['type'];
}

$sql = $db->getRows("select class from class");

// 	$result = mysql_query($sql);
//   while ($row = mysql_fetch_assoc($result))
foreach ($sql as $row) {
    $jsonn[] = $row['class'];
    $json['status'] = 1;
    $json['msg'] = "successful";
    $json['data'] = array("class" => $jsonn, "section" => $jsonc, "exam_term" => $jsond, "criteria" => $jsonp, "criteria_new"=>$cri);
    //	$json['section']=$jsonc;

}

$exam_name_array = array();
$exam_name = $db->getRows("SELECT name FROM examname");
foreach ($exam_name as $item_data) {
    $exam_name_array[] = $item_data['name'];
}

$json['exam_name'] = $exam_name_array;


echo json_encode($json);
