<?php
$ROOT = dirname(__DIR__, 3);
require_once $ROOT . '/config/config.php';
require_once $ROOT . '/src/lib/session.php';
require_auth();

$pdo = getDbConnection();

$description = trim($_POST['description'] ?? '');
$status = trim($_POST['STATUS'] ?? '');

if ($description === '' || $status === '') {
    die("Tous les champs sont obligatoires");
}

$stmt = $pdo->prepare("
    INSERT INTO regulations (description, STATUS)
    VALUES (:description, :status)
");
$stmt->execute([
    ':description' => $description,
    ':status' => $status
]);

$_SESSION['success_message'] = "✅ Enregistrement réussi !";

// Retour direct à la page précédente
header("Location: ../regulations.php");
exit;
