 <header class="header-desktop">
	<div class="section__content section__content--p30">
		<div class="container-fluid">
			<div class="header-wrap">
			<?php 
			$invalid_input = "";
			$has_warning = "";
			//echo "session projectLocation: ".$_SESSION["projectLocation"];
			//$_SESSION["projectLocation"] = $_POST["projectLocation"];
			?>
			   <form class="<?php echo $has_warning ?> form-header" action="staff_dashboard.php?menu=Dashboard" method="post" >
					<input type="hidden" name="login" value="<?php echo $_GET["login"]?>">
					 
						<input id="inputIsInvalid"  class="<?php echo $invalid_input;?> au-input au-input--xl" type="text" list="projectLocation" name="projectLocation" onChange="javascript: submit();" size="50" value="<?php echo $_SESSION['projectLocation']?>" placeholder="Select Location"/>
						<button class="au-btn--submit" type="submit">
							<i class="zmdi zmdi-search"></i>
							<datalist id="projectLocation">
								
								<?php
								
								//echo "USERNAME: ".$_SESSION["username"] ;
									/* if($_SESSION["username"] != "admin"){
										  $sqlLocations = "SELECT * FROM ( 
															(select EL.location_id, locations.location_name, projects.project_name from extra_locations as EL 
															inner join locations on locations.id = EL.location_id 
															inner join projects on locations.project_id = projects.id 
															inner join users on EL.user_id =  users.id
															where users.id = ". $_SESSION['staff_id'] ." and locations.status = 'enable') 
														UNION 
															(select locations.id, locations.location_name, projects.project_name from locations 
															inner join users on locations.id = users.location_id 
															inner join projects on locations.project_id = projects.id
															where users.id = ". $_SESSION['staff_id'] ." and locations.status = 'enable') 
														) results ORDER BY project_name ASC";
										
										$runLocations = mysqli_query($link,$sqlLocations);
										if($runLocations === FALSE){
											die(mysqli_error($link));//TODO: better error handling
										}
									}
									else if($_SESSION["username"] == "admin"){
											 $sqlLocations = "select locations.*,projects.project_name, projects.id as project_id from locations 
												
												inner join projects on locations.project_id = projects.id
												where projects.status = 'enable' and projects.project_name != 'admin' and locations.status = 'enable'
												ORDER BY `projects`.`project_name` ASC";
										$runLocations = mysqli_query($link, $sqlLocations);
										if($runLocations === FALSE){
											die(mysqli_error($link));
										}
									} */
									
									 if($_SESSION["username"] != "admin"){
									    /* $sqlLocations = "SELECT * FROM ( 
														(select EL.location_id, locations.location_name, projects.project_name from extra_locations as EL 
														inner join locations on locations.id = EL.location_id 
														inner join projects on locations.project_id = projects.id 
														inner join users on EL.user_id =  users.id
														where users.id = ". $_SESSION['staff_id'] ." extra_location.status = 'enable' ) 
													UNION 
														(select locations.id, locations.location_name, projects.project_name from locations 
														inner join users on locations.id = users.location_id 
														inner join projects on locations.project_id = projects.id
														where users.id = ". $_SESSION['staff_id'] ." extra_location.status = 'enable' ) 
													) results ORDER BY project_name ASC";
									 */
									 $sqlLocations = "select EL.location_id, locations.location_name, projects.project_name from extra_locations as EL 
														inner join locations on locations.id = EL.location_id 
														inner join projects on locations.project_id = projects.id 
														inner join users on EL.user_id =  users.id
														where users.id = ". $_SESSION['staff_id'] ." and EL.status = 'enable' ";
									
									$runLocations = mysqli_query($link,$sqlLocations);
									if($runLocations === FALSE){
										die(mysqli_error($link));//TODO: better error handling
									}
								}
								else if($_SESSION["username"] == "admin"){
										 $sqlLocations = "select locations.*,projects.project_name, projects.id as project_id from locations 
											
											inner join projects on locations.project_id = projects.id
											where projects.status = 'enable' and projects.project_name != 'admin' and locations.status = 'enable'
											ORDER BY `projects`.`project_name` ASC";
									$runLocations = mysqli_query($link, $sqlLocations);
									if($runLocations === FALSE){
										die(mysqli_error($link));
									}
								}
									
									
									 $countListLocations = mysqli_num_rows($runLocations);
									if($countListLocations == 1){
										$resultLocations = mysqli_fetch_assoc($runLocations);
										$location_id = $resultLocations["id"];
										$location_name = $resultLocations["location_name"];
										$project_name = $resultLocations["project_name"];
										$_SESSION["projectLocation"] = strtoupper($project_name . "-" . $location_name);?>
										
										<option <?php echo (strtoupper($_SESSION["projectLocation"]) ==  strtoupper($project_name . "-" . $location_name))  ? "selected" : "" ?> value="<?php echo strtoupper($project_name . "-" . $location_name); ?>" >
									<?php }
									else if($countListLocations > 1){ 
										while($resultLocations = mysqli_fetch_array($runLocations)){
											$location_id = $resultLocations["id"];
											$location_name = $resultLocations["location_name"];
											$project_name = $resultLocations["project_name"];
												?>
												<option <?php echo (strtoupper($_SESSION["projectLocation"]) ==  strtoupper($project_name . "-" . $location_name))  ? "selected" : "" ?> value="<?php echo strtoupper($project_name . "-" . $location_name); ?>" >
												
												<?php
										}
									}
								?>
							</datalist>
						</button> 
					</form>
					<form action="tenant_listing.php" method="post" >
						<?php 
						if($_SESSION["projectLocation"] == ""){
							$invalid_input = "is-invalid" ;
							$has_warning = "has-warning" ;
							?>
							 <button type="button" class="btn btn-warning">
								<i class="fa fa-map-marker"></i>&nbsp; Please select location </button>
							<?php
						}
						else if($_SESSION["projectLocation"] != ""){
						?>
						
						<div class="input-group">
							
							<?php 
							$_SESSION['properties_unitno'] = $_POST["properties_unitno"];
							 "TENANT NAME LIST::: " .$_SESSION['tenant_name_listing'] = $_POST["tenant_name_listing"];
							
							?>
									<input class="form-control" type="text"  id="properties_unitno_input" list="properties_unitno" name="properties_unitno" onChange="javascript: submit();"  value="<?php echo $_SESSION['properties_unitno']?>" placeholder="Select Unit No" autocomplete="off"/>
									<datalist id="properties_unitno">
									<?php
										if($_SESSION["username"] <> "admin"){
											
												$sqlPropertiesUnitNo = "select properties.* from properties 
													inner join locations on properties.location_id = locations.id 
													where locations.location_name = '".$_SESSION["locationName"]."' 
													and locations.project_id = ".$_SESSION["project_id"]." 
													";
										}
										else if($_SESSION["username"] == "admin"){
											
											 $sqlPropertiesUnitNo = "select properties.* from properties 
													inner join locations on properties.location_id = locations.id 
													where locations.location_name = '".$_SESSION["locationName"]."' 
													and locations.project_id = ".$_SESSION["project_id"]."
													";
										}
										
										$runProeprtiesUnit  = mysqli_query($link, $sqlPropertiesUnitNo );
									if($runProeprtiesUnit === FALSE){
										die(mysqli_error($link));
									}
									
									
										while($resultPropertiesUnit = mysqli_fetch_array($runProeprtiesUnit)){
											$propertiesID = $resultPropertiesUnit["id"];
											$properties_unitno = $resultPropertiesUnit["unit_no"];
											
												?>
												
											<option value="<?php echo strtoupper($properties_unitno); ?>">
											<?php
										}
									?>
									
									</datalist>
									<input class="form-control" type="text"  id="tenant_name_id" list="tenant_name_listing" name="tenant_name_listing" onChange="javascript: submit();"  value="<?php echo $_SESSION['tenant_name_listing']?>" placeholder="Select Tenant Name" autocomplete="off"/>
									<datalist id="tenant_name_listing">
									<?php
										
										
										 echo $sqlTenants = "select tenants.id, tenants.tenant_name from tenants
												inner join properties on tenants.property_id = properties.id
												inner join locations on properties.location_id = locations.id 
												where locations.location_name = '".$_SESSION["locationName"]."' 
												and locations.project_id = ".$_SESSION["project_id"]."
												";
										
										
										$runTenants  = mysqli_query($link, $sqlTenants );
									if($runTenants === FALSE){
										die(mysqli_error($link));
									}
									
									
										while($resultTenants = mysqli_fetch_array($runTenants)){
											$tenant_id = $resultTenants["id"];
											$tenant_name_listing = $resultTenants["tenant_name"];
											
												?>
												
											<option value="<?php echo strtoupper($tenant_name_listing); ?>">
											<?php
										}
									?>
									
									</datalist>
									<?php
									if($_SESSION["tenant_name_listing"] != "" || $_SESSION["properties_unitno"] != ""){
										?>
										<div class="input-group-btn">
                                                            <button type="submit" name="reset" class="btn btn-danger">Reset</button>
                                                        </div>
										<!--<button type="submit" class="btn btn-outline-danger btn-sm"  name="reset" >Reset</button>-->
									<?php } ?>
						</div>
						<?php } 
							
						?>
						
							
					<input type="hidden" name="menu" value="<?php echo $_SESSION["menu"]?>">
					<input type="hidden" name="submenu" value="<?php echo $_SESSION["submenu"]?>">
				
				</form>
				<div class="header-button">
					<div class="noti-wrap">
					</div>
					<div class="account-wrap">
						<div class="account-item clearfix js-item-menu">
							<div class="image">
								<img src="images/icon/phssb-front.jpg" alt="John Doe" />
							</div>
							<div class="content">
								<a class="js-acc-btn" href="#"><?php echo strtoupper($_SESSION["username"])?></a>
							</div>
							<div class="account-dropdown js-dropdown">
								<div class="info clearfix">
									<div class="image">
										<a href="#">
											<img src="images/icon/phssb-front.jpg" alt="John Doe" />
										</a>
									</div>
									<div class="content">
										<h5 class="name">
											<a href="#"><?php echo $_SESSION["type"]?></a>
										</h5>
										<span class="email">phssbrpmsadmin@phssb.com</span>
									</div>
								</div>
								<div class="account-dropdown__body">
									<div class="account-dropdown__item">
										<a href="#">
											<i class="zmdi zmdi-account"></i>Account</a>
									</div>
									<div class="account-dropdown__item">
										<a href="#">
											<i class="zmdi zmdi-settings"></i>Setting</a>
									</div>
									<div class="account-dropdown__item">
										<a href="#">
											<i class="zmdi zmdi-money-box"></i>Billing</a>
									</div>
								</div>
								<div class="account-dropdown__footer">
									<a href="logout.php">
										<i class="zmdi zmdi-power"></i>Logout</a>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</header>
