<?php

/*Student API*/


/*Fetching API*/


/* Attempt to connect to MySQL database */
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'Restax_final');

define('DB_PASSWORD', 'Restax_final123');

define('DB_NAME', 'Restax_api_data'); 

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

$get_course = $request->getAttribute('course_id');
$get_season = $request->getAttribute('season_id');
$get_exams = $request->getAttribute('exams_id');
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$response=array();



//$sql="SELECT * FROM seated_students WHERE date ='2019-12-12'";
if(isset($get_course)&&isset($get_season)&&isset($get_exams))
{
	$sql="SELECT seated_students.*,course.course_name,season.seasonname,Exams.examname,set_rooms.room_name FROM seated_students INNER JOIN course ON course.course_id = seated_students.course_id INNER JOIN season ON season.id = seated_students.season_id INNER JOIN Exams ON Exams.id = seated_students.exams_id INNER JOIN set_rooms ON set_rooms.room_id = seated_students.room_id WHERE seated_students.course_id = '$get_course' AND seated_students.season_id = '$get_season' AND seated_students.exams_id = '$get_exams'";
}
elseif(isset($get_course)&&isset($get_season)){
$sql="SELECT seated_students.*,course.course_name,season.seasonname,Exams.examname,set_rooms.room_name FROM seated_students INNER JOIN course ON course.course_id = seated_students.course_id INNER JOIN season ON season.id = seated_students.season_id INNER JOIN Exams ON Exams.id = seated_students.exams_id INNER JOIN set_rooms ON set_rooms.room_id = seated_students.room_id WHERE seated_students.course_id = '$get_course' AND seated_students.season_id = '$get_season'";
}
elseif(isset($get_course)){
$sql="SELECT seated_students.*,course.course_name,season.seasonname,Exams.examname,set_rooms.room_name FROM seated_students INNER JOIN course ON course.course_id = seated_students.course_id INNER JOIN season ON season.id = seated_students.season_id INNER JOIN Exams ON Exams.id = seated_students.exams_id INNER JOIN set_rooms ON set_rooms.room_id = seated_students.room_id WHERE seated_students.course_id = '$get_course'";
}
else{
	$sql="SELECT seated_students.*,course.course_name,season.seasonname,Exams.examname,set_rooms.room_name FROM seated_students INNER JOIN course ON course.course_id = seated_students.course_id INNER JOIN season ON season.id = seated_students.season_id INNER JOIN Exams ON Exams.id = seated_students.exams_id INNER JOIN set_rooms ON set_rooms.room_id = seated_students.room_id ";
}


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

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

      $user=$row;

    }

   // echo json_encode($user);

for($i=0;$i<count($user);$i++){
$user[$i]['student_roll'] = json_decode($user[$i]['student_roll']);
$user[$i]['papers_shortcode'] = json_decode($user[$i]['papers_shortcode']);
$user[$i]['papers_id'] = json_decode($user[$i]['papers_id']);

}


echo json_encode($user, JSON_PRETTY_PRINT);




?>