<?php
    /*---
        function: create_dept_dropdown
        purpose: expects an Oracle username and
            password (for HSU), and builds a drop-down
            of current departments (and returns nothing)
    ---*/

    function create_dept_dropdown($username, $password)
    {
        $conn = hsu_conn_sess($username, $password);
        ?>

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

            <?php
            $dept_query = 'select dept_name
                           from dept';
            $dept_stmt = oci_parse($conn, $dept_query);
            oci_execute($dept_stmt, OCI_DEFAULT);
            ?>

            <label for="dept_choice"> Department: </label>
            <select name="dept_choice" id="dept_choice">

            <?php
            while (oci_fetch($dept_stmt))
            {
                 $curr_dept_name = oci_result($dept_stmt,
                                     "DEPT_NAME");
                 ?>

                 <option value="<?= $curr_dept_name ?>">
                     <?= $curr_dept_name ?> </option>
                 <?php
            }

            oci_free_statement($dept_stmt);
            oci_close($conn);
            ?>
            </select>

            <div class="submit">
                <input type="submit" value="get info" />
            </div>

            </fieldset>
        </form>
        <?php
    }
?>