I'll help you move the logout functionality to a dropdown menu that appears when clicking the user icon or username in the header. Here's the modified code:
<!DOCTYPE html>
<html lang="<?php language_attributes(); ?>">
<head>
<!-- Previous head content remains the same -->
<style>
/* Add these new styles for the dropdown */
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-content a {
color: #333;
padding: 12px 16px;
text-decoration: none;
display: block;
font-size: 14px;
}
.user-dropdown-content a:hover {
background-color: #77693A;
color: white;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
</style>
</head>
<body <?php body_class(); ?>>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">ArKi Inventory</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="http://localhost/inventory/index.php/admin-page/"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<?php
// Use the $is_admin flag derived from $_SESSION['username']
if ($is_admin) :
?>
<li><a href="http://localhost/inventory/index.php/usersmanagement/"><i class="fas fa-users-cog"></i> User Management</a></li>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<li><a href="http://localhost/inventory/index.php/view-order/"><i class="fas fa-eye"></i> View Orders</a></li>
<li><a href="http://localhost/inventory/index.php/sales/"><i class="fas fa-chart-line"></i> Sales & Report</a></li>
<li><a href="http://localhost/inventory/index.php/report/"><i class="fas fa-file-alt"></i> Inventory Report</a></li>
<li><a href="http://localhost/inventory/index.php/history/"><i class="fas fa-history"></i> Inventory History</a></li>
<?php else : ?>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<?php endif; ?>
<!-- Removed logout from sidebar -->
</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">
<!-- Updated user info with dropdown -->
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?php echo esc_html($current_username); ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<a href="http://localhost/inventory/index.php/sign-in2/" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt"></i> Logout
</a>
</div>
</div>
</div>
</header>
<!-- Rest of the content remains the same -->
</main>
</div>
<!-- Add this JavaScript to handle the dropdown -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
// Toggle dropdown on click
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
if (dropdownContent.style.display === 'block') {
dropdownContent.style.display = 'none';
} else {
dropdownContent.style.display = 'block';
}
});
// Close dropdown when clicking outside
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
});
</script>
<!-- Rest of your scripts remain the same -->
</body>
</html>
<!DOCTYPE html>
<html lang="<?php language_attributes(); ?>">
<head>
<!-- Previous head content remains the same -->
<style>
/* Add these new styles for the dropdown */
.user-dropdown {
position: relative;
display: inline-block;
cursor: pointer;
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
border-radius: 4px;
}
.user-dropdown-content a {
color: #333;
padding: 12px 16px;
text-decoration: none;
display: block;
font-size: 14px;
}
.user-dropdown-content a:hover {
background-color: #77693A;
color: white;
}
.user-dropdown:hover .user-dropdown-content {
display: block;
}
</style>
</head>
<body <?php body_class(); ?>>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">ArKi Inventory</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="http://localhost/inventory/index.php/admin-page/"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<?php
// Use the $is_admin flag derived from $_SESSION['username']
if ($is_admin) :
?>
<li><a href="http://localhost/inventory/index.php/usersmanagement/"><i class="fas fa-users-cog"></i> User Management</a></li>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<li><a href="http://localhost/inventory/index.php/view-order/"><i class="fas fa-eye"></i> View Orders</a></li>
<li><a href="http://localhost/inventory/index.php/sales/"><i class="fas fa-chart-line"></i> Sales & Report</a></li>
<li><a href="http://localhost/inventory/index.php/report/"><i class="fas fa-file-alt"></i> Inventory Report</a></li>
<li><a href="http://localhost/inventory/index.php/history/"><i class="fas fa-history"></i> Inventory History</a></li>
<?php else : ?>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<?php endif; ?>
<!-- Removed logout from sidebar -->
</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">
<!-- Updated user info with dropdown -->
<div class="user-dropdown">
<div class="user-info">
<span id="current-username-header">
<?php echo esc_html($current_username); ?>
<i class="fas fa-user-circle"></i>
</span>
</div>
<div class="user-dropdown-content">
<a href="http://localhost/inventory/index.php/sign-in2/" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt"></i> Logout
</a>
</div>
</div>
</div>
</header>
<!-- Rest of the content remains the same -->
</main>
</div>
<!-- Add this JavaScript to handle the dropdown -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownContent = document.querySelector('.user-dropdown-content');
// Toggle dropdown on click
dropdown.addEventListener('click', function(e) {
e.stopPropagation();
if (dropdownContent.style.display === 'block') {
dropdownContent.style.display = 'none';
} else {
dropdownContent.style.display = 'block';
}
});
// Close dropdown when clicking outside
document.addEventListener('click', function() {
dropdownContent.style.display = 'none';
});
});
</script>
<!-- Rest of your scripts remain the same -->
</body>
</html>
Key changes made:
The dropdown will now appear when clicking the user icon or username in the header, and it will contain the logout option. The dropdown will close when clicking anywhere else on the page.
All other functionality remains the same, including the logout confirmation dialog. The styling matches your existing color scheme._
Here's the improved version with a properly styled user dropdown that includes the user icon, username, and logout option:
<!DOCTYPE html>
<html lang="<?php language_attributes(); ?>">
<head>
<!-- Previous head content remains the same -->
<style>
/* Add these new styles for the dropdown */
.user-dropdown {
position: relative;
display: inline-block;
}
.user-dropdown-trigger {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
padding: 5px 10px;
border-radius: 4px;
transition: background-color 0.2s;
}
.user-dropdown-trigger:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: white;
min-width: 200px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
border-radius: 6px;
z-index: 1000;
margin-top: 5px;
overflow: hidden;
}
.user-dropdown-header {
padding: 12px 16px;
background-color: #f8f9fa;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 10px;
}
.user-dropdown-header i {
font-size: 20px;
color: #77693A;
}
.user-dropdown-header span {
font-weight: 500;
color: #333;
}
.user-dropdown-item {
padding: 10px 16px;
color: #333;
text-decoration: none;
display: flex;
align-items: center;
gap: 10px;
transition: background-color 0.2s;
}
.user-dropdown-item i {
width: 20px;
text-align: center;
color: #6c757d;
}
.user-dropdown-item:hover {
background-color: #f1f3f5;
color: #77693A;
}
.user-dropdown-item:hover i {
color: #77693A;
}
.show-dropdown {
display: block;
}
</style>
</head>
<body <?php body_class(); ?>>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">ArKi Inventory</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="http://localhost/inventory/index.php/admin-page/"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<?php
// Use the $is_admin flag derived from $_SESSION['username']
if ($is_admin) :
?>
<li><a href="http://localhost/inventory/index.php/usersmanagement/"><i class="fas fa-users-cog"></i> User Management</a></li>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<li><a href="http://localhost/inventory/index.php/view-order/"><i class="fas fa-eye"></i> View Orders</a></li>
<li><a href="http://localhost/inventory/index.php/sales/"><i class="fas fa-chart-line"></i> Sales & Report</a></li>
<li><a href="http://localhost/inventory/index.php/report/"><i class="fas fa-file-alt"></i> Inventory Report</a></li>
<li><a href="http://localhost/inventory/index.php/history/"><i class="fas fa-history"></i> Inventory History</a></li>
<?php else : ?>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<?php endif; ?>
<!-- Removed logout from sidebar -->
</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">
<!-- Updated user info with dropdown -->
<div class="user-dropdown">
<div class="user-dropdown-trigger">
<i class="fas fa-user-circle" style="font-size: 24px;"></i>
<span><?php echo esc_html($current_username); ?></span>
<i class="fas fa-chevron-down" style="font-size: 12px;"></i>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<a href="http://localhost/inventory/index.php/sign-in2/" class="user-dropdown-item" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt"></i>
<span>Logout</span>
</a>
</div>
</div>
</div>
</header>
<!-- Rest of the content remains the same -->
</main>
</div>
<!-- Add this JavaScript to handle the dropdown -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownTrigger = document.querySelector('.user-dropdown-trigger');
const dropdownContent = document.querySelector('.user-dropdown-content');
// Toggle dropdown on click
dropdownTrigger.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.classList.toggle('show-dropdown');
});
// Close dropdown when clicking outside
document.addEventListener('click', function() {
dropdownContent.classList.remove('show-dropdown');
});
});
</script>
<!-- Rest of your scripts remain the same -->
</body>
</html>
<!DOCTYPE html>
<html lang="<?php language_attributes(); ?>">
<head>
<!-- Previous head content remains the same -->
<style>
/* Add these new styles for the dropdown */
.user-dropdown {
position: relative;
display: inline-block;
}
.user-dropdown-trigger {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
padding: 5px 10px;
border-radius: 4px;
transition: background-color 0.2s;
}
.user-dropdown-trigger:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: white;
min-width: 200px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
border-radius: 6px;
z-index: 1000;
margin-top: 5px;
overflow: hidden;
}
.user-dropdown-header {
padding: 12px 16px;
background-color: #f8f9fa;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 10px;
}
.user-dropdown-header i {
font-size: 20px;
color: #77693A;
}
.user-dropdown-header span {
font-weight: 500;
color: #333;
}
.user-dropdown-item {
padding: 10px 16px;
color: #333;
text-decoration: none;
display: flex;
align-items: center;
gap: 10px;
transition: background-color 0.2s;
}
.user-dropdown-item i {
width: 20px;
text-align: center;
color: #6c757d;
}
.user-dropdown-item:hover {
background-color: #f1f3f5;
color: #77693A;
}
.user-dropdown-item:hover i {
color: #77693A;
}
.show-dropdown {
display: block;
}
</style>
</head>
<body <?php body_class(); ?>>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">ArKi Inventory</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="http://localhost/inventory/index.php/admin-page/"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<?php
// Use the $is_admin flag derived from $_SESSION['username']
if ($is_admin) :
?>
<li><a href="http://localhost/inventory/index.php/usersmanagement/"><i class="fas fa-users-cog"></i> User Management</a></li>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<li><a href="http://localhost/inventory/index.php/view-order/"><i class="fas fa-eye"></i> View Orders</a></li>
<li><a href="http://localhost/inventory/index.php/sales/"><i class="fas fa-chart-line"></i> Sales & Report</a></li>
<li><a href="http://localhost/inventory/index.php/report/"><i class="fas fa-file-alt"></i> Inventory Report</a></li>
<li><a href="http://localhost/inventory/index.php/history/"><i class="fas fa-history"></i> Inventory History</a></li>
<?php else : ?>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<?php endif; ?>
<!-- Removed logout from sidebar -->
</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">
<!-- Updated user info with dropdown -->
<div class="user-dropdown">
<div class="user-dropdown-trigger">
<i class="fas fa-user-circle" style="font-size: 24px;"></i>
<span><?php echo esc_html($current_username); ?></span>
<i class="fas fa-chevron-down" style="font-size: 12px;"></i>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<a href="http://localhost/inventory/index.php/sign-in2/" class="user-dropdown-item" onclick="return confirm('Are you sure you want to log out?');">
<i class="fas fa-sign-out-alt"></i>
<span>Logout</span>
</a>
</div>
</div>
</div>
</header>
<!-- Rest of the content remains the same -->
</main>
</div>
<!-- Add this JavaScript to handle the dropdown -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownTrigger = document.querySelector('.user-dropdown-trigger');
const dropdownContent = document.querySelector('.user-dropdown-content');
// Toggle dropdown on click
dropdownTrigger.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.classList.toggle('show-dropdown');
});
// Close dropdown when clicking outside
document.addEventListener('click', function() {
dropdownContent.classList.remove('show-dropdown');
});
});
</script>
<!-- Rest of your scripts remain the same -->
</body>
</html>
Key improvements:
Better Dropdown Structure:
Improved Styling:
Enhanced User Experience:
Visual Hierarchy:
The dropdown now looks more professional and provides better visual feedback when interacting with it. The styling matches your existing design language while improving the user experience._
Here's the updated version with a cleaner logout option that only shows an underline on hover:
<!DOCTYPE html>
<html lang="<?php language_attributes(); ?>">
<head>
<!-- Previous head content remains the same -->
<style>
/* Add these new styles for the dropdown */
.user-dropdown {
position: relative;
display: inline-block;
}
.user-dropdown-trigger {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
padding: 5px 10px;
border-radius: 4px;
transition: background-color 0.2s;
}
.user-dropdown-trigger:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: white;
min-width: 200px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
border-radius: 6px;
z-index: 1000;
margin-top: 5px;
overflow: hidden;
}
.user-dropdown-header {
padding: 12px 16px;
background-color: #f8f9fa;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 10px;
}
.user-dropdown-header i {
font-size: 20px;
color: #77693A;
}
.user-dropdown-header span {
font-weight: 500;
color: #333;
}
.user-dropdown-item {
padding: 10px 16px;
color: #333;
text-decoration: none;
display: block;
transition: all 0.2s;
}
.user-dropdown-item:hover {
text-decoration: underline;
color: #77693A;
}
.show-dropdown {
display: block;
}
</style>
</head>
<body <?php body_class(); ?>>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">ArKi Inventory</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="http://localhost/inventory/index.php/admin-page/"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<?php
// Use the $is_admin flag derived from $_SESSION['username']
if ($is_admin) :
?>
<li><a href="http://localhost/inventory/index.php/usersmanagement/"><i class="fas fa-users-cog"></i> User Management</a></li>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<li><a href="http://localhost/inventory/index.php/view-order/"><i class="fas fa-eye"></i> View Orders</a></li>
<li><a href="http://localhost/inventory/index.php/sales/"><i class="fas fa-chart-line"></i> Sales & Report</a></li>
<li><a href="http://localhost/inventory/index.php/report/"><i class="fas fa-file-alt"></i> Inventory Report</a></li>
<li><a href="http://localhost/inventory/index.php/history/"><i class="fas fa-history"></i> Inventory History</a></li>
<?php else : ?>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<?php endif; ?>
<!-- Removed logout from sidebar -->
</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">
<!-- Updated user info with dropdown -->
<div class="user-dropdown">
<div class="user-dropdown-trigger">
<i class="fas fa-user-circle" style="font-size: 24px;"></i>
<span><?php echo esc_html($current_username); ?></span>
<i class="fas fa-chevron-down" style="font-size: 12px;"></i>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<a href="http://localhost/inventory/index.php/sign-in2/" class="user-dropdown-item" onclick="return confirm('Are you sure you want to log out?');">
Logout
</a>
</div>
</div>
</div>
</header>
<!-- Rest of the content remains the same -->
</main>
</div>
<!-- Add this JavaScript to handle the dropdown -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownTrigger = document.querySelector('.user-dropdown-trigger');
const dropdownContent = document.querySelector('.user-dropdown-content');
// Toggle dropdown on click
dropdownTrigger.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.classList.toggle('show-dropdown');
});
// Close dropdown when clicking outside
document.addEventListener('click', function() {
dropdownContent.classList.remove('show-dropdown');
});
});
</script>
<!-- Rest of your scripts remain the same -->
</body>
</html>
<!DOCTYPE html>
<html lang="<?php language_attributes(); ?>">
<head>
<!-- Previous head content remains the same -->
<style>
/* Add these new styles for the dropdown */
.user-dropdown {
position: relative;
display: inline-block;
}
.user-dropdown-trigger {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
padding: 5px 10px;
border-radius: 4px;
transition: background-color 0.2s;
}
.user-dropdown-trigger:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: white;
min-width: 200px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
border-radius: 6px;
z-index: 1000;
margin-top: 5px;
overflow: hidden;
}
.user-dropdown-header {
padding: 12px 16px;
background-color: #f8f9fa;
border-bottom: 1px solid #e9ecef;
display: flex;
align-items: center;
gap: 10px;
}
.user-dropdown-header i {
font-size: 20px;
color: #77693A;
}
.user-dropdown-header span {
font-weight: 500;
color: #333;
}
.user-dropdown-item {
padding: 10px 16px;
color: #333;
text-decoration: none;
display: block;
transition: all 0.2s;
}
.user-dropdown-item:hover {
text-decoration: underline;
color: #77693A;
}
.show-dropdown {
display: block;
}
</style>
</head>
<body <?php body_class(); ?>>
<div class="dashboard-container">
<aside class="sidebar">
<div class="sidebar-header">
<div class="inventory-name">ArKi Inventory</div>
</div>
<div class="sidebar-menu">
<ul>
<li><a href="http://localhost/inventory/index.php/admin-page/"><i class="fas fa-tachometer-alt"></i> Dashboard</a></li>
<?php
// Use the $is_admin flag derived from $_SESSION['username']
if ($is_admin) :
?>
<li><a href="http://localhost/inventory/index.php/usersmanagement/"><i class="fas fa-users-cog"></i> User Management</a></li>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<li><a href="http://localhost/inventory/index.php/view-order/"><i class="fas fa-eye"></i> View Orders</a></li>
<li><a href="http://localhost/inventory/index.php/sales/"><i class="fas fa-chart-line"></i> Sales & Report</a></li>
<li><a href="http://localhost/inventory/index.php/report/"><i class="fas fa-file-alt"></i> Inventory Report</a></li>
<li><a href="http://localhost/inventory/index.php/history/"><i class="fas fa-history"></i> Inventory History</a></li>
<?php else : ?>
<li><a href="http://localhost/inventory/index.php/category-page/"><i class="fas fa-list"></i> Categories</a></li>
<li><a href="http://localhost/inventory/index.php/products/"><i class="fas fa-boxes"></i> Products</a></li>
<li><a href="http://localhost/inventory/index.php/order/"><i class="fas fa-shopping-cart"></i> Orders</a></li>
<?php endif; ?>
<!-- Removed logout from sidebar -->
</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">
<!-- Updated user info with dropdown -->
<div class="user-dropdown">
<div class="user-dropdown-trigger">
<i class="fas fa-user-circle" style="font-size: 24px;"></i>
<span><?php echo esc_html($current_username); ?></span>
<i class="fas fa-chevron-down" style="font-size: 12px;"></i>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<a href="http://localhost/inventory/index.php/sign-in2/" class="user-dropdown-item" onclick="return confirm('Are you sure you want to log out?');">
Logout
</a>
</div>
</div>
</div>
</header>
<!-- Rest of the content remains the same -->
</main>
</div>
<!-- Add this JavaScript to handle the dropdown -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const dropdown = document.querySelector('.user-dropdown');
const dropdownTrigger = document.querySelector('.user-dropdown-trigger');
const dropdownContent = document.querySelector('.user-dropdown-content');
// Toggle dropdown on click
dropdownTrigger.addEventListener('click', function(e) {
e.stopPropagation();
dropdownContent.classList.toggle('show-dropdown');
});
// Close dropdown when clicking outside
document.addEventListener('click', function() {
dropdownContent.classList.remove('show-dropdown');
});
});
</script>
<!-- Rest of your scripts remain the same -->
</body>
</html>
Key changes made:
The logout option now appears as simple text that underlines when hovered, creating a cleaner and more minimalist look while maintaining all functionality._
Here's the optimized version with reduced space between the user info and logout option:
<!DOCTYPE html>
<html lang="<?php language_attributes(); ?>">
<head>
<!-- Previous head content remains the same -->
<style>
/* Updated dropdown styles */
.user-dropdown {
position: relative;
display: inline-block;
}
.user-dropdown-trigger {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
padding: 5px 10px;
border-radius: 4px;
transition: background-color 0.2s;
}
.user-dropdown-trigger:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 160px;
box-shadow: 0px 4px 8px rgba(0,0,0,0.1);
z-index: 1000;
border-radius: 4px;
padding: 8px 0;
}
.user-dropdown-header {
padding: 8px 12px;
display: flex;
align-items: center;
gap: 8px;
border-bottom: 1px solid rgba(0,0,0,0.1);
}
.user-dropdown-header i {
font-size: 18px;
color: #000000;
}
.user-dropdown-header span {
font-weight: 500;
color: #000000;
font-size: 14px;
}
.user-dropdown-item {
display: block;
padding: 8px 12px;
color: #000000;
text-decoration: none;
font-size: 14px;
transition: all 0.2s;
}
.user-dropdown-item:hover {
text-decoration: underline;
background-color: rgba(0,0,0,0.05);
}
.show-dropdown {
display: block;
}
</style>
</head>
<body <?php body_class(); ?>>
<!-- Rest of your HTML remains the same until the header -->
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<!-- Updated user dropdown -->
<div class="user-dropdown">
<div class="user-dropdown-trigger">
<i class="fas fa-user-circle" style="font-size: 24px;"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<a href="http://localhost/inventory/index.php/sign-in2/" class="user-dropdown-item" onclick="return confirm('Are you sure you want to log out?');">
Logout
</a>
</div>
</div>
</div>
</header>
<!-- Rest of your HTML remains the same -->
</body>
</html>
<!DOCTYPE html>
<html lang="<?php language_attributes(); ?>">
<head>
<!-- Previous head content remains the same -->
<style>
/* Updated dropdown styles */
.user-dropdown {
position: relative;
display: inline-block;
}
.user-dropdown-trigger {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
padding: 5px 10px;
border-radius: 4px;
transition: background-color 0.2s;
}
.user-dropdown-trigger:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 160px;
box-shadow: 0px 4px 8px rgba(0,0,0,0.1);
z-index: 1000;
border-radius: 4px;
padding: 8px 0;
}
.user-dropdown-header {
padding: 8px 12px;
display: flex;
align-items: center;
gap: 8px;
border-bottom: 1px solid rgba(0,0,0,0.1);
}
.user-dropdown-header i {
font-size: 18px;
color: #000000;
}
.user-dropdown-header span {
font-weight: 500;
color: #000000;
font-size: 14px;
}
.user-dropdown-item {
display: block;
padding: 8px 12px;
color: #000000;
text-decoration: none;
font-size: 14px;
transition: all 0.2s;
}
.user-dropdown-item:hover {
text-decoration: underline;
background-color: rgba(0,0,0,0.05);
}
.show-dropdown {
display: block;
}
</style>
</head>
<body <?php body_class(); ?>>
<!-- Rest of your HTML remains the same until the header -->
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<!-- Updated user dropdown -->
<div class="user-dropdown">
<div class="user-dropdown-trigger">
<i class="fas fa-user-circle" style="font-size: 24px;"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<a href="http://localhost/inventory/index.php/sign-in2/" class="user-dropdown-item" onclick="return confirm('Are you sure you want to log out?');">
Logout
</a>
</div>
</div>
</div>
</header>
<!-- Rest of your HTML remains the same -->
</body>
</html>
Key improvements:
The dropdown now has a much more compact appearance while still being readable and functional. The logout option appears immediately below the user info without excessive spacing.
Here's the corrected version with the missing .user-dropdown-content a CSS rule added, while keeping all the other improvements:
<!DOCTYPE html>
<html lang="<?php language_attributes(); ?>">
<head>
<!-- Previous head content remains the same -->
<style>
/* Updated dropdown styles */
.user-dropdown {
position: relative;
display: inline-block;
}
.user-dropdown-trigger {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
padding: 5px 10px;
border-radius: 4px;
transition: background-color 0.2s;
}
.user-dropdown-trigger:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 160px;
box-shadow: 0px 4px 8px rgba(0,0,0,0.1);
z-index: 1000;
border-radius: 4px;
padding: 8px 0;
}
.user-dropdown-content a {
display: block;
padding: 8px 12px;
color: #000000;
text-decoration: none;
font-size: 14px;
transition: all 0.2s;
}
.user-dropdown-header {
padding: 8px 12px;
display: flex;
align-items: center;
gap: 8px;
border-bottom: 1px solid rgba(0,0,0,0.1);
}
.user-dropdown-header i {
font-size: 18px;
color: #000000;
}
.user-dropdown-header span {
font-weight: 500;
color: #000000;
font-size: 14px;
}
.user-dropdown-item {
display: block;
padding: 8px 12px;
color: #000000;
text-decoration: none;
font-size: 14px;
transition: all 0.2s;
}
.user-dropdown-content a:hover,
.user-dropdown-item:hover {
text-decoration: underline;
background-color: rgba(0,0,0,0.05);
}
.show-dropdown {
display: block;
}
</style>
</head>
<body <?php body_class(); ?>>
<!-- Rest of your HTML remains the same until the header -->
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<!-- Updated user dropdown -->
<div class="user-dropdown">
<div class="user-dropdown-trigger">
<i class="fas fa-user-circle" style="font-size: 24px;"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<a href="http://localhost/inventory/index.php/sign-in2/" class="user-dropdown-item" onclick="return confirm('Are you sure you want to log out?');">
Logout
</a>
</div>
</div>
</div>
</header>
<!-- Rest of your HTML remains the same -->
</body>
</html>
<!DOCTYPE html>
<html lang="<?php language_attributes(); ?>">
<head>
<!-- Previous head content remains the same -->
<style>
/* Updated dropdown styles */
.user-dropdown {
position: relative;
display: inline-block;
}
.user-dropdown-trigger {
display: flex;
align-items: center;
gap: 8px;
cursor: pointer;
padding: 5px 10px;
border-radius: 4px;
transition: background-color 0.2s;
}
.user-dropdown-trigger:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.user-dropdown-content {
display: none;
position: absolute;
right: 0;
background-color: #D1B48C;
min-width: 160px;
box-shadow: 0px 4px 8px rgba(0,0,0,0.1);
z-index: 1000;
border-radius: 4px;
padding: 8px 0;
}
.user-dropdown-content a {
display: block;
padding: 8px 12px;
color: #000000;
text-decoration: none;
font-size: 14px;
transition: all 0.2s;
}
.user-dropdown-header {
padding: 8px 12px;
display: flex;
align-items: center;
gap: 8px;
border-bottom: 1px solid rgba(0,0,0,0.1);
}
.user-dropdown-header i {
font-size: 18px;
color: #000000;
}
.user-dropdown-header span {
font-weight: 500;
color: #000000;
font-size: 14px;
}
.user-dropdown-item {
display: block;
padding: 8px 12px;
color: #000000;
text-decoration: none;
font-size: 14px;
transition: all 0.2s;
}
.user-dropdown-content a:hover,
.user-dropdown-item:hover {
text-decoration: underline;
background-color: rgba(0,0,0,0.05);
}
.show-dropdown {
display: block;
}
</style>
</head>
<body <?php body_class(); ?>>
<!-- Rest of your HTML remains the same until the header -->
<header class="header">
<div class="header-left">
<span class="date-time" id="current-date-time"></span>
</div>
<div class="header-right">
<!-- Updated user dropdown -->
<div class="user-dropdown">
<div class="user-dropdown-trigger">
<i class="fas fa-user-circle" style="font-size: 24px;"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<div class="user-dropdown-content">
<div class="user-dropdown-header">
<i class="fas fa-user-circle"></i>
<span><?php echo esc_html($current_username); ?></span>
</div>
<a href="http://localhost/inventory/index.php/sign-in2/" class="user-dropdown-item" onclick="return confirm('Are you sure you want to log out?');">
Logout
</a>
</div>
</div>
</div>
</header>
<!-- Rest of your HTML remains the same -->
</body>
</html>
Key changes made:
.user-dropdown-content a CSS rule with proper styling.user-dropdown-content a and .user-dropdown-item to maintain consistencya tag directly or the user-dropdown-item classThe dropdown will now look consistent and properly styled, with the logout link appearing immediately below the user info without excessive spacing.
The error occurs because you're trying to use $category_to_delete before it's defined in your delete action handler. Here's the corrected version of your delete category code section:
// --- Handle Delete Category Action ---
if (isset($_GET['action']) && $_GET['action'] === 'delete_category' && isset($_GET['id']) && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'delete_category_' . absint($_GET['id']))) {
$category_id_to_delete = absint($_GET['id']);
if ($category_id_to_delete) {
// First get the category details before deleting
$category_to_delete = $wpdb->get_row(
$wpdb->prepare("SELECT * FROM $table_name WHERE id = %d", $category_id_to_delete),
ARRAY_A
);
if ($category_to_delete) {
// Log the action before deleting
log_category_action('delete', $category_to_delete['name'], "Category '{$category_to_delete['name']}' was deleted.");
$deleted = $wpdb->delete(
$table_name,
['id' => $category_id_to_delete],
['%d']
);
if ($deleted) {
$message = 'Category deleted successfully!';
$message_type = 'success';
wp_redirect(remove_query_arg(array('action', 'id', '_wpnonce')));
exit;
} else {
$message = 'Error deleting category.';
$message_type = 'error';
}
} else {
$message = 'Category not found.';
$message_type = 'error';
}
}
}
// --- Handle Delete Category Action ---
if (isset($_GET['action']) && $_GET['action'] === 'delete_category' && isset($_GET['id']) && isset($_GET['_wpnonce']) && wp_verify_nonce($_GET['_wpnonce'], 'delete_category_' . absint($_GET['id']))) {
$category_id_to_delete = absint($_GET['id']);
if ($category_id_to_delete) {
// First get the category details before deleting
$category_to_delete = $wpdb->get_row(
$wpdb->prepare("SELECT * FROM $table_name WHERE id = %d", $category_id_to_delete),
ARRAY_A
);
if ($category_to_delete) {
// Log the action before deleting
log_category_action('delete', $category_to_delete['name'], "Category '{$category_to_delete['name']}' was deleted.");
$deleted = $wpdb->delete(
$table_name,
['id' => $category_id_to_delete],
['%d']
);
if ($deleted) {
$message = 'Category deleted successfully!';
$message_type = 'success';
wp_redirect(remove_query_arg(array('action', 'id', '_wpnonce')));
exit;
} else {
$message = 'Error deleting category.';
$message_type = 'error';
}
} else {
$message = 'Category not found.';
$message_type = 'error';
}
}
}
Key changes made:
log_inventory_action was called after log_category_action)Also, you have a duplicate logging call in your code. You're calling both:
log_category_action('delete', $category_to_delete['name'], "Category '{$category_to_delete['name']}' was deleted.");
log_category_action('delete', $category_to_delete['name'], "Category '{$category_to_delete['name']}' was deleted.");
and
log_inventory_action('delete', 'category', $category_name, "Category deleted: {$category_name} ");
log_inventory_action('delete', 'category', $category_name, "Category deleted: {$category_name} ");
You should remove one of these to avoid duplicate logging. Since you have a dedicated log_category_action function, I recommend keeping that one and removing the log_inventory_action call.
The error occurred because you were trying to access $category_to_delete['name'] before the variable was defined. The corrected version first fetches the category data, then uses it for logging before performing the deletion.*_
The search functionality isn't working because you haven't implemented the actual search logic in your PHP code. Here's the fixed version with a working search feature:
<?php
session_start();
global $wpdb;
// Initialize variables, Table Names, Fetch Inventory Data
$message = '';
$message_type = '';
$inventory_history_data = [];
$fetch_error = '';
$inventory_history_table_name = 'inventory_history';
$search_term = isset($_GET['product_search']) ? sanitize_text_field($_GET['product_search']) : '';
// Check if the inventory history table exists
$history_table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $inventory_history_table_name)) == $inventory_history_table_name;
if ($history_table_exists) {
// Base SQL query
$sql = "
SELECT ih.*, u.username AS user_username
FROM $inventory_history_table_name ih
LEFT JOIN users u ON ih.username = u.username
";
// Add search condition if search term exists
if (!empty($search_term)) {
$sql .= $wpdb->prepare("
WHERE ih.item_name LIKE %s
OR ih.description LIKE %s
OR ih.action_type LIKE %s
OR ih.item_type LIKE %s
OR u.username LIKE %s
",
'%' . $wpdb->esc_like($search_term) . '%',
'%' . $wpdb->esc_like($search_term) . '%',
'%' . $wpdb->esc_like($search_term) . '%',
'%' . $wpdb->esc_like($search_term) . '%',
'%' . $wpdb->esc_like($search_term) . '%');
}
// Add order by
$sql .= " ORDER BY timestamp DESC";
$inventory_history_results = $wpdb->get_results($sql, ARRAY_A);
if ($inventory_history_results === null) {
$fetch_error = "Error fetching inventory history data: " . $wpdb->last_error;
} else {
$inventory_history_data = $inventory_history_results;
}
} else {
$fetch_error = "Error: Inventory history table '{$inventory_history_table_name}' not found.";
}
// Rest of your existing code for delete and clear all...
?>
<!-- Your HTML remains the same until the search form -->
<div class="inventory-container">
<form method="GET" class="search-container">
<div class="search-wrapper">
<input type="text" id="product-search" class="product-search-bar" name="product_search"
placeholder="Search history..." value="<?php echo esc_attr($search_term); ?>">
<?php if (!empty($search_term)): ?>
<button type="button" class="clear-search-button"
onclick="this.form.product_search.value = ''; this.form.submit();">
×
</button>
<?php endif; ?>
<button type="submit" class="search-submit-button">
<i class="fas fa-search"></i>
</button>
</div>
</form>
<!-- Rest of your table code... -->
</div>
<!-- Add this JavaScript for better search UX -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const searchInput = document.getElementById('product-search');
const clearButton = document.querySelector('.clear-search-button');
if (searchInput && clearButton) {
// Show/hide clear button based on input
searchInput.addEventListener('input', function() {
clearButton.style.display = this.value ? 'block' : 'none';
});
// Submit form when pressing Enter
searchInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
this.form.submit();
}
});
}
});
</script>
<?php
session_start();
global $wpdb;
// Initialize variables, Table Names, Fetch Inventory Data
$message = '';
$message_type = '';
$inventory_history_data = [];
$fetch_error = '';
$inventory_history_table_name = 'inventory_history';
$search_term = isset($_GET['product_search']) ? sanitize_text_field($_GET['product_search']) : '';
// Check if the inventory history table exists
$history_table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $inventory_history_table_name)) == $inventory_history_table_name;
if ($history_table_exists) {
// Base SQL query
$sql = "
SELECT ih.*, u.username AS user_username
FROM $inventory_history_table_name ih
LEFT JOIN users u ON ih.username = u.username
";
// Add search condition if search term exists
if (!empty($search_term)) {
$sql .= $wpdb->prepare("
WHERE ih.item_name LIKE %s
OR ih.description LIKE %s
OR ih.action_type LIKE %s
OR ih.item_type LIKE %s
OR u.username LIKE %s
",
'%' . $wpdb->esc_like($search_term) . '%',
'%' . $wpdb->esc_like($search_term) . '%',
'%' . $wpdb->esc_like($search_term) . '%',
'%' . $wpdb->esc_like($search_term) . '%',
'%' . $wpdb->esc_like($search_term) . '%');
}
// Add order by
$sql .= " ORDER BY timestamp DESC";
$inventory_history_results = $wpdb->get_results($sql, ARRAY_A);
if ($inventory_history_results === null) {
$fetch_error = "Error fetching inventory history data: " . $wpdb->last_error;
} else {
$inventory_history_data = $inventory_history_results;
}
} else {
$fetch_error = "Error: Inventory history table '{$inventory_history_table_name}' not found.";
}
// Rest of your existing code for delete and clear all...
?>
<!-- Your HTML remains the same until the search form -->
<div class="inventory-container">
<form method="GET" class="search-container">
<div class="search-wrapper">
<input type="text" id="product-search" class="product-search-bar" name="product_search"
placeholder="Search history..." value="<?php echo esc_attr($search_term); ?>">
<?php if (!empty($search_term)): ?>
<button type="button" class="clear-search-button"
onclick="this.form.product_search.value = ''; this.form.submit();">
×
</button>
<?php endif; ?>
<button type="submit" class="search-submit-button">
<i class="fas fa-search"></i>
</button>
</div>
</form>
<!-- Rest of your table code... -->
</div>
<!-- Add this JavaScript for better search UX -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const searchInput = document.getElementById('product-search');
const clearButton = document.querySelector('.clear-search-button');
if (searchInput && clearButton) {
// Show/hide clear button based on input
searchInput.addEventListener('input', function() {
clearButton.style.display = this.value ? 'block' : 'none';
});
// Submit form when pressing Enter
searchInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
this.form.submit();
}
});
}
});
</script>
Key changes made:
The search will now work across:
The search is case-insensitive and uses partial matching (LIKE with wildcards). The clear button will appear when there's text in the search field and will clear the search when clicked.
Also fixed a small issue in your table display logic where you were checking empty($products) instead of empty($inventory_history_data).*