<?php
include "includes/functions.php";

checkPost();

$_SESSION["nome"] = $_POST["nome"];
$_SESSION["sceltaHobby"] = $_POST["sceltaHobby"];

$domande = [];

if ($_POST["sceltaHobby"] == "m") {
    $domande = json_decode(file_get_contents("includes/musica.json"));
} else if ($_POST["sceltaHobby"] == "s") {
    $domande = json_decode(file_get_contents("includes/sport.json"));
}

createNecessaryCookies();

?>

<!DOCTYPE HTML>
<html lang="it">

<head>
    <title>Login</title>
    <?php require "includes/head.php" ?>
</head>

<body>
<div class="container">
    <h1>Ciao <?php echo $_SESSION["nome"] ?></h1>
    <h2>Rispondi alle seguenti domande</h2>
    <form action="risultati.php" method="post">
        <?php
        foreach ($domande as $numeroDomanda => $domanda) {
            echo '<div class="mb-3">';
            echo '<label for="risposta_domanda_' . $numeroDomanda . '" class="form-label">' . $domanda[0] . '</label>';
            echo '<input type="number" class="form-control" id="risposta_domanda_' . $numeroDomanda . '" name="risposta_domanda_' . $numeroDomanda . '">';
            echo '</div>';
        }
        ?>
        <button type="submit" class="btn btn-primary">Invia voti</button>
    </form>
</div>

<?php require "includes/footer.php" ?>

</body>
</html>

