
<?php

$con = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

$course_id = $request->getAttribute('course_id');
$session_id=$request->getAttribute('session_id');
$dept_id=$request->getAttribute('dept_id');
$level_id=$request->getAttribute('level_id');
$year=$request->getAttribute('year');
$term=$request->getAttribute('term');
$section=$request->getAttribute('section');


$response=array();

///total_students
if ($total_students=="") {
  $total_students="0";
 }
 if ($all_clear_students=="") {
  $all_clear_students="0";
 }
 if ($detained_students=="") {
  $detained_students="0";
 }
 if ($buffered_students=="") {
  $buffered_students="0";
 }
if(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&isset($year)&&isset($term)&&isset($section)){
$sql=("SELECT student_name  from set_student_season  WHERE course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year AND term=$term AND section=$section" );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&isset($year)&&isset($term)){
$sql=("SELECT student_name  from set_student_season  WHERE course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year AND term=$term" );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&($year)){
$sql=("SELECT student_name  from set_student_season  WHERE course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year"  );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)){
$sql=("SELECT student_name  from set_student_season  WHERE course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id " );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)){
$sql=("SELECT student_name  from set_student_season  WHERE course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id" );
}

elseif(isset($course_id)&&isset($session_id)){
$sql=("SELECT student_name  from set_student_season  WHERE course_id=$course_id AND session_id=$session_id");
}

elseif(isset($course_id)){
$sql=("SELECT student_name  from set_student_season  WHERE course_id=$course_id");
}

else{
$sql=("SELECT student_name  from set_student_season");
}
$result=mysqli_query($con,$sql);

    while ($row1[]=mysqli_fetch_assoc($result)) {  

      $total_students=count($row1);

	}

///all_clear_students

if(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&isset($year)&&isset($term)&&isset($section)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=0 AND buffered=0 AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year AND term=$term AND section=$section" );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&isset($year)&&isset($term)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=0 AND buffered=0 AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year AND term=$term" );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&($year)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=0 AND buffered=0 AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year"  );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=0 AND buffered=0 AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id " );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=0 AND buffered=0 AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id" );
}

elseif(isset($course_id)&&isset($session_id)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=0 AND buffered=0 AND course_id=$course_id AND session_id=$session_id");
}

elseif(isset($course_id)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=0 AND buffered=0 AND course_id=$course_id");
}

else{
$sql=("SELECT student_name  from set_student_season WHERE detained=0 AND buffered=0");
}

$result=mysqli_query($con,$sql);

    while ($row2[]=mysqli_fetch_assoc($result)) {  

      $all_clear_students=count($row2);

	}

///detained_students

if(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&isset($year)&&isset($term)&&isset($section)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=1  AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year AND term=$term AND section=$section" );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&isset($year)&&isset($term)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=1  AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year AND term=$term" );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&($year)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=1  AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year"  );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=1  AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id " );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=1  AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id" );
}

elseif(isset($course_id)&&isset($session_id)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=1  AND course_id=$course_id AND session_id=$session_id");
}

elseif(isset($course_id)){
$sql=("SELECT student_name  from set_student_season  WHERE detained=1  AND course_id=$course_id");
}

else{
$sql=("SELECT student_name  from set_student_season WHERE detained=1");
}

$result=mysqli_query($con,$sql);

    while ($row3[]=mysqli_fetch_assoc($result)) {  

      $detained_students=count($row3);

	}
	
	
	
	///buffered_students

if(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&isset($year)&&isset($term)&&isset($section)){
$sql=("SELECT student_name  from set_student_season  WHERE buffered=1 AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year AND term=$term AND section=$section" );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&isset($year)&&isset($term)){
$sql=("SELECT student_name  from set_student_season  WHERE buffered=1 AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year AND term=$term" );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)&&($year)){
$sql=("SELECT student_name  from set_student_season  WHERE buffered=1 AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id AND year=$year"  );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)&&isset($level_id)){
$sql=("SELECT student_name  from set_student_season  WHERE buffered=1 AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id AND level_id=$level_id " );
}

elseif(isset($course_id)&&isset($session_id)&&isset($dept_id)){
$sql=("SELECT student_name  from set_student_season  WHERE buffered=1 AND course_id=$course_id AND session_id=$session_id AND dept_id=$dept_id" );
}

elseif(isset($course_id)&&isset($session_id)){
$sql=("SELECT student_name  from set_student_season  WHERE buffered=1 AND course_id=$course_id AND session_id=$session_id");
}

elseif(isset($course_id)){
$sql=("SELECT student_name  from set_student_season  WHERE buffered=1 AND course_id=$course_id");
}

else{
$sql=("SELECT student_name  from set_student_season WHERE buffered=1");
}
$result=mysqli_query($con,$sql);

    while ($row4[]=mysqli_fetch_assoc($result)) {  

      $buffered_students=count($row4);

	}
	
	
echo '[{"total_students":"'.$total_students.'","all_clear_students":"'.$all_clear_students.'","detained_students":"'.$detained_students.'","buffered_students":"'.$buffered_students.'"}]';
?>