|
Server : LiteSpeed System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : outerorb ( 1091) PHP Version : 8.1.34 Disable Function : mail Directory : /home2/outerorb/emp.outerorbittech.in/admin/ | |
|
Path: /home2/outerorb/emp.outerorbittech.in/admin/users.php
Size: 25.64 KB
Permissions: 0666
<?php
require_once '../config/config.php';
require_once '../includes/helpers.php';
// Check if user is logged in and is admin
session_start();
if (!isset($_SESSION['employee_id']) || $_SESSION['role'] !== 'admin') {
header('Location: ../index.php');
exit;
}
$admin_profile = get_employee_profile($_SESSION['employee_id']);
$message = '';
$error = '';
// Handle user actions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST['action'] ?? '';
$user_id = (int)($_POST['user_id'] ?? 0);
if ($action === 'update_status') {
$status = $_POST['status'] ?? '';
if (update_user_status($user_id, $status)) {
$message = "User status updated successfully!";
log_activity($_SESSION['employee_id'], 'update_status', 'employees', $user_id, "Status changed to $status");
} else {
$error = "Failed to update user status.";
}
} elseif ($action === 'update_role') {
$role = $_POST['role'] ?? '';
if (update_user_role($user_id, $role)) {
$message = "User role updated successfully!";
log_activity($_SESSION['employee_id'], 'update_role', 'employees', $user_id, "Role changed to $role");
} else {
$error = "Failed to update user role.";
}
} elseif ($action === 'reset_password') {
$new_password = $_POST['new_password'] ?? '';
if (strlen($new_password) >= 6) {
if (reset_user_password($user_id, $new_password)) {
$message = "Password reset successfully!";
log_activity($_SESSION['employee_id'], 'reset_password', 'employees', $user_id, "Password reset");
} else {
$error = "Failed to reset password.";
}
} else {
$error = "Password must be at least 6 characters long.";
}
} elseif ($action === 'delete_user') {
if (delete_user($user_id)) {
$message = "User deleted successfully!";
log_activity($_SESSION['employee_id'], 'delete_user', 'employees', $user_id, "User deleted");
} else {
$error = "Failed to delete user.";
}
} elseif ($action === 'update_card') {
$card = sanitize_text($_POST['card_number'] ?? '');
if (update_user_card_number($user_id, $card)) {
$message = "Card number updated successfully!";
log_activity($_SESSION['employee_id'], 'update_card', 'employees', $user_id, "Card set to $card");
} else {
$error = "Failed to update card number.";
}
}
}
// Get filter parameters
$role_filter = $_GET['role'] ?? '';
$status_filter = $_GET['status'] ?? '';
// Get all users with filters
$users = get_all_users($role_filter ?: null, $status_filter ?: null);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Management - Admin Panel</title>
<link rel="stylesheet" href="../assets/css/style.css">
<link rel="stylesheet" href="../assets/css/polish.css">
<style>
.management-filters {
display: flex;
gap: 1rem;
margin-bottom: 2rem;
flex-wrap: wrap;
}
.management-filters .form-group {
flex: 0 0 auto;
min-width: 150px;
}
.filter-link {
display: inline-block;
padding: 0.5rem 1rem;
border-radius: 6px;
background: rgba(37, 99, 235, 0.1);
color: #2563eb;
text-decoration: none;
font-size: 0.875rem;
transition: all 0.3s ease;
}
.filter-link:hover {
background: rgba(37, 99, 235, 0.2);
}
.filter-link.active {
background: #2563eb;
color: white;
}
.users-table {
background: rgba(255, 255, 255, 0.05);
backdrop-filter: blur(10px);
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
overflow: hidden;
}
.users-table table {
width: 100%;
border-collapse: collapse;
}
.users-table thead {
background: rgba(255, 255, 255, 0.08);
}
.users-table th {
padding: 1rem;
text-align: left;
color: #cbd5e1;
font-size: 0.875rem;
font-weight: 600;
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.users-table td {
padding: 1rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
color: #e2e8f0;
}
.users-table tbody tr:hover {
background: rgba(255, 255, 255, 0.03);
}
.user-name {
font-weight: 600;
}
.user-email {
color: #cbd5e1;
font-size: 0.875rem;
}
.badge {
display: inline-block;
padding: 0.25rem 0.75rem;
border-radius: 6px;
font-size: 0.75rem;
font-weight: 600;
}
.badge-role-admin {
background: rgba(239, 68, 68, 0.2);
color: #ef4444;
}
.badge-role-hr {
background: rgba(37, 99, 235, 0.2);
color: #2563eb;
}
.badge-role-manager {
background: rgba(245, 158, 11, 0.2);
color: #f59e0b;
}
.badge-role-employee {
background: rgba(16, 185, 129, 0.2);
color: #10b981;
}
.badge-status-active {
background: rgba(16, 185, 129, 0.2);
color: #10b981;
}
.badge-status-inactive {
background: rgba(156, 163, 175, 0.2);
color: #9ca3af;
}
.badge-status-suspended {
background: rgba(239, 68, 68, 0.2);
color: #ef4444;
}
.user-actions {
display: flex;
gap: 0.25rem;
flex-wrap: wrap;
}
.action-btn {
padding: 0.4rem 0.8rem;
font-size: 0.75rem;
border: none;
border-radius: 4px;
cursor: pointer;
transition: all 0.3s ease;
background: rgba(37, 99, 235, 0.2);
color: #2563eb;
}
.action-btn:hover {
background: #2563eb;
color: white;
}
.action-btn.danger {
background: rgba(239, 68, 68, 0.2);
color: #ef4444;
}
.action-btn.danger:hover {
background: #ef4444;
color: white;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.7);
z-index: 1000;
justify-content: center;
align-items: center;
}
.modal.show {
display: flex;
}
.modal-content {
background: #1e293b;
padding: 2rem;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
min-width: 400px;
max-width: 90%;
}
.modal-header {
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 1rem;
color: #e2e8f0;
}
.modal-close {
position: absolute;
top: 1rem;
right: 1rem;
background: none;
border: none;
color: #cbd5e1;
font-size: 1.5rem;
cursor: pointer;
}
@media (max-width: 768px) {
.management-filters {
flex-direction: column;
}
.users-table table {
font-size: 0.875rem;
}
.users-table th,
.users-table td {
padding: 0.75rem;
}
.user-actions {
flex-direction: column;
}
.action-btn {
width: 100%;
}
}
</style>
</head>
<body>
<div class="main-container">
<!-- Sidebar -->
<aside class="sidebar">
<div class="sidebar-header">
<h2>HR Admin</h2>
</div>
<nav class="sidebar-nav">
<a href="dashboard.php" class="nav-link">
<span><i class="fas fa-chart-line"></i> Dashboard</span>
</a>
<a href="users.php" class="nav-link active">
<span><i class="fas fa-users"></i> User Management</span>
</a>
<a href="settings.php" class="nav-link">
<span>⚙️ Settings</span>
</a>
<a href="backups.php" class="nav-link">
<span><i class="fas fa-database"></i> Backups</span>
</a>
<a href="activity-logs.php" class="nav-link">
<span><i class="fas fa-book"></i> Activity Logs</span>
</a>
<a href="logout.php" class="nav-link">
<span><i class="fas fa-sign-out-alt"></i> Logout</span>
</a>
</nav>
</aside>
<!-- Main Content -->
<div class="main-content">
<!-- Top Bar -->
<div class="top-bar">
<div class="top-bar-left">
<h1>User Management</h1>
</div>
<div class="top-bar-right">
<div class="notification-bell">
<button id="notificationBell" class="bell-button">
<i class="fas fa-bell"></i>
<span class="badge" id="unreadCount">0</span>
</button>
<div id="notificationDropdown" class="notification-dropdown" style="display: none;">
<div class="dropdown-header">Notifications</div>
<div id="notificationList" class="notification-list">
<div class="notification-item">Loading...</div>
</div>
</div>
</div>
<span class="user-greeting">Welcome, <?php echo htmlspecialchars($admin_profile['first_name']); ?></span>
</div>
</div>
<!-- Content Area -->
<div class="content">
<!-- Messages -->
<?php if ($message): ?>
<div class="alert alert-success" role="alert">
✓ <?php echo htmlspecialchars($message); ?>
</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="alert alert-danger" role="alert">
✖ <?php echo htmlspecialchars($error); ?>
</div>
<?php endif; ?>
<!-- Filters -->
<div class="management-filters">
<a href="users.php" class="filter-link <?php echo !$role_filter && !$status_filter ? 'active' : ''; ?>">
All Users (<?php echo count($users); ?>)
</a>
<a href="users.php?status=active" class="filter-link <?php echo $status_filter === 'active' ? 'active' : ''; ?>">
Active
</a>
<a href="users.php?status=inactive" class="filter-link <?php echo $status_filter === 'inactive' ? 'active' : ''; ?>">
Inactive
</a>
<a href="users.php?role=admin" class="filter-link <?php echo $role_filter === 'admin' ? 'active' : ''; ?>">
Admins
</a>
<a href="users.php?role=employee" class="filter-link <?php echo $role_filter === 'employee' ? 'active' : ''; ?>">
Employees
</a>
</div>
<!-- Users Table -->
<div class="users-table">
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Card</th>
<th>Role</th>
<th>Status</th>
<th>Last Login</th>
<th>Joined</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (count($users) > 0): ?>
<?php foreach ($users as $user): ?>
<tr>
<td>
<div class="user-name"><?php echo htmlspecialchars($user['first_name'] . ' ' . $user['last_name']); ?></div>
<div class="user-email"><?php echo htmlspecialchars($user['email']); ?></div>
</td>
<td><?php echo htmlspecialchars($user['phone'] ?? '-'); ?></td>
<td><?php echo htmlspecialchars($user['card_number'] ?? '-'); ?></td>
<td>
<span class="badge badge-role-<?php echo strtolower($user['role']); ?>">
<?php echo ucfirst($user['role']); ?>
</span>
</td>
<td>
<span class="badge badge-status-<?php echo strtolower($user['status']); ?>">
<?php echo ucfirst($user['status']); ?>
</span>
</td>
<td><?php echo $user['last_login'] ? date('d M Y H:i', strtotime($user['last_login'])) : 'Never'; ?></td>
<td><?php echo date('d M Y', strtotime($user['created_at'])); ?></td>
<td>
<div class="user-actions">
<button class="action-btn" onclick="openStatusModal(<?php echo $user['id']; ?>, '<?php echo htmlspecialchars($user['first_name']); ?>', '<?php echo $user['status']; ?>')">
Status
</button>
<button class="action-btn" onclick="openRoleModal(<?php echo $user['id']; ?>, '<?php echo htmlspecialchars($user['first_name']); ?>', '<?php echo $user['role']; ?>')">
Role
</button>
<button class="action-btn" onclick="openPasswordModal(<?php echo $user['id']; ?>, '<?php echo htmlspecialchars($user['first_name']); ?>')">
Password
</button>
<button class="action-btn" onclick="openCardModal(<?php echo $user['id']; ?>, '<?php echo htmlspecialchars($user['first_name']); ?>', '<?php echo htmlspecialchars($user['card_number'] ?? ''); ?>')">
Card
</button>
<button class="action-btn danger" onclick="confirmDelete(<?php echo $user['id']; ?>, '<?php echo htmlspecialchars($user['first_name']); ?>')">
Delete
</button>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="8" style="text-align: center; color: #a0aec0;">
No users found.
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- Status Modal -->
<div id="statusModal" class="modal">
<div class="modal-content">
<button class="modal-close" onclick="closeModal('statusModal')">×</button>
<div class="modal-header">Change User Status</div>
<form method="POST">
<input type="hidden" name="action" value="update_status">
<input type="hidden" id="statusUserId" name="user_id">
<div class="form-group">
<label>User:</label>
<input type="text" id="statusUserName" class="form-control" readonly>
</div>
<div class="form-group">
<label for="statusSelect">New Status:</label>
<select id="statusSelect" name="status" class="form-control" required>
<option value="active">Active</option>
<option value="inactive">Inactive</option>
<option value="suspended">Suspended</option>
</select>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Update Status</button>
<button type="button" class="btn btn-secondary" onclick="closeModal('statusModal')">Cancel</button>
</div>
</form>
</div>
</div>
<!-- Role Modal -->
<div id="roleModal" class="modal">
<div class="modal-content">
<button class="modal-close" onclick="closeModal('roleModal')">×</button>
<div class="modal-header">Change User Role</div>
<form method="POST">
<input type="hidden" name="action" value="update_role">
<input type="hidden" id="roleUserId" name="user_id">
<div class="form-group">
<label>User:</label>
<input type="text" id="roleUserName" class="form-control" readonly>
</div>
<div class="form-group">
<label for="roleSelect">New Role:</label>
<select id="roleSelect" name="role" class="form-control" required>
<option value="employee">Employee</option>
<option value="manager">Manager</option>
<option value="hr">HR</option>
<option value="admin">Admin</option>
</select>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Update Role</button>
<button type="button" class="btn btn-secondary" onclick="closeModal('roleModal')">Cancel</button>
</div>
</form>
</div>
</div>
<!-- Password Modal -->
<div id="passwordModal" class="modal">
<div class="modal-content">
<button class="modal-close" onclick="closeModal('passwordModal')">×</button>
<div class="modal-header">Reset User Password</div>
<form method="POST">
<input type="hidden" name="action" value="reset_password">
<input type="hidden" id="passwordUserId" name="user_id">
<div class="form-group">
<label>User:</label>
<input type="text" id="passwordUserName" class="form-control" readonly>
</div>
<div class="form-group">
<label for="passwordInput">New Password:</label>
<input type="password" id="passwordInput" name="new_password" class="form-control" required minlength="6">
<small style="color: #a0aec0;">Minimum 6 characters</small>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Reset Password</button>
<button type="button" class="btn btn-secondary" onclick="closeModal('passwordModal')">Cancel</button>
</div>
</form>
</div>
</div>
<!-- Card Modal -->
<div id="cardModal" class="modal">
<div class="modal-content">
<button class="modal-close" onclick="closeModal('cardModal')">×</button>
<div class="modal-header">Update Card Number</div>
<form method="POST">
<input type="hidden" name="action" value="update_card">
<input type="hidden" id="cardUserId" name="user_id">
<div class="form-group">
<label>User:</label>
<input type="text" id="cardUserName" class="form-control" readonly>
</div>
<div class="form-group">
<label for="cardInput">Card Number:</label>
<input type="text" id="cardInput" name="card_number" class="form-control" placeholder="e.g. 123456" />
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save Card</button>
<button type="button" class="btn btn-secondary" onclick="closeModal('cardModal')">Cancel</button>
</div>
</form>
</div>
</div>
<script src="../assets/js/app.js"></script>
<script>
function openStatusModal(userId, userName, currentStatus) {
document.getElementById('statusUserId').value = userId;
document.getElementById('statusUserName').value = userName;
document.getElementById('statusSelect').value = currentStatus;
document.getElementById('statusModal').classList.add('show');
}
function openRoleModal(userId, userName, currentRole) {
document.getElementById('roleUserId').value = userId;
document.getElementById('roleUserName').value = userName;
document.getElementById('roleSelect').value = currentRole;
document.getElementById('roleModal').classList.add('show');
}
function openPasswordModal(userId, userName) {
document.getElementById('passwordUserId').value = userId;
document.getElementById('passwordUserName').value = userName;
document.getElementById('passwordInput').value = '';
document.getElementById('passwordModal').classList.add('show');
}
function openCardModal(userId, userName, card) {
document.getElementById('cardUserId').value = userId;
document.getElementById('cardUserName').value = userName;
document.getElementById('cardInput').value = card || '';
document.getElementById('cardModal').classList.add('show');
}
function closeModal(modalId) {
document.getElementById(modalId).classList.remove('show');
}
function confirmDelete(userId, userName) {
if (confirm(`Are you sure you want to delete user ${userName}?`)) {
const form = document.createElement('form');
form.method = 'POST';
form.innerHTML = `
<input type="hidden" name="action" value="delete_user">
<input type="hidden" name="user_id" value="${userId}">
`;
document.body.appendChild(form);
form.submit();
}
}
// Close modal when clicking outside
document.querySelectorAll('.modal').forEach(modal => {
modal.addEventListener('click', function(e) {
if (e.target === this) {
this.classList.remove('show');
}
});
});
// Load notifications
const notificationBell = document.getElementById('notificationBell');
const notificationDropdown = document.getElementById('notificationDropdown');
notificationBell.addEventListener('click', function(e) {
e.stopPropagation();
notificationDropdown.style.display = notificationDropdown.style.display === 'none' ? 'block' : 'none';
});
document.addEventListener('click', function() {
notificationDropdown.style.display = 'none';
});
</script>
</body>
</html>