<?php include "headerLink.php"?>
<!DOCTYPE html>
<html lang="en">

<script>
function newPopup(url) {
	popupWindow = window.open(
	//url,'popUpWindow','height=600,width=700,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
	url,'_blank','left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
</script>
<body class="animsition">
    <div class="page-wrapper">
        <!-- HEADER MOBILE-->
        <?php include "menuSideBar_mobile.php" ;?>
        <!-- END HEADER MOBILE-->
		
        <!-- MENU SIDEBAR-->
        <?php include "menuSideBar.php" ;?>
        <!-- END MENU SIDEBAR-->

        <!-- PAGE CONTAINER-->
        <div class="page-container">
            <!-- HEADER DESKTOP-->
			<?php include "headerPage.php"?>
            <!-- END HEADER DESKTOP-->
			
			
			
			<!-- MAIN CONTENT-->
			<?php
			
			
			?>
			
            
            <div class="main-content"  >
                <div class="section__content section__content--p30" >
                    <div class="container-fluid" >
                        <!-- menu show on page after selected - start -->
                        <?php include "selectedMenuSubMenu.php"?>
						<!-- menu show on page after selected - end -->
						<div class="row" >
							<!--<img src="images/icon/website under contruction.jpg" alt="PAYPRO-V3" />-->
                            <div class="col-lg-12">
                                <div class="table-responsive table--no-card m-b-30">
                                    <table  class="table table-borderless table-striped table-earning">
                                        <thead>
                                            <tr>
                                                <th>#</th>
                                                <th>Name</th>
                                                <th>email</th>
												<th>Status</th>
                                                <th>Username</th>
												<th>Projects</th>
                                                <th>Locations</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
										<tbody>
										<?php 
										echo $sqlUsers = "select users.* from users where status = 'enable'";
										$runUsers = mysqli_query($link, $sqlUsers);
										if($runUsers === FALSE){
											die(mysqli_error($link));
										}
										
										$no = 1;
										
										while($resultUsers = mysqli_fetch_array($runUsers)){ 
											$noResultLocation = 1;
											
											$staff_id = $resultUsers["id"];
											echo $sqlStaffLocationInfo = "select extra_locations.user_id, extra_locations.location_id, locations.location_name, projects.project_name from  
															extra_locations 
															inner join locations on locations.id = extra_locations.location_id 
															inner join users on extra_locations.user_id =  users.id 
															inner join projects on locations.project_id = projects.id where users.id = $staff_id";
											$runStaffLocationInfo = mysqli_query($link, $sqlStaffLocationInfo);
											if($runStaffLocationInfo === FALSE){
												die(mysqli_error($link));
											}
											$countResultStaffLocationInfo = mysqli_num_rows($runStaffLocationInfo);
											
											
										?>
										<tr>
                                                <td rowspan="<?php echo $countResultStaffLocationInfo?>"><?php echo $no; ?></td>
												<td rowspan="<?php echo $countResultStaffLocationInfo?>"><?php echo $resultUsers["name"]; ?></td>
                                                <td rowspan="<?php echo $countResultStaffLocationInfo?>"><?php echo $resultUsers["email"]; ?></td>
                                                <td rowspan="<?php echo $countResultStaffLocationInfo?>"><?php echo $resultUsers["status"]; ?></td>
                                                <td rowspan="<?php echo $countResultStaffLocationInfo?>"><?php echo $resultUsers["username"]; ?></td>
										<?php
											
											if($countResultStaffLocationInfo == 1){
												$resultStaffLocationInfo = mysqli_fetch_assoc($runStaffLocationInfo);
												?>
												
												<td><?php echo $resultStaffLocationInfo["project_name"]; ?></td>
                                                <td><?php echo $resultStaffLocationInfo["location_name"]; ?></td>
												<td>
													<button type="button"  onclick="Javascript:newPopup('action.php?staff_id=<?php echo $staff_id;?>&action=pwd')" class="btn btn-outline-danger btn-sm">Change Password</button>
													<button type="button"  onclick="Javascript:newPopup('action.php?staff_id=<?php echo $staff_id;?>&action=ud')" class="btn btn-outline-warning btn-sm">Update Details</button>
												</td>
											</tr>
												<?php
											}
											else if($countResultStaffLocationInfo > 1){
												while($resultStaffLocationInfo = mysqli_fetch_array($runStaffLocationInfo)){
												if($noResultLocation == 1){
													?>
													<td><?php echo $resultStaffLocationInfo["project_name"]; ?></td>
													<td><?php echo $resultStaffLocationInfo["location_name"]; ?></td>
													<td>
														<button type="button"  onclick="Javascript:newPopup('action.php?staff_id=<?php echo $staff_id;?>&action=pwd')" class="btn btn-outline-danger btn-sm">Change Password</button>
														<button type="button"  onclick="Javascript:newPopup('action.php?staff_id=<?php echo $staff_id;?>&action=ud')" class="btn btn-outline-warning btn-sm">Update Details</button>
													</td>
												</tr>
													<?php
												}
												else if($noResultLocation > 1){
													
													?>
												<tr>
													<td><?php echo "11" . $resultStaffLocationInfo["project_name"]; ?></td>
													<td><?php echo "11" . $resultStaffLocationInfo["location_name"]; ?></td>
													<td>
														<button type="button"  onclick="Javascript:newPopup('action.php?staff_id=<?php echo $staff_id;?>&action=pwd')" class="btn btn-outline-danger btn-sm">Change Password</button>
														<button type="button"  onclick="Javascript:newPopup('action.php?staff_id=<?php echo $staff_id;?>&action=ud')" class="btn btn-outline-warning btn-sm">Update Details</button>
													</td>
												</tr>
													<?php
														$noResultLocation++;
													}
												}
										?>
                                           
                                                
                                            </tr>
										<?php 
											
										}
										$no++;
										}										?>
                                           
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                        
                        <?PHP include "footer.php";?>
                        
                    </div>
                </div>
            </div>
            <!-- END MAIN CONTENT-->
            <!-- END PAGE CONTAINER-->
        </div>
		
    </div>
    <?PHP include "footerLink.php";?>
</body>

</html>
<!-- end document-->
