<?php

include 'load.php';

if(isset($_GET['employee'])){
	
	$employee=mysqli_real_escape_string($conn,$_GET['employee']);
	$status=mysqli_real_escape_string($conn,$_GET['status']);

	mysqli_query($conn,"UPDATE mobileemployee SET status='$status' WHERE emid='$employee'");
	header("refresh:2;employeelist.php"); // redirects image view page after 5 seconds
	
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<meta name="description" content="POS - Eat More Resturant   | Pos & Invetory System | Dashboard

">
<meta name="keywords" content="Eat More Resturant   | Pos & Invetory System | Dashboard

">
<meta name="author" content="Eat More Resturant   | Pos & Invetory System | Dashboard

">
<meta name="robots" content="noindex, nofollow">

<title>Employee | Eat More Resturant   | Pos & Invetory System | Dashboard

</title>


<?php
require_once 'headercss.php';
?>
</head>
<body>
<div id="global-loader">
<div class="whirly-loader"> </div>
</div>

<div class="main-wrapper">
<?php
require_once 'header.php';
?>

<?php
require_once 'navbar.php';
?>

<div class="page-wrapper">
<div class="content">
<div class="page-header">
<div class="page-title">
<h4>Employee List</h4>
<h6>Manage your Employee</h6>
</div>
<div class="pcredit-btn">
<a href="addemployee.php" class="btn btn-added"><img src="assets/img/icons/plus.svg" alt="img" class="me-1">Add New Employee</a>
</div>
</div>

<div class="card">
<div class="card-body">
<div class="table-top">

</div>

<div class="table-responsive">
<table class="table" id="betable">
<thead>
<tr>
<th>ID#</th>
<th>Actions</th>
<th>Status</th>
<th>Profile</th>
<th>Employee Details</th>
<th>Type</th>
<th>User Type</th>
<th>Agency</th>
<th>User Name</th>
<th>Date</th>
</tr>
</thead>
<tbody> 
<?php
$count=0;
$stmt = $DB_con->prepare('SELECT * FROM mobileemployee ORDER BY emid');

$stmt->execute();

if($stmt->rowCount() > 0)

{

while($row=$stmt->fetch(PDO::FETCH_ASSOC))

{

extract($row);

?>
<tr>
<td>#<?php echo $row['emid']; ?></td>
<td>
<a href="editemployee.php?emid=<?php echo $row["emid"]; ?>" class="btn btn-block btn-outline-primary active btn-sm text-white"><i class="fa fa-edit" data-bs-toggle="tooltip" title="" data-bs-original-title="fa fa-edit" aria-label="fa fa-edit"></i></a>
<a href="employee_password_change.php?emid=<?php echo $row["emid"]; ?>" title="Change Password" class="btn btn-block btn-outline-secondary active btn-sm text-white"><i class="fa fa-key" data-bs-toggle="tooltip" title="" data-bs-original-title="fa fa-key"></i></a>													
<a href="deleteemployee.php?emid=<?php echo $row["emid"]; ?>" class="btn btn-block btn-outline-danger active btn-sm text-white"><i class="fa fa-trash" data-bs-toggle="tooltip" title="" data-bs-original-title="fa fa-trash" aria-label="fa fa-trash"></i></a>
<a href="employeelist.php?employee=<?php echo $row["emid"]; ?>&status=1" class="btn btn-block btn-outline-info active btn-sm text-white" title="Active Employee" onClick="JavaScript:return confirm('Are your sure change this Employee Active status?');"><i class="fa fa-check-circle" data-bs-toggle="tooltip" title="" data-bs-original-title="fa fa-check-circle" aria-label="fa fa-check-circle"></i></a>
<a href="employeelist.php?employee=<?php echo $row["emid"]; ?>&status=0" class="btn btn-block btn-outline-warning active btn-sm text-white" title="Deactive Employee" onClick="JavaScript:return confirm('Are your sure change this Employee Deactive status?');"><i class="fa fa-window-close" data-bs-toggle="tooltip" title="" data-bs-original-title="fa fa-window-close" aria-label="fa fa-window-close"></i></a>
</td>
<td>
										<?php 
						
														if($row['status'] == "1"){

														echo '<span class="badge bg-success"><i class="bx bxs-circle me-1"></i>Active</span>';

													    }else if($row['status'] == "0"){

														echo '<span class="badge bg-danger"><i class="bx bxs-circle me-1"></i>Deactive</span>';

														}
						
												
										?>
										</td>
										<td><?php if($row['profile_picture']==""){$pro_img="assets/img/empty.png";}else{$pro_img="images/employee/".$row['profile_picture'];} ?><img src="<?php echo $pro_img; ?>" class="pro_pick" style="width:80px;"></td>
										<td><?php echo $row['emname']; ?><br><?php echo $row['emaddress']; ?><br><?php echo $row['emphonenumber']; ?></td>
<td>
										<?php 
						
														if($row['comtype'] == "1"){

														echo '<span class="badge bg-success"><i class="bx bxs-circle me-1"></i>Company</span>';

													    }else if($row['comtype'] == "0"){

														echo '<span class="badge bg-danger"><i class="bx bxs-circle me-1"></i>Agency</span>';

														}
						
												
										?>
										</td>
										<td>
										<?php 
						
										if($row['emusertype'] == "0"){

										echo '<span class="badge bg-primary"><i class="bx bxs-circle me-1"></i>None</span>';

									    }else if($row['emusertype'] == "1"){

										echo '<span class="badge bg-primary"><i class="bx bxs-circle me-1"></i>Super Admin</span>';

									    }else if($row['emusertype'] == "2"){

										echo '<span class="badge bg-secondary"><i class="bx bxs-circle me-1"></i>Director</span>';

										}else if($row['emusertype'] == "3"){

										echo '<span class="badge bg-dark"><i class="bx bxs-circle me-1"></i>Account</span>';
										
										}else if($row['emusertype'] == "4"){

										echo '<span class="badge bg-warning"><i class="bx bxs-circle me-1"></i>Area Manager</span>';

										}else if($row['emusertype'] == "5"){

										echo '<span class="badge bg-info"><i class="bx bxs-circle me-1"></i>Sales Manager</span>';
										
										}else if($row['emusertype'] == "6"){

										echo '<span class="badge bg-danger"><i class="bx bxs-circle me-1"></i>Ref</span>';

										}else if($row['emusertype'] == "7"){

										echo '<span class="badge bg-success"><i class="bx bxs-circle me-1"></i>Office Assistant</span>';

										}else if($row['emusertype'] == "8"){

										echo '<span class="badge bg-success"><i class="bx bxs-circle me-1"></i>Factory</span>';

										}else if($row['emusertype'] == "9"){

										echo '<span class="badge bg-success"><i class="bx bxs-circle me-1"></i>Distributor</span>';

										}
		
										?>
										</td>
										<td>
										<?php

												$id = $row['em_agency'];  

												$query = $DB_con->prepare('SELECT agname FROM mobileagency WHERE agid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['agname'];

										?>
										</td>
										<td><?php echo $row['user_name']; ?></td>
										<td><?php echo $row['add_date']; ?></td>

</tr>
<?php 
} 
}
?>
</tbody>
</table>
</div>
</div>
</div>

</div>
</div>
</div>

<?php require_once 'footerjs.php'; ?>

</body>
</html>