37970-vm/parent.php
Flatlogic Bot e29ef2dff4 v2
2026-01-30 14:21:32 +00:00

135 lines
5.8 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
$db = db();
$current_role = 'Parent';
$pageTitle = 'Parent Portal | Township Schools Platform';
$learner = null;
$attendance_history = [];
$search_id = $_GET['student_id'] ?? '';
if ($search_id) {
// Fetch Learner
$stmt = $db->prepare("SELECT * FROM learners WHERE student_id = ?");
$stmt->execute([$search_id]);
$learner = $stmt->fetch();
if ($learner) {
// Fetch Attendance History (Last 30 days)
$stmt = $db->prepare("SELECT * FROM attendance WHERE learner_id = ? ORDER BY date DESC LIMIT 30");
$stmt->execute([$learner['id']]);
$attendance_history = $stmt->fetchAll();
}
}
include 'includes/header.php';
?>
<div class="container pb-5">
<div class="row mb-4">
<div class="col-12">
<h2 class="h4 mb-1">Parent Engagement Portal</h2>
<p class="text-muted small">Stay updated on your child's progress with minimal data usage.</p>
</div>
</div>
<div class="row g-4">
<div class="col-md-4">
<div class="card p-4">
<h5 class="mb-3">Find My Child</h5>
<form method="GET">
<div class="mb-3">
<label class="form-label small">Student ID / National ID</label>
<input type="text" name="student_id" class="form-control" placeholder="e.g. STU10023" value="<?= htmlspecialchars($search_id) ?>" required>
</div>
<button type="submit" class="btn btn-primary w-100">
<i class="bi bi-search me-2"></i> View Progress
</button>
</form>
</div>
<?php if ($search_id && !$learner): ?>
<div class="alert alert-warning mt-3">
<i class="bi bi-exclamation-triangle me-2"></i> No learner found with ID <strong><?= htmlspecialchars($search_id) ?></strong>. Please contact the school office.
</div>
<?php endif; ?>
</div>
<div class="col-md-8">
<?php if ($learner): ?>
<div class="card mb-4">
<div class="card-header bg-white py-3">
<h5 class="mb-0">Learner Profile: <strong><?= htmlspecialchars($learner['full_name']) ?></strong></h5>
</div>
<div class="card-body">
<div class="row text-center">
<div class="col-4">
<p class="text-muted small mb-1">Grade</p>
<h6><?= htmlspecialchars($learner['grade']) ?></h6>
</div>
<div class="col-4">
<p class="text-muted small mb-1">Attendance</p>
<?php
$total = count($attendance_history);
$present = 0;
foreach ($attendance_history as $a) if ($a['status'] === 'present') $present++;
$rate = $total > 0 ? round(($present / $total) * 100) : 0;
?>
<h6><?= $rate ?>%</h6>
</div>
<div class="col-4">
<p class="text-muted small mb-1">Status</p>
<span class="badge bg-success">Enrolled</span>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header bg-white py-3">
<h5 class="mb-0">Recent Attendance</h5>
</div>
<div class="card-body p-0">
<div class="table-responsive">
<table class="table table-hover mb-0">
<thead>
<tr>
<th class="ps-4">Date</th>
<th class="text-end pe-4">Status</th>
</tr>
</thead>
<tbody>
<?php if (empty($attendance_history)): ?>
<tr>
<td colspan="2" class="text-center py-4 text-muted">No attendance records found for the last 30 days.</td>
</tr>
<?php endif; ?>
<?php foreach ($attendance_history as $record): ?>
<tr>
<td class="ps-4"><?= date('l, d M Y', strtotime($record['date'])) ?></td>
<td class="text-end pe-4">
<?php if ($record['status'] === 'present'): ?>
<span class="badge bg-success">Present</span>
<?php else: ?>
<span class="badge bg-danger">Absent</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php else: ?>
<div class="h-100 d-flex flex-column align-items-center justify-content-center text-muted py-5 border rounded bg-white">
<i class="bi bi-person-badge mb-3" style="font-size: 3rem; opacity: 0.3;"></i>
<p>Please enter a Student ID to view details.</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>