<?php

/*Student API*/


/*Fetching API*/


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

define('DB_PASSWORD', 'restax@123');

define('DB_NAME', 'Restax'); 

$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');


// Check connection

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$response=array();


if(isset($course_id)&&isset($season_id)&&isset($exams_id)){
$sql="SELECT create_slots.id,create_slots.course_id,create_slots.exams_id,create_slots.season_id,create_slots.paper,create_slots.slots,course.course_name,Exams.examname,season.seasonname,set_papers.papers_shortcode FROM create_slots INNER JOIN course ON course.course_id = create_slots.course_id INNER JOIN Exams
ON Exams.id = create_slots.exams_id INNER JOIN season ON season.id=create_slots.season_id INNER JOIN set_papers ON set_papers.papers_id=create_slots.paper WHERE create_slots.course_id = '$course_id' AND create_slots.season_id = '$season_id' AND create_slots.exams_id='$exams_id'";
} 

elseif(isset($course_id)&&isset($season_id)){
$sql="SELECT create_slots.id,create_slots.course_id,create_slots.exams_id,create_slots.season_id,create_slots.paper,create_slots.slots,course.course_name,Exams.examname,season.seasonname,set_papers.papers_shortcode FROM create_slots INNER JOIN course ON course.course_id = create_slots.course_id INNER JOIN Exams
ON Exams.id = create_slots.exams_id INNER JOIN season ON season.id=create_slots.season_id INNER JOIN set_papers ON set_papers.papers_id=create_slots.paper WHERE create_slots.course_id = '$course_id' AND create_slots.season_id = '$season_id'";
}

elseif(isset($course_id)){
$sql="SELECT create_slots.id,create_slots.course_id,create_slots.exams_id,create_slots.season_id,create_slots.paper,create_slots.slots,course.course_name,Exams.examname,season.seasonname,set_papers.papers_shortcode FROM create_slots INNER JOIN course ON course.course_id = create_slots.course_id INNER JOIN Exams
ON Exams.id = create_slots.exams_id INNER JOIN season ON season.id=create_slots.season_id INNER JOIN set_papers ON set_papers.papers_id=create_slots.paper WHERE create_slots.course_id = '$course_id'";
}
else{
$sql="SELECT create_slots.id,create_slots.course_id,create_slots.exams_id,create_slots.season_id,create_slots.paper,create_slots.slots,course.course_name,Exams.examname,season.seasonname,set_papers.papers_shortcode FROM create_slots INNER JOIN course ON course.course_id = create_slots.course_id INNER JOIN Exams
ON Exams.id = create_slots.exams_id INNER JOIN season ON season.id=create_slots.season_id INNER JOIN set_papers ON set_papers.papers_id=create_slots.paper";
}


// $sql="SELECT  set_grade.set_grade_id,set_grade.course_id,set_grade.dept_id,set_grade.level_id,set_grade.range_in,set_grade.grade,department.dept_shortcode,level.level_shortcode  FROM set_grade INNER JOIN department ON department.dept_id = set_grade.dept_id INNER JOIN level ON level.level_id = set_grade.level_id WHERE course_id = '$course_id'AND dept_id = '$dept_id'";


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

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

      $user=$row;

//      $array1 = array("5","26","38","42");

// $array2 = array("15","36","38","42");

//      $user = array_intersect($array1, $array2);



    }
// foreach ($user as &$value) {
//     $intersect[] = $value;

//        $providers = array_intersect($intersect[$value]);

// }
      // echo json_encode($course_id);
      // echo json_encode($dept_id);


echo json_encode($user);





?>