<?php header("Content-Type:application/json");
if(isset($_GET['matric_no']) && isset($_GET['session']) && isset($_GET['semester_num']) && isset($_GET['course_code'])){
	
	include("../connect.php");
	
	$course_code=strtolower($_GET['course_code']);
	$matric_no=strtolower($_GET['matric_no']);
	$ses_len=((int)strlen($_GET['session']))/2;
	$session=substr($_GET['session'],0,$ses_len).'/'.substr($_GET['session'],$ses_len);
	$semester_num=$_GET['semester_num'];
	$status='success';
	
	$aga=mysqli_query($con,"select * from reg_course where LCASE(matric_no)='$matric_no' AND LCASE(course_code)='$course_code' AND session='$session' AND semester_num='$semester_num'");
	$cha=mysqli_fetch_assoc($aga);
	
	
	if(mysqli_num_rows($aga)>0 && strtolower($cha['course_code'])==$course_code && strtolower($cha['matric_no'])==$matric_no){
		response($matric_no,$course_code,$session,$semester_num,$status);
	}else{
		response(NULL, NULL, NULL, NULL, 'failed');
	}
	
	}else{
		response(NULL, NULL, NULL, NULL, 'failed');
		}

function response($matric_no,$course_code,$session,$semester_num,$status){
	$response['matric_no'] = $matric_no;
	$response['course_code'] = $course_code;
	$response['session'] = $session;
	$response['semester_num'] = $semester_num;
	$response['status'] = $status;
	
	$json_response = json_encode($response);
	echo $json_response;
}
?>
