-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsidebar.php
More file actions
234 lines (213 loc) · 10.5 KB
/
sidebar.php
File metadata and controls
234 lines (213 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
include 'config.php';
include 'session.php';
// Fetch user details including role
$stmt = $conn->prepare("SELECT name, email, role FROM users WHERE id = ?");
$stmt->bind_param("i", $_SESSION['user_id']);
$stmt->execute();
$result = $stmt->get_result();
$user = $result->fetch_assoc();
$stmt->close();
function getDocumentsToSignCount($userId) {
global $conn;
$stmt = $conn->prepare("SELECT COUNT(*) FROM documents WHERE recipient_id = ? AND status = 'sent'");
$stmt->bind_param("i", $userId);
$stmt->execute();
$result = $stmt->get_result();
$count = $result->fetch_row()[0];
$stmt->close();
return $count;
}
function getUnreadMessagesCount($userId) {
global $conn;
$stmt = $conn->prepare("SELECT COUNT(*) FROM messages WHERE receiver_id = ? AND `read` = 0");
$stmt->bind_param("i", $userId);
$stmt->execute();
$result = $stmt->get_result();
$count = $result->fetch_row()[0];
$stmt->close();
return $count;
}
function getPendingUsersCount() {
global $conn;
$stmt = $conn->prepare("SELECT COUNT(*) FROM users WHERE status = 'pending'");
$stmt->execute();
$result = $stmt->get_result();
$count = $result->fetch_row()[0];
$stmt->close();
return $count;
}
// Fetch notification counts
$documentsToSignCount = getDocumentsToSignCount($_SESSION['user_id']);
$unreadMessagesCount = getUnreadMessagesCount($_SESSION['user_id']);
$pendingUsersCount = $user['role'] === 'admin' ? getPendingUsersCount() : 0;
// Define shared menu items
$sharedMenuItems = [
['url' => 'dashboard.php', 'icon' => 'fas fa-tachometer-alt', 'text' => 'Dashboard'],
['url' => '#', 'icon' => 'fas fa-file-signature', 'text' => 'eSign', 'submenu' => [
['url' => 'upload_documents.php', 'text' => 'Document Upload'],
['url' => 'documents_to_sign.php', 'text' => 'Documents to Sign', 'badge' => $documentsToSignCount],
]],
['url' => 'activity_log.php', 'icon' => 'fas fa-history', 'text' => 'Activity Log'],
['url' => 'insights_hub.php', 'icon' => 'fas fa-chart-line', 'text' => 'Support Center'],
['url' => 'chat.php', 'icon' => 'fas fa-comments', 'text' => 'Live Chat', 'badge' => $unreadMessagesCount],
['url' => 'validator.php', 'icon' => 'fas fa-check-circle', 'text' => 'Document Validator'],
];
// Define admin-specific menu items
$adminMenuItems = [
['url' => 'document_management.php', 'icon' => 'fas fa-folder-open', 'text' => 'Document Management'],
['url' => 'user_management.php', 'icon' => 'fas fa-users-cog', 'text' => 'User Management', 'badge' => $pendingUsersCount],
['url' => 'reports.php', 'icon' => 'fas fa-chart-bar', 'text' => 'Reports'],
];
// Combine menu items based on user role
$menuItems = $sharedMenuItems;
if ($user['role'] === 'admin') {
$menuItems = array_merge($menuItems, $adminMenuItems);
}
$menuItems[] = ['url' => 'edit_profile.php', 'icon' => 'fas fa-user-edit', 'text' => 'Edit Profile'];
function renderMenuItem($item, $isAdmin) {
// Get current page URL for comparison
$currentPage = basename($_SERVER['PHP_SELF']);
$isActive = basename($item['url']) === $currentPage;
$submenuHtml = '';
if (isset($item['submenu'])) {
$submenuHtml .= '<ul class="ml-4 mt-2 space-y-2 hidden submenu">';
foreach ($item['submenu'] as $subitem) {
$isSubActive = basename($subitem['url']) === $currentPage;
$activeSubClass = $isSubActive ? 'bg-sidebar-hover' : '';
$badgeHtml = isset($subitem['badge']) && $subitem['badge'] > 0 ? '<span class="inline-flex items-center justify-center w-5 h-5 ml-2 text-xs font-semibold text-white bg-red-500 rounded-full">' . $subitem['badge'] . '</span>' : '';
$submenuHtml .= '<li><a href="' . $subitem['url'] . '" class="flex items-center p-2 text-white rounded-lg hover:bg-sidebar-hover group ' . $activeSubClass . '">' . $subitem['text'] . $badgeHtml . '</a></li>';
}
$submenuHtml .= '</ul>';
}
// Add active state classes
$adminClass = $isAdmin ? 'border-l-4 border-sidebar-text pl-3' : '';
$dropdownClass = isset($item['submenu']) ? 'dropdown-toggle' : '';
$activeClass = $isActive ? 'bg-sidebar-hover text-white' : '';
$badgeHtml = isset($item['badge']) && $item['badge'] > 0 ? '<span class="inline-flex items-center justify-center w-5 h-5 ml-2 text-xs font-semibold text-white bg-red-500 rounded-full">' . $item['badge'] . '</span>' : '';
return '
<li>
<a href="' . $item['url'] . '" class="flex items-center p-2 text-white rounded-lg hover:bg-sidebar-hover group ' . $adminClass . ' ' . $dropdownClass . ' ' . $activeClass . '">
<i class="' . $item['icon'] . ' w-5 h-5 text-sidebar-text group-hover:text-sidebar-text ' . ($isActive ? 'text-white' : '') . '"></i>
<span class="ml-3">' . $item['text'] . '</span>
' . $badgeHtml . '
' . (isset($item['submenu']) ? '<i class="fas fa-chevron-down ml-auto text-sidebar-text group-hover:text-sidebar-text transition-transform duration-200"></i>' : '') . '
</a>
' . $submenuHtml . '
</li>';
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SignEase</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
primary: {
DEFAULT: '#880404',
dark: '#880404',
},
hover: {
DEFAULT: '#deb80cf8',
dark: '#deb80cf8',
},
sidebar: {
bg: '#880404',
text: 'white',
hover: '#deb80cf8',
}
}
}
}
}
</script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
<script src="theme.js"></script>
</head>
<body class="bg-gray-100 dark:bg-gray-900">
<div id="sidebar" class="fixed top-0 left-0 z-40 w-64 h-screen transition-transform -translate-x-full sm:translate-x-0">
<div class="h-full px-3 py-4 overflow-y-auto bg-sidebar-bg text-sidebar-text">
<div class="flex flex-col items-center justify-center mb-5 pb-3 border-b border-sidebar-text">
<?php if ($user['role'] === 'admin'): ?>
<div class="w-16 h-16 bg-white rounded-full flex items-center justify-center mb-2">
<i class="fas fa-user-shield text-3xl text-primary"></i>
</div>
<span class="text-xl font-bold text-white">SignEase Admin</span>
<?php else: ?>
<span class="text-xl font-semibold text-white">SignEase</span>
<?php endif; ?>
<button id="sidebarToggle" class="mt-2 text-white focus:outline-none sm:hidden">
<i class="fas fa-bars"></i>
</button>
</div>
<ul class="space-y-2 font-medium">
<?php
foreach ($menuItems as $item) {
echo renderMenuItem($item, $user['role'] === 'admin');
}
?>
<li>
<button id="themeToggle" class="flex items-center w-full p-2 text-sidebar-text rounded-lg hover:bg-sidebar-hover group">
<i id="themeIcon" class="fas fa-sun w-5 h-5 text-sidebar-text transition duration-75 group-hover:text-sidebar-text"></i>
<span class="ml-3">Toggle Theme</span>
</button>
</li>
</ul>
<div class="pt-4 mt-4 space-y-2 font-medium border-t border-sidebar-text">
<div id="userProfileTrigger" class="flex items-center p-2 text-white cursor-pointer hover:bg-sidebar-hover rounded-lg">
<div class="flex-shrink-0">
<div class="w-10 h-10 rounded-full bg-white flex items-center justify-center">
<span class="text-xl font-semibold text-primary"><?php echo strtoupper(substr($user['name'], 0, 1)); ?></span>
</div>
</div>
<div class="ml-3">
<p class="text-sm font-semibold"><?php echo htmlspecialchars($user['name']); ?></p>
<p class="text-xs text-white"><?php echo htmlspecialchars($user['email']); ?></p>
</div>
</div>
<a href="logout.php" class="flex items-center p-2 text-white rounded-lg hover:bg-sidebar-hover group">
<i class="fas fa-sign-out-alt w-5 h-5 text-sidebar-text group-hover:text-sidebar-text"></i>
<span class="ml-3">Logout</span>
</a>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const userProfileTrigger = document.getElementById('userProfileTrigger');
const themeToggle = document.getElementById('themeToggle');
const themeIcon = document.getElementById('themeIcon');
const dropdownToggles = document.querySelectorAll('.dropdown-toggle');
dropdownToggles.forEach(toggle => {
toggle.addEventListener('click', function(e) {
e.preventDefault();
const submenu = this.nextElementSibling;
submenu.classList.toggle('hidden');
const chevron = this.querySelector('.fa-chevron-down');
chevron.classList.toggle('rotate-180');
});
});
function updateThemeIcon(theme) {
themeIcon.className = theme === 'dark'
? 'fas fa-moon w-5 h-5 text-sidebar-text transition duration-75 group-hover:text-sidebar-text'
: 'fas fa-sun w-5 h-5 text-sidebar-text transition duration-75 group-hover:text-sidebar-text';
}
themeToggle.addEventListener('click', function() {
window.themeUtils.toggleTheme();
});
window.addEventListener('themeChanged', (event) => {
updateThemeIcon(event.detail);
});
window.themeUtils.initTheme();
updateThemeIcon(localStorage.getItem('theme'));
});
</script>
</body>
</html>