<?php include "../parts/header.php"; ?>
<?php include "../parts/sidepanel.php"; ?>

<?php
include_once("../opendb.php");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $title = mysqli_real_escape_string($conn, $_POST['title']);
    $link = mysqli_real_escape_string($conn, $_POST['link']);

    $sql = "INSERT INTO notification (title, link) VALUES ('$title', '$link')";
    if (mysqli_query($conn, $sql)) {
        // Redirect with success flag
        header("Location: notification.php?success=1");
        exit;
    } else {
        header("Location: notification.php?error=" . urlencode(mysqli_error($conn)));
        exit;
    }
}
?>

<h4 class="page-title">NOTIFICATION</h4>
    <div class="row">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <div class="card-title">Add Notification</div>
                </div>
                <form action="" method="POST" enctype="multipart/form-data">
                    <div class="card-body">
                        <div class="form-group">
                            <label for="title">Title</label>
                            <input type="text" class="form-control" id="title" name="title" placeholder="Enter Title">
                        </div>
                        <div class="form-group">
                            <label for="link">Link</label>
                            <input type="text" class="form-control" id="link" name="link" placeholder="Enter link">
                        </div>
                        
                        <div class="card-action">
                            <button class="btn btn-success">Submit</button>
                            <button type="button" class="btn btn-danger" onclick="window.location.href='notification.php'">Cancel</button>
                        </div>
                    </div>
                </form>
            </div>

<?php include "../parts/footer.php"; ?>