Mini Shell
<?php
session_start();
$rootPath = realpath(dirname(__FILE__) . '/..');
require_once $rootPath . '/Portal/config/config.php';
require_once $rootPath . '/Portal/include/auth_validate.php';
// Get user info from session
$userId = $_SESSION['id'];
$FullName = $_SESSION['Full_Name'];
$User_Type = $_SESSION['User_Type'];
// Initialize counter for notifications
$numx = 0;
$newComplaintsCount = 0;
$newResponsesCount = 0;
// Check complaints table for new complaints assigned to or for attention of the user
$complaintsQuery = "SELECT COUNT(*) as count FROM complaints WHERE View_Status = 'New' AND (Assigned_To = '$userId' OR Atentioned_User = '$userId')";
$complaintsResult = mysqli_query($conn, $complaintsQuery);
if ($complaintsResult) {
$complaintsRow = mysqli_fetch_assoc($complaintsResult);
$newComplaintsCount = $complaintsRow['count'];
$numx += $newComplaintsCount;
}
// Check responce_trend table for responses sent FROM this user (responses they sent to others)
// OR responses sent TO this user (where they are the recipient)
$responseQuery = "SELECT COUNT(*) as count FROM responce_trend WHERE View_Status = 'New' AND (`From` = '$userId' OR UserID = '$userId')";
$responseResult = mysqli_query($conn, $responseQuery);
if ($responseResult) {
$responseRow = mysqli_fetch_assoc($responseResult);
$newResponsesCount = $responseRow['count'];
$numx += $newResponsesCount;
}
// Fetch complete user profile
$profileQuery = "SELECT * FROM admin_accounts WHERE id = '$userId' LIMIT 1";
$profileResult = mysqli_query($conn, $profileQuery);
$userProfile = mysqli_fetch_assoc($profileResult);
// Fetch all departments from Department table
$departmentsQuery = "SELECT * FROM Department WHERE Deleted = 'No' ORDER BY Name";
$departmentsResult = mysqli_query($conn, $departmentsQuery);
$departmentsList = [];
$departmentMap = [];
if ($departmentsResult && mysqli_num_rows($departmentsResult) > 0) {
while ($dept = mysqli_fetch_assoc($departmentsResult)) {
$departmentsList[] = $dept;
$departmentMap[$dept['id']] = $dept['Name'];
}
}
// Get department name for current user
$departmentName = 'Not Assigned';
if (!empty($userProfile['UserDepartment']) && isset($departmentMap[$userProfile['UserDepartment']])) {
$departmentName = $departmentMap[$userProfile['UserDepartment']];
} elseif (!empty($userProfile['UserDepartment'])) {
$departmentName = $userProfile['UserDepartment']; // Fallback to stored value
}
// Fetch new notifications from complaints with View_Status = 'New'
// AND from responce_trend with View_Status = 'New'
$notificationsQuery = "SELECT
c.ComplaintID,
c.Heading,
c.Name,
c.Problem,
c.Date_Reported,
c.Assigned_To,
c.Atentioned_User,
c.Originated_From,
c.View_Status,
'complaint' as notification_type,
a1.Full_Name as Assigned_Full_Name,
a2.Full_Name as Attention_Full_Name,
a3.Full_Name as Originator_Full_Name,
a3.Full_Name as From_Name
FROM complaints c
LEFT JOIN admin_accounts a1 ON c.Assigned_To = a1.id
LEFT JOIN admin_accounts a2 ON c.Atentioned_User = a2.id
LEFT JOIN admin_accounts a3 ON c.Originated_From = a3.id
WHERE c.View_Status = 'New' AND (c.Assigned_To = '$userId' OR c.Atentioned_User = '$userId')
UNION ALL
SELECT
r.ComplaintID,
c.Heading,
c.Name,
r.Responce as Problem,
r.Responce_Date as Date_Reported,
NULL as Assigned_To,
NULL as Atentioned_User,
r.`From` as Originated_From,
r.View_Status,
'response' as notification_type,
NULL as Assigned_Full_Name,
NULL as Attention_Full_Name,
NULL as Originator_Full_Name,
a4.Full_Name as From_Name
FROM responce_trend r
LEFT JOIN complaints c ON r.ComplaintID = c.ComplaintID
LEFT JOIN admin_accounts a4 ON r.`From` = a4.id
WHERE r.View_Status = 'New' AND (r.`From` = '$userId' OR r.UserID = '$userId')
ORDER BY Date_Reported DESC";
$notificationsResult = mysqli_query($conn, $notificationsQuery);
$newNotifications = [];
if ($notificationsResult && mysqli_num_rows($notificationsResult) > 0) {
while ($row = mysqli_fetch_assoc($notificationsResult)) {
$newNotifications[] = $row;
}
}
include_once('include/AdminHeader.php');
?>
<style>
/* Compact & Beautiful Dashboard Styling */
:root {
--primary: #2ecc71;
--primary-dark: #27ae60;
--primary-light: #e8f5e9;
--text-dark: #2c3e50;
--text-gray: #7f8c8d;
--bg-light: #f8f9fa;
--white: #ffffff;
--border: #e9ecef;
--shadow: 0 1px 3px rgba(0,0,0,0.08);
--shadow-md: 0 2px 8px rgba(0,0,0,0.1);
--danger: #e74c3c;
--warning: #f39c12;
--black: #000000;
--dark-gray: #333333;
}
body {
background: #f5f7fb;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}
#page-wrapper {
min-height: 100vh;
padding: 10px;
}
/* Profile Container - Full Width */
.profile-container {
max-width: 100%;
margin: 0;
width: 100%;
}
/* Profile Card - Full Width Design */
.profile-card {
background: var(--white);
border-radius: 12px;
box-shadow: var(--shadow);
overflow: hidden;
margin-bottom: 20px;
width: 100%;
}
.profile-card-header {
background: var(--white);
padding: 12px 20px;
border-bottom: 1px solid var(--border);
}
.profile-card-header h3 {
margin: 0;
color: var(--text-dark);
font-size: 14px;
font-weight: 600;
}
.profile-card-header h3 i {
margin-right: 8px;
color: var(--primary);
font-size: 14px;
}
.profile-card-body {
padding: 20px;
}
/* Profile Header - Full Width Layout */
.profile-header {
display: flex;
align-items: center;
gap: 20px;
margin-bottom: 0;
flex-wrap: wrap;
}
.profile-avatar {
width: 70px;
height: 70px;
background: linear-gradient(135deg, var(--primary), var(--primary-dark));
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
color: var(--white);
font-size: 28px;
font-weight: 600;
text-transform: uppercase;
box-shadow: 0 2px 8px rgba(46,204,113,0.2);
}
.profile-title {
flex: 1;
}
.profile-title h2 {
margin: 0 0 8px 0;
font-size: 20px;
color: var(--text-dark);
font-weight: 600;
}
.profile-badges {
display: flex;
flex-wrap: wrap;
gap: 8px;
align-items: center;
}
.badge {
display: inline-flex;
align-items: center;
gap: 5px;
padding: 4px 12px;
border-radius: 20px;
font-size: 11px;
font-weight: 500;
}
.badge-position {
background: var(--primary-light);
color: var(--primary-dark);
}
.badge-email {
background: #e3f2fd;
color: #1976d2;
}
.badge-phone {
background: #fff3e0;
color: #f57c00;
}
.badge-dept {
background: #f3e5f5;
color: #7b1fa2;
}
/* Region Badge Styling */
.badge-region {
background: #e8f0fe;
color: #1a73e8;
}
.hod-badge-simple {
background: #fff8e7;
color: #e67e22;
border-left: 2px solid #f39c12;
padding: 4px 12px;
border-radius: 20px;
}
.hod-badge-simple i {
color: #f39c12;
font-size: 11px;
}
/* Action Buttons Container - Align to Right */
.action-buttons-container {
display: flex;
gap: 10px;
align-items: center;
justify-content: flex-end;
}
/* Add New File Button Styling */
.btn-add-file {
background: linear-gradient(135deg, #3498db, #2980b9);
color: white;
border: none;
padding: 8px 20px;
border-radius: 8px;
font-size: 13px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.btn-add-file:hover {
background: linear-gradient(135deg, #2980b9, #21618c);
transform: translateY(-1px);
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
color: white;
text-decoration: none;
}
.btn-add-file i {
font-size: 14px;
}
/* Notifications Table */
.notifications-section {
margin-top: 20px;
width: 100%;
}
.notifications-card {
background: var(--white);
border-radius: 12px;
box-shadow: var(--shadow);
overflow: hidden;
width: 100%;
}
.notifications-header {
background: linear-gradient(135deg, var(--dark-gray) 0%, var(--black) 100%);
padding: 12px 20px;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 10px;
}
.notifications-header h4 {
margin: 0;
color: var(--white);
font-size: 14px;
font-weight: 600;
}
.notifications-header h4 i {
margin-right: 8px;
font-size: 14px;
}
.notifications-badge {
background: rgba(255,255,255,0.2);
padding: 3px 10px;
border-radius: 20px;
font-size: 11px;
color: var(--white);
}
.notifications-table-container {
overflow-x: auto;
padding: 0;
}
.notifications-table {
width: 100%;
border-collapse: collapse;
font-size: 12px;
}
.notifications-table thead {
background: var(--bg-light);
}
.notifications-table th {
padding: 12px 15px;
text-align: left;
font-weight: 600;
color: var(--text-dark);
border-bottom: 2px solid var(--border);
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.notifications-table td {
padding: 12px 15px;
border-bottom: 1px solid var(--border);
color: var(--text-gray);
vertical-align: middle;
}
.notifications-table tbody tr:hover {
background: var(--primary-light);
cursor: pointer;
}
.notification-new {
background: #fffef7;
border-left: 3px solid var(--primary);
}
.notification-title {
font-weight: 600;
color: var(--text-dark);
margin-bottom: 3px;
}
.notification-desc {
font-size: 11px;
color: var(--text-gray);
}
.notification-type {
display: inline-block;
padding: 3px 8px;
border-radius: 12px;
font-size: 10px;
font-weight: 600;
}
.type-assigned {
background: #e3f2fd;
color: #1976d2;
}
.type-attention {
background: #f3e5f5;
color: #7b1fa2;
}
.type-response {
background: #fff3e0;
color: #e65100;
}
.type-sent {
background: #e8f5e9;
color: #2e7d32;
}
.btn-view {
background: var(--primary);
color: white;
border: none;
padding: 5px 12px;
border-radius: 6px;
font-size: 11px;
cursor: pointer;
transition: all 0.2s;
text-decoration: none;
display: inline-block;
}
.btn-view:hover {
background: var(--primary-dark);
transform: translateY(-1px);
}
.empty-notifications {
text-align: center;
padding: 40px;
color: var(--text-gray);
}
.empty-notifications i {
font-size: 48px;
color: var(--border);
margin-bottom: 10px;
}
/* Date styling */
.date-sent {
font-size: 11px;
white-space: nowrap;
}
.date-sent i {
margin-right: 4px;
color: var(--primary);
}
/* Coming From styling */
.from-user {
font-weight: 500;
color: var(--text-dark);
font-size: 12px;
}
.from-user i {
color: var(--primary);
margin-right: 4px;
}
/* Compact Footer */
.dashboard-footer {
text-align: center;
margin-top: 20px;
padding: 15px;
color: var(--text-gray);
font-size: 11px;
}
/* Responsive */
@media (max-width: 768px) {
.profile-header {
flex-direction: column;
text-align: center;
gap: 12px;
}
.profile-card-body {
padding: 15px;
}
.profile-badges {
justify-content: center;
}
.notifications-table th,
.notifications-table td {
padding: 10px;
}
.date-sent {
white-space: normal;
}
.action-buttons-container {
justify-content: center;
flex-wrap: wrap;
}
}
/* Notification button adjustments */
.btn-success {
padding: 6px 12px;
font-size: 12px;
}
.btn-success i {
font-size: 18px !important;
}
.page-action-links {
margin-bottom: 15px;
}
.page-action-links h6 {
margin: 0;
}
.status-badge {
display: inline-block;
padding: 4px 8px;
border-radius: 12px;
font-size: 11px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.2px;
}
</style>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<div class="page-action-links">
<div class="action-buttons-container">
<!-- ADD NEW FILE BUTTON -->
<?php if ($Add_File == 1) { ?>
<a href="add_complaint.php?operation=create" class="btn-add-file">
<i class="fa fa-plus-circle"></i> Add New File
</a>
<?php } ?>
<!-- NOTIFICATIONS BUTTON -->
<a href="#" data-toggle="modal" data-target="#AddTopic-TESITING">
<button class="btn btn-success">
Notifications
<i class="fa fa-envelope" style="font-size:18px; color:white">
<sup><strong><?php if($numx > 0){ echo $numx; } ?></strong></sup>
</i>
</button>
</a>
</div>
</div>
</div>
</div>
<!-- Full Width Profile Card -->
<div class="profile-container">
<div class="profile-card">
<div class="profile-card-header">
<h3><i class="fa fa-user-circle-o"></i> Profile Information</h3>
</div>
<div class="profile-card-body">
<!-- Profile Header - Full Width -->
<div class="profile-header">
<div class="profile-avatar">
<?php
$initials = '';
if(!empty($FullName)) {
$nameParts = explode(' ', trim($FullName));
$initials = strtoupper(substr($nameParts[0], 0, 1));
if(isset($nameParts[1])) {
$initials .= strtoupper(substr($nameParts[1], 0, 1));
}
}
echo $initials ?: 'U';
?>
</div>
<div class="profile-title">
<h2><?php echo htmlspecialchars($FullName); ?></h2>
<div class="profile-badges">
<span class="badge badge-position">
<i class="fa fa-briefcase"></i> <?php echo htmlspecialchars($userProfile['Position'] ?? 'Not Specified'); ?>
</span>
<span class="badge badge-email">
<i class="fa fa-envelope"></i> <?php echo htmlspecialchars($userProfile['email'] ?? 'Not Provided'); ?>
</span>
<span class="badge badge-dept">
<i class="fa fa-building"></i> <?php echo htmlspecialchars($departmentName); ?>
</span>
<!-- REGION BADGE ADDED HERE -->
<span class="badge badge-region">
<i class="fa fa-map-marker"></i> <?php echo htmlspecialchars($userProfile['Region'] ?? 'Not Assigned'); ?>
</span>
<?php if(isset($userProfile['HOD']) && $userProfile['HOD'] == 1): ?>
<span class="hod-badge-simple">
<i class="fa fa-trophy"></i> Head of Department
</span>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<!-- New Notifications Table -->
<div class="notifications-section">
<div class="notifications-card">
<div class="notifications-header">
<h4><i class="fa fa-bell"><sup><strong><?php if($numx > 0){ echo $numx; } ?></strong></sup></i> New Notifications</h4>
</div>
<div class="notifications-table-container">
<?php if (count($newNotifications) > 0): ?>
<table class="notifications-table">
<thead>
<tr>
<th>Heading</th>
<th>Client Name</th>
<th>From / To</th>
<th>Type</th>
<th>Date Sent</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($newNotifications as $notification):
$notificationType = '';
$typeClass = '';
$fromToText = '';
if ($notification['notification_type'] == 'complaint') {
if ($notification['Assigned_To'] == $userId) {
$notificationType = 'Assigned to you';
$typeClass = 'type-assigned';
$fromToText = 'Assigned to: You';
} elseif ($notification['Atentioned_User'] == $userId) {
$notificationType = 'Your attention needed';
$typeClass = 'type-attention';
$fromToText = 'For your attention';
}
} else {
// For responses, determine if it was sent FROM or TO the user
$responseQueryCheck = "SELECT `From`, UserID FROM responce_trend WHERE ComplaintID = '{$notification['ComplaintID']}' AND View_Status = 'New' LIMIT 1";
$responseCheckResult = mysqli_query($conn, $responseQueryCheck);
if ($responseCheckResult && mysqli_num_rows($responseCheckResult) > 0) {
$responseData = mysqli_fetch_assoc($responseCheckResult);
if ($responseData['From'] == $userId) {
$notificationType = 'Response you sent';
$typeClass = 'type-sent';
$fromToText = 'Sent by you';
} else {
$notificationType = 'Response to you';
$typeClass = 'type-response';
$fromToText = 'Sent to you';
}
} else {
$notificationType = 'Response';
$typeClass = 'type-response';
$fromToText = 'Response';
}
}
// Get the "Coming From" user name
$fromUserName = '';
if ($notification['notification_type'] == 'complaint') {
$fromUserName = !empty($notification['Originator_Full_Name']) ? $notification['Originator_Full_Name'] : 'System';
} else {
$fromUserName = !empty($notification['From_Name']) ? $notification['From_Name'] : 'Unknown';
}
// Format the date
$dateSent = '';
if (!empty($notification['Date_Reported'])) {
$dateSent = date('d M Y, h:i A', strtotime($notification['Date_Reported']));
} else {
$dateSent = 'Not specified';
}
?>
<tr class="notification-new">
<td>
<div class="notification-title"><?php echo htmlspecialchars($notification['Heading'] ?? '—'); ?></div>
<div class="notification-desc"><?php echo htmlspecialchars(substr($notification['Problem'] ?? '', 0, 50)); ?><?php echo strlen($notification['Problem'] ?? '') > 50 ? '...' : ''; ?></div>
</td>
<td><?php echo htmlspecialchars($notification['Name'] ?? '—'); ?></td>
<td class="from-user">
<i class="fa fa-user-circle"></i>
<?php
if ($notification['notification_type'] == 'response' && $fromUserName) {
if ($fromUserName == $FullName) {
echo 'You';
} else {
echo htmlspecialchars($fromUserName);
}
} else {
echo htmlspecialchars($fromUserName);
}
?>
<br>
<small style="font-size: 10px; color: var(--text-gray);"><?php echo $fromToText; ?></small>
</td>
<td><span class="notification-type <?php echo $typeClass; ?>"><?php echo $notificationType; ?></span></td>
<td class="date-sent"><i class="fa fa-calendar"></i> <?php echo $dateSent; ?></td>
<td>
<span class="status-badge" style="background: #fef3f2; color: #e74c3c;">New</span>
</td>
<td>
<a href="AddResponce.php?ComplaintID=<?php echo urlencode($notification['ComplaintID'] ?? ''); ?>&operation=launch_complaint" class="btn-view">
<i class="fa fa-eye"></i> View
</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<div class="empty-notifications">
<i class="fa fa-bell-slash"></i>
<p>No new notifications at this time</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<!-- Original Modal -->
<div class="modal fade" id="AddTopic-TESITING" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header" style="text-align:center; background-color:#BAC4CC; padding: 10px;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h5 class="modal-title" style="text-align:center; font-size: 14px;"><i class="fa fa-bell"></i><strong> NEW NOTIFICATIONS</strong> </h5>
</div>
<div class="modal-body" style="text-align:center; background-color:#F6F7FA; padding: 15px;">
<?php if ($numx > 0) { ?>
<div align='center'>
<h5 style="font-size: 14px; margin: 0;"><a href="Complaints.php"> You have <?php echo $numx ; ?> New File(s) sent to you</a> </h5>
</div>
<?php } else { ?>
<div align='center'><h5 style="font-size: 14px; margin: 0;"> There is no New Notification </h5></div>
<?php } ?>
</div>
<div class="modal-footer" style="padding: 8px;">
<button type="button" class="btn btn-primary btn-sm" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span></button>
</div>
</div>
</div>
</div>
</div>
<div class="dashboard-footer">
<i class="fa fa-shield-alt"></i> MHC Portal © <?php echo date('Y'); ?>
</div>
<?php include_once('include/footer.php'); ?>