<?php



$errors = array();
$info = array();
$info_success = array();



//check the id passed
if(isset($_POST['aid']))
{
	$id =  $_POST['aid'];
}



//check the id passed
//if(isset($_POST['prog_type']))
//{
//	$programme_type =  $_POST['prog_type'];
//}







//validate the Programme type
  if($_POST['programme_type'] =='0')
  {
	   
	  $_SESSION['pt'] = mysqli_real_escape_string($dbc, $_POST['programme_type']);
	   $errors[] = '<p> * </p>';
	 
   
  }
  else
  {
	  $programme_type = mysqli_real_escape_string($dbc, $_POST['programme_type']);
	  $_SESSION['pt'] = $programme_type;
	
  }
  
  
  
  
  
  //validate the department
  if($_POST['department'] =='0')
  {
	   
	  $_SESSION['dep'] = mysqli_real_escape_string($dbc, $_POST['department']);
	   $errors[] = '<p> * </p>';
	 
   
  }
  else
  {
	  $department = mysqli_real_escape_string($dbc, $_POST['department']);
	  $_SESSION['dep'] = $department;
	
  }
  
  
    //validate the programme
  if($_POST['programme'] == '')
  {
	   $programme = (!empty($_POST['sub_programme']))? (mysqli_real_escape_string($dbc,$_POST['sub_programme'])): NULL;
       $_SESSION['prog'] = mysqli_real_escape_string($dbc, $_POST['sub_programme']);
	  // $errors[] = '<p> * </p>';
	 
   
  }
  else
  {
	  $programme = mysqli_real_escape_string($dbc, $_POST['programme']);
	  $_SESSION['prog'] = $programme;
	
  }
  

 //collect the batch
$batch = (!empty($_POST['batch']))? (mysqli_real_escape_string($dbc,$_POST['batch'])): 
 NULL;
$_SESSION['batch'] = $batch;





//collect the description
$description = (!empty($_POST['description']))? (mysqli_real_escape_string($dbc,$_POST['description'])): 
 NULL;
$_SESSION['description'] = $description;



 
 
 
if(empty($errors))
{
	//destroy session if there is no error
	unset($_SESSION['pt']);
	unset($_SESSION['dep']);
	unset($_SESSION['prog']);
	unset($_SESSION['batch']);
	unset($_SESSION['description']);
	
	
	
	//collect the department admitted to 
	$dept_title = get_applicant_department_title($department);
	
	
	//collect the programme admitted to  so as to pass information
	$prog_title = get_applicant_programme_title($programme);
	
	
	
	$dep = get_dep_id_prog_id($programme);
	
	//get school id for a particular programme so to attached
    $school_id = get_school_id_by_programme($programme);
	

	 //check if the query is for adding den add
	
	
		$q = "UPDATE `applicants_nce` SET `type_id`='$programme_type', `school_id`='$school_id',`department_id`='$department',`programme_id`='$programme', admission_status = 1, batch ='$batch',
			 admission_criteria = '$description'  
			 
			 WHERE id = '$id'";
							
							
			  $r = mysqli_query($dbc,$q);
		  
		  if($r)
		  {
			  $info_success['success'] =  'successfully admitted into Dept: '.$dept_title.', Programme:'.$prog_title.'';
			  header("Location: gateway.php?act=view_applicant_profile&is=".urlencode($info_success['success'])."&id=".md5('profile')."&xd=".$id.""); //is - info success
			  
					  
		  }
		  else
		  {
			  $errors['error'] =  'Not done due to a system error. We apologize for any inconvenience.';
											  
			   header("Location: gateway.php?act=view_applicant_profile&error=".urlencode($errors['error'])."&id=".md5('profile')."&xd=".$id."");
		  }
	
}
else
{//stay back in departments


	$errors['error'] =  'Not done, Please re-select and Fill the form appropriately, take note of <span class="ast">*</span>.';
										
	header("Location: gateway.php?act=view_applicant_profile&error=".urlencode($errors['error'])."&id=".md5('profile')."&xd=".$id."");

}




?>