
	<div id="message" class="message alert alert-success"></div>

    <div style="height:20px; displat:block;"></div>

    <ul class="breadcrumb">

        <li class="active" >MY BED SPACE <span class="divider"></span> </li>
    </ul>


<div class="well">
    <div class="row">
         <div class="col-lg-12">




					 <?php
	//session_start();
		$user_id =$_SESSION['id'];
		include('../includes/configuration_1.php');

	$get_rec = mysqli_query($dbc, "SELECT *FROM students WHERE id='$user_id' ") or die(mysqli_error($dbc));
	$rows_rec = mysqli_fetch_array($get_rec);
	$faculty = $rows_rec['department_applied_for'];
	$gender= $rows_rec['gender'];

	?>
	<div class="col-md-12" style="padding-left:0px; padding-right:0px;">
				<div class="list-group">
					<ul class="list-group">
						<li class="list-group-item list-group-item-success">
							<h4>My Bed Space</h4>
						</li>
					</ul>



				</div>

				<?php


					$check_my_acc = mysqli_query($dbc, "SELECT *FROM hostel_allocation WHERE std_id='$user_id' ") or die(mysqli_error($dbc));
					if($check_my_acc){
						if(mysqli_num_rows($check_my_acc) > 0){
							$get_my_room_info = mysqli_fetch_array($check_my_acc);
							$room_info_room_id = $get_my_room_info['room_id'];
							$room_info_site_id = $get_my_room_info['hostel_site'];
							$room_info_block_id = $get_my_room_info['hostel_categories'];



							$mm = mysqli_query($dbc, "SELECT *FROM hostel_rooms WHERE id='$room_info_room_id'");
								$ronn = mysqli_fetch_array($mm);
								$title_room = $ronn ['title'];

							$mm = mysqli_query($dbc, "SELECT *FROM hostel_categories  WHERE id='$room_info_block_id'");
								$ronn = mysqli_fetch_array($mm);
								$title_block = $ronn ['title'];

							$mm = mysqli_query($dbc, "SELECT *FROM hostel_sites WHERE id='$room_info_site_id' ");
							$ronn = mysqli_fetch_array($mm);
								$site_title = $ronn ['title'];


		echo '

	<div class="panel panel-default">
	  <div class="panel-heading">
	    <h3 class="panel-title">'.strtoupper($site_title).' --- '.strtoupper($title_block).' --- '.strtoupper($title_room).'</h3>
	  </div>
	  <div class="panel-body">';
	   	//geting room member
	   	$sql=mysqli_query($dbc, "SELECT *FROM students INNER JOIN hostel_allocation ON students.id= hostel_allocation.std_id WHERE room_id='$room_info_room_id' ");
	   	if($sql){
	   		$sql_row=mysqli_num_rows($sql);
	   		if($sql_row > 0){
	   			//get the student detals
	   			while($row=mysqli_fetch_array($sql)){
	   			$img=$row['image'];
	   			$email=$row['email'];
	   			$fullname=$row['first_name'].' '.$row['surname'].' '.$row['other_names'];
	   			$phone_number=$row['phone_number'];
	   			if($img==""){

				$pic='<img src="../uploads/0.png" width="120px" height="130px" class="img-circle"/>';
			}else{

				$pic='<img src="../uploads/'.$img.'" width="120px" height="130px" class="img-circle"/>';

			}

	   			echo '

	   				<table width="100%" class="table">
	   					<tr>
	   						<td width="10%">'.$pic.'</td>
	   						<td width="90%">
	   							<table width="100%">
	   								<tr>
	   									<td width="100%"><h3 class="label label-success">NAME: '.$fullname.'</h3><hr/>


	   									</td>
	   								</tr>
	   								<tr>
	   									<td width="100%"><h3 class="label label-success">Phone Number: '.$phone_number.'</h3><hr/>

	   									</td>
	   								</tr>
	   								<tr>
	   									<td width="100%"><h3 class="label label-success">Email: '.$email.'</h3><hr/>


	   									</td>
	   								</tr>
	   							</table>
	   						</td>
	   					</tr>
	   				</table><hr/>';
	   			}
	   		}
	   	}
	  echo'</div>
	</div>';
						}else{

							$check_blocks = mysqli_query($dbc, "SELECT *FROM hostel_categories  WHERE hostel_site='$faculty'  AND gender='$gender'") or die(mysql_error($dbc));
							if($check_blocks){
								while($rows_blocks = mysqli_fetch_array($check_blocks)){
									$block_name = $rows_blocks['title'];
									$block_id = $rows_blocks['id'];
									//echo '<div class="col-md-12">'.$block_name.'</div>';

									echo '


									<div class="panel panel-success">
	  <div class="panel-heading">
	    <h3 class="panel-title">'.$block_name.'</h3>
	  </div>
	  <div class="panel-body">';

	   $get_rooms = mysqli_query($dbc, "SELECT *FROM hostel_rooms WHERE hostel_site='$faculty' AND hostel_categories='$block_id' AND reserved='1' ");
									if($get_rooms){
										if(mysqli_num_rows($get_rooms) > 0){
											while($rooms_get_row = mysqli_fetch_array($get_rooms) ){
												$room_title = $rooms_get_row['title'];
												$room_id = $rooms_get_row['id'];
												$hostel_categories_id = $rooms_get_row['hostel_categories'];
												$bedspace_no = $rooms_get_row['bedspace'];
								$check_my_alllll = mysqli_query($dbc, "SELECT *FROM hostel_allocation WHERE room_id='$room_id' ") or die(mysqli_error($dbc));
								$num_of_allocated = mysqli_num_rows($check_my_alllll);
								$remainder = $bedspace_no - $num_of_allocated;
								if($remainder > 0){
									echo '<div class="col-sm-1"><button onClick="select_room('.$id.','.$room_id.')">'.$room_title.'</buttton></div>';
								}

											}
										}else{
											echo '<div class="col-md-12">NO AVAILABLE ROOM IN THIS BLOCK</div>';
										}
									}
	 echo' </div>
	</div>

									';













								}
							}
						}
					}

				?>
	</div>


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

				<div class="col-md-12">
					<div class="col-md-8" style="margin-left:20px">
						<select class="form-control">
							<option>Select Block </div>
								<?php


										//include_once('../connection.php');
											//get state
											$sql_get_state=mysqli_query($dbc, "SELECT *FROM programmes WHERE id='$type'") or die(mysqli_error($dbc));
											if($sql_get_state){
												$sql_get_state_row=mysqli_num_rows($sql_get_state);
												if($sql_get_state_row > 0){
													while($row=mysqli_fetch_array($sql_get_state)){

														echo '<option>'.$row['title'].'</option>';
													}
												}
											}


									?>
						</select>
					</div>
					<div class="col-md-3" style="margin-left:-25px">
						<button class="form-control btn btn-primary">
							Check Here
						</button>
					</div>
				</div>



    </div><!-- /.row -->
</div><!-- /well -->
