

	<form id="allocate_hostel" method="POST">

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

    <ul class="breadcrumb" >

        <li class="active btn btn-login btn-green" style="background: #027174; color:#FFF;  width:830px"><b><span style="font-size:20px;">MY BED SPACE</span> </b><span class="divider"></span> </li>
    </ul>


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







	<?php
@session_start();

include_once '../db_connect/db.php';
//include_once('../functions.php');

if (isset($_SESSION['student_id'])) {
    $student_id = $_SESSION['student_id'];
		$session = 6;
		$session2 = 2;
	$session_title = get_current_session($session);
	//get the type the student belongs too
	$type_id = get_student_type($student_id);
	$image = get_user_image($student_id);
	//check if the student have pay school fee
	if($type_id=='1')
	{
	    $matric_no = get_student_matric_no($conn_1, $student_id);
	    $student_m_id = get_student_id_prence($conn_1, $matric_no);
		$school_fee = get_prence_school_fee_payment_status($conn_1,$student_m_id,$session);
	}else if($type_id=='2')
	{
	   
	    $matric_no = get_student_matric_no($conn_1, $student_id);
	    $student_m_id = get_student_id_nce($conn_1, $matric_no);
		$school_fee = get_nce_school_fee_payment_status($conn_1,$student_m_id,$session);
	}else if($type_id=='3')
	{
	    $matric_no = get_student_matric_no($conn_1, $student_id);
	    $student_m_id = get_student_id_duap($conn_2, $matric_no);
		$school_fee = get_duap_school_fee_payment_status($conn_2,$student_m_id,$session2);
	}else if($type_id=='4')
	{
	    $matric_no = get_student_matric_no($conn_1, $student_id);
	    $student_m_id = get_student_id_summer($conn_1, $matric_no);
		$school_fee = get_summer_school_fee_payment_status($conn_1,$student_m_id,$session);
	}else if($type_id=='5')
	{
	    $matric_no = get_student_matric_no($conn_1, $student_id);
	    $student_m_id = get_student_id_lvsp($conn_1, $matric_no);
		$school_fee = get_duap_school_fee_payment_status($conn_1,$student_m_id,$session2);
	}


  

	//check if the student have paid the application fee.
	$hostel_app_fee = get_hostel_app_fee_payment_status($conn_1,$student_id,$session);

	if($school_fee)
	{
	//	if($hostel_app_fee){
				//get datas from the form


        //check if student have make payments
        $checking = mysqli_query($conn_1, "SELECT * FROM hostel_fee_payments WHERE student_id = '$student_id' AND session_id = '$session' AND payment_status= '1' ") or die(mysqli_error($conn_1));
        if ($checking) {

           $sql_verify = mysqli_num_rows($checking);

            if ($sql_verify > 0) {

                //get room Members
                $member = mysqli_query($conn_1, "SELECT CONCAT_WS(' ', first_name, other_names) as `name`, phone_no,number, hostel_students.id AS id,
				hostel_students.gender AS gender, state.title AS state, lga.title AS lga, hostel_campuses.title AS site, hostel_students.image AS image,
				application_number, programmes.title AS programme, hostel_students.email as email, hostel_blocks.title AS category,
				hostel_rooms.title AS room FROM state, lga, hostel_campuses, hostel_allocation,hostel_blocks,hostel_rooms,
				hostel_students, programmes, hostel_fee_payments  WHERE hostel_students.programme_id =programmes.id  AND hostel_students.state_id = state.id AND
				hostel_students.lga_id = lga.id AND hostel_students.id = hostel_allocation.student_id AND
				hostel_allocation.campus_id = hostel_campuses.id AND hostel_allocation.room_id = hostel_rooms.id AND hostel_allocation.block_id = hostel_blocks.id AND 
				hostel_students.hostel_allocation = 1 AND hostel_students.id = hostel_fee_payments.student_id
					 ") or die(mysqli_error($conn_1));

                if ($member) {
                    if (mysqli_num_rows($member) > 0) {
                        echo '<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">
													<h3>My Room Member Information</h3>
												</li>
											</ul>



										</div>


							</div>';
                        while ($get = mysqli_fetch_array($member)) {
                            echo '


							<div class="panel panel-default">
								<div class="panel-heading">

									<h3 class="panel-title">' . strtoupper($get['site']) . ' --- ' . strtoupper($get['category']) . ' --- ' . strtoupper($get['room']) . '</h3>
								</div>
								<div class="panel-body">';

                            $img = $get['image'];

                            if ($img == "") {

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

                                $pic = '<img src="../uploads/bg.jpg" 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: ' . strtoupper($get['name']) . '</h3><hr/>


																		</td>
																	</tr>
																	<tr>
																		<td width="100%"><h3 class="label label-success">Phone Number: ' . strtoupper($get['phone_no']) . '</h3><hr/>

																		</td>
																	</tr>
																	<tr>
																		<td width="100%"><h3 class="label label-success">Email: ' . strtoupper($get['email']) . '</h3><hr/>


																		</td>
																	</tr>
																</table>
															</td>
														</tr>
													</table><hr/>';
                        }
                    }

                    echo '</div>
								</div>';
                }

            } else {
                //check invoice to make sure the student have generated invoice already
                $checking = mysqli_query($conn_1, "SELECT * FROM hostel_allocation WHERE student_id='$student_id' AND session_id = '$session' AND status='1' ") or die(mysqli_error($conn_1));
                if ($checking) {
                    $sql_verify = mysqli_num_rows($checking);
                    if ($sql_verify > 0) {

                        //get hostel allocation of the student
                        $allocate = mysqli_query($conn_1, "SELECT * FROM hostel_allocation WHERE student_id = '$student_id' AND session_id = '$session' AND status='1' ") or die(mysqli_error($conn_1));
                        $sql = mysqli_fetch_assoc($allocate);
                        $cat_id = $sql['block_id'];
                        $site_id = $sql['campus_id'];
                        $room_id = $sql['room_id'];

                        //get his room title
                        $allocate = mysqli_query($conn_1, "SELECT  title FROM hostel_rooms WHERE id='$room_id' ") or die(mysqli_error($conn_1));
                        $sqll = mysqli_fetch_assoc($allocate);
                        $room_title = $sqll['title'];

                        //get his hostel site title
                        $allocate = mysqli_query($conn_1, "SELECT title FROM hostel_campuses WHERE id='$site_id' ") or die(mysqli_error($conn_1));
                        $sqls = mysqli_fetch_assoc($allocate);
                        $site_title = $sqls['title'];

                        //get his category title
                        $allocate = mysqli_query($conn_1, "SELECT title FROM hostel_blocks WHERE id='$cat_id' ") or die(mysqli_error($conn_1));
                        $sqlss = mysqli_fetch_assoc($allocate);
                        $cat_title = $sqlss['title'];

                        //get student biodata
                        $q = "SELECT id, CONCAT_WS(' ', first_name, other_names) as name,`image`, phone_no,
									gender,`number`, email,`level`,programme_id FROM hostel_students WHERE id='$student_id' ";
                        $r = mysqli_query($conn_1, $q);
                        $sql_verify = mysqli_fetch_assoc($r);

                        $programme_id = $sql_verify['programme_id'];

                        $gen = $sql_verify['gender'];
                        if ($gen == 'F') {
                            $gender = "Female";
                        } else {
                            $gender = "Male";
                        }

                        $img = $sql_verify['image'];

                        if ($img == "" && !file_exists('../uploads/' . $img)) {

                            $pic = '<img src="../images/user.jpg" width="120px" height="130px" class="img-circle"/>';
                        } else {

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

                        }

                        echo '

												<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">
																		<h3>My Bed Space Information/ Make Payment</h3>
																	</li>
																</ul>



															</div>


												</div>

												<div class="panel panel-default">
													<div class="panel-heading">
														<h3 class="panel-title">' . strtoupper($site_title) . ' ----- ' . strtoupper($cat_title) . ' ----- ' . strtoupper($room_title) . '</h3>
													</div>
													<div class="panel-body">';

                        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" style="font-size:12px;">NAME: ' . strtoupper($sql_verify['name']) . '</h3><hr/>


																			</td>
																		</tr>
																		<tr>
																			<td width="100%"><h3 class="label label-success" style="font-size:12px;">Matric Number: ' . strtoupper($sql_verify['number']) . '</h3><hr/>

																			</td>
																		</tr>
																		<tr>
																			<td width="100%"><h3 class="label label-success" style="font-size:12px;">Phone Number: ' . strtoupper($sql_verify['phone_no']) . '</h3><hr/>

																			</td>
																		</tr>
																		<tr>
																			<td width="100%"><h3 class="label label-success" style="font-size:12px;">Email: ' . strtoupper($sql_verify['email']) . '</h3><hr/>


																			</td>
																		</tr>
																		<tr>
																			<td width="100%"><h3 class="label label-success" style="font-size:12px;">Gender: ' . strtoupper($gender) . '</h3><hr/>


																			</td>
																		</tr>
																	</table>
																	<!-- PROCEED TO PAYMENT --> <a class="btn btn-login btn-green" style="width:80%; margin-top:20px;" href="dashboard.php?sms=payment" data-toggle="tooltip" title="Click here to Proceed to payment" data-placement="top"> <span>PROCEED TO PAYMENT</span></a>
																</td>
															</tr>

														</table><hr/>';

                        echo '</div>
													</div>';

                    } else {
                        //query the database

                        echo '
				<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">
										<h3>My Bed Space Information</h3>
									</li>
								</ul>



							</div>


				</div>


				<div class="form-group has-success has-feedback form-inline">
				<label class="control-label" for="inputSuccess4" style="padding-left:20px; font-size:20px;">Click here to select Hostel </label>
				<div class="col-md-9">
				<select class="form-control"  name="site" onkeypress="check()" style="width:600px; float:left;" autofocus required placeholder="Username (Email Address:)">
				<option>Select your campus</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>
				<div class="col-md-3">
				<div id="allocating"><button class="form-control btn btn-login btn-green col-md-3" name="submit" onclick="check()">
				<span>Check Here!</span></div>
				</button>
				</div>
				<div>
				<br>
				<div id="q"></div>';

                    }
                }
            }

        }

   // } else {

      //  echo '<div class="alert alert-info">
	//							<button class="close" data-dismiss="alert" type="button">X</button>
	//								<img src="images/info.png" /> &nbsp<h1> You must pay your Hostel Application fee, before getting access to the hostel.</h1>
	//					 </div>
	//						';
   // }

}else{
	echo '<div class="alert alert-info">
					<button class="close" data-dismiss="alert" type="button">X</button>
						<img src="images/info.png" /> &nbsp<h1> You must pay your School fee, before getting access to the hostel.</h1>
			 </div>';
}



}
?>




				<div id="outputt_allocated">

				</div>

				</form>

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

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



<script type="text/javascript">
			$(document).ready(function(e){



					$("#allocate_hostel").submit(function(event){
						event.preventDefault(); //prevent default action
						var post_url = "includes/pages/check_site.php"; //get form action url
						var request_method = $(this).attr("method"); //get form GET/POST method

						$("#outputt_allocated").html('<div style="margin-top:10px"><center>fetching your allocation Data, please wait...<br/><img src="images/ajax-loader1.gif" width="10%"/></center></div>');
						document.getElementById("allocating").style.display = "none";
						var form_data = new FormData(this); //Creates new FormData object


							$.ajax({
								url : post_url,
								type: request_method,
								data : form_data,
								contentType: false,
								cache: false,
								processData:false
							}).done(function(response){ //

								if(response==1){


								 document.getElementById("allocating").style.display = "block";
								 $("#outputt_allocated").html("");
								  //swal(response);



								}else{

								$("#outputt_allocated").html(response);
								document.getElementById("allocating").style.display = "block";
								//swal(response);
								}
							});

					});
			});


			</script>
