<?php
include 'config.php';

header('Content-Type: application/json');

$title = trim($_POST['title'] ?? '');
$image_link = trim($_POST['image_link'] ?? '');
$message = trim($_POST['message'] ?? '');
$date = trim($_POST['date'] ?? '');
$time = trim($_POST['time'] ?? '');

if (
    empty($title) ||
    empty($message) ||
    empty($date) ||
    empty($time)
) {
    echo json_encode([
        "status" => "failed",
        "message" => "All fields required"
    ]);
    exit;
}

$stmt = $conn->prepare("INSERT INTO announcements (title, image_link, message, announce_date, announce_time) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssss", $title, $image_link, $message, $date, $time);

if ($stmt->execute()) {
    echo json_encode([
        "status" => "success",
        "message" => "Announcement Added"
    ]);
} else {
    echo json_encode([
        "status" => "failed",
        "message" => "Database Error"
    ]);
}
?>