diff --git a/admin.php b/admin.php index ff469a1..91677e8 100644 --- a/admin.php +++ b/admin.php @@ -135,11 +135,14 @@ include 'includes/header.php'; Manage Learners - + + + + + + +
+
+
+
CSV Template Guide
+

Your CSV file should look like this:

+
Full Name,Grade,Student ID,Parent Email
+John Doe,10,SOW-101,parent@example.com
+Jane Smith,11,SOW-102,jane_parent@gmail.com
+Bob Brown,10,SOW-103,
+
    +
  • The first line is treated as a header and skipped.
  • +
  • Existing Student IDs will be updated.
  • +
  • Parent Email is used for automated performance notifications.
  • +
+
+
+
+ + + + \ No newline at end of file diff --git a/includes/header.php b/includes/header.php index aa5560b..d5d0b15 100644 --- a/includes/header.php +++ b/includes/header.php @@ -76,6 +76,12 @@ $is_logged_in = isset($_SESSION['user_id']); + + @@ -97,4 +103,4 @@ $is_logged_in = isset($_SESSION['user_id']); - \ No newline at end of file + diff --git a/notifications.php b/notifications.php new file mode 100644 index 0000000..89f2dcc --- /dev/null +++ b/notifications.php @@ -0,0 +1,196 @@ +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 (%)
+
+
+ +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
LearnerGradeAverageParent Email
No learners found below this threshold.
+
+
ID:
+
Grade + % + + Missing' ?> +
+
+
+
+
+
+
+ + diff --git a/sw.js b/sw.js index fb4a1b2..63d6110 100644 --- a/sw.js +++ b/sw.js @@ -1,4 +1,4 @@ -const CACHE_NAME = 'township-schools-v4'; +const CACHE_NAME = 'township-schools-v5'; const STATIC_ASSETS = [ '/', '/index.php', @@ -9,6 +9,8 @@ const STATIC_ASSETS = [ '/learners.php', '/assessments.php', '/reports.php', + '/bulk-upload.php', + '/notifications.php', '/parent.php', '/assets/css/custom.css', '/assets/js/main.js', @@ -63,4 +65,4 @@ self.addEventListener('fetch', (event) => { }); }) ); -}); \ No newline at end of file +});