<?php
require_once '../../config.php';
require_once '../../functions.php';

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

check_user_auth();

if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $stmt = $pdo->prepare("SELECT message FROM sms_templates WHERE id = ? AND status = 'active'");
    $stmt->execute([$id]);
    $template = $stmt->fetch();

    if ($template) {
        echo json_encode(['success' => true, 'message' => $template['message']]);
    } else {
        echo json_encode(['success' => false, 'error' => 'Template not found']);
    }
} else {
    echo json_encode(['success' => false, 'error' => 'No ID provided']);
}
?>