<?php
	session_start();
	include("library/conn.php");
?>
<!DOCTYPE html>
<html lang="en">
	<head>
        <?php include("library/head.php");?>
        <title>User Logins | <?php echo $_SESSION['systemName']; ?></title>
	</head>
	<body class="app sidebar-mini">

		<!-- Navbar-->
		<?php include("library/header.php");?>
		<!-- Sidebar menu-->
		<div class="app-sidebar__overlay" data-toggle="sidebar"></div>
		<?php include("library/sidebar.php");?>
  
		<main class="app-content">
			<div class="app-title">
				<div>
					<h4><i class="fa fa-sign-in fa-lg"></i> USER LOGINS</h4>
					<p>User Logins Page</p>
				</div>
				<ul class="app-breadcrumb breadcrumb">
					<li class="breadcrumb-item"><i class="fa fa-home"></i></li>
					<li class="breadcrumb-item"><a href="user-logins">User Logins</a></li>
				</ul>
			</div>
      
			<?php include("models/admin_config.php");?>
			<?php include("models/system_config.php");?>

			<div class="row">
				<div class="col-md-12">
					<div class="tile">
						<div class="tile-body">
							<div class="table-responsive">
								<table class="table table-bordered table-hover table-sm" id="userLoginsTable">
									<thead>
										<tr class="text-center bg-primary text-light">
											<th>No</th>
											<th>Photo</th>
											<th>Username</th>
											<th>Fullname</th>
											<th>Position</th>
											<th>Login DT</th>
											<th>Logout DT</th>
										</tr>
									</thead>
									<tbody>
										<?php
											$getUserLogins = mysqli_query($conn, "SELECT employees.employeePhoto, system_users.Username, employees.employeeName, employee_positions.positionName, user_logins.loginDateTime, user_logins.logoutDateTime
                                            FROM user_logins
                                            INNER JOIN system_users ON user_logins.userID = user_logins.userID
                                            INNER JOIN employees ON system_users.employeeID = employees.employeeID
                                            INNER JOIN employee_positions ON employees.employeePosition = employee_positions.positionID
                                            ORDER BY user_logins.loginID DESC") or die(mysqli_error($conn));
											$x = 1;
											while ($rs = mysqli_fetch_array($getUserLogins)) {
												?>
													<tr>
														<td class="text-center"><?php echo $x; ?></td>
														<td class="py-1 text-center"><img class="img-fluid rounded-circle" src="<?php echo $rs[0]; ?> " width="26px" height="26px"/></td>
														<td class="text-left"><?php echo $rs[1]; ?></td>
														<td class="text-left"><?php echo $rs[2]; ?></td>
														<td class="text-left"><?php echo $rs[3]; ?></td>
														<td class="text-center"><?php echo substr($rs[4], 0, 16); ?></td>
														<td class="text-center"><?php echo substr($rs[5], 0, 16); ?></td>
													</tr>
												<?php
												$x++;
											}
										?>
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</main>
  
		<!-- Essential javascripts for application to work-->
		<?php include("library/footer.php");?>  
		<?php include("library/scripts.php");?>

		<script type="text/javascript">
			$('#userLoginsTable').DataTable({"pageLength": 100, "order": []})
		</script>

	</body>
</html>