-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.php
More file actions
307 lines (281 loc) · 13.2 KB
/
Copy pathheader.php
File metadata and controls
307 lines (281 loc) · 13.2 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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CS (Computer Science) Curriculum</title>
<link rel="stylesheet" href="styles.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<header>
<h1>CS (Computer Science) Curriculum</h1>
<nav>
<ul>
<li><a href="index.php">Home</a></li>
<!-- Static course navigation (fallback) -->
<li class="dropdown">
<a href="python.php">🐍 Python</a>
<ul class="dropdown-menu">
<li><a href="python.php">Course Content</a></li>
<li><a href="python-exercises.php">Exercises</a></li>
<li><a href="python-projects.php">Projects</a></li>
<li><a href="python-finals.php">Finals</a></li>
</ul>
</li>
<li class="dropdown">
<a href="cybersecurity.php">🔒 Cybersecurity</a>
<ul class="dropdown-menu">
<li><a href="cybersecurity.php">Course Content</a></li>
<li><a href="cybersecurity-exercises.php">Exercises</a></li>
<li><a href="cybersecurity-projects.php">Projects</a></li>
<li><a href="cybersecurity-finals.php">Finals</a></li>
</ul>
</li>
<?php
// Load additional active courses for navigation
$course_nav_query = $conn->query("SELECT id, name, slug, icon FROM courses WHERE is_active = 1 AND slug NOT IN ('python', 'cybersecurity') ORDER BY created_at");
while ($course = $course_nav_query->fetch_assoc()):
$course_slug = $course['slug'];
?>
<li class="dropdown">
<a href="<?php echo $course_slug; ?>.php"><?php echo htmlspecialchars($course['icon'] . ' ' . $course['name']); ?></a>
<ul class="dropdown-menu">
<li><a href="<?php echo $course_slug; ?>.php">Course Content</a></li>
<li><a href="<?php echo $course_slug; ?>-exercises.php">Exercises</a></li>
<li><a href="<?php echo $course_slug; ?>-projects.php">Projects</a></li>
<li><a href="<?php echo $course_slug; ?>-finals.php">Finals</a></li>
</ul>
</li>
<?php endwhile; ?>
<?php if (isset($_SESSION['user_id'])): ?>
<li class="dropdown">
<a href="#" class="login-btn">Welcome, <?php echo htmlspecialchars($_SESSION['first_name'] ?: $_SESSION['username']); ?> ▼</a>
<ul class="dropdown-menu">
<li><a href="dashboard.php">Dashboard</a></li>
<li><a href="skills_panel.php">Skills Panel</a></li>
<?php if ($_SESSION['role'] === 'admin'): ?>
<li><a href="admin_dashboard.php">Admin Panel</a></li>
<li><a href="course_panel.php">Course Panel</a></li>
<li><a href="checklist_manager.php">Checklist Manager</a></li>
<li><a href="admin_xp_management.php">XP Management</a></li>
<?php endif; ?>
<?php if ($_SESSION['role'] === 'teacher'): ?>
<li><a href="admin_xp_management.php">XP Management</a></li>
<?php endif; ?>
<li><a href="logout.php">Logout</a></li>
</ul>
</li>
<li class="notifications">
<a href="#" class="notification-btn" onclick="toggleNotifications()">
🔔 <span class="notification-badge" style="display: none;">0</span>
</a>
<div id="notifications-dropdown" class="notifications-dropdown">
<div class="notifications-header">
<h4>Notifications</h4>
<div class="notification-actions">
<button onclick="markAllRead()" class="mark-read-btn">Mark All Read</button>
<button onclick="clearAllNotifications()" class="clear-all-btn">Clear All</button>
</div>
</div>
<div id="notifications-list" class="notifications-list">
<div class="loading">Loading notifications...</div>
</div>
</div>
</li>
<?php else: ?>
<li><a href="login.php" class="login-btn">Login</a></li>
<?php endif; ?>
</ul>
</nav>
<!-- Scroll to Top Button -->
<button id="scroll-to-top-btn" class="scroll-to-top-btn" title="Scroll to Top">↑</button>
</header>
<script>
// Notification functionality
function toggleNotifications() {
const dropdown = document.getElementById('notifications-dropdown');
dropdown.classList.toggle('active');
if (dropdown.classList.contains('active')) {
loadNotifications();
}
}
function loadNotifications() {
const container = document.getElementById('notifications-list');
container.innerHTML = '<div class="loading">Loading notifications...</div>';
fetch('notification_handler.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'action=get_notifications'
})
.then(response => response.json())
.then(data => {
if (data.success) {
displayNotifications(data.notifications);
} else {
container.innerHTML = '<div class="no-notifications">Error loading notifications</div>';
}
})
.catch(error => {
container.innerHTML = '<div class="no-notifications">Network error</div>';
});
}
function displayNotifications(notifications) {
const container = document.getElementById('notifications-list');
if (notifications.length === 0) {
container.innerHTML = '<div class="no-notifications">No notifications yet</div>';
return;
}
let html = '';
notifications.forEach(notification => {
const unreadClass = notification.is_read == 0 ? 'unread' : '';
const timeAgo = getTimeAgo(new Date(notification.created_at));
html += `
<div class="notification-item ${unreadClass}">
<div class="notification-content" onclick="markAsRead(${notification.id})">
<div class="notification-title">${notification.title}</div>
<div class="notification-message">${notification.message}</div>
<div class="notification-time">${timeAgo}</div>
</div>
<button class="notification-delete-btn" onclick="deleteSingleNotification(${notification.id})" title="Delete notification">×</button>
</div>
`;
});
container.innerHTML = html;
}
function markAsRead(notificationId) {
fetch('notification_handler.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `action=mark_notification_read¬ification_id=${notificationId}`
})
.then(response => response.json())
.then(data => {
if (data.success) {
loadNotifications(); // Refresh the list
updateNotificationBadge(); // Update badge count
}
})
.catch(error => {
console.error('Error marking notification as read:', error);
});
}
function markAllRead() {
fetch('notification_handler.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'action=mark_all_notifications_read'
})
.then(response => response.json())
.then(data => {
if (data.success) {
loadNotifications(); // Refresh the list
updateNotificationBadge(); // Update badge count
}
})
.catch(error => {
console.error('Error marking all notifications as read:', error);
});
}
function clearAllNotifications() {
if (confirm('Are you sure you want to clear all notifications? This action cannot be undone.')) {
fetch('notification_handler.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'action=clear_all_notifications'
})
.then(response => response.json())
.then(data => {
if (data.success) {
loadNotifications(); // Refresh the list
updateNotificationBadge(); // Update badge count
} else {
alert('Error clearing notifications: ' + (data.message || 'Unknown error'));
}
})
.catch(error => {
console.error('Error clearing notifications:', error);
alert('Network error clearing notifications');
});
}
}
function deleteSingleNotification(notificationId) {
if (confirm('Delete this notification?')) {
fetch('notification_handler.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `action=delete_single_notification¬ification_id=${notificationId}`
})
.then(response => response.json())
.then(data => {
if (data.success) {
loadNotifications(); // Refresh the list
updateNotificationBadge(); // Update badge count
} else {
alert('Error deleting notification: ' + (data.message || 'Unknown error'));
}
})
.catch(error => {
console.error('Error deleting notification:', error);
alert('Network error deleting notification');
});
}
}
function updateNotificationBadge() {
fetch('notification_handler.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: 'action=get_unread_count'
})
.then(response => response.json())
.then(data => {
if (data.success) {
const badge = document.querySelector('.notification-badge');
if (data.count > 0) {
if (badge) {
badge.textContent = data.count;
badge.style.display = 'inline-block';
} else {
// Create badge if it doesn't exist
const btn = document.querySelector('.notification-btn');
const newBadge = document.createElement('span');
newBadge.className = 'notification-badge';
newBadge.textContent = data.count;
newBadge.style.display = 'inline-block';
btn.appendChild(newBadge);
}
} else {
if (badge) {
badge.style.display = 'none';
}
}
}
})
.catch(error => {
console.error('Error updating notification badge:', error);
});
}
function getTimeAgo(date) {
const now = new Date();
const diffInSeconds = Math.floor((now - date) / 1000);
if (diffInSeconds < 60) return 'just now';
if (diffInSeconds < 3600) return `${Math.floor(diffInSeconds / 60)} minutes ago`;
if (diffInSeconds < 86400) return `${Math.floor(diffInSeconds / 3600)} hours ago`;
if (diffInSeconds < 604800) return `${Math.floor(diffInSeconds / 86400)} days ago`;
return date.toLocaleDateString();
}
// Close notifications dropdown when clicking outside
document.addEventListener('click', function(event) {
const notifications = document.querySelector('.notifications');
const notificationsDropdown = document.getElementById('notifications-dropdown');
if (notifications && !notifications.contains(event.target)) {
notificationsDropdown.classList.remove('active');
}
});
// Initialize notification badge on page load
document.addEventListener('DOMContentLoaded', function() {
updateNotificationBadge();
});
// Auto-refresh notification badge every 30 seconds
setInterval(updateNotificationBadge, 30000);
</script>