<?php
    /* stub version to start */

    /*=====
    function show_farewell()
    {
        ?>
        <p> called function show_farewell </p>
        <p> <a href="<?= htmlentities($_SERVER["PHP_SELF"],
                                       ENT_QUOTES) ?>">
            Continue </a> </p>
        <?php
    }
    =====*/

    /* end of stub version */
?>

<?php
    /*====
        function: show_farewell
        purpose: expects no parameters, tries
            to read the user's favorite color from the
            submitting form, and (safely) use that PLUS
            $_SESSION["name"] and $_SESSION["quest"]
            to create a personalized, quest-including,
            color-including farewell

        ASSUMES: that caller is going to destroy session
            after this; does NOT destroy session itself
            because less convenient to iteratively-build application
            (stubs THEN each function WITH running in between)
            otherwise. 

        requires: build_mini_form.php

        by: Sharon Tuttle
        last modified: 2025-04-23
    ====*/

    function show_farewell()
    {
        // if get here, there BETTER be a just-submitted color!

        if ( (! array_key_exists("color", $_POST) ) or
             (trim($_POST["color"]) == "") )
        {
            complain_and_exit("color");
        }

        // if get here, SOMETHING was entered for color...

        $user_color = trim(htmlspecialchars(strip_tags($_POST["color"])));

        // and grab (carefully) this info from the $_SESSION

        $user_name = trim(htmlspecialchars(strip_tags($_SESSION["name"])));
        $user_quest = trim(htmlspecialchars($_SESSION["quest"]));

        // craft a personalized farewell including name, quest, and color
        ?>
        <h2> AHA, <?= $user_name ?>, <br />
             lover of the gentle hue of <?= $user_color ?>, <br />
             I let you pass, and wish you well on your quest:
             <?= $user_quest ?> </h2>
        <p> <a href="<?= htmlentities($_SERVER["PHP_SELF"], ENT_QUOTES) ?>">
            Start over </a> </p>
        <?php
    }
?>