<?php
session_name('teacher_session');
session_start();
include('includes/dbconnection.php');
include('includes/flash.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['teacher_id'])) {
    $teacher_id = (int)$_POST['teacher_id'];
    $class = isset($_POST['class']) ? $_POST['class'] : '';
    $section = isset($_POST['section']) ? $_POST['section'] : '';

    // Generate a default message
    $message = "Reminder: Please submit results for  $class - $section.";

    $stmt = $con->prepare("INSERT INTO notifications (teacher_id, message) VALUES (?, ?)");
    $stmt->bind_param("is", $teacher_id, $message);
    $stmt->execute();
    $stmt->close();

    flash_alert('Notification Sent successfully!');
        header('Location: ' . ($_SERVER['HTTP_REFERER'] ?? 'javascript:history.back()')); exit;
    exit();
} else {
    flash_alert('Invalid Request!');
        header('Location: ' . ($_SERVER['HTTP_REFERER'] ?? 'javascript:history.back()')); exit;
    exit();
}
