-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudent_dashboard.php
More file actions
1280 lines (1007 loc) · 36.1 KB
/
Copy pathstudent_dashboard.php
File metadata and controls
1280 lines (1007 loc) · 36.1 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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
function isMobileDevice() {
return preg_match(
"/android|iphone|ipad|ipod|blackberry|windows phone/i",
$_SERVER['HTTP_USER_AGENT']
);
}
if (isMobileDevice()) {
header("Location: nohref.php");
exit;
}
session_start();
require "config.php";
if (!function_exists('isVideo')) {
function isVideo($file) {
$ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
return in_array($ext, ['mp4', 'webm', 'ogg']);
}
}
if (!isset($_SESSION['id'])) {
header("Location: index.php");
exit;
}
/* ALWAYS re-check user status from DB */
$stmt = $pdo->prepare("SELECT role, is_active FROM users WHERE id = ?");
$stmt->execute([$_SESSION['id']]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$user) {
session_destroy();
header("Location: index.php");
exit;
}
if ((int)$user['is_active'] !== 1) {
session_destroy();
header("Location: nohref.php");
exit;
}
/* Update session with fresh values */
$_SESSION['role'] = $user['role'];
$_SESSION['is_active'] = (int)$user['is_active'];
/* Role check */
if ($user['role'] !== 'student') {
header("Location: index.php?error=access_denied");
exit;
}
$user_id = $_SESSION['id'];
/* -------------------------------------------
FETCH STUDENT PROFILE
-------------------------------------------- */
$stmt = $pdo->prepare("
SELECT
s.*,
s.level_id,
u.reg_number,
u.student_id,
d.name AS department_name
FROM students s
LEFT JOIN users u ON s.user_id = u.id
LEFT JOIN departments d ON s.department_id = d.id
WHERE s.user_id = ?
");
$stmt->execute([$user_id]);
$student = $stmt->fetch(PDO::FETCH_ASSOC);
@$student_id = (int)$student['id'];
if (!$student) {
$student = [
"id" => 0,
"first_name" => "",
"username" => "",
"last_name" => "",
"student_number" => "Not Assigned",
"reg_number" => "Not Assigned",
"department_name" => "Not Assigned",
"email" => "",
"phone" => "",
"address" => "",
"dob" => "",
"emergency_phone" => "",
"department_id" => 0
];
}
$pic = $student['profile_pic'] ?? 'default.png';
/* -------------------------------------------
ASSIGNMENTS FOR STUDENT + UNREAD COUNT
-------------------------------------------- */
$assignmentsStmt = $pdo->prepare("
SELECT DISTINCT
a.*,
c.code AS course_code,
c.title AS course_title,
u.full_name AS posted_by_name
FROM assignments a
JOIN registrations r ON r.course_id = a.course_id
JOIN courses c ON a.course_id = c.id
JOIN teachers t ON a.posted_by = t.id
JOIN users u ON t.user_id = u.id
WHERE r.user_id = ?
ORDER BY a.created_at DESC
");
$assignmentsStmt->execute([$user_id]);
$student_assignments = $assignmentsStmt->fetchAll(PDO::FETCH_ASSOC);
//live vidoe counter
$liveCountStmt = $pdo->prepare("
SELECT COUNT(*)
FROM live_classes lc
WHERE lc.status IN ('scheduled','live')
AND EXISTS (
SELECT 1
FROM registrations r
WHERE r.course_id = lc.course_id
AND r.user_id = ?
)
");
$liveCountStmt->execute([$user_id]);
$live_class_count = (int)$liveCountStmt->fetchColumn();
// unread assignment count (not yet viewed)
$assignCountStmt = $pdo->prepare("
SELECT COUNT(DISTINCT a.id)
FROM assignments a
JOIN registrations r ON r.course_id = a.course_id
WHERE r.user_id = :uid
AND a.id NOT IN (
SELECT assignment_id
FROM assignment_views
WHERE user_id = :user
)
");
$assignCountStmt->execute([
'uid' => $user_id, // registrations.user_id
'user' => $user_id // assignment_views.user_id (users.id)
]);
$assignment_unread_count = (int) $assignCountStmt->fetchColumn();
/* -------------------------------------------
ATTENDANCE COUNTERS
-------------------------------------------- */
// First, get the correct student_id from attendance table directly
// Logged-in student (users.id)
$user_id = $_SESSION['id'];
// Convert users.id → students.id
$stmt = $pdo->prepare("
SELECT id
FROM students
WHERE user_id = ?
LIMIT 1
");
$stmt->execute([$user_id]);
$student_id = $stmt->fetchColumn();
if (!$student_id) {
$present = $absent = $late = 0;
} else {
// MONTHLY attendance summary (teacher-recorded)
$stmt = $pdo->prepare("
SELECT
COUNT(*) AS total_days,
SUM(status = 'present') AS present_days,
SUM(status = 'absent') AS absent_days,
SUM(status = 'late') AS late_days
FROM attendance
WHERE student_id = ?
AND MONTH(attendance_date) = MONTH(CURDATE())
AND YEAR(attendance_date) = YEAR(CURDATE())
");
$stmt->execute([$student_id]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$present = (int)$row['present_days'];
$absent = (int)$row['absent_days'];
$late = (int)$row['late_days'];
}
/* -------------------------------------------
FETCH ALL SECTIONS
-------------------------------------------- */
$notices = $pdo->query("
SELECT * FROM notices
WHERE visible_to IN ('all','students')
ORDER BY id DESC LIMIT 5
")->fetchAll(PDO::FETCH_ASSOC);
/* -------------------------------------------
NOTICE COUNTER (Shows all notices for students)
-------------------------------------------- */
$user_id = $_SESSION["id"]; // logged-in student id
// Get UNREAD notices only
$noticeCountStmt = $pdo->prepare("
SELECT COUNT(*) FROM notices n
WHERE n.visible_to IN ('all','students')
AND n.id NOT IN (
SELECT notice_id FROM notice_reads WHERE user_id = :uid
)
");
$noticeCountStmt->execute(["uid" => $user_id]);
$notice_count = $noticeCountStmt->fetchColumn();
/* -------------------------------------------
MESSAGE COUNTER (unread messages)
-------------------------------------------- */
$msgCountStmt = $pdo->prepare("
SELECT COUNT(*)
FROM messages
WHERE recipient_id = ? AND is_read = 0
");
$msgCountStmt->execute([$user_id]);
$message_count = $msgCountStmt->fetchColumn();
//result
$resultsStmt = $pdo->prepare("
SELECT r.* FROM results r
JOIN students s ON r.student_id = s.id
WHERE s.user_id = ?
ORDER BY r.id DESC
");
$resultsStmt->execute([$user_id]);
$results = $resultsStmt->fetchAll(PDO::FETCH_ASSOC);
//timetable
$timetableStmt = $pdo->prepare("
SELECT
t.day,
t.start_time,
t.end_time,
t.venue,
c.code AS course_code,
c.title AS course_title,
s.subject_title,
u.full_name AS lecturer_name
FROM timetables t
JOIN (
SELECT DISTINCT course_id
FROM registrations
WHERE user_id = ?
) r ON t.course_id = r.course_id
JOIN courses c ON t.course_id = c.id
LEFT JOIN course_subjects s ON t.subject_id = s.id
LEFT JOIN users u ON t.teacher_id = u.id
ORDER BY
FIELD(t.day,'Friday','Saturday','Sunday'),
t.start_time
");
$timetableStmt->execute([$user_id]);
$timetable = $timetableStmt->fetchAll(PDO::FETCH_ASSOC);
//payment
$paymentsStmt = $pdo->prepare("
SELECT * FROM payments
WHERE student_id = ?
ORDER BY created_at DESC
");
$paymentsStmt->execute([$student['id']]);
$payments = $paymentsStmt->fetchAll(PDO::FETCH_ASSOC);
$msgStmt = $pdo->prepare("
SELECT m.*, u.full_name AS sender_name
FROM messages m
LEFT JOIN users u ON m.sender_id = u.id
WHERE m.recipient_id = ?
ORDER BY m.id DESC LIMIT 6
");
$msgStmt->execute([$user_id]);
$messages = $msgStmt->fetchAll(PDO::FETCH_ASSOC);
$examsStmt = $pdo->prepare("
SELECT * FROM exams
WHERE (department_id = ? OR department_id IS NULL)
AND (start_at IS NULL OR start_at <= NOW())
AND (end_at IS NULL OR end_at >= NOW())
");
$examsStmt->execute([$student['department_id']]);
$exams = $examsStmt->fetchAll(PDO::FETCH_ASSOC);
$courses = $pdo->query("
SELECT c.*, d.name AS dept
FROM courses c
LEFT JOIN departments d ON c.department_id = d.id
ORDER BY c.code
")->fetchAll(PDO::FETCH_ASSOC);
$regStmt = $pdo->prepare("
SELECT r.*, c.code, c.title
FROM registrations r
JOIN courses c ON r.course_id = c.id
WHERE r.user_id = ?
ORDER BY r.created_at DESC
");
$regStmt->execute([$user_id]);
$registrations = $regStmt->fetchAll(PDO::FETCH_ASSOC);
$userQuery = $pdo->prepare("
SELECT full_name, student_id, reg_number
FROM users
WHERE id = ?
");
$userQuery->execute([$_SESSION['id']]);
$userData = $userQuery->fetch(PDO::FETCH_ASSOC);
$regData = $pdo->prepare("
SELECT
r.course_id, r.subject_id,
c.title AS course_title,
c.code AS course_code,
l.level_name,
s.subject_code,
s.subject_title
FROM registrations r
JOIN courses c ON r.course_id = c.id
JOIN levels l ON c.level_id = l.id
JOIN course_subjects s ON r.subject_id = s.id
WHERE r.user_id = ?
");
$regData->execute([$user_id]);
$studentRegistrations = $regData->fetchAll(PDO::FETCH_ASSOC);
$gradesStmt = $pdo->prepare("
SELECT
s.*,
a.title AS assignment_title
FROM assignment_submissions s
JOIN assignments a ON s.assignment_id = a.id
WHERE s.user_id = ?
ORDER BY s.id DESC
");
$gradesStmt->execute([$user_id]);
$assignment_grades = $gradesStmt->fetchAll(PDO::FETCH_ASSOC);
//video session
$stmt = $pdo->prepare("
SELECT lc.*
FROM live_classes lc
WHERE lc.status IN ('scheduled','live')
AND EXISTS (
SELECT 1
FROM registrations r
WHERE r.course_id = lc.course_id
AND r.user_id = ?
)
");
$stmt->execute([$user_id]);
$liveClasses = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html>
<head>
<title>Student Dashboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="students_dashboard.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
</head>
<body>
<!-- SIDEBAR -->
<div class="sidebar">
<!-- Profile Section -->
<div class="sidebar-profile">
<img class="sidebar-avatar"
src="uploads/profile_pic/<?= htmlspecialchars($student['profile_pic'] ?? 'default.png') ?>"
id="pic_preview">
<div class="sidebar-user">
<p class="hello">👋 Hi,</p>
<p class="username"><?= htmlspecialchars($_SESSION['fullname']) ?></p>
</div>
</div>
<div class="sidebar-title">PIEDELITE</div>
<div class="sidebar-menu">
<button onclick="openAndScroll('profile')" id="nav-profile">
<i class="fa fa-user"></i> Profile
</button>
<button onclick="openNoticePopup()" id="nav-notices">
<i class="fa fa-bullhorn"></i> Notices
<span class="badge" id="noticeBadge"><?= $notice_count ?>
<?php if ($notice_count == 0): ?>
<script>
document.getElementById("noticeBadge").style.display = "none";
</script>
<?php endif; ?>
</span>
</button>
<button onclick="openMessagePopup()" id="nav-messages">
<i class="fa fa-envelope"></i> Inbox
<span class="badge" id="messageBadge"><?= $message_count ?>
</button>
<?php if ($message_count == 0): ?>
<script>
document.getElementById("messageBadge").style.display = "none";
</script>
<?php endif; ?></span>
<button onclick="openAssignmentPopup()" id="nav-assignments">
<i class="fa fa-file-alt"></i>Assignment <span class="badge" id="assignmentBadge"><?= $assignment_unread_count ?></span>
</button>
<?php if($assignment_unread_count == 0): ?>
<script>
document.getElementById("assignmentBadge").style.display = "none";
</script>
<?php endif; ?></span>
<button onclick="openAndScroll('results')" id="nav-results">
<i class="fa fa-chart-column"></i>Result
</button>
<button onclick="openAndScroll('timetable')" id="nav-timetable">
<i class="fa fa-calendar"></i> Timetable / Calander
</button>
<button onclick="openAndScroll('live-classes')" id="nav-live-classes">
<i class="fa fa-video"></i> Live Classes
<?php if ($live_class_count > 0): ?>
<span class="badge"><?= $live_class_count ?></span>
<?php endif; ?>
</button>
<button onclick="openAndScroll('learning-resources')" id="nav-learning-resources">
<i class="fa fa-book"></i> Learning Resources
</button>
<button onclick="openRegistrationModal()">
<i class="fa fa-book"></i> Registration
</button>
<button onclick="openAndScroll('exams')" id="nav-exams">
<i class="fa fa-file-invoice"></i> Exams
</button>
</div>
</div>
<!-- MAIN SECTION -->
<div class="main">
<!-- TOP BAR -->
<div class="topbar">
<!-- LEFT -->
<div class="topbar-left">
<span class="role-badge"><?= strtoupper($_SESSION['role']); ?></span>
<span class="dept-badge">
<i class="fa fa-building"></i> <?= htmlspecialchars($student['department_name']); ?>
</span>
<span class="attendance present">
<i class="fa fa-check-circle"></i> Present: <?= $present ?>
</span>
<span class="attendance absent">
<i class="fa fa-times-circle"></i> Absent: <?= $absent ?>
</span>
</div>
<!-- RIGHT -->
<div class="topbar-right">
<div class="level-course-box">
<div class="level-course-box">
<!-- LEVEL (unchanged) -->
<div>
<i class="fa fa-layer-group"></i>
<?= $studentRegistrations ? $studentRegistrations[0]['level_name'] : "Not registered" ?>
</div>
<!-- COURSES — unique and safe for your CSS -->
<?php
if ($studentRegistrations) {
// Collect unique courses without affecting layout
$unique = [];
foreach ($studentRegistrations as $r) {
$unique[$r['course_id']] = $r; // keeps only one per course
}
foreach ($unique as $course):
?>
<div>
<i class="fa fa-book"></i>
<?= $course['course_code'] ?> - <?= $course['course_title'] ?>
</div>
<?php
endforeach;
} else {
?>
<div>
Not registered
</div>
<?php } ?>
</div>
</div>
<div class="topbar-profile">
<img src="uploads/profile_pic/<?= htmlspecialchars($student['profile_pic'] ?? 'default.png') ?>" class="topbar-pic">
<div class="topbar-dropdown">
<a onclick="openSection('profile')"><i class="fa fa-user"></i> My Profile</a>
<a onclick="openSection('messages')"><i class="fa fa-envelope"></i> Messages</a>
<a onclick="openSection('settings')"><i class="fa fa-gear"></i> Settings</a>
<a href="logout.php" class="logout"><i class="fa fa-power-off"></i> Logout</a>
</div>
</div>
</div>
</div>
<!-- CONTENT -->
<div class="content">
<!-- PROFILE SECTION -->
<div class="section active" id="profile">
<div class="profile-header">
<div class="avatar-box">
<img src="logo.jpeg" class="logome">
</div>
<div class="profile-basic">
<h2 class="student-name"><?= $_SESSION["fullname"]; ?></h2>
<div class="student-meta">
<span><i class="fa fa-hashtag"></i> ID: <?= htmlspecialchars($userData['student_id']); ?></span>
<span><i class="fa fa-id-card"></i> Reg: <?= htmlspecialchars($userData['reg_number']); ?></span>
<span><i class="fa fa-envelope"></i> <?= $student["email"]; ?></span>
</div>
</div>
</div>
<div class="panel">
<div class="panel-title">📘 Student Profile Overview</div>
<div class="profile-grid">
<div class="profile-item">
<label><i class="fa fa-phone"></i> Phone</label>
<div><?= $student["phone"]; ?></div>
</div>
<div class="profile-item">
<label><i class="fa fa-signature"></i> First Name</label>
<div><?= $student["first_name"]; ?></div>
</div>
<div class="profile-item">
<label><i class="fa fa-signature"></i> Last Name</label>
<div><?= $student["last_name"]; ?></div>
</div>
<div class="profile-item">
<label><i class="fa fa-calendar"></i> Date of Birth</label>
<div><?= $student["dob"]; ?></div>
</div>
<div class="profile-item">
<label><i class="fa fa-location-dot"></i> Address</label>
<div><?= $student["address"]; ?></div>
</div>
<div class="profile-item">
<label><i class="fa fa-phone-alt"></i> Emergency Phone</label>
<div><?= $student["emergency_phone"]; ?></div>
</div>
</div>
<a href="update_student_profile.php" class="edit-btn">Edit Profile</a>
</div>
</div>
<br><br>
<tr>
<td class="section-title"></td>
<td>
<?php if ($studentRegistrations): ?>
<div class="subject-wrapper">
<h3 class="subject-header">Registered Subjects</h3>
<div class="subjects-grid">
<?php foreach ($studentRegistrations as $sub): ?>
<div class="subject-card">
<div class="subject-icon">
<span><?= strtoupper(substr($sub['subject_title'], 0, 1)) ?></span>
</div>
<div class="subject-info">
<div class="sub-title"><?= $sub['subject_title'] ?></div>
<div class="sub-code"><?= $sub['subject_code'] ?></div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php else: ?>
<div class="no-subjects">No subjects registered.</div>
<?php endif; ?>
</td>
</tr>
<!-- NOTICES -->
<center><div class="section" id="notices">
<h3>📢 Latest School Notices</h3>
<?php if (empty($notices)): ?>
<p>No notices available.</p>
<?php endif; ?>
<?php foreach ($notices as $n): ?>
<div class="card">
<strong><?= htmlspecialchars($n['title']); ?></strong>
<br>
<small style="color:gray;">
Posted on <?= date("M d, Y", strtotime($n['created_at'])); ?>
</small>
<p><?= nl2br(htmlspecialchars($n['body'])); ?></p>
</div>
<?php endforeach; ?>
</div></center>
<!-- INBOX -->
<div class="section" id="messages">
<h3>📨 Messages</h3>
<?php foreach ($messages as $m): ?>
<div class="card">
<strong><?= $m['subject']; ?></strong><br>
<em>From: <?= $m['sender_name']; ?></em>
<p><?= $m['body']; ?></p>
</div>
<?php endforeach; ?>
</div>
<!-- ASSIGNMENTS -->
<?php if ($assignment_unread_count == 0): ?>
<script>document.addEventListener('DOMContentLoaded', ()=> {
const b = document.getElementById('assignmentBadge'); if(b) b.style.display='none';
});</script>
<?php endif; ?></span>
<!-- LEARNING RESOURCES -->
<section class="lms-card" id="learning-resources">
<div class="card-header">
<h3>📚 Learning Resources</h3>
<p>Download lecture notes, slides, PDFs, and audio tutorials</p>
</div>
<?php
// Fetch resources assigned to this student 👈 HERE
$stmt = $pdo->prepare("
SELECT
r.*,
c.title AS course_title,
l.level_name,
cs.subject_title
FROM resources r
JOIN courses c ON r.course_id = c.id
JOIN levels l ON c.level_id = l.id
LEFT JOIN course_subjects cs ON r.subject_id = cs.id
WHERE r.course_id IN (
SELECT course_id
FROM registrations
WHERE user_id = :uid
)
ORDER BY r.uploaded_at DESC
");
$stmt->execute([
'uid' => $user_id
]);
$resources = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<?php if (empty($resources)): ?>
<div class="empty-state">
<p>📭 No learning resources uploaded yet.</p>
</div>
<?php else: ?>
<div class="table-responsive">
<table class="lms-table">
<thead>
<tr>
<th>Level</th>
<th>Course</th>
<th>Subject</th>
<th>Resource</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php foreach ($resources as $r): ?>
<tr>
<td>
<span class="badge badge-level">
<?= htmlspecialchars($r['level_name']) ?>
</span>
</td>
<td><?= htmlspecialchars($r['course_title']) ?></td>
<td><?= htmlspecialchars($r['subject_title'] ?? 'General') ?></td>
<td class="file-name">
📄 <?= htmlspecialchars($r['filename']) ?>
</td>
<td><?= date("d M Y", strtotime($r['uploaded_at'])) ?></td>
<td class="actions">
<?php if (isVideo($r['filename'])): ?>
<?php
$ext = strtolower(pathinfo($r['filename'], PATHINFO_EXTENSION));
$mime = match ($ext) {
'webm' => 'video/webm',
'ogg' => 'video/ogg',
default => 'video/mp4'
};
?>
<div style="margin-top:6px;">
<a class="btn download"
href="<?= htmlspecialchars($r['filepath']) ?>"
download>
⬇ Download
</a>
</div>
<?php else: ?>
<?php if (isVideo($r['filename'])): ?>
<video width="100" height="40" controls preload="metadata">
<source src="<?= htmlspecialchars($r['filepath']) ?>" type="video/mp4">
Your browser does not support the video tag.
</video>
<?php else: ?>
<a href="<?= htmlspecialchars($r['filepath']) ?>" download>Download</a> |
<a href="<?= htmlspecialchars($r['filepath']) ?>" target="_blank">View</a>
<?php endif; ?>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</section>
<!-- RESULTS -->
<div class="section" id="results">
<h3>📊 Assignment Grades</h3>
<?php if (empty($assignment_grades)): ?>
<p>No grades available yet.</p>
<?php endif; ?>
<?php foreach ($assignment_grades as $g): ?>
<div class="card">
<strong><?= htmlspecialchars($g['assignment_title']) ?></strong>
<div class="row">
Status:
<span class="grade-status <?= $g['graded'] ? 'graded' : 'pending' ?>">
<?= $g['graded'] ? 'Graded' : 'Pending' ?>
</span>
</div>
<div class="row">
Grade:
<span class="grade-value">
<?= $g['graded'] ? htmlspecialchars($g['grade']) : '—' ?>
</span>
</div>
<div class="grade-comment">
<?= $g['graded']
? nl2br(htmlspecialchars($g['grade_comment']))
: 'No feedback yet.'
?>
</div>
</div>
<?php endforeach; ?>
</div>
<!-- TIMETABLE -->
<div class="section" id="timetable">
<h3 class="section-title">📅 Weekly Lecture Timetable</h3>
<?php if (empty($timetable)): ?>
<div class="empty-state">
Timetable not yet published.
</div>
<?php else: ?>
<?php
// Group timetable by day
$days = ['Friday','Saturday','Sunday'];
$grouped = [];
foreach ($timetable as $t) {
$grouped[$t['day']][] = $t;
}
?>
<div class="calendar-grid">
<?php foreach ($days as $day): ?>
<div class="calendar-column">
<div class="calendar-day-header"><?= $day ?></div>
<?php if (!empty($grouped[$day])): ?>
<?php foreach ($grouped[$day] as $t): ?>
<div class="calendar-lecture">
<div class="calendar-time">
<?= date("H:i", strtotime($t['start_time'])) ?>
–
<?= date("H:i", strtotime($t['end_time'])) ?>
</div>
<div class="calendar-course">
<?= htmlspecialchars($t['course_code']) ?>
</div>
<div class="calendar-subject">
<?= htmlspecialchars($t['subject_title'] ?: 'General Lecture') ?>
</div>
<div class="calendar-lecturer">
👨🏫 <?= htmlspecialchars($t['lecturer_name'] ?: 'TBA') ?>
</div>
<div class="calendar-venue" value="pied campus">
📍 <?= htmlspecialchars($t['venue'] ?: 'TBA') ?>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<div class="calendar-empty">No lectures</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<div class="timetable-actions">
<button onclick="window.location='download_timetable.php'" class="download-btn">
⬇ Download Timetable (PDF)
</button>
</div>
<?php endif; ?>
</div>
<!-- PAYMENTS -->
<div class="section" id="payments">
<h3>💳 Payments</h3>
<?php foreach ($payments as $p): ?>
<div class="card">
₵<?= $p['amount']; ?> — <strong><?= strtoupper($p['status']); ?></strong>
</div>
<?php endforeach; ?>
</div>
<!-- EXAMS -->
<div class="section" id="exams">
<h3>🧾 Available Exams</h3>
<?php foreach ($exams as $e): ?>
<div class="card">
<strong><?= $e['title']; ?></strong><br><br>
<button onclick="alert('Load exam in center section…')">Take Exam</button>
</div>
<?php endforeach; ?>
</div>
<!-- LIVE CLASSES -->
<div class="section" id="live-classes">
<h3>📡 Live Classes</h3>
<?php
$now = date('Y-m-d H:i:s');
?>
<?php if (empty($liveClasses)): ?>
<p>No live classes scheduled.</p>
<?php endif; ?>
<?php foreach ($liveClasses as $class): ?>
<div class="card">
<strong><?= htmlspecialchars($class['title'] ?? 'Live Class') ?></strong>