<?php
	include("includes/dbconfig.php");
	$pagetitle = "System Users";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
	
	$results = DB::query("SELECT personnel_details.id, personnel_details.display_name, personnel_details.employee_role,  personnel_details.phone, personnel_details.email, personnel_details.login_name, personnel_details.status, peronnel_role.role_name, shop.full_name, personnel_details.is_loggedin, personnel_details.is_locked, personnel_details.version FROM personnel_details LEFT JOIN shop ON personnel_details.branch = shop.id LEFT JOIN peronnel_role ON personnel_details.role = peronnel_role.id ORDER BY shop.full_name, peronnel_role.role_name, personnel_details.display_name");
	
?>
			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
				<!-- Content Header (Page header) -->
				<section class="content-header">
					<h1>System Users</h1>
					<ol class="breadcrumb">
					</ol>
				</section>

				<!-- Main content -->
				<!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-12">
          <div class="card">
            
					 
						<?php
							if($_SESSION["connectedusergroup"] == 1)
							{
						?>
						<div class="card-header">
						  <h3 class="card-title">System Users List</h3>
						</div>
						 
						
						 
							<div id="servererrormessage">
							</div>
							
							
          
                            <div class="card-body">	
								<div class="col-sm-12">
									<div class="input-group-btn">
										<a href="systemusersetup.php" class="btn btn-sm btn-primary pull-right"><i class="fa fa-plus"></i> Add System User</a>
									</div>
								</div>
								
								<table id="example1"   class="table table-bordered table-striped">
									<thead>
										<tr>
											<th>Name</th>
											<th>Role</th>
											<th>Login</th>
											<th>Phone</th>
											<th>Email</th>
											<th class="text-center"> Category</th>
											<th class="text-center">Status</th>
											<th class="text-center">Lock Status</th>
											<th>Branch</th>
											<th class="text-center">Action</th>
										</tr>
									</thead>
									<tfoot>
										<tr>
											<th>Name</th>
											<th>Role</th>
											<th>Login</th>
											<th>Phone</th>
											<th>Email</th>
											<th class="text-center"> Category</th>
											<th class="text-center">Status</th>
											<th class="text-center">Lock Status</th>
											<th>Branch</th>
											<th class="text-center">Action</th>
										</tr>
									</tfoot>
									<tbody>
									<?php
										foreach($results as $user)
										{
									?>
										<tr>
											<td><?php echo $user['display_name']; ?></td>
											<td><?php echo $user['role_name']; ?></td>
											<td><?php echo $user['login_name']; ?></td>
											<td><?php echo $user['phone']; ?></td>
											<td><?php echo $user['email']; ?></td>
											<td class="text-center">
											
											<?php
											$role_name = 'N/A';
												$employee_roledata = DB::query("SELECT * FROM employee_category");
												
												foreach($employee_roledata as $useemployee_role)
												{
													if($useemployee_role['id'] == $user['employee_role'] ){
														$role_name =  $useemployee_role['name'];
													}
											 
											 
												}
												echo $role_name ;
											?>
											 
											
											</td>
											
											<td class="text-center"><?php echo ($user['status'] == 1) ? '<label class="label label-success" >Active</label>' : '<label class="label label-danger" >Inactive</label>'; ?></td>
											<td class="text-center"><?php echo ($user['is_locked'] == 0) ? '<label class="label label-success" >Open</label>' : '<label class="label label-danger" >Locked</label>'; ?></td>
											<td><?php echo $user['full_name']; ?></td>
											<td class="text-center">
												<a href="javascript:void(0);" onclick="gendawano('systemusersetup', 'userfocus', <?php echo $user['id']; ?>)" data-toggle="tooltip" title="Edit System User" class="tooltips"><span class="label label-primary" ><i class="fa fa-edit"></i></span></a>
												<a href="javascript:void(0);" onclick="unlockuser(<?php echo $user['id'].", ".$user['version']; ?>)" data-toggle="tooltip" title="Unlock System User" class="tooltips"><span class="label label-success" ><i class="fa
												fa-unlock"></i></span></a>
											</td>
										</tr>
									<?php
										}
									?>
									</tbody>
								</table>
							</div>
						</div>
						<?php
							}
							else
							{
						?>
						<div class="alert alert-danger alert-dismissable">
							<i class="fa fa-ban-circle"></i><br>
							Limited Access
						</div>
						<?php
							}
						?>
					   </div>
					</div>
					 
					
				</section><!-- /.content -->
			</div><!-- /.content-wrapper -->

			<footer class="main-footer text-center">
				<strong>Copyright &copy; <?php echo date("Y"); ?> BSMPOS.</strong> All rights reserved.
			</footer>
		</div><!-- ./wrapper -->
		
		<div class="modal" id="waitdialogmodal"  data-backdrop="static">
            <div class="modal-dialog modal-sm">
              <div class="modal-content">
                  <div class="modal-body">
					<div class="text-center">
						<img src="<?php echo $base_url . $ajax_loading_image; ?>" />
					</div>
				  </div>
              </div>
            </div>
        </div>
 
		
<?php include ('includes/general_footer.php')?>
 
		<script src="plugins/bert/storepos.js" type="text/javascript"></script>
		<script src="plugins/bert/systemusers.js" type="text/javascript"></script>
		
	</body>
</html>