-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparent.php
More file actions
511 lines (472 loc) · 29.6 KB
/
Copy pathparent.php
File metadata and controls
511 lines (472 loc) · 29.6 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
<?php
declare(strict_types=1);
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/app/helpers.php';
require_once __DIR__ . '/config/database.php';
require_once __DIR__ . '/app/auth.php';
require_once __DIR__ . '/app/parents.php';
require_once __DIR__ . '/app/grades.php';
require_once __DIR__ . '/app/announcements.php';
require_once __DIR__ . '/app/theme_settings.php';
function parent_portal_format_date(?string $value, string $format = 'D, M j, Y'): string
{
if ($value === null || $value === '') {
return '-';
}
$timestamp = strtotime($value);
return $timestamp === false ? $value : date($format, $timestamp);
}
function parent_portal_format_time(?string $value): string
{
if ($value === null || $value === '') {
return '-';
}
$timestamp = strtotime($value);
return $timestamp === false ? $value : date('h:i A', $timestamp);
}
parent_portal_bootstrap();
grade_book_bootstrap();
announcements_bootstrap();
theme_settings_bootstrap();
$user = require_roles(['parent']);
$linkedLearners = parent_linked_learners((int) $user['id']);
$filters = parent_portal_filters($linkedLearners);
$selectedChild = parent_portal_selected_child($linkedLearners, $filters['child_id']);
$selectedMonthLabel = parent_portal_month_label($filters['report_month']);
$adminAnnouncements = announcement_list(['role' => 'admin', 'is_published' => 1]);
$teacherAnnouncements = announcement_for_parent((int) $user['id']);
$allAnnouncements = array_merge($adminAnnouncements, $teacherAnnouncements);
usort($allAnnouncements, static fn ($a, $b) => strtotime($b['published_at'] ?? $b['created_at']) <=> strtotime($a['published_at'] ?? $a['created_at']));
$attendanceRows = [];
$attendanceSummary = parent_child_month_summary([]);
$gradeHistoryGroups = [];
if ($selectedChild !== null) {
$attendanceRows = parent_child_month_attendance(
(int) $user['id'],
(int) $selectedChild['id'],
$filters['report_month']
);
$attendanceSummary = parent_child_month_summary($attendanceRows);
$gradeHistoryGroups = grade_group_history_by_level(
grade_parent_child_history((int) $user['id'], (int) $selectedChild['id'])
);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo escape(APP_NAME); ?> Parent Portal</title>
<?php echo theme_stylesheet_markup(); ?>
<link rel="stylesheet" href="<?php echo escape(asset_url('assets/css/app.css')); ?>">
<style>
.parent-child-photo {
width: 56px;
height: 56px;
border-radius: 50%;
object-fit: cover;
flex-shrink: 0;
border: 2px solid var(--surface-strong, #fff);
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.learner-header-row.with-photo .learner-photo-frame {
width: 96px;
height: 96px;
flex-shrink: 0;
}
.parent-child-detail.health-detail {
font-size: 0.8125rem; /* 13px */
opacity: 0.85;
margin-top: 4px;
}
</style>
</head>
<body class="dashboard-body">
<main class="dashboard-shell fullscreen-shell">
<header class="topbar">
<div class="header-title-block">
<img class="school-logo" src="<?php echo escape(school_logo_url()); ?>" alt="School logo">
<div class="header-copy">
<p class="eyebrow">Parent Portal</p>
<h1>Child Attendance</h1>
</div>
</div>
<div class="topbar-actions">
<p class="signed-in-as">Signed in as <?php echo escape($user['username']); ?></p>
<a href="<?php echo escape(route_url('change_password.php')); ?>" class="secondary-link">Change Password</a>
<a href="<?php echo escape(route_url('logout.php')); ?>" class="secondary-link">Logout</a>
</div>
</header>
<section class="parent-portal-grid">
<aside class="parent-overview-stack">
<article class="parent-panel-card">
<div class="panel-heading">
<h2>Family Overview</h2>
<p>Parents can review their linked child attendance records month by month.</p>
</div>
<div class="summary-grid parent-summary-grid">
<div class="summary-card">
<span class="summary-code">Linked Children</span>
<strong><?php echo escape((string) count($linkedLearners)); ?></strong>
<small>Available in this portal</small>
</div>
<div class="summary-card">
<span class="summary-code">Viewing Month</span>
<strong><?php echo escape(date('M Y', strtotime($filters['report_month'] . '-01'))); ?></strong>
<small>Active month filter</small>
</div>
</div>
</article>
<article class="parent-panel-card">
<div class="panel-heading">
<h2>Linked Children</h2>
<p>Select a child to switch the attendance log view.</p>
</div>
<?php if ($linkedLearners === []): ?>
<div class="alert neutral">No linked learners are available for this parent account yet.</div>
<?php else: ?>
<div class="parent-child-grid">
<?php foreach ($linkedLearners as $child): ?>
<a
href="<?php echo escape(route_url('parent.php?child_id=' . urlencode((string) $child['id']) . '&report_month=' . urlencode($filters['report_month']))); ?>"
class="parent-child-card<?php echo (string) $child['id'] === $filters['child_id'] ? ' is-active' : ''; ?>"
>
<!-- <img class="parent-child-photo" src="<?php echo escape(learner_photo_url($child['lrn'])); ?>" alt="Photo of <?php echo escape(trim($child['first_name'] . ' ' . $child['last_name'])); ?>"> -->
<div class="parent-child-card-content">
<p class="parent-child-eyebrow">
<?php echo escape($child['relationship']); ?>
<?php echo (int) $child['is_primary_contact'] === 1 ? ' • Primary contact' : ''; ?>
</p>
<h3>
<?php echo escape(trim($child['first_name'] . ' ' . $child['middle_name'] . ' ' . $child['last_name'])); ?>
</h3>
<p class="parent-child-detail"><?php echo escape($child['grade_level'] . ' - ' . $child['section_name']); ?></p>
<p class="parent-child-detail">LRN: <?php echo escape($child['lrn']); ?></p>
<p class="parent-child-detail health-detail">
<?php echo escape('H: ' . ($child['height_cm'] ?? '-') . 'cm'); ?> •
<?php echo escape('W: ' . ($child['weight_kg'] ?? '-') . 'kg'); ?> •
<?php echo escape('BMI: ' . $child['bmi_remarks']); ?>
</p>
</div>
<div class="parent-child-footer">
<strong><?php echo escape($child['latest_attendance_status']); ?></strong>
<span><?php echo escape(parent_portal_format_date($child['latest_attendance_date'], 'M j, Y')); ?></span>
</div>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</article>
</aside>
<section class="parent-history-stack">
<article class="parent-panel-card">
<div class="panel-heading">
<h2>Attendance Filters</h2>
<p>Choose a child and month to review attendance records.</p>
</div>
<form method="get" class="report-filter-grid parent-filter-grid">
<div class="report-filter-field report-filter-field-wide">
<label for="child_id">Child</label>
<select id="child_id" name="child_id"<?php echo $linkedLearners === [] ? ' disabled' : ''; ?>>
<?php if ($linkedLearners === []): ?>
<option value="">No linked learners</option>
<?php else: ?>
<?php foreach ($linkedLearners as $child): ?>
<option value="<?php echo escape((string) $child['id']); ?>"<?php echo (string) $child['id'] === $filters['child_id'] ? ' selected' : ''; ?>>
<?php echo escape(trim($child['last_name'] . ', ' . $child['first_name'] . ' ' . $child['middle_name']) . ' [' . $child['lrn'] . ']'); ?>
</option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
<div class="report-filter-field">
<label for="report_month">Month</label>
<input id="report_month" name="report_month" type="month" value="<?php echo escape($filters['report_month']); ?>">
</div>
<div class="report-actions">
<button type="submit" class="primary-button"<?php echo $linkedLearners === [] ? ' disabled' : ''; ?>>View Attendance</button>
<a href="<?php echo escape(route_url('parent.php')); ?>" class="secondary-link">Reset</a>
</div>
</form>
</article>
<?php if ($selectedChild !== null): ?>
<article class="parent-panel-card">
<div class="learner-header-row with-photo">
<div class="learner-photo-frame">
<img class="learner-photo" src="<?php echo escape(learner_photo_url($selectedChild['lrn'])); ?>" alt="Photo of <?php echo escape(trim($selectedChild['first_name'] . ' ' . $selectedChild['last_name'])); ?>">
</div>
<div class="learner-summary">
<h3><?php echo escape(trim($selectedChild['first_name'] . ' ' . $selectedChild['middle_name'] . ' ' . $selectedChild['last_name'])); ?></h3>
<p>Attendance records for <?php echo escape($selectedMonthLabel); ?>.</p>
</div>
</div>
<dl class="detail-grid wide">
<div>
<dt>LRN</dt>
<dd><?php echo escape($selectedChild['lrn']); ?></dd>
</div>
<div>
<dt>Grade Level</dt>
<dd><?php echo escape($selectedChild['grade_level']); ?></dd>
</div>
<div>
<dt>Section</dt>
<dd><?php echo escape($selectedChild['section_name']); ?></dd>
</div>
<div>
<dt>School Year</dt>
<dd><?php echo escape($selectedChild['school_year_label']); ?></dd>
</div>
<div>
<dt>Relationship</dt>
<dd><?php echo escape($selectedChild['relationship']); ?></dd>
</div>
<div>
<dt>Primary Contact</dt>
<dd><?php echo (int) $selectedChild['is_primary_contact'] === 1 ? 'Yes' : 'No'; ?></dd>
</div>
<div>
<dt>Latest Status</dt>
<dd><?php echo escape($selectedChild['latest_attendance_status']); ?></dd>
</div>
<div>
<dt>Latest Attendance Date</dt>
<dd><?php echo escape(parent_portal_format_date($selectedChild['latest_attendance_date'])); ?></dd>
</div>
<div>
<dt>Height</dt>
<dd><?php echo escape($selectedChild['height_cm'] !== null ? $selectedChild['height_cm'] . ' cm' : '-'); ?></dd>
</div>
<div>
<dt>Weight</dt>
<dd><?php echo escape($selectedChild['weight_kg'] !== null ? $selectedChild['weight_kg'] . ' kg' : '-'); ?></dd>
</div>
<div>
<dt>BMI</dt>
<dd><?php echo escape($selectedChild['bmi'] !== null ? (string) $selectedChild['bmi'] : '-'); ?></dd>
</div>
<div>
<dt>BMI Remarks</dt>
<dd><?php echo escape($selectedChild['bmi_remarks']); ?></dd>
</div>
</dl>
</article>
<article class="parent-panel-card">
<div class="panel-heading compact-heading">
<h2>Monthly Attendance Logs</h2>
<p>Showing <?php echo escape((string) count($attendanceRows)); ?> recorded day(s) for <?php echo escape($selectedMonthLabel); ?>.</p>
</div>
<div class="parent-month-summary-grid">
<div class="summary-card">
<span class="summary-code">Recorded Days</span>
<strong><?php echo escape((string) $attendanceSummary['days_with_records']); ?></strong>
<small>Days with attendance entries</small>
</div>
<div class="summary-card">
<span class="summary-code">Attended</span>
<strong><?php echo escape((string) $attendanceSummary['attended_days']); ?></strong>
<small>Present or late days</small>
</div>
<div class="summary-card">
<span class="summary-code">Present</span>
<strong><?php echo escape((string) $attendanceSummary['present_count']); ?></strong>
<small>Marked present</small>
</div>
<div class="summary-card">
<span class="summary-code">Late</span>
<strong><?php echo escape((string) $attendanceSummary['late_count']); ?></strong>
<small>Marked late</small>
</div>
<div class="summary-card">
<span class="summary-code">Absent</span>
<strong><?php echo escape((string) $attendanceSummary['absent_count']); ?></strong>
<small>Marked absent</small>
</div>
<div class="summary-card">
<span class="summary-code">Excused</span>
<strong><?php echo escape((string) $attendanceSummary['excused_count']); ?></strong>
<small>Marked excused</small>
</div>
</div>
<div class="table-shell">
<table class="records-table">
<thead>
<tr>
<th>Date</th>
<th>Status</th>
<th>AM In</th>
<th>AM Out</th>
<th>PM In</th>
<th>PM Out</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<?php if ($attendanceRows === []): ?>
<tr>
<td colspan="7" class="empty-row">No attendance records were found for the selected child and month.</td>
</tr>
<?php else: ?>
<?php foreach ($attendanceRows as $row): ?>
<tr>
<td><?php echo escape(parent_portal_format_date($row['attendance_date'])); ?></td>
<td><span class="table-status"><?php echo escape($row['attendance_status']); ?></span></td>
<td><?php echo escape(parent_portal_format_time($row['am_time_in'])); ?></td>
<td><?php echo escape(parent_portal_format_time($row['am_time_out'])); ?></td>
<td><?php echo escape(parent_portal_format_time($row['pm_time_in'])); ?></td>
<td><?php echo escape(parent_portal_format_time($row['pm_time_out'])); ?></td>
<td><?php echo escape($row['remarks'] ?? '-'); ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</article>
<article class="parent-panel-card">
<div class="panel-heading compact-heading">
<h2>Grade History</h2>
<p>Subject grades are grouped by school year and grade level.</p>
</div>
<?php if ($gradeHistoryGroups === []): ?>
<div class="alert neutral">No grade records are available for this learner yet.</div>
<?php else: ?>
<div class="grade-history-stack">
<?php foreach ($gradeHistoryGroups as $gradeGroup): ?>
<?php $usesSeniorGradeLayout = grade_is_senior_high((string) $gradeGroup['grade_level']); ?>
<section class="grade-history-section">
<div class="monthly-report-info">
<p><strong>School Year:</strong> <?php echo escape($gradeGroup['school_year_label']); ?></p>
<p><strong>Grade:</strong> <?php echo escape($gradeGroup['grade_level']); ?></p>
<p><strong>Section:</strong> <?php echo escape($gradeGroup['section_name']); ?></p>
<p><strong>Grand Average:</strong> <?php echo escape($gradeGroup['grand_average'] !== null ? (string) $gradeGroup['grand_average'] : '-'); ?></p>
</div>
<div class="table-shell">
<?php if ($usesSeniorGradeLayout): ?>
<table class="records-table report-table">
<thead>
<tr>
<th colspan="4">First Semester</th>
</tr>
<tr>
<th>Subject</th>
<th>Q1</th>
<th>Q2</th>
<th>1st Sem Avg</th>
</tr>
</thead>
<tbody>
<?php foreach ($gradeGroup['rows'] as $gradeRow): ?>
<tr>
<td><?php echo escape($gradeRow['subject_name']); ?></td>
<td><?php echo escape($gradeRow['quarter_1_grade'] ?? '-'); ?></td>
<td><?php echo escape($gradeRow['quarter_2_grade'] ?? '-'); ?></td>
<td><?php echo escape($gradeRow['first_semester_average'] ?? '-'); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<table class="records-table report-table grade-semester-table">
<thead>
<tr>
<th colspan="6">Second Semester</th>
</tr>
<tr>
<th>Subject</th>
<th>Q3</th>
<th>Q4</th>
<th>2nd Sem Avg</th>
<th>Final Avg</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<?php foreach ($gradeGroup['rows'] as $gradeRow): ?>
<tr>
<td><?php echo escape($gradeRow['subject_name']); ?></td>
<td><?php echo escape($gradeRow['quarter_3_grade'] ?? '-'); ?></td>
<td><?php echo escape($gradeRow['quarter_4_grade'] ?? '-'); ?></td>
<td><?php echo escape($gradeRow['second_semester_average'] ?? '-'); ?></td>
<td><?php echo escape($gradeRow['final_average'] ?? '-'); ?></td>
<td><?php echo escape($gradeRow['remarks'] ?? '-'); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else: ?>
<table class="records-table report-table">
<thead>
<tr>
<th>Subject</th>
<th>Q1</th>
<th>Q2</th>
<th>Q3</th>
<th>Q4</th>
<th>Average</th>
<th>Final Avg</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<?php foreach ($gradeGroup['rows'] as $gradeRow): ?>
<tr>
<td><?php echo escape($gradeRow['subject_name']); ?></td>
<td><?php echo escape($gradeRow['quarter_1_grade'] ?? '-'); ?></td>
<td><?php echo escape($gradeRow['quarter_2_grade'] ?? '-'); ?></td>
<td><?php echo escape($gradeRow['quarter_3_grade'] ?? '-'); ?></td>
<td><?php echo escape($gradeRow['quarter_4_grade'] ?? '-'); ?></td>
<?php $quarterAverage = grade_quarter_average($gradeRow); ?>
<td><?php echo escape($quarterAverage !== null ? (string) $quarterAverage : '-'); ?></td>
<td><?php echo escape($gradeRow['final_average'] ?? '-'); ?></td>
<td><?php echo escape($gradeRow['remarks'] ?? '-'); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</section>
<?php endforeach; ?>
</div>
<?php endif; ?>
</article>
<?php else: ?>
<article class="parent-panel-card">
<div class="alert neutral">Choose a linked child to review monthly attendance logs.</div>
</article>
<?php endif; ?>
</section>
</section>
</main>
<?php if ($allAnnouncements !== [] && !isset($_SESSION['seen_parent_announcements'])): ?>
<div id="announcement-modal" class="modal-backdrop is-open">
<div class="modal-panel">
<div class="panel-heading">
<h2>Announcements</h2>
<p>Important updates from the school.</p>
</div>
<div class="teacher-link-stack">
<?php foreach ($allAnnouncements as $announcement): ?>
<article class="admin-module-card">
<div class="panel-heading compact-heading">
<h3><?php echo escape($announcement['title']); ?></h3>
<p>
Published by <?php echo escape($announcement['username'] ?? 'System'); ?>
on <?php echo escape(parent_portal_format_date($announcement['published_at'])); ?>
</p>
</div>
<p><?php echo nl2br(escape($announcement['content'])); ?></p>
</article>
<?php endforeach; ?>
</div>
<div class="modal-actions">
<button id="close-announcement-modal" type="button" class="primary-button">Close</button>
</div>
</div>
</div>
<?php $_SESSION['seen_parent_announcements'] = true; ?>
<?php endif; ?>
<script src="<?php echo escape(asset_url('assets/js/admin.js')); ?>"></script>
</body>
</html>