prepare($query); $stmt->execute([$school_id, $threshold]); $low_performers = $stmt->fetchAll(PDO::FETCH_ASSOC); if (isset($_POST['send_notifications'])) { $sent_count = 0; $fail_count = 0; $use_ai = isset($_POST['use_ai']); foreach ($low_performers as $learner) { if (empty($learner['parent_email'])) { $fail_count++; continue; } $avg = round($learner['average_percent'], 1); $subject = "Urgent: Academic Progress Report for " . $learner['full_name']; $htmlBody = "

Academic Progress Alert

Dear Parent,

This is an automated notification regarding the academic performance of {$learner['full_name']} (ID: {$learner['student_id']}).

The current academic average is {$avg}%, which is below the school's monitoring threshold of {$threshold}%.

We encourage you to log into the Parent Portal using the Student ID to view detailed assessment marks and discuss this with the class teacher.

Best Regards,
School Administration

"; if ($use_ai) { $ai_prompt = "Generate a short, encouraging, and supportive email to a parent whose child, {$learner['full_name']}, is currently averaging {$avg}% in school (threshold is {$threshold}%). The tone should be professional yet empathetic. Mention that they can check the portal with ID {$learner['student_id']}. Keep it under 150 words."; $ai_resp = LocalAIApi::createResponse([ 'input' => [ ['role' => 'system', 'content' => 'You are an educational assistant helping schools communicate with parents.'], ['role' => 'user', 'content' => $ai_prompt], ], ]); if (!empty($ai_resp['success'])) { $ai_text = LocalAIApi::extractText($ai_resp); if ($ai_text) { $htmlBody = nl2br(htmlspecialchars($ai_text)); } } } $res = MailService::sendMail($learner['parent_email'], $subject, $htmlBody); if (!empty($res['success'])) { $sent_count++; } else { $fail_count++; } } $message = "Successfully sent $sent_count notifications. (Failed/Missing Email: $fail_count)"; // Refresh list $stmt->execute([$school_id, $threshold]); $low_performers = $stmt->fetchAll(PDO::FETCH_ASSOC); } include 'includes/header.php'; ?>

Automated Performance Notifications

Notify parents of learners performing below a specific threshold.

Settings
Currently showing learners with average < %
Only learners with a Parent Email defined will receive notifications.
Learners Below Threshold (%)
Learner Grade Average Parent Email
No learners found below this threshold.
ID:
Grade % Missing' ?>