<?php
@session_start();
include_once('../includes/configuration_old.php');
	$new_error="";
	$new_error='<div class="alert alert-danger">
							  <button class="close" data-dismiss="alert" type="button">X</button>
								   &nbsp All the fields are required
					      </div>';
	if(isset($_POST['btncreateAccount'])){
		$regno=$_POST['regno'];
		$phoneno=$_POST['phoneno'];
		$email=$_POST['email'];



		if(empty($regno)){
			$new_error='<div class="alert alert-danger">
							  <button class="close" data-dismiss="alert" type="button">X</button>
								   &nbsp Matric Number field is empty
					      </div>';

		}elseif(empty($phoneno)){
			$new_error='<div class="alert alert-danger">
							  <button class="close" data-dismiss="alert" type="button">X</button>
								   &nbsp Phone Number field is empty
					      </div>';

		}elseif(empty($email)){
		$new_error='<div class="alert alert-danger">
							  <button class="close" data-dismiss="alert" type="button">X</button>
								   &nbsp Email field is empty
					      </div>';

		}else{

			//chk if the email has been use or not
		$chkemail=mysqli_query($dbc, "SELECT email FROM  students_nce WHERE email='$email' AND number ='$regno' ") or die(mysqli_error($dbc));
		if($chkemail){
			$chkemailrow=mysqli_num_rows($chkemail);
			if($chkemailrow > 0){
				$new_error='<div class="alert alert-danger">
							  <button class="close" data-dismiss="alert" type="button">X</button>
								   &nbsp This Email has been used
					      </div>';
			}else{
				//chk pho no
				$chkpno=mysqli_query($dbc, "SELECT phone_no FROM students_nce WHERE phone_no ='$phoneno' AND `number`='$regno' ") or die(mysqli_error($dbc));
		if($chkpno){
			$chkpnorow=mysqli_num_rows($chkpno);
			if($chkpnorow > 0){
				$new_error='<div class="alert alert-danger">
							  <button class="close" data-dismiss="alert" type="button">X</button>
								   &nbsp This Phone Number has been used
					      </div>';
			}else{
				//chk reg no
		$chkregno=mysqli_query($dbc, "SELECT `number`, hostel_eligibility FROM students_nce WHERE `number`='$regno' AND hostel_eligibility= 1 ") or die(mysqli_error($dbc));
		if($chkregno){
			$chkregnorow=mysqli_num_rows($chkregno);
			if($chkregnorow > 0){

				$_SESSION = mysqli_fetch_array($chkregno, MYSQLI_ASSOC);
				$std_id =$_SESSION['id'];

				$new_error='<div class="alert alert-danger">
							  <button class="close" data-dismiss="alert" type="button">X</button>
								   &nbsp This matric number has been used, please use your own matric number or contact the admin for any Complain
					      </div>';

			}else{


				//create account
				//$key="HMS";
				//$key.=rand(1000,9000);
				//$link_code=rand(100000,900000);
				//$a=md5(a);
				//$link='<a href="apply.php?token='.md5(3).'&a&t='.$link_code.'">here</a>';
				//$key.="2015";
				$sql_update=mysqli_query($dbc, "UPDATE students_nce SET hostel_eligibility='1' WHERE  number = '$regno'") or die(mysqli_error($dbc));
				if($sql_update){
					$new_error='<div class="alert alert-info">
							<button class="close" data-dismiss="info" type="button">

								</button>
							<img src="images/info.png" />Your account has been created successfuly, you can now log in with your <h3><b>Matric Number</b></h3> And <h3><b>0000</b></h3> as your password</font>
					 <font color="green"><a href="index.php">Click here to login</a></font>
											 </div>';
									}else{
										$new_error='<div class="alert alert-danger">
												<button class="close" data-dismiss="info" type="button">

													</button>
												<img src="images/info.png" />Error! Contact ICT </font>

																 </div>';
									}


			}
		}

		}
	}
}
}




}




		}


?>
