<?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=$request->getAttribute('date');
	 $time=$request->getAttribute('time');
     $proctor_id=$request->getAttribute('proctor_id');
     


$response=array();

/*
if(isset($course_id)&&isset($season_id)&&isset($exams_id)&&isset($date_time)&&isset($proctor_id)){
	$sql="SELECT submit_answer_script.course_id, submit_answer_script.season_id, submit_answer_script.exams_id, submit_answer_script.date_time, 
	submit_answer_script.proctor_id,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name
	from (submit_answer_script  INNER JOIN course ON course.course_id=submit_answer_script.course_id 
 INNER JOIN season ON season.id=submit_answer_script.season_id
 INNER JOIN Exams ON Exams.id=submit_answer_script.exams_id
  INNER JOIN faculty ON faculty.id=submit_answer_script.proctor_id
 )WHERE submit_answer_script.course_id='$course_id' AND submit_answer_script.season_id='$season_id' 
 AND submit_answer_script.exams_id='$exams_id' AND submit_answer_script.date_time='$date_time' AND submit_answer_script.proctor_id='$proctor_id'";
}
*/

if(isset($course_id)&&isset($season_id)&&isset($exams_id)&&isset($date)&&isset($time)){
	$sql="SELECT submit_answer_script.course_id, submit_answer_script.season_id, submit_answer_script.exams_id, 
	submit_answer_script.date, submit_answer_script.time, 
	submit_answer_script.proctor_id,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name
	from (submit_answer_script  INNER JOIN course ON course.course_id=submit_answer_script.course_id 
 INNER JOIN season ON season.id=submit_answer_script.season_id
 INNER JOIN Exams ON Exams.id=submit_answer_script.exams_id
  INNER JOIN faculty ON faculty.id=submit_answer_script.proctor_id
 )WHERE submit_answer_script.course_id='$course_id' AND submit_answer_script.season_id='$season_id' 
 AND submit_answer_script.exams_id='$exams_id' AND submit_answer_script.date='$date' AND submit_answer_script.time='$time'";
}

elseif(isset($course_id)&&isset($season_id)&&isset($exams_id)&&($date)){
	$sql="SELECT submit_answer_script.course_id, submit_answer_script.season_id, submit_answer_script.exams_id,
	submit_answer_script.date, submit_answer_script.time, 
	submit_answer_script.proctor_id,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name
	from (submit_answer_script  INNER JOIN course ON course.course_id=submit_answer_script.course_id 
 INNER JOIN season ON season.id=submit_answer_script.season_id
 INNER JOIN Exams ON Exams.id=submit_answer_script.exams_id
  INNER JOIN faculty ON faculty.id=submit_answer_script.proctor_id
 )WHERE submit_answer_script.course_id='$course_id' AND submit_answer_script.season_id='$season_id' 
 AND submit_answer_script.exams_id='$exams_id' AND submit_answer_script.date='$date'";
}
elseif(isset($course_id)&&isset($season_id)&&isset($exams_id)){
	$sql="SELECT submit_answer_script.course_id, submit_answer_script.season_id, submit_answer_script.exams_id,
	submit_answer_script.date, submit_answer_script.time, 
	submit_answer_script.proctor_id,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name
	from (submit_answer_script  INNER JOIN course ON course.course_id=submit_answer_script.course_id 
 INNER JOIN season ON season.id=submit_answer_script.season_id
 INNER JOIN Exams ON Exams.id=submit_answer_script.exams_id
  INNER JOIN faculty ON faculty.id=submit_answer_script.proctor_id
 )WHERE submit_answer_script.course_id='$course_id' AND submit_answer_script.season_id='$season_id' 
 AND submit_answer_script.exams_id='$exams_id'";
}
elseif(isset($course_id)&&isset($season_id)){
	$sql="SELECT submit_answer_script.course_id, submit_answer_script.season_id, submit_answer_script.exams_id,
	submit_answer_script.date, submit_answer_script.time, 
	submit_answer_script.proctor_id,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name
	from (submit_answer_script  INNER JOIN course ON course.course_id=submit_answer_script.course_id 
 INNER JOIN season ON season.id=submit_answer_script.season_id
 INNER JOIN Exams ON Exams.id=submit_answer_script.exams_id
  INNER JOIN faculty ON faculty.id=submit_answer_script.proctor_id
 ) WHERE submit_answer_script.course_id='$course_id' AND submit_answer_script.season_id='$season_id'";
}
elseif(isset($course_id)){
	$sql="SELECT submit_answer_script.course_id, submit_answer_script.season_id, submit_answer_script.exams_id, 
	submit_answer_script.date, submit_answer_script.time, 
	submit_answer_script.proctor_id,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name
	from (submit_answer_script  INNER JOIN course ON course.course_id=submit_answer_script.course_id 
 INNER JOIN season ON season.id=submit_answer_script.season_id
 INNER JOIN Exams ON Exams.id=submit_answer_script.exams_id
  INNER JOIN faculty ON faculty.id=submit_answer_script.proctor_id
 )WHERE submit_answer_script.course_id='$course_id'";
}
else{
	$sql="SELECT submit_answer_script.course_id, submit_answer_script.season_id,
	submit_answer_script.exams_id, submit_answer_script.date, submit_answer_script.time, 
	submit_answer_script.proctor_id,
	course.course_name, season.seasonname, Exams.examname, faculty.Faculty_name
	from (submit_answer_script  INNER JOIN course ON course.course_id=submit_answer_script.course_id 
 INNER JOIN season ON season.id=submit_answer_script.season_id
 INNER JOIN Exams ON Exams.id=submit_answer_script.exams_id
  INNER JOIN faculty ON faculty.id=submit_answer_script.proctor_id
 )";

}

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

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

      $user=$row;

	}

echo json_encode($user);

?>