beginTransaction(); $stmt = $db->prepare("INSERT INTO attendance (learner_id, status, date) VALUES (:learner_id, :status, :date) ON DUPLICATE KEY UPDATE status = VALUES(status)"); foreach ($_POST['attendance'] as $learner_id => $status) { $stmt->execute([ 'learner_id' => $learner_id, 'status' => $status, 'date' => $date ]); } $db->commit(); $message = "Attendance saved successfully for $date."; } catch (Exception $e) { $db->rollBack(); $message = "Error: " . $e->getMessage(); } } // Fetch Learners and their current attendance for today $query = "SELECT l.*, a.status as today_status FROM learners l LEFT JOIN attendance a ON l.id = a.learner_id AND a.date = :date ORDER BY l.full_name ASC"; $stmt = $db->prepare($query); $stmt->execute(['date' => $date]); $learners = $stmt->fetchAll(); // Stats $total_learners = count($learners); $present_count = 0; foreach ($learners as $l) { if ($l['today_status'] === 'present') $present_count++; } $presence_rate = $total_learners > 0 ? round(($present_count / $total_learners) * 100) : 0; // Project Info $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Education Ecosystem Platform for South African Schools'; $projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? ''; ?>
Daily attendance for = date('l, d F Y') ?>
Total Learners
Presence Rate
Pending Reports