
<?php

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

$course_id = $request->getAttribute('course_id');
$season_id=$request->getAttribute('season_id');
$exams_id=$request->getAttribute('exams_id');
$date_time=$request->getAttribute('date_time');



$response=array();

///total_students

if ($total_students=="") {
  $total_students="0";
 }
 
 if(isset($course_id)&&isset($season_id)&&isset($exams_id)&&isset($date_time)){
	$sql="SELECT proctors_sheet.course_id, proctors_sheet.season_id, proctors_sheet.exams_id, proctors_sheet.date_time, 
	proctors_sheet.proctor_id, proctors_sheet.room,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name, faculty.Staff_number 
	from (proctors_sheet  INNER JOIN course ON course.course_id=proctors_sheet.course_id 
 INNER JOIN season ON season.id=proctors_sheet.season_id
 INNER JOIN Exams ON Exams.id=proctors_sheet.exams_id
 INNER JOIN faculty ON faculty.id=proctors_sheet.proctor_id) WHERE proctors_sheet.course_id='$course_id' AND proctors_sheet.season_id='$season_id' 
 AND proctors_sheet.exams_id='$exams_id' AND proctors_sheet.date_time='$date_time'";
}
elseif(isset($course_id)&&isset($season_id)&&isset($exams_id)){
	$sql="SELECT proctors_sheet.course_id, proctors_sheet.season_id, proctors_sheet.exams_id, proctors_sheet.date_time, 
	proctors_sheet.proctor_id, proctors_sheet.room,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name, faculty.Staff_number 
	from (proctors_sheet  INNER JOIN course ON course.course_id=proctors_sheet.course_id 
 INNER JOIN season ON season.id=proctors_sheet.season_id
 INNER JOIN Exams ON Exams.id=proctors_sheet.exams_id
 INNER JOIN faculty ON faculty.id=proctors_sheet.proctor_id) WHERE proctors_sheet.course_id='$course_id' AND proctors_sheet.season_id='$season_id' AND proctors_sheet.exams_id='$exams_id'";
}
elseif(isset($course_id)&&isset($season_id)){
	$sql="SELECT proctors_sheet.course_id, proctors_sheet.season_id, proctors_sheet.exams_id, proctors_sheet.date_time, 
	proctors_sheet.proctor_id, proctors_sheet.room,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name, faculty.Staff_number 
	from (proctors_sheet  INNER JOIN course ON course.course_id=proctors_sheet.course_id 
 INNER JOIN season ON season.id=proctors_sheet.season_id
 INNER JOIN Exams ON Exams.id=proctors_sheet.exams_id
 INNER JOIN faculty ON faculty.id=proctors_sheet.proctor_id) WHERE proctors_sheet.course_id='$course_id' AND proctors_sheet.season_id='$season_id'";
}
elseif(isset($course_id)){
	$sql="SELECT proctors_sheet.course_id, proctors_sheet.season_id, proctors_sheet.exams_id, proctors_sheet.date_time, 
	proctors_sheet.proctor_id, proctors_sheet.room,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name, faculty.Staff_number 
	from (proctors_sheet  INNER JOIN course ON course.course_id=proctors_sheet.course_id 
 INNER JOIN season ON season.id=proctors_sheet.season_id
 INNER JOIN Exams ON Exams.id=proctors_sheet.exams_id
 INNER JOIN faculty ON faculty.id=proctors_sheet.proctor_id) 	WHERE proctors_sheet.course_id='$course_id'";
}
else{
	$sql="SELECT proctors_sheet.course_id, proctors_sheet.season_id, proctors_sheet.exams_id, proctors_sheet.date_time, 
	proctors_sheet.proctor_id, proctors_sheet.room,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name, faculty.Staff_number 
	from (proctors_sheet  INNER JOIN course ON course.course_id=proctors_sheet.course_id 
 INNER JOIN season ON season.id=proctors_sheet.season_id
 INNER JOIN Exams ON Exams.id=proctors_sheet.exams_id
 INNER JOIN faculty ON faculty.id=proctors_sheet.proctor_id) ";
}
$result=mysqli_query($con,$sql);

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

      $total_students=count($row1);

	}


	echo json_encode($total_students);

?>