<?php
 error_reporting(E_ALL);
 ini_set('display_errors', 1);

 include('../../../config/config.php');
 
 $campus = $_POST["campus"];
 $subjectid = $_POST["subjectid"];
 $classid = $_POST["classid"];

 $session = "SELECT * FROM `session` WHERE `sessionStatus` = 1";

 $ekeneselect = mysqli_query($link, $session);
 $ekene_get_select_details = mysqli_fetch_assoc($ekeneselect);
 $ekene_row_select = mysqli_num_rows($ekeneselect);

 $ekene_session_name = $ekene_get_select_details['sessionName'];


 $term = "SELECT * FROM `termorsemester` WHERE `status` = 1";
 $ekeneterm = mysqli_query($link, $term);
 $ekene_get_term_details = mysqli_fetch_assoc($ekeneterm);
 $ekene_row_term = mysqli_num_rows($ekeneterm);
      
 $ekene_term = $ekene_get_term_details['TermOrSemesterID'];

 $assigment = array();
 $ekene_select_totalassignment =" SELECT * FROM assignmentsettings WHERE CampusID = '$campus' AND (ClassOrDepartmentID = '$classid' OR $classid IS NULL) AND (SubjectOrCourseID = '$subjectid' OR 
$subjectid IS NULL) AND sessionID = '$ekene_session_name' AND TermOrSemesterID = '$ekene_term'";
$ekene_query_link_class = mysqli_query($link, $ekene_select_totalassignment);
$ekene_get_details_class = mysqli_fetch_assoc($ekene_query_link_class);
$ekene_row_cnt_ekene = mysqli_num_rows($ekene_query_link_class);
if ($ekene_row_cnt_ekene > 0)
{
      $assiegnmenset = $ekene_row_cnt_ekene;
}
else
{
    $assiegnmenset = 0;
}

    $select_class = "SELECT * FROM `assignmentanswer` WHERE `CampusID` = '$campus' AND (ClassOrDepartmentID = '$classid' OR $classid IS NULL) AND (SubjectOrCourseID = '$subjectid' OR 
    $subjectid IS NULL)";
    $ekene_query_link_answer = mysqli_query($link, $select_class);
    $ekene_get_details_answer = mysqli_fetch_assoc($ekene_query_link_answer);
    $ekene_row_cnt_ekeneanswer = mysqli_num_rows($ekene_query_link_answer);
    if($ekene_row_cnt_ekeneanswer > 0)
    {
        $assiegnmenanswer = $ekene_row_cnt_ekeneanswer;
    }
    else
    {
        $assiegnmenanswer = 0;
    }

    $result = $assiegnmenset - $assiegnmenanswer;
  
    $assigment = [
  
        'Notsubmitted' => $result,
     
        'Submitted' =>$assiegnmenanswer,
        'Assignmentset' =>$assiegnmenset,
    

    ];
     $json_data = json_encode($assigment);
     echo $json_data;




 ?>