<?php 

session_start(); //session start


include_once('includes/switch/sms.php');

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


//collect registration number
if(isset($_GET['regn']))
{
	$reg_no = $_GET['regn'];
}



//collect mode of entry
$entry_mode = get_mode_of_entry_from_jamb_list($reg_no);



if(isset($_POST['btncreateAccount']))
{
		
		//validate the phone_no
		if(!empty($_POST['phone_no']))
		{
		   $phone_no = mysqli_real_escape_string($dbc, $_POST['phone_no']);
		   
		   $_SESSION['phone_no'] = $phone_no;
		 
		}
		else
		{
			
			
		   $errors[] = '<p> * </p>';
		}
		
		//validate the email
		if(!empty($_POST['email']))
		{
		   $email = mysqli_real_escape_string($dbc, $_POST['email']);
		   
		   $_SESSION['email'] = $email;
		 
		}
		else
		{
			
			
		   $errors[] = '<p> * </p>';
		}

		
		if(empty($errors))
		{
			//destroy session if there is no error
			 unset($_SESSION['phone_no']); 
			 unset($_SESSION['email']); 
			
				
				
			
				$q = "SELECT * FROM  applicants_jamb_list WHERE reg_no ='$reg_no'";
									
									
				$r = mysqli_query($dbc,$q);
			
				if(mysqli_num_rows($r) > 0 )
				{
					$info_success['success'] = 'Eligibility successful.. now, you can create account with us';
					header('Location:new_applicant.php?a=alpha_ayotimsjud&token='.md5(2).'&cp=new_account&regn='.$reg_no.'&is='.urlencode($info_success['success']));
							
				}
				else
				{
					$errors['error'] =  'We are sorry for the inconvenience, you are not eligible to apply.';
					header('Location:new_applicant.php?a=beta_ayotimsjud&token='.md5(1).'&&error='.urlencode($errors['error']));
				}
			
		}
		else
		{//stay back in update profile form
		
		
			$errors['error'] =  'Please Enter Your Jamb Registration Number';
			header('Location:new_applicant.php?a=beta_ayotimsjud&token='.md5(1).'&&error='.urlencode($errors['error']));
		
		}
		
		

}//end of if posted eligiblility
	
	

?>



<div class="list-group">
<form  method="POST" action="new_student.php?token=<?php echo md5(2);?>&cp=new_account">
			       		
  <div class="form-group">
    <label for="regno">Jamb (UTME) Reg. No.</label>
    <input value="<?php if($reg_no != ''){echo  $reg_no ;} ?>" name="reg_no" type="text" class="form-control"  readonly>
  </div>
  
  
  <div class="form-group">
    <label>Application type:</label>
		<input value="<?php if($entry_mode != ''){echo  $entry_mode ;} ?>" name="mode" type="text" class="form-control"  readonly>
  </div>
  
  <div class="form-group">
    <label for="phoneno">Phone Number</label>
    <input name="phone_no" type="text" class="form-control" id="phoneno" placeholder="Phone Number">
  </div>
   <div class="form-group">
    <label for="email">Email</label>
    <input name="email" type="email" class="form-control" id="email" placeholder="Email">
  </div>
  
  <div style="height:30px; display:block;"> </div>
  <input name="btncreateAccount" type="submit" class="btn btn-success btn-lg" value="Create Account"/>

   </form>
</div>