<?php
if(isset($_POST['token'])){

		include_once('../../../db_connect/db.php');
		$student_id = $_POST["token"];
		$type_id = $_POST["type_id"];
		if($type_id=='1')
		{
			$q = "SELECT CONCAT_WS(' ',first_name, middle_name, other_names) AS name,
			number,phone_no, students_prence.level AS level, students_prence.id AS id,
			students_prence.gender AS gender, programmes.title as programme FROM students_prence, programmes WHERE
			students_prence.programme_id=programmes.id AND students_prence.id = '$student_id'";
			$r = mysqli_query($conn_1, $q) or die(mysqli_error($con));

			if(!$r) { die(mysqli_error()); }


				if(mysqli_num_rows($r) > 0)
				{//begin if result exist
					while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
					{//begin while
						$name = $row['name'];
						$matric = $row['number'];
						$phone_number = $row['phone_no'];
						$level = $row['level'];
						$programme = $row['programme'];
						$gen = $row['gender'];
						$student_id = $row['id'];

						if($gen=='M'){
							$gender ='Male';
						}else{
							$gender = 'Female';
						}

						echo '


										 ';



	echo'
	<div class="col-lg-12">

			<div class="col-lg-10">
	';
					//	$gender = $row['gender'];



}

}
		}else if($type_id=='2')
		{
			$q = "SELECT CONCAT_WS(' ',first_name, middle_name, other_names) AS name,
			number,phone_no, students_nce.level AS level, students_nce.id AS id,
			students_nce.gender AS gender, programmes.title as programme FROM students_nce, programmes WHERE
			students_nce.programme_id=programmes.id AND students_nce.id = '$student_id'";
			$r = mysqli_query($conn_1, $q) or die(mysqli_error($con));

			if(!$r) { die(mysqli_error()); }


				if(mysqli_num_rows($r) > 0)
				{//begin if result exist
					while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
					{//begin while
						$name = $row['name'];
						$matric = $row['number'];
						$phone_number = $row['phone_no'];
						$level = $row['level'];
						$programme = $row['programme'];
						$gen = $row['gender'];
						$student_id = $row['id'];

						if($gen=='M'){
							$gender ='Male';
						}else{
							$gender = 'Female';
						}

						echo '


										 ';



	echo'
	<div class="col-lg-12">

			<div class="col-lg-10">
	';
					//	$gender = $row['gender'];



}

}
		}else if($type_id=='3')
		{
			$q = "SELECT CONCAT_WS(' ',first_name, middle_name, other_names) AS name,
			number,phone_no, students_nce.level AS level, students_nce.id AS id,
			students_nce.gender AS gender, programmes.title as programme FROM students_nce, programmes WHERE
			students_nce.programme_id=programmes.id AND students_nce.id = '$student_id'";
			$r = mysqli_query($conn_2, $q) or die(mysqli_error($conn_2));

			if(!$r) { die(mysqli_error()); }


				if(mysqli_num_rows($r) > 0)
				{//begin if result exist
					while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
					{//begin while
						$name = $row['name'];
						$matric = $row['number'];
						$phone_number = $row['phone_no'];
						$level = $row['level'];
						$programme = $row['programme'];
						$gen = $row['gender'];
						$student_id = $row['id'];

						if($gen=='M'){
							$gender ='Male';
						}else{
							$gender = 'Female';
						}

						echo '


										 ';



	echo'
	<div class="col-lg-12">

			<div class="col-lg-10">
	';
					//	$gender = $row['gender'];



}

}
		}else if($type_id=='4')
		{
			$q = "SELECT CONCAT_WS(' ',first_name, middle_name, other_names) AS name,
			number,phone_no, students_udus.level AS level, students_udus.id AS id,
			students_udus.gender AS gender, programmes.title as programme FROM students_udus, programmes WHERE
			students_udus.programme_applied_for=programmes.id AND students_udus.id = '$student_id'";
			$r = mysqli_query($conn_2, $q) or die(mysqli_error($conn_2));

			if(!$r) { die(mysqli_error()); }


				if(mysqli_num_rows($r) > 0)
				{//begin if result exist
					while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
					{//begin while
						$name = $row['name'];
						$matric = $row['number'];
						$phone_number = $row['phone_no'];
						$level = $row['level'];
						$programme = $row['programme'];
						$gen = $row['gender'];
						$student_id = $row['id'];

						if($gen=='M'){
							$gender ='Male';
						}else{
							$gender = 'Female';
						}

						echo '


										 ';



	echo'
	<div class="col-lg-12">

			<div class="col-lg-10">
	';
					//	$gender = $row['gender'];



}

}
		}else if($type_id=='5')
		{
			$q = "SELECT CONCAT_WS(' ',first_name, middle_name, other_names) AS name,
			number,phone_no, summer_students.level AS level, summer_students.id AS id,
			summer_students.gender AS gender, programmes.title as programme FROM summer_students,
			programmes WHERE
			summer_students.programme_id=programmes.id AND summer_students.id = '$student_id'";
			$r = mysqli_query($conn_1, $q) or die(mysqli_error($conn_1));

			if(!$r) { die(mysqli_error()); }


				if(mysqli_num_rows($r) > 0)
				{//begin if result exist
					while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
					{//begin while
						$name = $row['name'];
						$matric = $row['number'];
						$phone_number = $row['phone_no'];
						$level = $row['level'];
						$programme = $row['programme'];
						$gen = $row['gender'];
						$student_id = $row['id'];

						if($gen=='M'){
							$gender ='Male';
						}else{
							$gender = 'Female';
						}

						echo '


										 ';



	echo'
	<div class="col-lg-12">

			<div class="col-lg-10">
	';
					//	$gender = $row['gender'];



}

}
		}else if($type_id=='6')
		{
			$q = "SELECT CONCAT_WS(' ',first_name, middle_name, other_names) AS name,
			number,phone_no, summer_students.level AS level, summer_students.id AS id,
			summer_students.gender AS gender, programmes.title as programme FROM summer_students, programmes WHERE
			summer_students.programme_id=programmes.id AND summer_students.id = '$student_id'";
		  $r = mysqli_query($conn_1, $q) or die(mysqli_error($con));

		  if(!$r) { die(mysqli_error()); }


			  if(mysqli_num_rows($r) > 0)
			  {//begin if result exist
				  while($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
				  {//begin while
						$name = $row['name'];
						$matric = $row['number'];
						$phone_number = $row['phone_no'];
						$level = $row['level'];
						$programme = $row['programme'];
						$gen = $row['gender'];
						$student_id = $row['id'];

						if($gen=='M'){
							$gender ='Male';
						}else{
							$gender = 'Female';
						}

						echo '


										 ';



	echo'
	<div class="col-lg-12">

			<div class="col-lg-10">
	';
					//	$gender = $row['gender'];



}

}
		}


}

?>
<form method="POST" id="edit_form_faculty" >

				<input id="faculty_id" name="student_id" type="hidden" class="form-control" value="<?=$student_id;?>" required />
				<input id="faculty_id" name="type_id" type="hidden" class="form-control" value="<?=$type_id;?>" required />
				<div class="form-group row">
				<label for="title" class="col-sm-3 col-form-label text-right">Name :
				</label>
					<div class="col-sm-9">
						<input id="title" name="name" type="text"
						 class="form-control required" value="<?=$name;?>" readonly />
					</div>
						 </div>
						 <div class="form-group row">
											<label class="col-sm-3 col-form-label text-right"> Matric No:</label>
								<div class="col-sm-9">
								<input id="title" name="matric_number" type="text"
								 class="form-control required" value="<?=$matric;?>" readonly />
								</div>
						</div>
						<div class="form-group row">
						<label for="title" class="col-sm-3 col-form-label text-right">Phone :
						</label>
							<div class="col-sm-9">
								<input id="title" name="phone_no" type="text"
								 class="form-control required" value="<?=$phone_number;?>" readonly />
							</div>
								 </div>
								 <div class="form-group row">
								<label for="title" class="col-sm-3 col-form-label text-right">Programme :
								</label>
									<div class="col-sm-9">
										<input id="title" name="programme" type="text"
										 class="form-control required" value="<?=$programme;?>" readonly />
									</div>
										 </div>
										 <div class="form-group row">
															<label class="col-sm-3 col-form-label text-right"> Level:</label>
												<div class="col-sm-9">
												<input id="title" name="level" type="text"
												 class="form-control required" value="<?=$level;?>" readonly />
												</div>
										</div>
										<div class="form-group row">
										<label for="title" class="col-sm-3 col-form-label text-right">Gender :
										</label>
											<div class="col-sm-9">
												<input id="title" name="gender" type="text"
												 class="form-control required" value="<?=$gender;?>" readonly />
											</div>
												 </div>
												 <div class="form-group row">
	             				<label for="category" class="col-sm-3 col-form-label text-right">Campus *</label>
	                         <div class="col-sm-9">
														 <input type="hidden" name="gender" id="gender" value="<?=$gender;?>">
	                               <select class="form-control select21" id="campus_id" title="Select School..." name="campus_id" onchange="load_block()">
	                                 <option disabled selected>Select Campus</option>
	             														<?php
																					$select="SELECT * FROM hostel_campuses WHERE status ='1'";
																											$sql_select=mysqli_query($conn_1,$select);
																											$num_rows=mysqli_num_rows($sql_select);
																											if($num_rows > 0){

																												while($campus_row=mysqli_fetch_array($sql_select)){
																													$campus_id=$campus_row['id'];
																													$campus_title=$campus_row['title'];
																													$campus_status=$campus_row['status'];

																													 $campus_output.='<option value="'.$campus_id.'">'.$campus_title.'</option>';

																												}

																											}
																											echo $campus_output;
	             														?>

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

										<div class="form-group row">
								 <label for="category" class="col-sm-3 col-form-label text-right">Block *</label>
											<div class="col-sm-9">
														<select class="form-control select21" id="block_id" title="Select School..." name="block_id" onchange="load_room()">
															<option disabled selected>Select Block</option>
																		 <?php
																		 $select="SELECT * FROM hostel_categories WHERE hostel_site='$campus_id' AND gender='$gender'";
 																								$sql_select=mysqli_query($con,$select);
 																								$num_rows=mysqli_num_rows($sql_select);
 																								if($num_rows > 0){

 																									while($block_row=mysqli_fetch_array($sql_select)){
																											$block_id=$block_row['id'];
																											//echo $block_id;
																										if($block_id == $block_row['id'])
																										{
																											$block_output = "<option value=\"$block_row[id]\" selected>";
																											$block_output .=  $block_row['title'];
																											$block_output .="</option>";

																										}
																										else
																										{
																											$block_output = "<option value=\"$block_row[id]\" >";
																											$block_output .= $block_row['title'];
																											$block_output .="</option>";

																										}





 																									}

 																								}
																								echo $block_output;
																		 ?>

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

							 <div class="form-group row">
						<label for="category" class="col-sm-3 col-form-label text-right">Block *</label>
								 <div class="col-sm-9">
											 <select class="form-control select21" id="room_id" title="Select School..." name="room_id">
												 <option disabled selected>Select Room</option>
																<?php
																$select="SELECT * FROM hostel_rooms WHERE hostel_categories='$block_id' ";
																					 $sql_select=mysqli_query($con,$select);
																					 $num_rows=mysqli_num_rows($sql_select);
																					 if($num_rows > 0){

																						 while($rm_row=mysqli_fetch_array($sql_select)){
																								 $room_id=$rm_row['id'];

																							 if($room_id == $rm_row['id'])
																							 {
																								 $room_outputs = "<option value=\"$rm_row[id]\" selected>";
																								 $room_outputs .=  $rm_row['title'];
																								 $room_outputs .="</option>";

																							 }
																							 else
																							 {
																								 $room_outputs = "<option value=\"$rm_row[id]\" >";
																								 $room_outputs .= $rm_row['title'];
																								 $room_outputs .="</option>";

																							 }





																						 }

																					 }
																					 echo $room_outputs;
																?>

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



						<div id="button_edit">
							<center>
														<button class="button button-3d button-primary button-rounded btn_3d" type="submit">Allocate
												</button>
						</div>
             </form>

			 <center>
				<div id="output_error_edit">

				</div>
			</center>
