<?php

/**

 * Flash alert helper — stores alerts in session so they render

 * after head.php (and SweetAlert2) has loaded.

 *

 * Usage (instead of echo "<script>alert('msg');</script>"):

 *   flash_alert('Your message here');

 *   flash_alert('Your message here', 'pay_tuition.php'); // with redirect

 */

function flash_alert(string $message, string $redirect = ''): void

{

    if (session_status() !== PHP_SESSION_ACTIVE)

        session_start();

    $_SESSION['_flash_alerts'][] = [

        'msg' => $message,

        'redirect' => $redirect,

    ];

}

