<?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: 2026-04-22
    ====*/
    
    function show_farewell()
    {
	// if get here, there BETTER be a color submitted!

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

        // if get here, I have a color!

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

        $user_name = $_SESSION["name"];
	$user_quest = $_SESSION["quest"];

        // craft a personalized farewell response
	
        ?>
        <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 for:
	     <?= $user_quest ?> </h2>
        <?php
	
	build_mini_form("", "START OVER");
    }
?>