<?php if (!$session->is_logged_in()) {
    redirect_to("index.php");
}
?>
<?php require_once("includes/initialize.php");
$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();
$user_data = Userdata::find_by_id($session->user_id);


echo "Student Process ID: ".$user_data->std_process_id;
 if (substr($user_data->formno,2,2)>=20){
      
       Switch(substr($user_data->formno,2,2))
      {
          case '20':$table='form_data';
          break;
          
          case '21': $table='form_data21';
          break;
          
          case '22': $table='form_data22';
      }
      
       $biodata = Biodata2::find_by_id($table,$user_data->formno, $user_data->email);
       
      
        $new_dp = DEPARTMENTCLASS::new_admin_dept($biodata->formno);
        
          if (!isset($new_dp->department)){
           $biodata->courses ='Nil';   
          }else{
        $biodata->courses = $new_dp->department;
          }
       $biodata->programme = $biodata->level;
       
       echo "<br>Department: ".$biodata->courses;
       //echo "Department: ".$biodata->department;
  
        // $pixf = substr($biodata->passport, 10);
       $dp = DEPARTMENTCLASS::department_authenticate($biodata->department);
       $pix = "http://admission.oscotechesaoke.edu.ng/passport/".trim($biodata->passport);
    
     
    
       
  }else{
     
     $biodata = Biodata::find_by_id($user_data->formno, $user_data->email); 


















$biodata = Biodata::find_by_id($session->user_id);
$session_class = SESSIONCLASS::session_authenticate();
$dp = DEPARTMENTCLASS::department_authenticate($biodata->courses);

}

   if ($biodata->courses=='Microbiology (Option)'){
       $biodata->courses='(Microbiology (Option)';
    }      

$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";

if (isset($_POST['course_code'])) {
    $matricno = $biodata->formno;
    $ses_sem_id = '$session_class->ses_sem_id';
    
    if ($biodata->courses=='Microbiology (Option)'){
        $dept='(Microbiology (Option)';
    }
    $dept = $biodata->courses;
    $date = date('Y-m-d');

    if ($biodata->programme == 'ND II') {
        if ($_POST['course_code'] == "") {
            echo " Please Select Cousres";
        } else {
            $courses = $_POST['course_code'];
            $query = "
			INSERT INTO ndii_tbl (matricno, ses_sem_id, department, courses,regDate) 
			VALUES('$matricno','$ses_sem_id','$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 = $statement->fetchAll();

            if (isset($result)) {
                echo 'done';//.$courses;
            }
        }
    } elseif ($biodata->programme == 'ND I') {
        if ($_POST['course_code'] == "") {
            echo " Please Select Cousres";
        } else {
            $courses = $_POST['course_code'];
            $query = "
			INSERT INTO ndi_tbl (matricno, ses_sem_id, department, courses, regDate) 
			VALUES('$matricno','$ses_sem_id','$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 = $statement->fetchAll();

            if (isset($result)) {
                echo 'done';//.$courses;
            }
        }
    } elseif ($biodata->programme == 'HND I') {
        if ($_POST['course_code'] == "") {
            echo " Please Select Cousres";
        } else {
            $courses = $_POST['course_code'];
            $query = "
			INSERT INTO hndi_tbl (matricno, ses_sem_id, department, courses, regDate) 
			VALUES('$matricno','$ses_sem_id','$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 = $statement->fetchAll();

            if (isset($result)) {
                echo 'done';//.$courses;
            }
        }
    } elseif ($_SESSION["level"] == 'HND II') {
        if ($_POST['course_code'] == "") {
            echo " Please Select Cousres";
        } else {
            $courses = $_POST['course_code'];
            $query = "
			INSERT INTO hndii_tbl (matricno, ses_sem_id, department, courses, regDate) 
			VALUES('$matricno','$ses_sem_id','$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 = $statement->fetchAll();

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

?>