<?php
    /*===
        function: build_dept_form: string -> void
        purpose: expects "radio" or "select", and
            tries to build a dynamic form allowing the user
            to choose one of the current departments using that
            widget type
            *   if anything unexpected happens, it complains and then exits,
                including destroying the current session and including a
                link to hopefully-conveniently start over

        requires: destroy_then_exit.php

        last modified: 2024-04-17
    ===*/

    function build_dept_form($widg_choice)
    {
        // now build a form to choose a department using the chosen
        //     widget type

        ?>
        <form method="post"
              action="<?= htmlentities($_SERVER['PHP_SELF'],
                                       ENT_QUOTES) ?>">
            <fieldset>
                <fieldset>
                    <legend> Choose department: </legend>
                    
        <?php

        // now add the department choices using the chosen form widget

        if ($widg_choice == "radio")
        {
            build_dept_radio();
        }
        elseif ($widg_choice == "select")
        {
            build_dept_drop_down();
        }
        else
        {
            destroy_then_exit("Illegal widget choice");
        }

        // now finish the form
        ?>
                </fieldset>

                <div class="sub">
                    <input type="submit" value="Submit" />
                </div>
            </fieldset>
        </form>
        <?php
    }
?>