<?php
		session_start();
//include_once('../../../includes/configuration.php') or die(mysqli_error($con));
//$current_page = basename($_SERVER['SCRIPT_NAME']); //get current page
include_once('../db_connect/db.php');
include_once('includes/functions.php');

if(isset($_GET['cp']))
{
	$current_page = $_GET['cp'];
}

if(isset($_GET['t']))
{
	$current_page = $_GET['t'];
}

include_once('includes/script/createAccount.php');
include_once('includes/script/activate.php');


	//$activate_error="Enter Your email and the key sent to your mobile phone";
	$e_error="";
	$create_account_error='<div class="alert alert-info">
							  <button class="close" data-dismiss="alert" type="button">X</button>
								   &nbsp Please enter the required fields
					      </div>';
	if(isset($_POST['btnEligibility'])){
		$regno=$_POST['regno'];
		$school_id=$_POST['school'];
		//$current_session = get_current_session($id = 1); //get current session
		$current_session =6;
		$session_title = get_session_title($current_session); //get session title

		//check to see if the student exit in the hostel-students table
		$chkregno=mysqli_query($conn_1, "SELECT *FROM  hostel_students WHERE `number`='$regno'");
	if($chkregno){
		$chkregnorow=mysqli_num_rows($chkregno);
		if($chkregnorow > 0){
			$error='<div class="alert alert-info">
							<button class="close" data-dismiss="alert" type="button">X</button>
								<img src="images/info.png" /> &nbsp This matric number has been used, Note that you
								cannot apply twice, Please contact the admin for more information
					 </div>';
		}else{

		if($school_id=='1')
		{
			$chkemail=mysqli_query($conn_1, "SELECT * FROM  students_prence WHERE number ='$regno' ") or die(mysqli_error($conn_1));
			if($chkemail)
				{
					$row =mysqli_fetch_array($chkemail);
					//get the datas
					$fn = mysqli_real_escape_string($conn_1,$row['first_name']); //first name
								   $md_n = mysqli_real_escape_string($conn_1,$row['middle_name']);
								   $on = mysqli_real_escape_string($conn_1,$row['other_names']);
								   $pn = mysqli_real_escape_string($conn_1,$row['phone_no']);
									$e = mysqli_real_escape_string($conn_1,$row['email']);
									$add = mysqli_real_escape_string($conn_1,$row['address']);
									$padd = mysqli_real_escape_string($conn_1,$row['permanent_address']);
									$pob = mysqli_real_escape_string($conn_1,$row['place_of_birth']);
									$gn = mysqli_real_escape_string($conn_1,$row['guardian_name']);
									$gr = mysqli_real_escape_string($conn_1,$row['guardian_relationship']);
									$gt = mysqli_real_escape_string($conn_1,$row['guardian_tel']);
									$ga = mysqli_real_escape_string($conn_1,$row['guardian_address']);
									$med = mysqli_real_escape_string($conn_1,$row['medi']);
									$day = mysqli_real_escape_string($conn_1,$row['day']);
									$month = mysqli_real_escape_string($conn_1,$row['month']);
									$year = mysqli_real_escape_string($conn_1,$row['year']);
									$marital_status = mysqli_real_escape_string($conn_1,$row['marital_status']);
									$department_id = mysqli_real_escape_string($conn_1,$row['department_id']);
									$programme_id = mysqli_real_escape_string($conn_1,$row['programme_id']);
									$state_id = mysqli_real_escape_string($conn_1,$row['state_id']);
									$lga_id = mysqli_real_escape_string($conn_1,$row['lga_id']);
									$gender = mysqli_real_escape_string($conn_1,$row['gender']);
									$number = mysqli_real_escape_string($conn_1,$row['number']);
									$application_number = mysqli_real_escape_string($conn_1,$row['application_number']);
									$image = mysqli_real_escape_string($conn_1,$row['image']);
									$level = mysqli_real_escape_string($conn_1,$row['level']);
									$H_status = mysqli_real_escape_string($conn_1,$row['H_status']);
									$blood_type = mysqli_real_escape_string($conn_1,$row['blood_type']);
									$disability = mysqli_real_escape_string($conn_1,$row['disability']);
									$religion = mysqli_real_escape_string($conn_1,$row['religion']);
									$nationality = mysqli_real_escape_string($conn_1,$row['nationality']);
									$password = md5('0000');
									//insert into the new hostel students table
									$qq = "INSERT INTO `hostel_students`(`type_id`,`school_id`,`department_id`,`programme_id`,`state_id`,
									`lga_id`,`first_name`,`middle_name`,`other_names`,`phone_no`,`gender`,`nationality`,`medi`,`day`,`month`,
									 `year`,`marital_status`,`number`,`application_number`,`username`,`password`,`email`,`address`,`permanent_address`,
								 	 `image`,`blood_type`,`disability`,`place_of_birth`,`religion`,`level`,`H_status`,`date_added`,`guardian_name`,
								 	 `guardian_relationship`,`guardian_tel`,`guardian_address`,`session_id`)
									 VALUES('$school_id','1','$department_id','$programme_id','$state_id','$lga_id','$fn','$md_n','$on','$pn','$gender',
									 '$nationality','$med','$day','$month','$year','$marital_status','$number','$application_number','$number','$password',
								 	 '$e','$add','$padd','$image','$blood_type','$disability','$pob','$religion','$level','$H_status', NOW(),'$gn',
								 		'$gr','$gt','$ga','$current_session')";
									 $rr = mysqli_query($conn_1,$qq);
									 if($rr)//mysqli_affected_rows($conn_1)
									{
										$error = '<div class="alert alert-success">
																  <button class="close" data-dismiss="alert" type="button">X</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
									{
										$error = '<div class="alert alert-danger">
																  <button class="close" data-dismiss="alert" type="button">X</button>
																	   &nbsp Error: Please contact the ICT
														      </div>';
									}
				}

		}else if($school_id=='2')
		{
			$chkemail=mysqli_query($conn_1, "SELECT * FROM  students_nce WHERE number ='$regno' ") or die(mysqli_error($conn_1));
			if($chkemail)
				{
					$row2=mysqli_fetch_array($chkemail);

					//get the datas
									$fn = mysqli_real_escape_string($conn_1,$row2['first_name']); //first name
								   $md_n = mysqli_real_escape_string($conn_1,$row2['middle_name']);
								   $on = mysqli_real_escape_string($conn_1,$row2['other_names']);
								   $pn = mysqli_real_escape_string($conn_1,$row2['phone_no']);
									$e = mysqli_real_escape_string($conn_1,$row2['email']);
									$add = mysqli_real_escape_string($conn_1,$row2['address']);
									$padd = mysqli_real_escape_string($conn_1,$row2['permanent_address']);
									$pob = mysqli_real_escape_string($conn_1,$row2['place_of_birth']);
									$gn = mysqli_real_escape_string($conn_1,$row2['guardian_name']);
									$gr = mysqli_real_escape_string($conn_1,$row2['guardian_relationship']);
									$gt = mysqli_real_escape_string($conn_1,$row2['guardian_tel']);
									$ga = mysqli_real_escape_string($conn_1,$row2['guardian_address']);
									$med = mysqli_real_escape_string($conn_1,$row2['medi']);
									$day = mysqli_real_escape_string($conn_1,$row2['day']);
									$month = mysqli_real_escape_string($conn_1,$row2['month']);
									$year = mysqli_real_escape_string($conn_1,$row2['year']);
									$marital_status = mysqli_real_escape_string($conn_1,$row2['marital_status']);
									$department_id = mysqli_real_escape_string($conn_1,$row2['department_id']);
									$programme_id = mysqli_real_escape_string($conn_1,$row2['programme_id']);
									$state_id = mysqli_real_escape_string($conn_1,$row2['state_id']);
									$lga_id = mysqli_real_escape_string($conn_1,$row2['lga_id']);
									$gender = mysqli_real_escape_string($conn_1,$row2['gender']);
									$number = mysqli_real_escape_string($conn_1,$row2['number']);
									$application_number = mysqli_real_escape_string($conn_1,$row2['application_number']);
									$image = mysqli_real_escape_string($conn_1,$row2['image']);
									$level = mysqli_real_escape_string($conn_1,$row2['level']);
									$H_status = mysqli_real_escape_string($conn_1,$row2['H_status']);
									$blood_type = mysqli_real_escape_string($conn_1,$row2['blood_type']);
									$disability = mysqli_real_escape_string($conn_1,$row2['disability']);
									$religion = mysqli_real_escape_string($conn_1,$row2['religion']);
									$nationality = mysqli_real_escape_string($conn_1,$row2['nationality']);
									$password = md5('0000');
									//insert into the new hostel students table
									$qq = "INSERT INTO `hostel_students`(`type_id`,`school_id`,`department_id`,`programme_id`,`state_id`,
									`lga_id`,`first_name`,`middle_name`,`other_names`,`phone_no`,`gender`,`nationality`,`medi`,`day`,`month`,
									 `year`,`marital_status`,`number`,`application_number`,`username`,`password`,`email`,`address`,`permanent_address`,
								 	 `image`,`blood_type`,`disability`,`place_of_birth`,`religion`,`level`,`H_status`,`date_added`,`guardian_name`,
								 	 `guardian_relationship`,`guardian_tel`,`guardian_address`,`session_id`)
									 VALUES('$school_id','1','$department_id','$programme_id','$state_id','$lga_id','$fn','$md_n','$on','$pn','$gender',
									 '$nationality','$med','$day','$month','$year','$marital_status','$number','$application_number','$number','$password',
								 	 '$e','$add','$padd','$image','$blood_type','$disability','$pob','$religion','$level','$H_status', NOW(),'$gn',
								 		'$gr','$gt','$ga','$current_session')";
									 $rr = mysqli_query($conn_1,$qq);
									 if($rr)//mysqli_affected_rows($conn_1)
									{
										$error = '<div class="alert alert-success">
										<button class="close" data-dismiss="alert" type="button">X</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
									{
										$error = '<div class="alert alert-danger">
																  <button class="close" data-dismiss="alert" type="button">X</button>
																	   &nbsp Error: Please contact the ICT
														      </div>';
									}
				}

		}else if($school_id=='3')
		{
			$chkemail=mysqli_query($conn_2, "SELECT * FROM  students_nce WHERE number ='$regno' ") or die(mysqli_error($conn_2));
			if($chkemail)
				{
					$row3=mysqli_fetch_array($chkemail);
					//get the datas
					$fn = mysqli_real_escape_string($conn_2,$row3['first_name']); //first name
								   $md_n = mysqli_real_escape_string($conn_2,$row3['middle_name']);
								   $on = mysqli_real_escape_string($conn_2,$row3['other_names']);
								   $pn = mysqli_real_escape_string($conn_2,$row3['phone_no']);
									$e = mysqli_real_escape_string($conn_2,$row3['email']);
									$add = mysqli_real_escape_string($conn_2,$row3['address']);
									$padd = mysqli_real_escape_string($conn_2,$row3['permanent_address']);
									$pob = mysqli_real_escape_string($conn_2,$row3['place_of_birth']);
									$gn = mysqli_real_escape_string($conn_2,$row3['guardian_name']);
									$gr = mysqli_real_escape_string($conn_2,$row3['guardian_relationship']);
									$gt = mysqli_real_escape_string($conn_2,$row3['guardian_tel']);
									$ga = mysqli_real_escape_string($conn_2,$row3['guardian_address']);
									$med = mysqli_real_escape_string($conn_2,$row3['medi']);
									$day = mysqli_real_escape_string($conn_2,$row3['day']);
									$month = mysqli_real_escape_string($conn_2,$row3['month']);
									$year = mysqli_real_escape_string($conn_2,$row3['year']);
									$marital_status = mysqli_real_escape_string($conn_2,$row3['marital_status']);
									$department_id = mysqli_real_escape_string($conn_2,$row3['department_id']);
									$programme_id = mysqli_real_escape_string($conn_2,$row3['programme_id']);
									$state_id = mysqli_real_escape_string($conn_2,$row3['state_id']);
									$lga_id = mysqli_real_escape_string($conn_2,$row3['lga_id']);
									$gender = mysqli_real_escape_string($conn_2,$row3['gender']);
									$number = mysqli_real_escape_string($conn_2,$row3['number']);
									$application_number = mysqli_real_escape_string($conn_2,$row3['application_number']);
									$image = mysqli_real_escape_string($conn_2,$row3['image']);
									$level = mysqli_real_escape_string($conn_2,$row3['level']);
									$H_status = mysqli_real_escape_string($conn_2,$row3['H_status']);
									$blood_type = mysqli_real_escape_string($conn_2,$row3['blood_type']);
									$disability = mysqli_real_escape_string($conn_2,$row3['disability']);
									$religion = mysqli_real_escape_string($conn_2,$row3['religion']);
									$nationality = mysqli_real_escape_string($conn_2,$row3['nationality']);
									$password = md5('0000');
									//insert into the new hostel students table
									$qq = "INSERT INTO `hostel_students`(`type_id`,`school_id`,`department_id`,`programme_id`,`state_id`,
									`lga_id`,`first_name`,`middle_name`,`other_names`,`phone_no`,`gender`,`nationality`,`medi`,`day`,`month`,
									 `year`,`marital_status`,`number`,`application_number`,`username`,`password`,`email`,`address`,`permanent_address`,
								 	 `image`,`blood_type`,`disability`,`place_of_birth`,`religion`,`level`,`H_status`,`date_added`,`guardian_name`,
								 	 `guardian_relationship`,`guardian_tel`,`guardian_address`,`session_id`)
									 VALUES('$school_id','1','$department_id','$programme_id','$state_id','$lga_id','$fn','$md_n','$on','$pn','$gender',
									 '$nationality','$med','$day','$month','$year','$marital_status','$number','$application_number','$number','$password',
								 	 '$e','$add','$padd','$image','$blood_type','$disability','$pob','$religion','$level','$H_status', NOW(),'$gn',
								 		'$gr','$gt','$ga','$current_session')";
									 $rr = mysqli_query($conn_1,$qq);
									 if($rr)//mysqli_affected_rows($conn_1)
									{
										$error = '<div class="alert alert-success">
										<button class="close" data-dismiss="alert" type="button">X</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
									{
										$error = '<div class="alert alert-danger">
																  <button class="close" data-dismiss="alert" type="button">X</button>
																	   &nbsp Error: Please contact the ICT
														      </div>';
									}
				}

		}else if($school_id=='4')
		{
			$chkemail=mysqli_query($conn_1, "SELECT * FROM  summer_students WHERE number ='$regno' ") or die(mysqli_error($conn_1));
			if($chkemail)
				{
					$row2=mysqli_fetch_array($chkemail);

					//get the datas
									$fn = mysqli_real_escape_string($conn_1,$row2['first_name']); //first name
								   $md_n = mysqli_real_escape_string($conn_1,$row2['middle_name']);
								   $on = mysqli_real_escape_string($conn_1,$row2['other_names']);
								   $pn = mysqli_real_escape_string($conn_1,$row2['phone_no']);
									$e = mysqli_real_escape_string($conn_1,$row2['email']);
									$add = mysqli_real_escape_string($conn_1,$row2['address']);
									$padd = mysqli_real_escape_string($conn_1,$row2['permanent_address']);
									$pob = mysqli_real_escape_string($conn_1,$row2['place_of_birth']);
									$gn = mysqli_real_escape_string($conn_1,$row2['guardian_name']);
									$gr = mysqli_real_escape_string($conn_1,$row2['guardian_relationship']);
									$gt = mysqli_real_escape_string($conn_1,$row2['guardian_tel']);
									$ga = mysqli_real_escape_string($conn_1,$row2['guardian_address']);
									$med = mysqli_real_escape_string($conn_1,$row2['medi']);
									$day = mysqli_real_escape_string($conn_1,$row2['day']);
									$month = mysqli_real_escape_string($conn_1,$row2['month']);
									$year = mysqli_real_escape_string($conn_1,$row2['year']);
									$marital_status = mysqli_real_escape_string($conn_1,$row2['marital_status']);
									$department_id = mysqli_real_escape_string($conn_1,$row2['department_id']);
									$programme_id = mysqli_real_escape_string($conn_1,$row2['programme_id']);
									$state_id = mysqli_real_escape_string($conn_1,$row2['state_id']);
									$lga_id = mysqli_real_escape_string($conn_1,$row2['lga_id']);
									$gender = mysqli_real_escape_string($conn_1,$row2['gender']);
									$number = mysqli_real_escape_string($conn_1,$row2['number']);
									$application_number = mysqli_real_escape_string($conn_1,$row2['application_number']);
									$image = mysqli_real_escape_string($conn_1,$row2['image']);
									$level = mysqli_real_escape_string($conn_1,$row2['level']);
									$H_status = mysqli_real_escape_string($conn_1,$row2['H_status']);
									$blood_type = mysqli_real_escape_string($conn_1,$row2['blood_type']);
									$disability = mysqli_real_escape_string($conn_1,$row2['disability']);
									$religion = mysqli_real_escape_string($conn_1,$row2['religion']);
									$nationality = mysqli_real_escape_string($conn_1,$row2['nationality']);
									$password = md5('0000');
									//insert into the new hostel students table
									$qq = "INSERT INTO `hostel_students`(`type_id`,`school_id`,`department_id`,`programme_id`,`state_id`,
									`lga_id`,`first_name`,`middle_name`,`other_names`,`phone_no`,`gender`,`nationality`,`medi`,`day`,`month`,
									 `year`,`marital_status`,`number`,`application_number`,`username`,`password`,`email`,`address`,`permanent_address`,
								 	 `image`,`blood_type`,`disability`,`place_of_birth`,`religion`,`level`,`H_status`,`date_added`,`guardian_name`,
								 	 `guardian_relationship`,`guardian_tel`,`guardian_address`,`session_id`)
									 VALUES('$school_id','1','$department_id','$programme_id','$state_id','$lga_id','$fn','$md_n','$on','$pn','$gender',
									 '$nationality','$med','$day','$month','$year','$marital_status','$number','$application_number','$number','$password',
								 	 '$e','$add','$padd','$image','$blood_type','$disability','$pob','$religion','$level','$H_status', NOW(),'$gn',
								 		'$gr','$gt','$ga','$current_session')";
									 $rr = mysqli_query($conn_1,$qq);
									 if($rr)//mysqli_affected_rows($conn_1)
									{
										$error = '<div class="alert alert-success">
										<button class="close" data-dismiss="alert" type="button">X</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
									{
										$error = '<div class="alert alert-danger">
																  <button class="close" data-dismiss="alert" type="button">X</button>
																	   &nbsp Error: Please contact the ICT
														      </div>';
									}
				}

		}else if($school_id=='5'){
		    $error = '<div class="alert alert-warning">
										<button class="close" data-dismiss="alert" type="button">X</button>
											 &nbsp Error:Please try again later.
										</div>';
		    }else{
			$error = '<div class="alert alert-danger">
										<button class="close" data-dismiss="alert" type="button">X</button>
											 &nbsp Error:Please select the Programme you belong to
										</div>';

		}

		}

}
}

