<?php //if (!$session->is_logged_in()){redirect_to("index.php");}	
?>

<?php require_once("includes/initialize.php");
global $database;
// $id=$session->user_id;
// $biodata = Biodata::find_by_id($session->user_id);
$user_data = Userdata::find_by_id($session->user_id);
$biodata = Biodata::find_by_id($user_data->formno,$user_data->email);
$session_class = SESSIONCLASS::session_authenticate();
$dp = DEPARTMENTCLASS::department_authenticate($biodata->courses);
$display_course = COURSECLASS::fetch_all_course($biodata->courses, $biodata->programme, $session_class->semester);

 $dept = $biodata->courses;
 $level = $biodata->programme;
//  $semester =$session_class->semester;
//echo " Please Select Cousres";
	$matricno = $biodata->formno;
 $level = $level." "."I";

if(isset($_GET['course_code']))
{
	$matricno = $biodata->formno;
// 	$ses_sem_id = $session_class->ses_sem_id;
// 	$semester = $session_class->semester;
    $semester = 'SECOND';
	$dept = $biodata->courses;
	$date=date('Y-m-d');

	if ($level == 'ND II')
	{
		if ($_GET['course_code'] == "")
		{
			echo "Please Select Cousres";
		}
		else
		{	
			$courses = $_GET['course_code'];
			$query = "
			INSERT INTO ndii_tbl (matricno, semester, department, courses, regDate) 
			VALUES('$matricno','$semester','$dept', '$courses', '$date')
			";
			/*$statement = $connect->prepare($query);
			$statement->execute(
				array(			
					':matricno'		=>	$_POST['matricno'],
					':ses_sem_id'	=>	$_POST['ses_sem_id'],
					':department'		=>	$_POST['department'],
					':course'			=>	$_POST['courses'],
					':date'			=>	$_POST['date']
				)
			);*/
			$result = $database->query($query);

			if(isset($result))
			{
				echo 'Registration Successful';//.$courses;
			}
		}
	}
	elseif ($level == 'ND I')
	{
		if ($_GET['course_code'] == "")
		{
			echo "Please Select Cousres";
		}
		else
		{
			$courses = $_GET['course_code'];
			$query = "
			INSERT INTO ndi_tbl (matricno, semester, department, courses, regDate) 
			VALUES('$matricno','$semester','$dept', '$courses', '$date')
			";
			/*$statement = $connect->prepare($query);
			$statement->execute(
				array(			
					':matricno'		=>	$_POST['matricno'],
					':ses_sem_id'	=>	$_POST['ses_sem_id'],
					':department'		=>	$_POST['department'],
					':course'			=>	$_POST['courses'],
					':date'			=>	$_POST['date']
				)
			);*/
			$result = $database->query($query);

			if(isset($result))
			{
				echo 'Registration Successful';//.$courses;
			}
		}
	}
	elseif ($level == 'HND I')
	{
		if ($_GET['course_code'] == "")
		{
			echo "Please Select Cousres Hnd1";
		}
		else
		{
			$courses = $_GET['course_code'];
			$query = "
			INSERT INTO hndi_tbl (matricno, semester, department, courses, regDate) 
			VALUES('$matricno','$semester','$dept', '$courses', '$date')
			";
		/*	$statement = $connect->prepare($query);
			$statement->execute(
				array(			
					':matricno'		=>	$_POST['matricno'],
					':ses_sem_id'	=>	$_POST['ses_sem_id'],
					':department'		=>	$_POST['department'],
					':course'			=>	$_POST['courses'],
					':date'			=>	$_POST['date']
				)
			);*/
			$result = $database->query($query);
			//$result = $statement->fetchAll();
			if(isset($result))
			{
				echo 'Registration Successful';
			}
		}
	}elseif ($level == 'HND II')
	{
		if ($_GET['course_code'] == "")
		{
			echo " Please Select Cousres";
		}
		else
		{
			$courses = $_GET['course_code'];
			$query = "
			INSERT INTO hndii_tbl (matricno, semester, department, courses, regDate) 
			VALUES('$matricno','$semester','$dept', '$courses', '$date')
			";
			/*$statement = $connect->prepare($query);
			$statement->execute(
				array(			
					':matricno'		=>	$_POST['matricno'],
					':ses_sem_id'	=>	$_POST['ses_sem_id'],
					':department'		=>	$_POST['department'],
					':course'			=>	$_POST['courses'],
					':date'			=>	$_POST['date']
				)
			);*/
			$result = $database->query($query);

			if(isset($result))
			{
				echo 'Registration Successful';//.$courses;
			}
		}
	}
}
else
{
	echo "Register no Post oooo".$matricno;
}
// echo " Here are the courses you register for:".$matricno;

?>