
<?php
//this page brings out a static form editing a user

//collect the passed
if(isset($_GET['id']))
{
 $user_id =  $_GET['id'];
}
//collect the passed
if(isset($_GET['type_id']))
{
 $type_id =  $_GET['type_id'];
}
?>
<input type="hidden" id="type_id" value="<?=$type_id;?>">

<div class="well">

      <ul class="tabs">
        <li><a href="#view1" >New Allocation</a></li>
      </ul>
      <div class="tabcontents">
        <div id="view1"  class="row">


        <?php
				if($type_id == 1)
				{
					  $q = "SELECT CONCAT_WS(' ',first_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 = '$user_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'];
									$gender = $row['gender'];
									$student_id = $row['id'];
									if($gender=='F' OR $gender== 'female')
									{
										$gender = 'female';
									}else if($gender=='M' OR $gender== 'male')
									{
										$gender = 'male';
									}


									echo '

									<div class="panel panel-default">
										<div class="panel-heading">
											<h3 class="panel-title">'.strtoupper($name).' ----- '.strtoupper($matric).'-----'.strtoupper($programme).'-----'.strtoupper($phone_number).' ----- '.strtoupper($level).' ----- '.strtoupper($gender).'</h3>
										</div>
										<div class="panel-body">';



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

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

								echo'<center>
								<div class="col-md-12">
							<div class="col-md-12">
									<input type="hidden" value="'.$gender.'" id="gender">
									<input type="hidden" value="'.$student_id.'" id="student_id">
								<select class="form-control"  id="site" onchange="load_lga()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
								<option>select hostel</option>';
								$q = "SELECT * FROM hostel_campuses WHERE status='1' ORDER BY date_added ASC ";
								$r = mysqli_query($conn_1, $q) ;

								if(mysqli_num_rows($r) > 0)
								{//show table
									while($row = mysqli_fetch_array($r)){


										echo '

										<option value="'.$row['id'].'">'.$row['title'].'</option>';

								}
							}

								echo '</select></div><br>
								<div class="col-md-12" style="margin-top:20px;">
								<select class="form-control"  id="block" onchange="load_room()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
								<option>select blocks</option>

								</select>
								</div>

								<div class="col-md-12" style="margin-top:20px;">
								<select class="form-control"  id="room" onkeypress="category_select()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
								<option>select Rooms</option>
								</select>
								</div><br><br>
								<button type="button" class="btn btn-success" style="margin-top:20px;" onclick="allocation()">Allocate Now </button>
								</div><br><br><br>
								<div id="result"></div>
								</center>


								';







										?>




						</div><!-- / col-lg -12 -->
						</div><!-- / col-lg -12 -->
						</div><!-- / col-lg -12 -->
						</div><!-- / col-lg -12 -->


				<?php
							  }//end of if
							  }//end of while

				}else if ($type_id == 2)
				{

						$q = "SELECT CONCAT_WS(' ',first_name,other_names) AS name, number,phone_number,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 = '$user_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_number'];
									$level = $row['level'];
									$programme = $row['programme'];
									$gender = $row['gender'];
									$student_id = $row['id'];
									if($gender=='F' OR $gender== 'female')
									{
										$gender = 'female';
									}else if($gender=='M' OR $gender== 'male')
									{
										$gender = 'male';
									}

									echo '

									<div class="panel panel-default">
										<div class="panel-heading">
											<h3 class="panel-title">'.strtoupper($name).' ----- '.strtoupper($matric).'-----'.strtoupper($programme).'-----'.strtoupper($phone_number).' ----- '.strtoupper($level).' ----- '.strtoupper($gender).'</h3>
										</div>
										<div class="panel-body">';



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

						<div class="col-lg-10">
				';
								//	$gender = $row['gender'];
									//loa_campus($gender,$student_id);
										echo'<center>
										<div class="col-md-12">
									<div class="col-md-12">
											<input type="hidden" value="'.$gender.'" id="gender">
											<input type="hidden" value="'.$student_id.'" id="student_id">
										<select class="form-control"  id="site" onchange="load_lga()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
										<option>select hostel</option>';
										$q = "SELECT * FROM hostel_campuses WHERE status='1' ORDER BY date_added ASC ";
										$r = mysqli_query($conn_1, $q) ;

										if(mysqli_num_rows($r) > 0)
										{//show table
											while($row = mysqli_fetch_array($r)){


												echo '

												<option value="'.$row['id'].'">'.$row['title'].'</option>';

										}
									}

										echo '</select></div><br>
										<div class="col-md-12" style="margin-top:20px;">
										<select class="form-control"  id="block" onchange="load_room()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
										<option>select blocks</option>

										</select>
										</div>

										<div class="col-md-12" style="margin-top:20px;">
										<select class="form-control"  id="room" onkeypress="category_select()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
										<option>select Rooms</option>
										</select>
										</div><br><br>
										<button type="button" class="btn btn-success" style="margin-top:20px;" onclick="allocation()">Allocate Now </button>
										</div><br><br><br>
										<div id="result"></div>
										</center>


										';







										?>




						</div><!-- / col-lg -12 -->
						</div><!-- / col-lg -12 -->
						</div><!-- / col-lg -12 -->
						</div><!-- / col-lg -12 -->


				<?php
								}//end of if
								}//end of while


				}else if ($type_id == 3)
				{

											$q = "SELECT CONCAT_WS(' ',first_name,other_names) AS name, number,phone_number,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 = '$user_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_number'];
														$level = $row['level'];
														$programme = $row['programme'];
														$gender = $row['gender'];
														$student_id = $row['id'];
														if($gender=='F' OR $gender== 'female')
														{
															$gender = 'female';
														}else if($gender=='M' OR $gender== 'male')
														{
															$gender = 'male';
														}

														echo '

														<div class="panel panel-default">
															<div class="panel-heading">
																<h3 class="panel-title">'.strtoupper($name).' ----- '.strtoupper($matric).'-----'.strtoupper($programme).'-----'.strtoupper($phone_number).' ----- '.strtoupper($level).' ----- '.strtoupper($gender).'</h3>
															</div>
															<div class="panel-body">';



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

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

													echo'<center>
													<div class="col-md-12">
												<div class="col-md-12">
														<input type="hidden" value="'.$gender.'" id="gender">
														<input type="hidden" value="'.$student_id.'" id="student_id">
													<select class="form-control"  id="site" onchange="load_lga()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
													<option>select hostel</option>';
													$q = "SELECT * FROM hostel_campuses WHERE status='1' ORDER BY date_added ASC ";
													$r = mysqli_query($conn_1, $q) ;

													if(mysqli_num_rows($r) > 0)
													{//show table
														while($row = mysqli_fetch_array($r)){


															echo '

															<option value="'.$row['id'].'">'.$row['title'].'</option>';

													}
												}

													echo '</select></div><br>
													<div class="col-md-12" style="margin-top:20px;">
													<select class="form-control"  id="block" onchange="load_room()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
													<option>select blocks</option>

													</select>
													</div>

													<div class="col-md-12" style="margin-top:20px;">
													<select class="form-control"  id="room" onkeypress="category_select()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
													<option>select Rooms</option>
													</select>
													</div><br><br>
													<button type="button" class="btn btn-success" style="margin-top:20px;" onclick="allocation()">Allocate Now </button>
													</div><br><br><br>
													<div id="result"></div>
													</center>


													';







															?>




											</div><!-- / col-lg -12 -->
											</div><!-- / col-lg -12 -->
											</div><!-- / col-lg -12 -->
											</div><!-- / col-lg -12 -->


									<?php
													}//end of if
													}//end of while

				}else if ($type_id == 4)
				{

											$q = "SELECT CONCAT_WS(' ',first_name,other_names) AS name, number,phone_number,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 = '$user_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_number'];
														$level = $row['level'];
														$programme = $row['programme'];
														$gender = $row['gender'];
														$student_id = $row['id'];
														if($gender=='F' OR $gender== 'female')
														{
															$gender = 'female';
														}else if($gender=='M' OR $gender== 'male')
														{
															$gender = 'male';
														}

														echo '

														<div class="panel panel-default">
															<div class="panel-heading">
																<h3 class="panel-title">'.strtoupper($name).' ----- '.strtoupper($matric).'-----'.strtoupper($programme).'-----'.strtoupper($phone_number).' ----- '.strtoupper($level).' ----- '.strtoupper($gender).'</h3>
															</div>
															<div class="panel-body">';



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

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

													echo'<center>
													<div class="col-md-12">
												<div class="col-md-12">
														<input type="hidden" value="'.$gender.'" id="gender">
														<input type="hidden" value="'.$student_id.'" id="student_id">
													<select class="form-control"  id="site" onchange="load_lga()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
													<option>select hostel</option>';
													$q = "SELECT * FROM hostel_campuses WHERE status='1' ORDER BY date_added ASC ";
													$r = mysqli_query($conn_1, $q) ;

													if(mysqli_num_rows($r) > 0)
													{//show table
														while($row = mysqli_fetch_array($r)){


															echo '

															<option value="'.$row['id'].'">'.$row['title'].'</option>';

													}
												}

													echo '</select></div><br>
													<div class="col-md-12" style="margin-top:20px;">
													<select class="form-control"  id="block" onchange="load_room()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
													<option>select blocks</option>

													</select>
													</div>

													<div class="col-md-12" style="margin-top:20px;">
													<select class="form-control"  id="room" onkeypress="category_select()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
													<option>select Rooms</option>
													</select>
													</div><br><br>
													<button type="button" class="btn btn-success" style="margin-top:20px;" onclick="allocation()">Allocate Now </button>
													</div><br><br><br>
													<div id="result"></div>
													</center>


													';







															?>




											</div><!-- / col-lg -12 -->
											</div><!-- / col-lg -12 -->
											</div><!-- / col-lg -12 -->
											</div><!-- / col-lg -12 -->


									<?php
													}//end of if
													}//end of while

				}else if ($type_id == 5)
				{

											$q = "SELECT CONCAT_WS(' ',first_name,other_names) AS name, number,phone_number,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 = '$user_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_number'];
														$level = $row['level'];
														$programme = $row['programme'];
														$gender = $row['gender'];
														$student_id = $row['id'];
														if($gender=='F' OR $gender== 'female')
														{
															$gender = 'female';
														}else if($gender=='M' OR $gender== 'male')
														{
															$gender = 'male';
														}

														echo '

														<div class="panel panel-default">
															<div class="panel-heading">
																<h3 class="panel-title">'.strtoupper($name).' ----- '.strtoupper($matric).'-----'.strtoupper($programme).'-----'.strtoupper($phone_number).' ----- '.strtoupper($level).' ----- '.strtoupper($gender).'</h3>
															</div>
															<div class="panel-body">';



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

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

													echo'<center>
													<div class="col-md-12">
												<div class="col-md-12">
														<input type="hidden" value="'.$gender.'" id="gender">
														<input type="hidden" value="'.$student_id.'" id="student_id">
													<select class="form-control"  id="site" onchange="load_lga()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
													<option>select hostel</option>';
													$q = "SELECT * FROM hostel_campuses WHERE status='1' ORDER BY date_added ASC ";
													$r = mysqli_query($conn_1, $q) ;

													if(mysqli_num_rows($r) > 0)
													{//show table
														while($row = mysqli_fetch_array($r)){


															echo '

															<option value="'.$row['id'].'">'.$row['title'].'</option>';

													}
												}

													echo '</select></div><br>
													<div class="col-md-12" style="margin-top:20px;">
													<select class="form-control"  id="block" onchange="load_room()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
													<option>select blocks</option>

													</select>
													</div>

													<div class="col-md-12" style="margin-top:20px;">
													<select class="form-control"  id="room" onkeypress="category_select()" style="lenght:100%" autofocus required placeholder="Username (Email Address:)">
													<option>select Rooms</option>
													</select>
													</div><br><br>
													<button type="button" class="btn btn-success" style="margin-top:20px;" onclick="allocation()">Allocate Now </button>
													</div><br><br><br>
													<div id="result"></div>
													</center>


													';







															?>




											</div><!-- / col-lg -12 -->
											</div><!-- / col-lg -12 -->
											</div><!-- / col-lg -12 -->
											</div><!-- / col-lg -12 -->


									<?php
													}//end of if
													}//end of while

				}else if ($type_id == 6)
				{

				}

	?>

        </div>  <!-- #view1 -->

      </div> <!-- /tab-content -->
</div> <!-- /well-->

<script type="text/javascript">
function load_lga(){


//alert('welcome');

		var site = document.getElementById("site").value;
			var gender = document.getElementById("gender").value;

			//alert(gender);

			$.post('php/load_blocks.php',{site:site,gender:gender},
			function(response,status){
				//alert(response);
			document.getElementById("block").innerHTML =response;

			});
}

function load_room(){


//alert('welcome');

			var site = document.getElementById("site").value;
			var block = document.getElementById("block").value;

					//	alert(site);

			$.post('php/load_room.php',{site:site,block:block},
			function(response,status){
				//alert(response);
			document.getElementById("room").innerHTML =response;

			});
}

function allocation(){


//alert('welcome');

			var site = document.getElementById("site").value;
			var block = document.getElementById("block").value;
			var room = document.getElementById("room").value;
			var student_id = document.getElementById("student_id").value;
			var type_id = document.getElementById("type_id").value;
			//alert(type_id)

			$.post('php/allocate.php',{site:site,block:block,room:room,student_id:student_id,type_id:type_id},
			function(response,status){
				//alert(response);
			document.getElementById("result").innerHTML =response;

			});
}
</script>