?>
<!DOCTYPE html>
<html>
  <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>.::COE HOSTEL MANAGEMENT PORTAL::.</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="images/coe.png" type="image/x-icon" />
    <!-- Bootstrap -->

    <!-- call bootstap styles -->
    <link href="bootstrap-3.3.4/css/bootstrap.min.css" rel="stylesheet">

    <!-- call custom admin styles -->
	<link href="login/css/signin.css" rel="stylesheet">
	<link href="login/css/docs.css" rel="stylesheet" >




     <!-- call full slider CSS here -->
	<link href="full-slider/css/full-slider.css" rel="stylesheet">


     <!-- call jquery file for ajax login -->
    <script src="login/js/jquery.js" type="text/javascript" language="javascript"></script>

     <!-- for full slider index -->
	<script type="text/javascript" src="full-slider/js/jquery-1.10.2.js"></script>
</head>
<body style="overflow-x: hidden;overflow-y:auto;">
	<header class="navbar" role="banner">

            <!-- call the header -->
            <?php include 'includes/header3.php'; ?>

		 <div style="border-bottom:#027174 solid 2px"></div>
    </header>

<div class="cont-bg">
<div class="wrap">
	<div class="clear"></div>
	<div class="border">

	</div>
	<br/>
		 <div class="col-lg-12">



	</div><!-- /col lg 12 -->
	<div class="col-md-12">
		<div class="list-group">

  <!-- Default panel contents -->
  <div class="panel-body" style="padding-top:0px;margin-top:0xp;">
		<div class="col-md-6">
		<div class="panel panel-default">

			<div class="btn-group btn-group-justified" role="group" aria-label="...">
  <div class="btn-group" role="group" >
    <button type="button" style="background:#027174; color:white;" class="btn btn-default <?php if($current_page == ''){echo 'active';} ?>"><b>Eligibility</b></button>
  </div>
  <div class="btn-group" role="group">
    <button type="button" style="background:#027174; color:white;" class="btn btn-default <?php if($current_page == 'new_account'){echo 'active';} ?>"><b>Create New Account</b></button>
  </div>
  <div class="btn-group" role="group">
    <button type="button" style="background:#027174; color:white;" class="btn btn-default  <?php if($current_page == '351025'){echo 'active';} ?>"><b>Activate Account</b></button>
  </div>
  </div>

	<div id="Tab_content" class="col-md-12" style="padding-left:0px;padding-right:0px;">
		<div class="list-group">
				<ul class="list-group">
					<li class="list-group-item">
						<?php

							if(isset($_GET['token'])){
								$token=$_GET['token'];

								if($token==md5(1)){
									include_once('includes/script/eligibility.php');
								}elseif($token==md5(2)){
									include_once('includes/script/new_account.php');
								}elseif($token==md5(3)){
									include_once('includes/script/account_activation.php');
								}
							}
						?>
					</li>
				</ul>

			</div>
	</div>
	</div>
</div>
		<div class="col-md-6">
			<div class="list-group" >
				<ul class="list-group" >
					<li class="list-group-item list-group-item-success" style="background:#027174; color:white;">
						INSTRUCTION
						<h4>Please read the instruction carefully. Help line: +234 - 08035956869, 07066651503, Alternatively, contact the Student Affairs Office</h4>
					</li>
					<li class="list-group-item ">
					<blockquote>
					<p>
					Students are advise to carefully READ AND STUDY the specification regulations governing their stay in the hostels and ABIDE by them. The students Hand book also carries the general residency regulation which should be strictly adhered to.
				</p>
					<footer>
						<ul>
							<li><h3>Select your entry programme</h3></li>
							<li><h3>Insert your matric number to apply</h3></li>
						</ul>


					</footer>
					<footer>
						Sale or giving-out bed-space and illegal swapping are strickly prohibited. The penalty for any defaulter ranges from ejection, rustication to expulsion
					</footer>
				</blockquote>

				</li>
				</ul>

			</div>
		</div>

</div>
		</div>
	</div>



  </div>


</div>

</div>
</body>
</html>
