<?php
include 'db.php';

$students_in_my_class = 0;
$active_examinations = 0;
$my_subjects = 0;
$passed_exam = 0;
$failed_exam = 0;
$attended_exams = 0;
$locked_exams = 0;
$notice = 0;
$mycategory=$_GET["category"];
$myid=$_GET["id"];

$sql = "SELECT * FROM tbl_users WHERE category = '$mycategory'";
$result = $con->query($sql);

if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
     $students_in_my_class++;
    }
} else {

}

$sql = "SELECT * FROM tbl_examinations WHERE category = '$mycategory' AND status = 'Active'";
$result = $con->query($sql);

if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
     $active_examinations++;
    }
} else {

}


$sql = "SELECT * FROM tbl_subjects WHERE category = '$mycategory'";
$result = $con->query($sql);

if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
     $my_subjects++;
    }
} else {

}

$sql = "SELECT * FROM tbl_assessment_records WHERE student_id = '$myid' AND status = 'PASS'";
$result = $con->query($sql);

if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
     $passed_exam++;
    }
} else {

}

$sql = "SELECT * FROM tbl_assessment_records WHERE student_id = '$myid' AND status = 'FAIL'";
$result = $con->query($sql);

if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
     $failed_exam++;
    }
} else {

}


$sql = "SELECT * FROM tbl_assessment_records WHERE student_id = '$myid'";
$result = $con->query($sql);

if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
     $attended_exams++;
    }
} else {

}


$sql = "SELECT * FROM tbl_examinations WHERE category = '$mycategory' AND status = 'Inactive'";
$result = $con->query($sql);

if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
     $locked_exams++;
    }
} else {

}

$sql = "SELECT * FROM tbl_notice";
$result = $con->query($sql);

if ($result->num_rows > 0) {
   
    while($row = $result->fetch_assoc()) {
     $notice++;
    }
} else {

}

if(!empty($students_in_my_class))
{
	$data=array('students_in_my_class'=>"$students_in_my_class",'active_examinations'=>"$active_examinations",'my_subjects'=>"$my_subjects",'notice'=>"$notice");
	$response=array('status' => "true",'Dasboard_details' => $data); 
	echo json_encode($response);
}
else
{
    $response=array('status' => "false",'Message' => "Login Failed");
    echo json_encode($response);
}
$con->close();