Here's a concise summary of the key CSS improvements made:
:root {
--sidebar-width: 240px;
--header-height: 60px;
--primary-color: #77693A;
--secondary-color: #D1B48C;
--card-colors: #63e5ff, #6c5ce7, #00b894, #fd79a8;
}
:root {
--sidebar-width: 240px;
--header-height: 60px;
--primary-color: #77693A;
--secondary-color: #D1B48C;
--card-colors: #63e5ff, #6c5ce7, #00b894, #fd79a8;
}
.dashboard-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 25px;
}
.dashboard-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 25px;
}
.card {
border-top: 4px solid var(--card-color);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.card {
border-top: 4px solid var(--card-color);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.card:hover {
transform: translateY(-5px);
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
@media (max-width: 768px) {
.sidebar { width: 100%; position: relative; }
.header { left: 0; }
.main-content { margin-left: 0; width: 100%; }
.dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
.sidebar { width: 100%; position: relative; }
.header { left: 0; }
.main-content { margin-left: 0; width: 100%; }
.dashboard-grid { grid-template-columns: 1fr; }
}
The changes maintain all existing functionality while improving the visual design and responsiveness.
Here's the improved version with the requested layout changes:
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Check if user is logged in and is admin
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header("Location: http://localhost/helpdesk/?page_id=24");
exit();
}
// Database connection
$host = 'localhost';
$dbname = 'helpdesk';
$username = 'root';
$password = '';
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Database connection failed: " . $e->getMessage());
}
// Initialize messages
$error = '';
$success = '';
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
// Validate inputs
if (empty($_POST['first_name']) || !preg_match('/^[A-Za-z. ]+$/', $_POST['first_name'])) {
throw new Exception("First name can only contain letters, periods and spaces");
}
if (empty($_POST['last_name']) || !preg_match('/^[A-Za-z. ]+$/', $_POST['last_name'])) {
throw new Exception("Last name can only contain letters, periods and spaces");
}
if (empty($_POST['username'])) {
throw new Exception("Username is required");
}
if (empty($_POST['password'])) {
throw new Exception("Password is required");
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$username = $_POST['username'];
$password = password_hash($_POST['password'], PASSWORD_BCRYPT);
$role = $_POST['role'];
$department_id = !empty($_POST['department_id']) ? (int)$_POST['department_id'] : null;
// Check if username exists
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
$stmt->execute([$username]);
if ($stmt->fetch()) {
throw new Exception("Username already exists. Please choose a different one.");
}
// Insert new user
$stmt = $pdo->prepare("INSERT INTO users
(first_name, last_name, username, password, role, department_id)
VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$first_name, $last_name, $username, $password, $role, $department_id]);
if ($stmt->rowCount() > 0) {
$success = "User added successfully!";
// Clear form fields on success
$_POST = [];
} else {
throw new Exception("Failed to add user. Please try again.");
}
} catch (Exception $e) {
$error = $e->getMessage();
}
}
// Get all users and departments for the table
$users = $pdo->query("SELECT users.*, departments.name as department_name
FROM users LEFT JOIN departments ON users.department_id = departments.id")->fetchAll();
$departments = $pdo->query("SELECT * FROM departments")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Management - RJL DeskTrack</title>
<style>
:root {
--sidebar-width: 240px;
--header-height: 80px;
--primary-color: #77693A;
--secondary-color: #D1B48C;
--text-dark: #333;
--text-light: #f8f9fa;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f7f9;
color: var(--text-dark);
}
.dashboard-container {
display: flex;
min-height: 100vh;
}
/* Sidebar Styles */
.sidebar {
width: var(--sidebar-width);
background-color: var(--secondary-color);
color: #000;
height: 100vh;
position: fixed;
left: 0;
top: 0;
overflow-y: auto;
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
z-index: 1000;
}
.logo {
padding: 20px;
text-align: left;
border-bottom: 1px solid rgba(0,0,0,0.1);
}
.logo h2 {
font-size: 24px;
font-weight: 700;
margin: 0;
color: #000;
}
.menu {
padding: 20px 0;
margin: 0;
}
.menu li {
list-style: none;
}
.menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
color: #000;
text-decoration: none;
font-size: 16px;
transition: all 0.3s ease;
}
.menu li a i {
margin-right: 10px;
font-style: normal;
font-size: 18px;
width: 25px;
text-align: center;
}
.menu li a:hover,
.menu li a.active {
background-color: #ffffff;
color: #000;
}
/* Main Content Area */
.main-content {
margin-left: var(--sidebar-width);
width: calc(100% - var(--sidebar-width));
min-height: 100vh;
}
/* Top Header Bar */
.top-bar {
background-color: var(--primary-color);
color: white;
height: var(--header-height);
display: flex;
align-items: center;
justify-content: center;
position: relative;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.top-bar h1 {
font-size: 24px;
margin: 0;
font-weight: 700;
}
.user-info {
position: absolute;
right: 30px;
display: flex;
align-items: center;
gap: 10px;
}
.user-info img {
width: 40px;
height: 40px;
border-radius: 50%;
object-fit: cover;
}
.user-info span {
font-size: 16px;
font-weight: 600;
color: white;
}
/* Content Layout */
.content-wrapper {
display: flex;
padding: 20px;
gap: 20px;
}
.form-section {
flex: 1;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 20px;
}
.table-section {
flex: 2;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 20px;
overflow-x: auto;
}
/* Form Styles */
.form-title {
margin-top: 0;
margin-bottom: 20px;
font-size: 20px;
color: var(--primary-color);
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: 600;
}
.form-group input,
.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
}
.btn {
background-color: var(--primary-color);
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
.btn:hover {
background-color: #5a4d1b;
}
/* Table Styles */
.table-title {
margin-top: 0;
margin-bottom: 20px;
font-size: 20px;
color: var(--primary-color);
}
.user-table {
width: 100%;
border-collapse: collapse;
}
.user-table th,
.user-table td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
.user-table th {
background-color: #f8f9fa;
font-weight: 600;
}
.user-table tr:hover {
background-color: #f1f3f5;
}
.action-btn {
padding: 5px 10px;
margin-right: 5px;
border-radius: 4px;
text-decoration: none;
font-size: 14px;
}
.edit-btn {
background-color: #3498db;
color: white;
}
.delete-btn {
background-color: #e74c3c;
color: white;
}
/* Message Styles */
.message {
padding: 10px 15px;
margin-bottom: 15px;
border-radius: 4px;
}
.success-message {
background-color: #d4edda;
color: #155724;
}
.error-message {
background-color: #f8d7da;
color: #721c24;
}
/* Responsive Adjustments */
@media (max-width: 992px) {
.content-wrapper {
flex-direction: column;
}
}
@media (max-width: 768px) {
.sidebar {
width: 70px;
}
.logo h2 {
display: none;
}
.menu li a span {
display: none;
}
.menu li a {
justify-content: center;
padding: 12px 0;
}
.menu li a i {
margin-right: 0;
font-size: 20px;
}
.main-content {
margin-left: 70px;
width: calc(100% - 70px);
}
}
@media (max-width: 576px) {
.sidebar {
width: 100%;
height: auto;
position: relative;
}
.main-content {
margin-left: 0;
width: 100%;
}
.top-bar {
justify-content: flex-start;
padding-left: 20px;
}
.user-info {
position: static;
margin-left: auto;
padding-right: 20px;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<!-- Sidebar -->
<div class="sidebar">
<div class="logo">
<h2>RJL DeskTrack</h2>
</div>
<ul class="menu">
<li><a href="http://localhost/helpdesk/?page_id=30"><i>📊</i> <span>Dashboard</span></a></li>
<li><a href="http://localhost/helpdesk/?page_id=35" class="active"><i>👥</i> <span>Users</span></a></li>
<li><a href="departments.php"><i>🏢</i> <span>Departments</span></a></li>
<li><a href="tickets.php"><i>🎫</i> <span>Tickets</span></a></li>
<li><a href="messages.php"><i>✉️</i> <span>Messages</span></a></li>
<li><a href="reports.php"><i>📈</i> <span>Reports</span></a></li>
</ul>
</div>
<!-- Main Content -->
<div class="main-content">
<!-- Top Bar -->
<div class="top-bar">
<h1>User Management</h1>
<div class="user-info">
<img src="https://ui-avatars.com/api/?name=<?= urlencode($_SESSION['username']) ?>&background=007bff&color=fff" alt="User">
<span><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
</div>
<!-- Content Wrapper -->
<div class="content-wrapper">
<!-- Add User Form Section -->
<div class="form-section">
<h2 class="form-title">Add New User</h2>
<?php if ($success): ?>
<div class="message success-message">
<?= htmlspecialchars($success) ?>
</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="message error-message">
<?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<form method="POST">
<div class="form-group">
<label for="first_name">First Name</label>
<input type="text" id="first_name" name="first_name"
pattern="[A-Za-z. ]+"
title="Only letters, periods and spaces allowed"
required
value="<?= isset($_POST['first_name']) ? htmlspecialchars($_POST['first_name']) : '' ?>">
</div>
<div class="form-group">
<label for="last_name">Last Name</label>
<input type="text" id="last_name" name="last_name"
pattern="[A-Za-z. ]+"
title="Only letters, periods and spaces allowed"
required
value="<?= isset($_POST['last_name']) ? htmlspecialchars($_POST['last_name']) : '' ?>">
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username"
required
value="<?= isset($_POST['username']) ? htmlspecialchars($_POST['username']) : '' ?>">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<label for="role">Role</label>
<select id="role" name="role" required>
<option value="admin" <?= (isset($_POST['role']) && $_POST['role'] === 'admin') ? 'selected' : '' ?>>Admin</option>
<option value="user" <?= !isset($_POST['role']) || $_POST['role'] === 'user' ? 'selected' : '' ?>>User</option>
</select>
</div>
<div class="form-group">
<label for="department_id">Department</label>
<select id="department_id" name="department_id">
<option value="">None</option>
<?php foreach ($departments as $dept): ?>
<option value="<?= $dept['id'] ?>"
<?= (isset($_POST['department_id']) && $_POST['department_id'] == $dept['id']) ? 'selected' : '' ?>>
<?= htmlspecialchars($dept['name']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn">Add User</button>
</form>
</div>
<!-- Users Table Section -->
<div class="table-section">
<h2 class="table-title">All Users</h2>
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th>Role</th>
<th>Department</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?= $user['id'] ?></td>
<td><?= htmlspecialchars($user['first_name']) ?></td>
<td><?= htmlspecialchars($user['last_name']) ?></td>
<td><?= htmlspecialchars($user['username']) ?></td>
<td><?= ucfirst($user['role']) ?></td>
<td><?= $user['department_name'] ?? 'None' ?></td>
<td>
<a href="edit_user.php?id=<?= $user['id'] ?>" class="action-btn edit-btn">Edit</a>
<a href="delete_user.php?id=<?= $user['id'] ?>" class="action-btn delete-btn" onclick="return confirm('Are you sure?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
// Simple script to handle active menu items
document.querySelectorAll('.menu a').forEach(link => {
if (link.href === window.location.href) {
link.classList.add('active');
}
link.addEventListener('click', function() {
document.querySelectorAll('.menu a').forEach(item => {
item.classList.remove('active');
});
this.classList.add('active');
});
});
</script>
</body>
</html>
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Check if user is logged in and is admin
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header("Location: http://localhost/helpdesk/?page_id=24");
exit();
}
// Database connection
$host = 'localhost';
$dbname = 'helpdesk';
$username = 'root';
$password = '';
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Database connection failed: " . $e->getMessage());
}
// Initialize messages
$error = '';
$success = '';
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
// Validate inputs
if (empty($_POST['first_name']) || !preg_match('/^[A-Za-z. ]+$/', $_POST['first_name'])) {
throw new Exception("First name can only contain letters, periods and spaces");
}
if (empty($_POST['last_name']) || !preg_match('/^[A-Za-z. ]+$/', $_POST['last_name'])) {
throw new Exception("Last name can only contain letters, periods and spaces");
}
if (empty($_POST['username'])) {
throw new Exception("Username is required");
}
if (empty($_POST['password'])) {
throw new Exception("Password is required");
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$username = $_POST['username'];
$password = password_hash($_POST['password'], PASSWORD_BCRYPT);
$role = $_POST['role'];
$department_id = !empty($_POST['department_id']) ? (int)$_POST['department_id'] : null;
// Check if username exists
$stmt = $pdo->prepare("SELECT id FROM users WHERE username = ?");
$stmt->execute([$username]);
if ($stmt->fetch()) {
throw new Exception("Username already exists. Please choose a different one.");
}
// Insert new user
$stmt = $pdo->prepare("INSERT INTO users
(first_name, last_name, username, password, role, department_id)
VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$first_name, $last_name, $username, $password, $role, $department_id]);
if ($stmt->rowCount() > 0) {
$success = "User added successfully!";
// Clear form fields on success
$_POST = [];
} else {
throw new Exception("Failed to add user. Please try again.");
}
} catch (Exception $e) {
$error = $e->getMessage();
}
}
// Get all users and departments for the table
$users = $pdo->query("SELECT users.*, departments.name as department_name
FROM users LEFT JOIN departments ON users.department_id = departments.id")->fetchAll();
$departments = $pdo->query("SELECT * FROM departments")->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Management - RJL DeskTrack</title>
<style>
:root {
--sidebar-width: 240px;
--header-height: 80px;
--primary-color: #77693A;
--secondary-color: #D1B48C;
--text-dark: #333;
--text-light: #f8f9fa;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f7f9;
color: var(--text-dark);
}
.dashboard-container {
display: flex;
min-height: 100vh;
}
/* Sidebar Styles */
.sidebar {
width: var(--sidebar-width);
background-color: var(--secondary-color);
color: #000;
height: 100vh;
position: fixed;
left: 0;
top: 0;
overflow-y: auto;
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
z-index: 1000;
}
.logo {
padding: 20px;
text-align: left;
border-bottom: 1px solid rgba(0,0,0,0.1);
}
.logo h2 {
font-size: 24px;
font-weight: 700;
margin: 0;
color: #000;
}
.menu {
padding: 20px 0;
margin: 0;
}
.menu li {
list-style: none;
}
.menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
color: #000;
text-decoration: none;
font-size: 16px;
transition: all 0.3s ease;
}
.menu li a i {
margin-right: 10px;
font-style: normal;
font-size: 18px;
width: 25px;
text-align: center;
}
.menu li a:hover,
.menu li a.active {
background-color: #ffffff;
color: #000;
}
/* Main Content Area */
.main-content {
margin-left: var(--sidebar-width);
width: calc(100% - var(--sidebar-width));
min-height: 100vh;
}
/* Top Header Bar */
.top-bar {
background-color: var(--primary-color);
color: white;
height: var(--header-height);
display: flex;
align-items: center;
justify-content: center;
position: relative;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.top-bar h1 {
font-size: 24px;
margin: 0;
font-weight: 700;
}
.user-info {
position: absolute;
right: 30px;
display: flex;
align-items: center;
gap: 10px;
}
.user-info img {
width: 40px;
height: 40px;
border-radius: 50%;
object-fit: cover;
}
.user-info span {
font-size: 16px;
font-weight: 600;
color: white;
}
/* Content Layout */
.content-wrapper {
display: flex;
padding: 20px;
gap: 20px;
}
.form-section {
flex: 1;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 20px;
}
.table-section {
flex: 2;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 20px;
overflow-x: auto;
}
/* Form Styles */
.form-title {
margin-top: 0;
margin-bottom: 20px;
font-size: 20px;
color: var(--primary-color);
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: 600;
}
.form-group input,
.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
}
.btn {
background-color: var(--primary-color);
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s;
}
.btn:hover {
background-color: #5a4d1b;
}
/* Table Styles */
.table-title {
margin-top: 0;
margin-bottom: 20px;
font-size: 20px;
color: var(--primary-color);
}
.user-table {
width: 100%;
border-collapse: collapse;
}
.user-table th,
.user-table td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
.user-table th {
background-color: #f8f9fa;
font-weight: 600;
}
.user-table tr:hover {
background-color: #f1f3f5;
}
.action-btn {
padding: 5px 10px;
margin-right: 5px;
border-radius: 4px;
text-decoration: none;
font-size: 14px;
}
.edit-btn {
background-color: #3498db;
color: white;
}
.delete-btn {
background-color: #e74c3c;
color: white;
}
/* Message Styles */
.message {
padding: 10px 15px;
margin-bottom: 15px;
border-radius: 4px;
}
.success-message {
background-color: #d4edda;
color: #155724;
}
.error-message {
background-color: #f8d7da;
color: #721c24;
}
/* Responsive Adjustments */
@media (max-width: 992px) {
.content-wrapper {
flex-direction: column;
}
}
@media (max-width: 768px) {
.sidebar {
width: 70px;
}
.logo h2 {
display: none;
}
.menu li a span {
display: none;
}
.menu li a {
justify-content: center;
padding: 12px 0;
}
.menu li a i {
margin-right: 0;
font-size: 20px;
}
.main-content {
margin-left: 70px;
width: calc(100% - 70px);
}
}
@media (max-width: 576px) {
.sidebar {
width: 100%;
height: auto;
position: relative;
}
.main-content {
margin-left: 0;
width: 100%;
}
.top-bar {
justify-content: flex-start;
padding-left: 20px;
}
.user-info {
position: static;
margin-left: auto;
padding-right: 20px;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<!-- Sidebar -->
<div class="sidebar">
<div class="logo">
<h2>RJL DeskTrack</h2>
</div>
<ul class="menu">
<li><a href="http://localhost/helpdesk/?page_id=30"><i>📊</i> <span>Dashboard</span></a></li>
<li><a href="http://localhost/helpdesk/?page_id=35" class="active"><i>👥</i> <span>Users</span></a></li>
<li><a href="departments.php"><i>🏢</i> <span>Departments</span></a></li>
<li><a href="tickets.php"><i>🎫</i> <span>Tickets</span></a></li>
<li><a href="messages.php"><i>✉️</i> <span>Messages</span></a></li>
<li><a href="reports.php"><i>📈</i> <span>Reports</span></a></li>
</ul>
</div>
<!-- Main Content -->
<div class="main-content">
<!-- Top Bar -->
<div class="top-bar">
<h1>User Management</h1>
<div class="user-info">
<img src="https://ui-avatars.com/api/?name=<?= urlencode($_SESSION['username']) ?>&background=007bff&color=fff" alt="User">
<span><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
</div>
<!-- Content Wrapper -->
<div class="content-wrapper">
<!-- Add User Form Section -->
<div class="form-section">
<h2 class="form-title">Add New User</h2>
<?php if ($success): ?>
<div class="message success-message">
<?= htmlspecialchars($success) ?>
</div>
<?php endif; ?>
<?php if ($error): ?>
<div class="message error-message">
<?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<form method="POST">
<div class="form-group">
<label for="first_name">First Name</label>
<input type="text" id="first_name" name="first_name"
pattern="[A-Za-z. ]+"
title="Only letters, periods and spaces allowed"
required
value="<?= isset($_POST['first_name']) ? htmlspecialchars($_POST['first_name']) : '' ?>">
</div>
<div class="form-group">
<label for="last_name">Last Name</label>
<input type="text" id="last_name" name="last_name"
pattern="[A-Za-z. ]+"
title="Only letters, periods and spaces allowed"
required
value="<?= isset($_POST['last_name']) ? htmlspecialchars($_POST['last_name']) : '' ?>">
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username"
required
value="<?= isset($_POST['username']) ? htmlspecialchars($_POST['username']) : '' ?>">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<label for="role">Role</label>
<select id="role" name="role" required>
<option value="admin" <?= (isset($_POST['role']) && $_POST['role'] === 'admin') ? 'selected' : '' ?>>Admin</option>
<option value="user" <?= !isset($_POST['role']) || $_POST['role'] === 'user' ? 'selected' : '' ?>>User</option>
</select>
</div>
<div class="form-group">
<label for="department_id">Department</label>
<select id="department_id" name="department_id">
<option value="">None</option>
<?php foreach ($departments as $dept): ?>
<option value="<?= $dept['id'] ?>"
<?= (isset($_POST['department_id']) && $_POST['department_id'] == $dept['id']) ? 'selected' : '' ?>>
<?= htmlspecialchars($dept['name']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn">Add User</button>
</form>
</div>
<!-- Users Table Section -->
<div class="table-section">
<h2 class="table-title">All Users</h2>
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th>Role</th>
<th>Department</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?= $user['id'] ?></td>
<td><?= htmlspecialchars($user['first_name']) ?></td>
<td><?= htmlspecialchars($user['last_name']) ?></td>
<td><?= htmlspecialchars($user['username']) ?></td>
<td><?= ucfirst($user['role']) ?></td>
<td><?= $user['department_name'] ?? 'None' ?></td>
<td>
<a href="edit_user.php?id=<?= $user['id'] ?>" class="action-btn edit-btn">Edit</a>
<a href="delete_user.php?id=<?= $user['id'] ?>" class="action-btn delete-btn" onclick="return confirm('Are you sure?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script>
// Simple script to handle active menu items
document.querySelectorAll('.menu a').forEach(link => {
if (link.href === window.location.href) {
link.classList.add('active');
}
link.addEventListener('click', function() {
document.querySelectorAll('.menu a').forEach(item => {
item.classList.remove('active');
});
this.classList.add('active');
});
});
</script>
</body>
</html>
Key changes made:
Here's the simplified version with basic CSS syntax as requested:
<?php
// [Previous PHP code remains exactly the same until the closing PHP tag]
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Management - RJL DeskTrack</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f7f9;
color: #333;
}
.sidebar {
width: 240px;
background-color: #D1B48C;
color: #000;
height: 100vh;
position: fixed;
left: 0;
top: 0;
overflow-y: auto;
box-shadow: 2px 0 5px rgba(0,0,0,0.1);
z-index: 1000;
}
.logo h2 {
font-size: 24px;
font-weight: 700;
padding: 20px;
margin: 0;
border-bottom: 1px solid rgba(0,0,0,0.1);
color: #000;
}
.menu {
padding-left: 20px;
margin-top: 20px;
}
.menu li {
list-style: none;
margin-bottom: 12px;
}
.menu li a {
font-size: 16px;
color: #000;
text-decoration: none;
display: flex;
align-items: center;
padding: 8px 12px;
border-radius: 6px;
}
.menu li a i {
margin-right: 10px;
font-style: normal;
font-size: 18px;
width: 25px;
text-align: center;
}
.menu li a:hover,
.menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
height: 60px;
background-color: #77693A;
color: #fff;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
z-index: 999;
}
.header h1 {
font-size: 24px;
margin: 0;
font-weight: 700;
}
.user-info {
position: absolute;
right: 30px;
display: flex;
align-items: center;
gap: 10px;
}
.user-info img {
width: 35px;
height: 35px;
border-radius: 50%;
object-fit: cover;
}
.user-info span {
font-size: 16px;
font-weight: 600;
color: #fff;
}
.main-content {
margin-left: 240px;
padding: 80px 30px 30px;
min-height: 100vh;
background-color: #f4f7f9;
display: flex;
}
.form-section {
flex: 1;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 20px;
margin-right: 20px;
}
.table-section {
flex: 2;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 20px;
overflow-x: auto;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: 600;
}
.form-group input,
.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
}
.btn {
background-color: #77693A;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.btn:hover {
background-color: #5a4d1b;
}
.user-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.user-table th,
.user-table td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
.user-table th {
background-color: #f8f9fa;
font-weight: 600;
}
.user-table tr:hover {
background-color: #f1f3f5;
}
.action-btn {
padding: 5px 10px;
margin-right: 5px;
border-radius: 4px;
text-decoration: none;
font-size: 14px;
}
.edit-btn {
background-color: #3498db;
color: white;
}
.delete-btn {
background-color: #e74c3c;
color: white;
}
.success-message {
color: green;
margin-bottom: 15px;
}
.error-message {
color: red;
margin-bottom: 15px;
}
@media (max-width: 768px) {
.sidebar {
width: 70px;
}
.logo h2,
.menu li a span {
display: none;
}
.menu li a {
justify-content: center;
padding: 8px;
}
.menu li a i {
margin-right: 0;
font-size: 20px;
}
.main-content {
margin-left: 70px;
flex-direction: column;
}
.form-section {
margin-right: 0;
margin-bottom: 20px;
}
.header {
left: 70px;
}
}
@media (max-width: 480px) {
.sidebar {
width: 100%;
height: auto;
position: relative;
}
.main-content {
margin-left: 0;
padding-top: 20px;
}
.header {
left: 0;
position: relative;
}
}
</style>
</head>
<body>
<!-- Sidebar -->
<div class="sidebar">
<div class="logo">
<h2>RJL DeskTrack</h2>
</div>
<ul class="menu">
<li><a href="http://localhost/helpdesk/?page_id=30"><i>📊</i> <span>Dashboard</span></a></li>
<li><a href="http://localhost/helpdesk/?page_id=35" class="active"><i>👥</i> <span>Users</span></a></li>
<li><a href="departments.php"><i>🏢</i> <span>Departments</span></a></li>
<li><a href="tickets.php"><i>🎫</i> <span>Tickets</span></a></li>
<li><a href="messages.php"><i>✉️</i> <span>Messages</span></a></li>
<li><a href="reports.php"><i>📈</i> <span>Reports</span></a></li>
</ul>
</div>
<!-- Main Content -->
<div class="main-content">
<div class="header">
<h1>User Management</h1>
<div class="user-info">
<img src="https://ui-avatars.com/api/?name=<?= urlencode($_SESSION['username']) ?>&background=007bff&color=fff" alt="User">
<span><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
</div>
<!-- Form Section -->
<div class="form-section">
<h2>Add New User</h2>
<?php if ($success): ?>
<div class="success-message"><?= htmlspecialchars($success) ?></div>
<?php endif; ?>
<?php if ($error): ?>
<div class="error-message"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="POST">
<div class="form-group">
<label for="first_name">First Name</label>
<input type="text" id="first_name" name="first_name"
pattern="[A-Za-z. ]+"
title="Only letters, periods and spaces allowed"
required
value="<?= isset($_POST['first_name']) ? htmlspecialchars($_POST['first_name']) : '' ?>">
</div>
<div class="form-group">
<label for="last_name">Last Name</label>
<input type="text" id="last_name" name="last_name"
pattern="[A-Za-z. ]+"
title="Only letters, periods and spaces allowed"
required
value="<?= isset($_POST['last_name']) ? htmlspecialchars($_POST['last_name']) : '' ?>">
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username"
required
value="<?= isset($_POST['username']) ? htmlspecialchars($_POST['username']) : '' ?>">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<label for="role">Role</label>
<select id="role" name="role" required>
<option value="admin" <?= (isset($_POST['role']) && $_POST['role'] === 'admin') ? 'selected' : '' ?>>Admin</option>
<option value="user" <?= !isset($_POST['role']) || $_POST['role'] === 'user' ? 'selected' : '' ?>>User</option>
</select>
</div>
<div class="form-group">
<label for="department_id">Department</label>
<select id="department_id" name="department_id">
<option value="">None</option>
<?php foreach ($departments as $dept): ?>
<option value="<?= $dept['id'] ?>"
<?= (isset($_POST['department_id']) && $_POST['department_id'] == $dept['id']) ? 'selected' : '' ?>>
<?= htmlspecialchars($dept['name']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn">Add User</button>
</form>
</div>
<!-- Table Section -->
<div class="table-section">
<h2>All Users</h2>
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th>Role</th>
<th>Department</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?= $user['id'] ?></td>
<td><?= htmlspecialchars($user['first_name']) ?></td>
<td><?= htmlspecialchars($user['last_name']) ?></td>
<td><?= htmlspecialchars($user['username']) ?></td>
<td><?= ucfirst($user['role']) ?></td>
<td><?= $user['department_name'] ?? 'None' ?></td>
<td>
<a href="edit_user.php?id=<?= $user['id'] ?>" class="action-btn edit-btn">Edit</a>
<a href="delete_user.php?id=<?= $user['id'] ?>" class="action-btn delete-btn" onclick="return confirm('Are you sure?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<script>
document.querySelectorAll('.menu a').forEach(link => {
if (link.href === window.location.href) {
link.classList.add('active');
}
link.addEventListener('click', function() {
document.querySelectorAll('.menu a').forEach(item => {
item.classList.remove('active');
});
this.classList.add('active');
});
});
</script>
</body>
</html>
<?php
// [Previous PHP code remains exactly the same until the closing PHP tag]
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Management - RJL DeskTrack</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f7f9;
color: #333;
}
.sidebar {
width: 240px;
background-color: #D1B48C;
color: #000;
height: 100vh;
position: fixed;
left: 0;
top: 0;
overflow-y: auto;
box-shadow: 2px 0 5px rgba(0,0,0,0.1);
z-index: 1000;
}
.logo h2 {
font-size: 24px;
font-weight: 700;
padding: 20px;
margin: 0;
border-bottom: 1px solid rgba(0,0,0,0.1);
color: #000;
}
.menu {
padding-left: 20px;
margin-top: 20px;
}
.menu li {
list-style: none;
margin-bottom: 12px;
}
.menu li a {
font-size: 16px;
color: #000;
text-decoration: none;
display: flex;
align-items: center;
padding: 8px 12px;
border-radius: 6px;
}
.menu li a i {
margin-right: 10px;
font-style: normal;
font-size: 18px;
width: 25px;
text-align: center;
}
.menu li a:hover,
.menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
height: 60px;
background-color: #77693A;
color: #fff;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
z-index: 999;
}
.header h1 {
font-size: 24px;
margin: 0;
font-weight: 700;
}
.user-info {
position: absolute;
right: 30px;
display: flex;
align-items: center;
gap: 10px;
}
.user-info img {
width: 35px;
height: 35px;
border-radius: 50%;
object-fit: cover;
}
.user-info span {
font-size: 16px;
font-weight: 600;
color: #fff;
}
.main-content {
margin-left: 240px;
padding: 80px 30px 30px;
min-height: 100vh;
background-color: #f4f7f9;
display: flex;
}
.form-section {
flex: 1;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 20px;
margin-right: 20px;
}
.table-section {
flex: 2;
background: white;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 20px;
overflow-x: auto;
}
.form-group {
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: 600;
}
.form-group input,
.form-group select {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
}
.btn {
background-color: #77693A;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.btn:hover {
background-color: #5a4d1b;
}
.user-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.user-table th,
.user-table td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
.user-table th {
background-color: #f8f9fa;
font-weight: 600;
}
.user-table tr:hover {
background-color: #f1f3f5;
}
.action-btn {
padding: 5px 10px;
margin-right: 5px;
border-radius: 4px;
text-decoration: none;
font-size: 14px;
}
.edit-btn {
background-color: #3498db;
color: white;
}
.delete-btn {
background-color: #e74c3c;
color: white;
}
.success-message {
color: green;
margin-bottom: 15px;
}
.error-message {
color: red;
margin-bottom: 15px;
}
@media (max-width: 768px) {
.sidebar {
width: 70px;
}
.logo h2,
.menu li a span {
display: none;
}
.menu li a {
justify-content: center;
padding: 8px;
}
.menu li a i {
margin-right: 0;
font-size: 20px;
}
.main-content {
margin-left: 70px;
flex-direction: column;
}
.form-section {
margin-right: 0;
margin-bottom: 20px;
}
.header {
left: 70px;
}
}
@media (max-width: 480px) {
.sidebar {
width: 100%;
height: auto;
position: relative;
}
.main-content {
margin-left: 0;
padding-top: 20px;
}
.header {
left: 0;
position: relative;
}
}
</style>
</head>
<body>
<!-- Sidebar -->
<div class="sidebar">
<div class="logo">
<h2>RJL DeskTrack</h2>
</div>
<ul class="menu">
<li><a href="http://localhost/helpdesk/?page_id=30"><i>📊</i> <span>Dashboard</span></a></li>
<li><a href="http://localhost/helpdesk/?page_id=35" class="active"><i>👥</i> <span>Users</span></a></li>
<li><a href="departments.php"><i>🏢</i> <span>Departments</span></a></li>
<li><a href="tickets.php"><i>🎫</i> <span>Tickets</span></a></li>
<li><a href="messages.php"><i>✉️</i> <span>Messages</span></a></li>
<li><a href="reports.php"><i>📈</i> <span>Reports</span></a></li>
</ul>
</div>
<!-- Main Content -->
<div class="main-content">
<div class="header">
<h1>User Management</h1>
<div class="user-info">
<img src="https://ui-avatars.com/api/?name=<?= urlencode($_SESSION['username']) ?>&background=007bff&color=fff" alt="User">
<span><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
</div>
<!-- Form Section -->
<div class="form-section">
<h2>Add New User</h2>
<?php if ($success): ?>
<div class="success-message"><?= htmlspecialchars($success) ?></div>
<?php endif; ?>
<?php if ($error): ?>
<div class="error-message"><?= htmlspecialchars($error) ?></div>
<?php endif; ?>
<form method="POST">
<div class="form-group">
<label for="first_name">First Name</label>
<input type="text" id="first_name" name="first_name"
pattern="[A-Za-z. ]+"
title="Only letters, periods and spaces allowed"
required
value="<?= isset($_POST['first_name']) ? htmlspecialchars($_POST['first_name']) : '' ?>">
</div>
<div class="form-group">
<label for="last_name">Last Name</label>
<input type="text" id="last_name" name="last_name"
pattern="[A-Za-z. ]+"
title="Only letters, periods and spaces allowed"
required
value="<?= isset($_POST['last_name']) ? htmlspecialchars($_POST['last_name']) : '' ?>">
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username"
required
value="<?= isset($_POST['username']) ? htmlspecialchars($_POST['username']) : '' ?>">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group">
<label for="role">Role</label>
<select id="role" name="role" required>
<option value="admin" <?= (isset($_POST['role']) && $_POST['role'] === 'admin') ? 'selected' : '' ?>>Admin</option>
<option value="user" <?= !isset($_POST['role']) || $_POST['role'] === 'user' ? 'selected' : '' ?>>User</option>
</select>
</div>
<div class="form-group">
<label for="department_id">Department</label>
<select id="department_id" name="department_id">
<option value="">None</option>
<?php foreach ($departments as $dept): ?>
<option value="<?= $dept['id'] ?>"
<?= (isset($_POST['department_id']) && $_POST['department_id'] == $dept['id']) ? 'selected' : '' ?>>
<?= htmlspecialchars($dept['name']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<button type="submit" class="btn">Add User</button>
</form>
</div>
<!-- Table Section -->
<div class="table-section">
<h2>All Users</h2>
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th>Role</th>
<th>Department</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user): ?>
<tr>
<td><?= $user['id'] ?></td>
<td><?= htmlspecialchars($user['first_name']) ?></td>
<td><?= htmlspecialchars($user['last_name']) ?></td>
<td><?= htmlspecialchars($user['username']) ?></td>
<td><?= ucfirst($user['role']) ?></td>
<td><?= $user['department_name'] ?? 'None' ?></td>
<td>
<a href="edit_user.php?id=<?= $user['id'] ?>" class="action-btn edit-btn">Edit</a>
<a href="delete_user.php?id=<?= $user['id'] ?>" class="action-btn delete-btn" onclick="return confirm('Are you sure?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
<script>
document.querySelectorAll('.menu a').forEach(link => {
if (link.href === window.location.href) {
link.classList.add('active');
}
link.addEventListener('click', function() {
document.querySelectorAll('.menu a').forEach(item => {
item.classList.remove('active');
});
this.classList.add('active');
});
});
</script>
</body>
</html>
Key changes: