I removed the chart but kept the tables (Highest Selling Products, Latest Sales, and Recently Added Products). Here's what was changed:
Removed:
$product_table_name_chart, $products_for_chart, etc.)Kept:
The file now shows just the overview boxes and tables without the stock chart visualization. The tables continue to display:
All the data fetching and display logic for these tables remains intact._
I'll help you incorporate the inventory dashboard's styling and layout into your helpdesk dashboard while keeping only the cards (without the chart and tables). Here's the updated helpdesk dashboard:
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: http://localhost/helpdesk/?page_id=30");
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());
}
// Get counts for dashboard cards
$ticketCount = $pdo->query("SELECT COUNT(*) FROM tickets")->fetchColumn();
$userCount = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$messageCount = $pdo->query("SELECT COUNT(*) FROM messages")->fetchColumn();
$departmentCount = $pdo->query("SELECT COUNT(*) FROM departments")->fetchColumn();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - RJL DeskTrack</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #000000;
}
.user-dropdown-content.user-info {
display: flex;
align-items: right;
gap: 1px;
color: #000000;
}
.user-dropdown-content a {
display: flex;
padding: 8px 15px;
align-items: center;
color: #000000;
text-decoration: none;
font-size: 16px;
transition: all 0.2s;
}
.user-dropdown-content a i {
font-size: 16px;
margin-right: 8px;
}
.user-dropdown-content a:hover {
text-decoration: underline;
color: #000000;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
.header-right i {
color: #ffffff;
font-size:40px;
}
.header-right span {
font-size: 15px;
color: #ffffff;
}
.main-content {
margin-left: 240px;
padding: 80px 20px 20px 20px;
flex-grow: 1;
}
/* Overview Boxes */
.overview-boxes {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 35px;
}
.overview-boxes .box {
background-color: #fff;
padding: 15px 12px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
border: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 12px;
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
width: 100%;
box-sizing: border-box;
}
.overview-boxes .box:hover {
transform: translateY(-3px);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.09);
}
.overview-boxes .box i.icon {
font-size: 20px;
color: #fff;
border-radius: 50%;
padding: 10px;
width: 45px;
height: 45px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.overview-boxes .box:nth-child(1) i.icon { background-color: #17a2b8; }
.overview-boxes .box:nth-child(2) i.icon { background-color: #28a745; }
.overview-boxes .box:nth-child(3) i.icon { background-color: #ffc107; }
.overview-boxes .box:nth-child(4) i.icon { background-color: #dc3545; }
.overview-boxes .box .detail {
text-align: left;
overflow: hidden;
}
.overview-boxes .box .count {
font-size: 20px;
font-weight: 600;
color: #343a40;
line-height: 1.1;
margin-bottom: 4px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.overview-boxes .box .label {
font-size: 13px;
color: #6c757d;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
/* Responsive Adjustments */
@media (max-width: 992px) {
.overview-boxes {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 576px) {
.overview-boxes {
grid-template-columns: 1fr;
}
.overview-boxes .box {
gap: 10px;
padding: 12px 10px;
}
.overview-boxes .box i.icon {
width: 40px;
height: 40px;
font-size: 18px;
padding: 8px;
}
.overview-boxes .box .count {
font-size: 18px;
}
.overview-boxes .box .label {
font-size: 12px;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">RJL DeskTrack</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="#" class="active"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<li><a href="#"><i class="fas fa-users"></i> Users</a></li>
<li><a href="#"><i class="fas fa-building"></i> Department</a></li>
<li><a href="#"><i class="fas fa-ticket-alt"></i> Tickets</a></li>
<li><a href="#"><i class="fas fa-envelope"></i> Messages</a></li>
<li><a href="#"><i class="fas fa-chart-bar"></i> Report</a></li>
</ul>
</div>
</aside>
<main class="main-content">
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?= htmlspecialchars($_SESSION['username']) ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle" style="color:#000000;"></i>
<span style="color:#000000;"><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
<a href="#" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt" style="font-size: 16px; color:#000000;"></i>Logout
</a>
</div>
</div>
</div>
</header>
<h1>Dashboard Overview</h1>
<section class="overview-boxes">
<div class="box">
<i class="fas fa-ticket-alt icon"></i>
<div class="detail">
<div class="count" id="ticket-count"><?= $ticketCount ?></div>
<div class="label">Tickets</div>
</div>
</div>
<div class="box">
<i class="fas fa-users icon"></i>
<div class="detail">
<div class="count" id="user-count"><?= $userCount ?></div>
<div class="label">Users</div>
</div>
</div>
<div class="box">
<i class="fas fa-envelope icon"></i>
<div class="detail">
<div class="count" id="message-count"><?= $messageCount ?></div>
<div class="label">Messages</div>
</div>
</div>
<div class="box">
<i class="fas fa-building icon"></i>
<div class="detail">
<div class="count" id="department-count"><?= $departmentCount ?></div>
<div class="label">Departments</div>
</div>
</div>
</section>
</main>
</div>
<script>
// Update date and time
function updateDateTime() {
const now = new Date();
const options = {
weekday: 'short', year: 'numeric', month: 'short',
day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit'
};
document.getElementById("current-date-time").textContent = now.toLocaleDateString('en-US', options);
}
setInterval(updateDateTime, 1000);
updateDateTime();
// Toggle dropdown
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
});
</script>
</body>
</html>
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: http://localhost/helpdesk/?page_id=30");
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());
}
// Get counts for dashboard cards
$ticketCount = $pdo->query("SELECT COUNT(*) FROM tickets")->fetchColumn();
$userCount = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$messageCount = $pdo->query("SELECT COUNT(*) FROM messages")->fetchColumn();
$departmentCount = $pdo->query("SELECT COUNT(*) FROM departments")->fetchColumn();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - RJL DeskTrack</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #000000;
}
.user-dropdown-content.user-info {
display: flex;
align-items: right;
gap: 1px;
color: #000000;
}
.user-dropdown-content a {
display: flex;
padding: 8px 15px;
align-items: center;
color: #000000;
text-decoration: none;
font-size: 16px;
transition: all 0.2s;
}
.user-dropdown-content a i {
font-size: 16px;
margin-right: 8px;
}
.user-dropdown-content a:hover {
text-decoration: underline;
color: #000000;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
.header-right i {
color: #ffffff;
font-size:40px;
}
.header-right span {
font-size: 15px;
color: #ffffff;
}
.main-content {
margin-left: 240px;
padding: 80px 20px 20px 20px;
flex-grow: 1;
}
/* Overview Boxes */
.overview-boxes {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
margin-bottom: 35px;
}
.overview-boxes .box {
background-color: #fff;
padding: 15px 12px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
border: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 12px;
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
width: 100%;
box-sizing: border-box;
}
.overview-boxes .box:hover {
transform: translateY(-3px);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.09);
}
.overview-boxes .box i.icon {
font-size: 20px;
color: #fff;
border-radius: 50%;
padding: 10px;
width: 45px;
height: 45px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.overview-boxes .box:nth-child(1) i.icon { background-color: #17a2b8; }
.overview-boxes .box:nth-child(2) i.icon { background-color: #28a745; }
.overview-boxes .box:nth-child(3) i.icon { background-color: #ffc107; }
.overview-boxes .box:nth-child(4) i.icon { background-color: #dc3545; }
.overview-boxes .box .detail {
text-align: left;
overflow: hidden;
}
.overview-boxes .box .count {
font-size: 20px;
font-weight: 600;
color: #343a40;
line-height: 1.1;
margin-bottom: 4px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.overview-boxes .box .label {
font-size: 13px;
color: #6c757d;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
/* Responsive Adjustments */
@media (max-width: 992px) {
.overview-boxes {
grid-template-columns: repeat(2, 1fr);
}
}
@media (max-width: 576px) {
.overview-boxes {
grid-template-columns: 1fr;
}
.overview-boxes .box {
gap: 10px;
padding: 12px 10px;
}
.overview-boxes .box i.icon {
width: 40px;
height: 40px;
font-size: 18px;
padding: 8px;
}
.overview-boxes .box .count {
font-size: 18px;
}
.overview-boxes .box .label {
font-size: 12px;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">RJL DeskTrack</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="#" class="active"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<li><a href="#"><i class="fas fa-users"></i> Users</a></li>
<li><a href="#"><i class="fas fa-building"></i> Department</a></li>
<li><a href="#"><i class="fas fa-ticket-alt"></i> Tickets</a></li>
<li><a href="#"><i class="fas fa-envelope"></i> Messages</a></li>
<li><a href="#"><i class="fas fa-chart-bar"></i> Report</a></li>
</ul>
</div>
</aside>
<main class="main-content">
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?= htmlspecialchars($_SESSION['username']) ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle" style="color:#000000;"></i>
<span style="color:#000000;"><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
<a href="#" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt" style="font-size: 16px; color:#000000;"></i>Logout
</a>
</div>
</div>
</div>
</header>
<h1>Dashboard Overview</h1>
<section class="overview-boxes">
<div class="box">
<i class="fas fa-ticket-alt icon"></i>
<div class="detail">
<div class="count" id="ticket-count"><?= $ticketCount ?></div>
<div class="label">Tickets</div>
</div>
</div>
<div class="box">
<i class="fas fa-users icon"></i>
<div class="detail">
<div class="count" id="user-count"><?= $userCount ?></div>
<div class="label">Users</div>
</div>
</div>
<div class="box">
<i class="fas fa-envelope icon"></i>
<div class="detail">
<div class="count" id="message-count"><?= $messageCount ?></div>
<div class="label">Messages</div>
</div>
</div>
<div class="box">
<i class="fas fa-building icon"></i>
<div class="detail">
<div class="count" id="department-count"><?= $departmentCount ?></div>
<div class="label">Departments</div>
</div>
</div>
</section>
</main>
</div>
<script>
// Update date and time
function updateDateTime() {
const now = new Date();
const options = {
weekday: 'short', year: 'numeric', month: 'short',
day: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit'
};
document.getElementById("current-date-time").textContent = now.toLocaleDateString('en-US', options);
}
setInterval(updateDateTime, 1000);
updateDateTime();
// Toggle dropdown
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
});
</script>
</body>
</html>
Key changes made:
Styling:
Layout:
Content:
Functionality:
The result is a clean, professional helpdesk dashboard that matches the visual style of your inventory system while focusing on the key metrics you want to display.
Here's the updated helpdesk dashboard with the date/time fixed and the boxes arranged in a 2x2 grid:
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: http://localhost/helpdesk/?page_id=30");
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());
}
// Get counts for dashboard cards
$ticketCount = $pdo->query("SELECT COUNT(*) FROM tickets")->fetchColumn();
$userCount = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$messageCount = $pdo->query("SELECT COUNT(*) FROM messages")->fetchColumn();
$departmentCount = $pdo->query("SELECT COUNT(*) FROM departments")->fetchColumn();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - RJL DeskTrack</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left {
display: flex;
align-items: center;
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #000000;
}
.user-dropdown-content.user-info {
display: flex;
align-items: right;
gap: 1px;
color: #000000;
}
.user-dropdown-content a {
display: flex;
padding: 8px 15px;
align-items: center;
color: #000000;
text-decoration: none;
font-size: 16px;
transition: all 0.2s;
}
.user-dropdown-content a i {
font-size: 16px;
margin-right: 8px;
}
.user-dropdown-content a:hover {
text-decoration: underline;
color: #000000;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
.header-right i {
color: #ffffff;
font-size:40px;
}
.header-right span {
font-size: 15px;
color: #ffffff;
}
.main-content {
margin-left: 240px;
padding: 80px 20px 20px 20px;
flex-grow: 1;
}
/* Overview Boxes Grid */
.overview-boxes {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
margin-bottom: 35px;
}
.overview-boxes .box {
background-color: #fff;
padding: 15px 12px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
border: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 12px;
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
width: 100%;
box-sizing: border-box;
}
.overview-boxes .box:hover {
transform: translateY(-3px);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.09);
}
.overview-boxes .box i.icon {
font-size: 20px;
color: #fff;
border-radius: 50%;
padding: 10px;
width: 45px;
height: 45px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.overview-boxes .box:nth-child(1) i.icon { background-color: #17a2b8; }
.overview-boxes .box:nth-child(2) i.icon { background-color: #28a745; }
.overview-boxes .box:nth-child(3) i.icon { background-color: #ffc107; }
.overview-boxes .box:nth-child(4) i.icon { background-color: #dc3545; }
.overview-boxes .box .detail {
text-align: left;
overflow: hidden;
}
.overview-boxes .box .count {
font-size: 20px;
font-weight: 600;
color: #343a40;
line-height: 1.1;
margin-bottom: 4px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.overview-boxes .box .label {
font-size: 13px;
color: #6c757d;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
/* Responsive Adjustments */
@media (max-width: 768px) {
.overview-boxes {
grid-template-columns: 1fr;
}
.overview-boxes .box {
gap: 10px;
padding: 12px 10px;
}
.overview-boxes .box i.icon {
width: 40px;
height: 40px;
font-size: 18px;
padding: 8px;
}
.overview-boxes .box .count {
font-size: 18px;
}
.overview-boxes .box .label {
font-size: 12px;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">RJL DeskTrack</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="#" class="active"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<li><a href="#"><i class="fas fa-users"></i> Users</a></li>
<li><a href="#"><i class="fas fa-building"></i> Department</a></li>
<li><a href="#"><i class="fas fa-ticket-alt"></i> Tickets</a></li>
<li><a href="#"><i class="fas fa-envelope"></i> Messages</a></li>
<li><a href="#"><i class="fas fa-chart-bar"></i> Report</a></li>
</ul>
</div>
</aside>
<main class="main-content">
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?= htmlspecialchars($_SESSION['username']) ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle" style="color:#000000;"></i>
<span style="color:#000000;"><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
<a href="#" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt" style="font-size: 16px; color:#000000;"></i>Logout
</a>
</div>
</div>
</div>
</header>
<h1>Dashboard Overview</h1>
<section class="overview-boxes">
<!-- First row -->
<div class="box">
<i class="fas fa-ticket-alt icon"></i>
<div class="detail">
<div class="count" id="ticket-count"><?= $ticketCount ?></div>
<div class="label">Tickets</div>
</div>
</div>
<div class="box">
<i class="fas fa-users icon"></i>
<div class="detail">
<div class="count" id="user-count"><?= $userCount ?></div>
<div class="label">Users</div>
</div>
</div>
<!-- Second row -->
<div class="box">
<i class="fas fa-envelope icon"></i>
<div class="detail">
<div class="count" id="message-count"><?= $messageCount ?></div>
<div class="label">Messages</div>
</div>
</div>
<div class="box">
<i class="fas fa-building icon"></i>
<div class="detail">
<div class="count" id="department-count"><?= $departmentCount ?></div>
<div class="label">Departments</div>
</div>
</div>
</section>
</main>
</div>
<script>
// Update date and time
function updateDateTime() {
const now = new Date();
const options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
const dateTimeElement = document.getElementById("current-date-time");
if (dateTimeElement) {
dateTimeElement.textContent = now.toLocaleDateString('en-US', options);
}
}
// Initialize immediately and set interval
updateDateTime();
setInterval(updateDateTime, 1000);
// Toggle dropdown
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
if (dropdown && dropdownContent) {
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
}
});
</script>
</body>
</html>
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: http://localhost/helpdesk/?page_id=30");
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());
}
// Get counts for dashboard cards
$ticketCount = $pdo->query("SELECT COUNT(*) FROM tickets")->fetchColumn();
$userCount = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$messageCount = $pdo->query("SELECT COUNT(*) FROM messages")->fetchColumn();
$departmentCount = $pdo->query("SELECT COUNT(*) FROM departments")->fetchColumn();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - RJL DeskTrack</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left {
display: flex;
align-items: center;
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #000000;
}
.user-dropdown-content.user-info {
display: flex;
align-items: right;
gap: 1px;
color: #000000;
}
.user-dropdown-content a {
display: flex;
padding: 8px 15px;
align-items: center;
color: #000000;
text-decoration: none;
font-size: 16px;
transition: all 0.2s;
}
.user-dropdown-content a i {
font-size: 16px;
margin-right: 8px;
}
.user-dropdown-content a:hover {
text-decoration: underline;
color: #000000;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
.header-right i {
color: #ffffff;
font-size:40px;
}
.header-right span {
font-size: 15px;
color: #ffffff;
}
.main-content {
margin-left: 240px;
padding: 80px 20px 20px 20px;
flex-grow: 1;
}
/* Overview Boxes Grid */
.overview-boxes {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
margin-bottom: 35px;
}
.overview-boxes .box {
background-color: #fff;
padding: 15px 12px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
border: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 12px;
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
width: 100%;
box-sizing: border-box;
}
.overview-boxes .box:hover {
transform: translateY(-3px);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.09);
}
.overview-boxes .box i.icon {
font-size: 20px;
color: #fff;
border-radius: 50%;
padding: 10px;
width: 45px;
height: 45px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.overview-boxes .box:nth-child(1) i.icon { background-color: #17a2b8; }
.overview-boxes .box:nth-child(2) i.icon { background-color: #28a745; }
.overview-boxes .box:nth-child(3) i.icon { background-color: #ffc107; }
.overview-boxes .box:nth-child(4) i.icon { background-color: #dc3545; }
.overview-boxes .box .detail {
text-align: left;
overflow: hidden;
}
.overview-boxes .box .count {
font-size: 20px;
font-weight: 600;
color: #343a40;
line-height: 1.1;
margin-bottom: 4px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
.overview-boxes .box .label {
font-size: 13px;
color: #6c757d;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
/* Responsive Adjustments */
@media (max-width: 768px) {
.overview-boxes {
grid-template-columns: 1fr;
}
.overview-boxes .box {
gap: 10px;
padding: 12px 10px;
}
.overview-boxes .box i.icon {
width: 40px;
height: 40px;
font-size: 18px;
padding: 8px;
}
.overview-boxes .box .count {
font-size: 18px;
}
.overview-boxes .box .label {
font-size: 12px;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">RJL DeskTrack</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="#" class="active"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<li><a href="#"><i class="fas fa-users"></i> Users</a></li>
<li><a href="#"><i class="fas fa-building"></i> Department</a></li>
<li><a href="#"><i class="fas fa-ticket-alt"></i> Tickets</a></li>
<li><a href="#"><i class="fas fa-envelope"></i> Messages</a></li>
<li><a href="#"><i class="fas fa-chart-bar"></i> Report</a></li>
</ul>
</div>
</aside>
<main class="main-content">
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?= htmlspecialchars($_SESSION['username']) ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle" style="color:#000000;"></i>
<span style="color:#000000;"><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
<a href="#" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt" style="font-size: 16px; color:#000000;"></i>Logout
</a>
</div>
</div>
</div>
</header>
<h1>Dashboard Overview</h1>
<section class="overview-boxes">
<!-- First row -->
<div class="box">
<i class="fas fa-ticket-alt icon"></i>
<div class="detail">
<div class="count" id="ticket-count"><?= $ticketCount ?></div>
<div class="label">Tickets</div>
</div>
</div>
<div class="box">
<i class="fas fa-users icon"></i>
<div class="detail">
<div class="count" id="user-count"><?= $userCount ?></div>
<div class="label">Users</div>
</div>
</div>
<!-- Second row -->
<div class="box">
<i class="fas fa-envelope icon"></i>
<div class="detail">
<div class="count" id="message-count"><?= $messageCount ?></div>
<div class="label">Messages</div>
</div>
</div>
<div class="box">
<i class="fas fa-building icon"></i>
<div class="detail">
<div class="count" id="department-count"><?= $departmentCount ?></div>
<div class="label">Departments</div>
</div>
</div>
</section>
</main>
</div>
<script>
// Update date and time
function updateDateTime() {
const now = new Date();
const options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
const dateTimeElement = document.getElementById("current-date-time");
if (dateTimeElement) {
dateTimeElement.textContent = now.toLocaleDateString('en-US', options);
}
}
// Initialize immediately and set interval
updateDateTime();
setInterval(updateDateTime, 1000);
// Toggle dropdown
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
if (dropdown && dropdownContent) {
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
}
});
</script>
</body>
</html>
Key improvements:
Fixed Date/Time Display:
2x2 Grid Layout:
grid-template-columns: repeat(2, 1fr)Responsive Design:
Other Fixes:
The boxes are now properly arranged in a 2x2 grid while maintaining all the visual styling from your inventory dashboard, and the date/time display works correctly.
Here's the updated helpdesk dashboard with a strict 2x2 grid layout (2 columns and 2 rows) for the boxes:
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: http://localhost/helpdesk/?page_id=30");
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());
}
// Get counts for dashboard cards
$ticketCount = $pdo->query("SELECT COUNT(*) FROM tickets")->fetchColumn();
$userCount = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$messageCount = $pdo->query("SELECT COUNT(*) FROM messages")->fetchColumn();
$departmentCount = $pdo->query("SELECT COUNT(*) FROM departments")->fetchColumn();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - RJL DeskTrack</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left {
display: flex;
align-items: center;
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #000000;
}
.user-dropdown-content.user-info {
display: flex;
align-items: right;
gap: 1px;
color: #000000;
}
.user-dropdown-content a {
display: flex;
padding: 8px 15px;
align-items: center;
color: #000000;
text-decoration: none;
font-size: 16px;
transition: all 0.2s;
}
.user-dropdown-content a i {
font-size: 16px;
margin-right: 8px;
}
.user-dropdown-content a:hover {
text-decoration: underline;
color: #000000;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
.header-right i {
color: #ffffff;
font-size:40px;
}
.header-right span {
font-size: 15px;
color: #ffffff;
}
.main-content {
margin-left: 240px;
padding: 80px 20px 20px 20px;
flex-grow: 1;
}
/* Strict 2x2 Grid Layout */
.overview-grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
gap: 20px;
width: 100%;
max-width: 800px;
margin: 0 auto;
}
.overview-box {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
border: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 15px;
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.overview-box:hover {
transform: translateY(-3px);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.09);
}
.overview-box i.icon {
font-size: 24px;
color: #fff;
border-radius: 50%;
padding: 12px;
width: 50px;
height: 50px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.overview-box:nth-child(1) i.icon { background-color: #17a2b8; }
.overview-box:nth-child(2) i.icon { background-color: #28a745; }
.overview-box:nth-child(3) i.icon { background-color: #ffc107; }
.overview-box:nth-child(4) i.icon { background-color: #dc3545; }
.overview-box .detail {
text-align: left;
overflow: hidden;
}
.overview-box .count {
font-size: 24px;
font-weight: 600;
color: #343a40;
line-height: 1.1;
margin-bottom: 5px;
}
.overview-box .label {
font-size: 14px;
color: #6c757d;
}
/* Responsive Adjustments */
@media (max-width: 768px) {
.overview-grid {
grid-template-columns: 1fr;
grid-template-rows: auto;
max-width: 400px;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">RJL DeskTrack</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="#" class="active"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<li><a href="#"><i class="fas fa-users"></i> Users</a></li>
<li><a href="#"><i class="fas fa-building"></i> Department</a></li>
<li><a href="#"><i class="fas fa-ticket-alt"></i> Tickets</a></li>
<li><a href="#"><i class="fas fa-envelope"></i> Messages</a></li>
<li><a href="#"><i class="fas fa-chart-bar"></i> Report</a></li>
</ul>
</div>
</aside>
<main class="main-content">
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?= htmlspecialchars($_SESSION['username']) ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle" style="color:#000000;"></i>
<span style="color:#000000;"><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
<a href="#" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt" style="font-size: 16px; color:#000000;"></i>Logout
</a>
</div>
</div>
</div>
</header>
<h1>Dashboard Overview</h1>
<div class="overview-grid">
<!-- Row 1 -->
<div class="overview-box">
<i class="fas fa-ticket-alt icon"></i>
<div class="detail">
<div class="count"><?= $ticketCount ?></div>
<div class="label">Tickets</div>
</div>
</div>
<div class="overview-box">
<i class="fas fa-users icon"></i>
<div class="detail">
<div class="count"><?= $userCount ?></div>
<div class="label">Users</div>
</div>
</div>
<!-- Row 2 -->
<div class="overview-box">
<i class="fas fa-envelope icon"></i>
<div class="detail">
<div class="count"><?= $messageCount ?></div>
<div class="label">Messages</div>
</div>
</div>
<div class="overview-box">
<i class="fas fa-building icon"></i>
<div class="detail">
<div class="count"><?= $departmentCount ?></div>
<div class="label">Departments</div>
</div>
</div>
</div>
</main>
</div>
<script>
// Update date and time
function updateDateTime() {
const now = new Date();
const options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
const dateTimeElement = document.getElementById("current-date-time");
if (dateTimeElement) {
dateTimeElement.textContent = now.toLocaleDateString('en-US', options);
}
}
// Initialize immediately and set interval
updateDateTime();
setInterval(updateDateTime, 1000);
// Toggle dropdown
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
if (dropdown && dropdownContent) {
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
}
});
</script>
</body>
</html>
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: http://localhost/helpdesk/?page_id=30");
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());
}
// Get counts for dashboard cards
$ticketCount = $pdo->query("SELECT COUNT(*) FROM tickets")->fetchColumn();
$userCount = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$messageCount = $pdo->query("SELECT COUNT(*) FROM messages")->fetchColumn();
$departmentCount = $pdo->query("SELECT COUNT(*) FROM departments")->fetchColumn();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - RJL DeskTrack</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left {
display: flex;
align-items: center;
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #000000;
}
.user-dropdown-content.user-info {
display: flex;
align-items: right;
gap: 1px;
color: #000000;
}
.user-dropdown-content a {
display: flex;
padding: 8px 15px;
align-items: center;
color: #000000;
text-decoration: none;
font-size: 16px;
transition: all 0.2s;
}
.user-dropdown-content a i {
font-size: 16px;
margin-right: 8px;
}
.user-dropdown-content a:hover {
text-decoration: underline;
color: #000000;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
.header-right i {
color: #ffffff;
font-size:40px;
}
.header-right span {
font-size: 15px;
color: #ffffff;
}
.main-content {
margin-left: 240px;
padding: 80px 20px 20px 20px;
flex-grow: 1;
}
/* Strict 2x2 Grid Layout */
.overview-grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
gap: 20px;
width: 100%;
max-width: 800px;
margin: 0 auto;
}
.overview-box {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
border: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 15px;
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.overview-box:hover {
transform: translateY(-3px);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.09);
}
.overview-box i.icon {
font-size: 24px;
color: #fff;
border-radius: 50%;
padding: 12px;
width: 50px;
height: 50px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.overview-box:nth-child(1) i.icon { background-color: #17a2b8; }
.overview-box:nth-child(2) i.icon { background-color: #28a745; }
.overview-box:nth-child(3) i.icon { background-color: #ffc107; }
.overview-box:nth-child(4) i.icon { background-color: #dc3545; }
.overview-box .detail {
text-align: left;
overflow: hidden;
}
.overview-box .count {
font-size: 24px;
font-weight: 600;
color: #343a40;
line-height: 1.1;
margin-bottom: 5px;
}
.overview-box .label {
font-size: 14px;
color: #6c757d;
}
/* Responsive Adjustments */
@media (max-width: 768px) {
.overview-grid {
grid-template-columns: 1fr;
grid-template-rows: auto;
max-width: 400px;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">RJL DeskTrack</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="#" class="active"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<li><a href="#"><i class="fas fa-users"></i> Users</a></li>
<li><a href="#"><i class="fas fa-building"></i> Department</a></li>
<li><a href="#"><i class="fas fa-ticket-alt"></i> Tickets</a></li>
<li><a href="#"><i class="fas fa-envelope"></i> Messages</a></li>
<li><a href="#"><i class="fas fa-chart-bar"></i> Report</a></li>
</ul>
</div>
</aside>
<main class="main-content">
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?= htmlspecialchars($_SESSION['username']) ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle" style="color:#000000;"></i>
<span style="color:#000000;"><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
<a href="#" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt" style="font-size: 16px; color:#000000;"></i>Logout
</a>
</div>
</div>
</div>
</header>
<h1>Dashboard Overview</h1>
<div class="overview-grid">
<!-- Row 1 -->
<div class="overview-box">
<i class="fas fa-ticket-alt icon"></i>
<div class="detail">
<div class="count"><?= $ticketCount ?></div>
<div class="label">Tickets</div>
</div>
</div>
<div class="overview-box">
<i class="fas fa-users icon"></i>
<div class="detail">
<div class="count"><?= $userCount ?></div>
<div class="label">Users</div>
</div>
</div>
<!-- Row 2 -->
<div class="overview-box">
<i class="fas fa-envelope icon"></i>
<div class="detail">
<div class="count"><?= $messageCount ?></div>
<div class="label">Messages</div>
</div>
</div>
<div class="overview-box">
<i class="fas fa-building icon"></i>
<div class="detail">
<div class="count"><?= $departmentCount ?></div>
<div class="label">Departments</div>
</div>
</div>
</div>
</main>
</div>
<script>
// Update date and time
function updateDateTime() {
const now = new Date();
const options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
const dateTimeElement = document.getElementById("current-date-time");
if (dateTimeElement) {
dateTimeElement.textContent = now.toLocaleDateString('en-US', options);
}
}
// Initialize immediately and set interval
updateDateTime();
setInterval(updateDateTime, 1000);
// Toggle dropdown
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
if (dropdown && dropdownContent) {
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
}
});
</script>
</body>
</html>
Key changes for the strict 2x2 grid:
Grid Layout:
.overview-grid class with explicit grid-template-columns: 1fr 1fr and grid-template-rows: 1fr 1frmargin: 0 autoBox Styling:
.overview-boxes to .overview-grid for clarityResponsive Design:
Other Improvements:
The result is a clean, professional 2x2 grid layout that matches your requirements while maintaining all the functionality of your helpdesk dashboard.
Here's the corrected version with the boxes properly arranged in a 2x2 grid layout:
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: http://localhost/helpdesk/?page_id=30");
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());
}
// Get counts for dashboard cards
$ticketCount = $pdo->query("SELECT COUNT(*) FROM tickets")->fetchColumn();
$userCount = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$messageCount = $pdo->query("SELECT COUNT(*) FROM messages")->fetchColumn();
$departmentCount = $pdo->query("SELECT COUNT(*) FROM departments")->fetchColumn();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - RJL DeskTrack</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left {
display: flex;
align-items: center;
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #000000;
}
.user-dropdown-content.user-info {
display: flex;
align-items: right;
gap: 1px;
color: #000000;
}
.user-dropdown-content a {
display: flex;
padding: 8px 15px;
align-items: center;
color: #000000;
text-decoration: none;
font-size: 16px;
transition: all 0.2s;
}
.user-dropdown-content a i {
font-size: 16px;
margin-right: 8px;
}
.user-dropdown-content a:hover {
text-decoration: underline;
color: #000000;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
.header-right i {
color: #ffffff;
font-size:40px;
}
.header-right span {
font-size: 15px;
color: #ffffff;
}
.main-content {
margin-left: 240px;
padding: 80px 20px 20px 20px;
flex-grow: 1;
}
/* Strict 2x2 Grid Layout */
.dashboard-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, auto);
gap: 20px;
width: 100%;
max-width: 800px;
margin: 0 auto;
}
.dashboard-box {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
border: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 15px;
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.dashboard-box:hover {
transform: translateY(-3px);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.09);
}
.dashboard-box i.icon {
font-size: 24px;
color: #fff;
border-radius: 50%;
padding: 12px;
width: 50px;
height: 50px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.dashboard-box:nth-child(1) i.icon { background-color: #17a2b8; }
.dashboard-box:nth-child(2) i.icon { background-color: #28a745; }
.dashboard-box:nth-child(3) i.icon { background-color: #ffc107; }
.dashboard-box:nth-child(4) i.icon { background-color: #dc3545; }
.dashboard-box .detail {
text-align: left;
overflow: hidden;
}
.dashboard-box .count {
font-size: 24px;
font-weight: 600;
color: #343a40;
line-height: 1.1;
margin-bottom: 5px;
}
.dashboard-box .label {
font-size: 14px;
color: #6c757d;
}
/* Responsive Adjustments */
@media (max-width: 768px) {
.dashboard-grid {
grid-template-columns: 1fr;
grid-template-rows: auto;
max-width: 400px;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">RJL DeskTrack</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="#" class="active"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<li><a href="#"><i class="fas fa-users"></i> Users</a></li>
<li><a href="#"><i class="fas fa-building"></i> Department</a></li>
<li><a href="#"><i class="fas fa-ticket-alt"></i> Tickets</a></li>
<li><a href="#"><i class="fas fa-envelope"></i> Messages</a></li>
<li><a href="#"><i class="fas fa-chart-bar"></i> Report</a></li>
</ul>
</div>
</aside>
<main class="main-content">
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?= htmlspecialchars($_SESSION['username']) ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle" style="color:#000000;"></i>
<span style="color:#000000;"><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
<a href="#" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt" style="font-size: 16px; color:#000000;"></i>Logout
</a>
</div>
</div>
</div>
</header>
<h1>Dashboard Overview</h1>
<div class="dashboard-grid">
<!-- Row 1 -->
<div class="dashboard-box">
<i class="fas fa-ticket-alt icon"></i>
<div class="detail">
<div class="count"><?= $ticketCount ?></div>
<div class="label">Tickets</div>
</div>
</div>
<div class="dashboard-box">
<i class="fas fa-users icon"></i>
<div class="detail">
<div class="count"><?= $userCount ?></div>
<div class="label">Users</div>
</div>
</div>
<!-- Row 2 -->
<div class="dashboard-box">
<i class="fas fa-envelope icon"></i>
<div class="detail">
<div class="count"><?= $messageCount ?></div>
<div class="label">Messages</div>
</div>
</div>
<div class="dashboard-box">
<i class="fas fa-building icon"></i>
<div class="detail">
<div class="count"><?= $departmentCount ?></div>
<div class="label">Departments</div>
</div>
</div>
</div>
</main>
</div>
<script>
// Update date and time
function updateDateTime() {
const now = new Date();
const options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
const dateTimeElement = document.getElementById("current-date-time");
if (dateTimeElement) {
dateTimeElement.textContent = now.toLocaleDateString('en-US', options);
}
}
// Initialize immediately and set interval
updateDateTime();
setInterval(updateDateTime, 1000);
// Toggle dropdown
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
if (dropdown && dropdownContent) {
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
}
});
</script>
</body>
</html>
<?php
session_start();
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: http://localhost/helpdesk/?page_id=30");
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());
}
// Get counts for dashboard cards
$ticketCount = $pdo->query("SELECT COUNT(*) FROM tickets")->fetchColumn();
$userCount = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$messageCount = $pdo->query("SELECT COUNT(*) FROM messages")->fetchColumn();
$departmentCount = $pdo->query("SELECT COUNT(*) FROM departments")->fetchColumn();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - RJL DeskTrack</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left {
display: flex;
align-items: center;
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #000000;
}
.user-dropdown-content.user-info {
display: flex;
align-items: right;
gap: 1px;
color: #000000;
}
.user-dropdown-content a {
display: flex;
padding: 8px 15px;
align-items: center;
color: #000000;
text-decoration: none;
font-size: 16px;
transition: all 0.2s;
}
.user-dropdown-content a i {
font-size: 16px;
margin-right: 8px;
}
.user-dropdown-content a:hover {
text-decoration: underline;
color: #000000;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
.header-right i {
color: #ffffff;
font-size:40px;
}
.header-right span {
font-size: 15px;
color: #ffffff;
}
.main-content {
margin-left: 240px;
padding: 80px 20px 20px 20px;
flex-grow: 1;
}
/* Strict 2x2 Grid Layout */
.dashboard-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, auto);
gap: 20px;
width: 100%;
max-width: 800px;
margin: 0 auto;
}
.dashboard-box {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.06);
border: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 15px;
transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.dashboard-box:hover {
transform: translateY(-3px);
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.09);
}
.dashboard-box i.icon {
font-size: 24px;
color: #fff;
border-radius: 50%;
padding: 12px;
width: 50px;
height: 50px;
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.dashboard-box:nth-child(1) i.icon { background-color: #17a2b8; }
.dashboard-box:nth-child(2) i.icon { background-color: #28a745; }
.dashboard-box:nth-child(3) i.icon { background-color: #ffc107; }
.dashboard-box:nth-child(4) i.icon { background-color: #dc3545; }
.dashboard-box .detail {
text-align: left;
overflow: hidden;
}
.dashboard-box .count {
font-size: 24px;
font-weight: 600;
color: #343a40;
line-height: 1.1;
margin-bottom: 5px;
}
.dashboard-box .label {
font-size: 14px;
color: #6c757d;
}
/* Responsive Adjustments */
@media (max-width: 768px) {
.dashboard-grid {
grid-template-columns: 1fr;
grid-template-rows: auto;
max-width: 400px;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">RJL DeskTrack</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="#" class="active"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<li><a href="#"><i class="fas fa-users"></i> Users</a></li>
<li><a href="#"><i class="fas fa-building"></i> Department</a></li>
<li><a href="#"><i class="fas fa-ticket-alt"></i> Tickets</a></li>
<li><a href="#"><i class="fas fa-envelope"></i> Messages</a></li>
<li><a href="#"><i class="fas fa-chart-bar"></i> Report</a></li>
</ul>
</div>
</aside>
<main class="main-content">
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?= htmlspecialchars($_SESSION['username']) ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle" style="color:#000000;"></i>
<span style="color:#000000;"><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
<a href="#" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt" style="font-size: 16px; color:#000000;"></i>Logout
</a>
</div>
</div>
</div>
</header>
<h1>Dashboard Overview</h1>
<div class="dashboard-grid">
<!-- Row 1 -->
<div class="dashboard-box">
<i class="fas fa-ticket-alt icon"></i>
<div class="detail">
<div class="count"><?= $ticketCount ?></div>
<div class="label">Tickets</div>
</div>
</div>
<div class="dashboard-box">
<i class="fas fa-users icon"></i>
<div class="detail">
<div class="count"><?= $userCount ?></div>
<div class="label">Users</div>
</div>
</div>
<!-- Row 2 -->
<div class="dashboard-box">
<i class="fas fa-envelope icon"></i>
<div class="detail">
<div class="count"><?= $messageCount ?></div>
<div class="label">Messages</div>
</div>
</div>
<div class="dashboard-box">
<i class="fas fa-building icon"></i>
<div class="detail">
<div class="count"><?= $departmentCount ?></div>
<div class="label">Departments</div>
</div>
</div>
</div>
</main>
</div>
<script>
// Update date and time
function updateDateTime() {
const now = new Date();
const options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
const dateTimeElement = document.getElementById("current-date-time");
if (dateTimeElement) {
dateTimeElement.textContent = now.toLocaleDateString('en-US', options);
}
}
// Initialize immediately and set interval
updateDateTime();
setInterval(updateDateTime, 1000);
// Toggle dropdown
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
if (dropdown && dropdownContent) {
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
}
});
</script>
</body>
</html>
Key fixes for the grid layout:
Proper Grid Implementation:
dashboard-grid for claritygrid-template-columns: repeat(2, 1fr) to create exactly 2 columnsgrid-template-rows: repeat(2, auto) to create exactly 2 rowsBox Styling:
dashboard-boxResponsive Behavior:
Other Improvements:
The boxes are now properly arranged in a 2x2 grid layout as requested, with two boxes in the first row and two boxes in the second row. The layout will automatically adjust to a single column on mobile devices.
Here's the updated helpdesk user management page with the styling and layout from your inventory system, incorporating both the "Add User" form and "All Users" table in a clean 2-column layout:
<?php
session_start();
// Check if user is logged in and is admin
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header("Location: http://localhost/helpdesk/?page_id=50");
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());
}
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Validate names (letters, periods, and spaces only)
if (!preg_match('/^[A-Za-z. ]+$/', $_POST['first_name'])) {
die("First name can only contain letters, periods and spaces");
}
if (!preg_match('/^[A-Za-z. ]+$/', $_POST['last_name'])) {
die("Last name can only contain letters, periods and spaces");
}
$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 = $_POST['department_id'];
$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]);
header("Location: http://localhost/helpdesk/?page_id=35");
exit();
}
// 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>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left {
display: flex;
align-items: center;
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #
<?php
session_start();
// Check if user is logged in and is admin
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header("Location: http://localhost/helpdesk/?page_id=50");
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());
}
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Validate names (letters, periods, and spaces only)
if (!preg_match('/^[A-Za-z. ]+$/', $_POST['first_name'])) {
die("First name can only contain letters, periods and spaces");
}
if (!preg_match('/^[A-Za-z. ]+$/', $_POST['last_name'])) {
die("Last name can only contain letters, periods and spaces");
}
$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 = $_POST['department_id'];
$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]);
header("Location: http://localhost/helpdesk/?page_id=35");
exit();
}
// 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>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left {
display: flex;
align-items: center;
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #
Here's the complete, properly formatted helpdesk user management page with the styling and layout from your inventory system:
<?php
session_start();
// Check if user is logged in and is admin
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header("Location: http://localhost/helpdesk/?page_id=50");
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());
}
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Validate names (letters, periods, and spaces only)
if (!preg_match('/^[A-Za-z. ]+$/', $_POST['first_name'])) {
die("First name can only contain letters, periods and spaces");
}
if (!preg_match('/^[A-Za-z. ]+$/', $_POST['last_name'])) {
die("Last name can only contain letters, periods and spaces");
}
$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 = $_POST['department_id'];
$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]);
header("Location: http://localhost/helpdesk/?page_id=35");
exit();
}
// 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>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left {
display: flex;
align-items: center;
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #000000;
}
.user-dropdown-content.user-info {
display: flex;
align-items: right;
gap: 1px;
color: #000000;
}
.user-dropdown-content a {
display: flex;
padding: 8px 15px;
align-items: center;
color: #000000;
text-decoration: none;
font-size: 16px;
transition: all 0.2s;
}
.user-dropdown-content a i {
font-size: 16px;
margin-right: 8px;
}
.user-dropdown-content a:hover {
text-decoration: underline;
color: #000000;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
.header-right i {
color: #ffffff;
font-size:40px;
}
.header-right span {
font-size: 15px;
color: #ffffff;
}
.main-content {
margin-left: 240px;
padding: 80px 20px 20px 20px;
flex-grow: 1;
}
/* User Management Layout */
.user-management {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.form-container {
flex: 1;
min-width: 300px;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.table-container {
flex: 2;
min-width: 300px;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
h2 {
margin-top: 0;
color: #2f4050;
font-size: 1.5em;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
.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;
}
button {
padding: 10px 15px;
border: none;
background-color: #77693A;
color: white;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #5a4d1b;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f8f9fa;
font-weight: 600;
}
tr:hover {
background-color: #f5f5f5;
}
.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;
}
/* Responsive Adjustments */
@media (max-width: 768px) {
.user-management {
flex-direction: column;
}
.form-container,
.table-container {
width: 100%;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">RJL DeskTrack</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="http://localhost/helpdesk/?page_id=57"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<li><a href="http://localhost/helpdesk/?page_id=62" class="active"><i class="fas fa-users-cog"></i> User Management</a></li>
<li><a href="departments.php"><i class="fas fa-building"></i> Departments</a></li>
<li><a href="tickets.php"><i class="fas fa-ticket-alt"></i> Tickets</a></li>
<li><a href="messages.php"><i class="fas fa-envelope"></i> Messages</a></li>
<li><a href="reports.php"><i class="fas fa-chart-bar"></i> Reports</a></li>
</ul>
</div>
</aside>
<main class="main-content">
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?= htmlspecialchars($_SESSION['username']) ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle" style="color:#000000;"></i>
<span style="color:#000000;"><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
<a href="#" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt" style="font-size: 16px; color:#000000;"></i>Logout
</a>
</div>
</div>
</div>
</header>
<h1>User Management</h1>
<div class="user-management">
<!-- Add User Form -->
<div class="form-container">
<h2>Add New User</h2>
<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>
</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>
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" required>
</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">Admin</option>
<option value="agent">Agent</option>
<option value="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'] ?>"><?= htmlspecialchars($dept['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<button type="submit">Add User</button>
</form>
</div>
<!-- Users Table -->
<div class="table-container">
<h2>All Users</h2>
<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>
</main>
</div>
<script>
// Update date and time
function updateDateTime() {
const now = new Date();
const options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
const dateTimeElement = document.getElementById("current-date-time");
if (dateTimeElement) {
dateTimeElement.textContent = now.toLocaleDateString('en-US', options);
}
}
// Initialize immediately and set interval
updateDateTime();
setInterval(updateDateTime, 1000);
// Toggle dropdown
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
if (dropdown && dropdownContent) {
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
}
});
// Name validation
document.querySelectorAll('input[name="first_name"], input[name="last_name"]').forEach(input => {
input.addEventListener('input', function() {
this.value = this.value.replace(/[^A-Za-z. ]/g, '');
});
input.addEventListener('blur', function() {
<?php
session_start();
// Check if user is logged in and is admin
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header("Location: http://localhost/helpdesk/?page_id=50");
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());
}
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Validate names (letters, periods, and spaces only)
if (!preg_match('/^[A-Za-z. ]+$/', $_POST['first_name'])) {
die("First name can only contain letters, periods and spaces");
}
if (!preg_match('/^[A-Za-z. ]+$/', $_POST['last_name'])) {
die("Last name can only contain letters, periods and spaces");
}
$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 = $_POST['department_id'];
$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]);
header("Location: http://localhost/helpdesk/?page_id=35");
exit();
}
// 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>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0; padding: 0;
background-color: #f4f7f9; color: #333;
}
.dashboard-container { display: flex; }
.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;
}
.sidebar-header {
padding: 20px;
text-align: center;
}
.sidebar-header .inventory-name {
font-size: 24px;
font-weight: bold;
color: #000;
}
.sidebar-menu {
padding: 0;
}
.sidebar-menu ul {
list-style: none;
margin: 0;
padding: 0;
}
.sidebar-menu li a {
display: flex;
align-items: center;
padding: 12px 20px;
text-decoration: none;
color: #000;
transition: 0.3s;
font-size: 16px;
}
.sidebar-menu li a i {
margin-right: 12px;
width: 20px;
text-align: center;
}
.sidebar-menu li a:hover,
.sidebar-menu li a.active {
background-color: #ffffff;
color: #000;
}
.header {
position: fixed;
top: 0;
left: 240px;
right: 0;
display: flex;
justify-content: space-between;
align-items: center;
background-color: #77693A;
padding: 10px 30px;
height: 60px;
z-index: 999;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.header-left {
display: flex;
align-items: center;
}
.header-left .date-time {
font-size: 15px;
color: #fff;
font-weight: 500;
}
.header-right {
display: flex;
align-items: center;
font-size: 16px;
color: #ffffff;
}
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-header {
padding: 8px 12px;
background-color: #D1B48C;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 8px;
}
.user-dropdown-header i {
font-size: 20px;
color: #000000;
}
.user-dropdown-content.user-info {
display: flex;
align-items: right;
gap: 1px;
color: #000000;
}
.user-dropdown-content a {
display: flex;
padding: 8px 15px;
align-items: center;
color: #000000;
text-decoration: none;
font-size: 16px;
transition: all 0.2s;
}
.user-dropdown-content a i {
font-size: 16px;
margin-right: 8px;
}
.user-dropdown-content a:hover {
text-decoration: underline;
color: #000000;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
.header-right i {
color: #ffffff;
font-size:40px;
}
.header-right span {
font-size: 15px;
color: #ffffff;
}
.main-content {
margin-left: 240px;
padding: 80px 20px 20px 20px;
flex-grow: 1;
}
/* User Management Layout */
.user-management {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.form-container {
flex: 1;
min-width: 300px;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.table-container {
flex: 2;
min-width: 300px;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
h2 {
margin-top: 0;
color: #2f4050;
font-size: 1.5em;
padding-bottom: 10px;
border-bottom: 1px solid #eee;
}
.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;
}
button {
padding: 10px 15px;
border: none;
background-color: #77693A;
color: white;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #5a4d1b;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
padding: 12px 15px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f8f9fa;
font-weight: 600;
}
tr:hover {
background-color: #f5f5f5;
}
.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;
}
/* Responsive Adjustments */
@media (max-width: 768px) {
.user-management {
flex-direction: column;
}
.form-container,
.table-container {
width: 100%;
}
}
</style>
</head>
<body>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">RJL DeskTrack</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="http://localhost/helpdesk/?page_id=57"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<li><a href="http://localhost/helpdesk/?page_id=62" class="active"><i class="fas fa-users-cog"></i> User Management</a></li>
<li><a href="departments.php"><i class="fas fa-building"></i> Departments</a></li>
<li><a href="tickets.php"><i class="fas fa-ticket-alt"></i> Tickets</a></li>
<li><a href="messages.php"><i class="fas fa-envelope"></i> Messages</a></li>
<li><a href="reports.php"><i class="fas fa-chart-bar"></i> Reports</a></li>
</ul>
</div>
</aside>
<main class="main-content">
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?= htmlspecialchars($_SESSION['username']) ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle" style="color:#000000;"></i>
<span style="color:#000000;"><?= htmlspecialchars($_SESSION['username']) ?></span>
</div>
<a href="#" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt" style="font-size: 16px; color:#000000;"></i>Logout
</a>
</div>
</div>
</div>
</header>
<h1>User Management</h1>
<div class="user-management">
<!-- Add User Form -->
<div class="form-container">
<h2>Add New User</h2>
<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>
</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>
</div>
<div class="form-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" required>
</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">Admin</option>
<option value="agent">Agent</option>
<option value="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'] ?>"><?= htmlspecialchars($dept['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<button type="submit">Add User</button>
</form>
</div>
<!-- Users Table -->
<div class="table-container">
<h2>All Users</h2>
<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>
</main>
</div>
<script>
// Update date and time
function updateDateTime() {
const now = new Date();
const options = {
weekday: 'short',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
};
const dateTimeElement = document.getElementById("current-date-time");
if (dateTimeElement) {
dateTimeElement.textContent = now.toLocaleDateString('en-US', options);
}
}
// Initialize immediately and set interval
updateDateTime();
setInterval(updateDateTime, 1000);
// Toggle dropdown
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
if (dropdown && dropdownContent) {
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.style.display = dropdownContent.style.display === 'block' ? 'none' : 'block';
});
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
}
});
// Name validation
document.querySelectorAll('input[name="first_name"], input[name="last_name"]').forEach(input => {
input.addEventListener('input', function() {
this.value = this.value.replace(/[^A-Za-z. ]/g, '');
});
input.addEventListener('blur', function() {