<?php
session_start();
if (!isset($_SESSION['modal_terms'], $_SESSION['modal_user_type'], $_SESSION['modal_user_id'])) {
    header("Location: logout.php");
    exit();
}

$terms = $_SESSION['modal_terms'];
$userType = $_SESSION['modal_user_type'];
$userId = $_SESSION['modal_user_id'];

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // User accepted the terms, redirect them
    $redirects = [
        'Franchiee' => 'user3/',
        'subFranchiee' => 'user4/'
    ];

    header("Location: " . $redirects[$userType]);
    exit();
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <title>Terms and Conditions</title>
    <?php include "include/meta.php"; ?>
    <?php include "include/css.php"; ?>
</head>

<body>
    <div class="modal" id="termsModal" tabindex="-1" role="dialog" style="display:block;">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">Terms and Conditions</h5>
                </div>
                <div class="modal-body">
                    <?php foreach ($terms as $term): ?>
                    <p><?php echo htmlspecialchars($term['data_long_des']); ?></p>
                    <?php endforeach; ?>
                </div>
                <div class="modal-footer">
                    <form method="POST" action="">
                        <button type="submit" class="btn btn-primary">Accept</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</body>

</html>