<?php



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

$course_id = $request->getAttribute('course_id');
$dept_id = $request->getAttribute('dept_id');
$level_id = $request->getAttribute('level_id');
$year = $request->getAttribute('year');
$term = $request->getAttribute('term');
// $set_grade_id=$request->getMethod('set_grade_id');                       
 // $dept_id=$request->getParsedBody()['dept_id'];
 // $level_id=$request->getParsedBody()['level_id'];
 //  $type=$request->getParsedBody()['type'];
// $start_module='2';

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

$response=array();



if(isset($dept_id)&&isset($level_id)&&isset($year)&&isset($term)){
		$sql="SELECT * FROM level AND dept_id='$dept_id' AND level_id='$level_id' AND year='$year'AND term='$term'";
}
elseif(isset($dept_id)&&isset($level_id)&&isset($year)){
		$sql="SELECT * FROM level WHERE  dept_id='$dept_id' AND level_id='$level_id' AND year='$year'";
}
elseif(isset($dept_id)&&isset($level_id)){
		$sql="SELECT * FROM level WHERE dept_id='$dept_id' AND level_id='$level_id'";
}
elseif(isset($dept_id)){
		$sql="SELECT * FROM level WHERE dept_id='$dept_id'";
}

else{
		$sql="SELECT * FROM level";
}


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




?>