function html_dynamic_tree($session_variable, $tree_array, $root_node, $highlighted = null, $column_map = array())
{
    # Get the expanded tree array from the session
    $s_display_options = session_get_display_options($session_variable);
    $expanded = $s_display_options["filter"]["tree"];
    # Add expanded node (if there is one)
    if (isset($_GET['expand'])) {
        $expanded[] = $_GET['expand'];
    }
    # Remove collapsed node (if there is one)
    if (isset($_GET['collapse'])) {
        $expanded = array_diff($expanded, array($_GET['collapse']));
    }
    # Create variable to update the session
    $update_expanded = array("tree" => $expanded);
    # Update the tree variable in the session and get the returned value
    $s_display_options = session_set_display_options($session_variable, $update_expanded);
    $expanded = $s_display_options["filter"]["tree"];
    global $db;
    # images html
    $img_tree_T = "<img align='absmiddle' border=0 src='" . IMG_SRC . "tree_dots_T.gif' alt=''>";
    $img_tree_L = "<img align='absmiddle' border=0 src='" . IMG_SRC . "tree_dots_L.gif' alt=''>";
    $img_tree_column = "<img align='absmiddle' border=0 src='" . IMG_SRC . "tree_dots_column.gif' alt=''>";
    $img_tree_plus = "<img align='absmiddle' border=0 src='" . IMG_SRC . "tree_dots_plus.gif' alt=''>";
    $img_tree_plus_b = "<img align='absmiddle' border=0 src='" . IMG_SRC . "tree_dots_plus_b.gif' alt=''>";
    $img_tree_minus = "<img align='absmiddle' border=0 src='" . IMG_SRC . "tree_dots_minus.gif' alt=''>";
    $img_tree_minus_b = "<img align='absmiddle' border=0 src='" . IMG_SRC . "tree_dots_minus_b.gif' alt=''>";
    $img_tree_folder = "<img align='absmiddle' border=0 src='" . IMG_SRC . "tree_folder.gif' alt=''>";
    $img_tree_folder_b = "<img align='absmiddle' border=0 src='" . IMG_SRC . "tree_folder_b.gif' alt=''>";
    $img_spacer = "<img align='absmiddle' border=0 src='" . IMG_SRC . "1px_transparent.gif' width=15 height=1 alt=''>";
    $column = $img_tree_column . $img_spacer;
    # display each child node
    for ($i = 0; $i < sizeof($tree_array); $i++) {
        $req_id = $tree_array[$i]['uid'];
        $req_version_id = requirement_get_latest_version($req_id);
        echo $img_spacer;
        foreach ($column_map as $column_type) {
            if ($column_type == "|") {
                echo $column;
            } elseif ($column_type == " ") {
                echo $img_spacer;
            }
        }
        # if the last node
        if ($i == sizeof($tree_array) - 1) {
            # if the last node has no children
            if (empty($tree_array[$i]["children"])) {
                echo $img_tree_L;
                # if the last node has children
            } else {
                # if last node has children and the node is in the expanded array
                if (util_array_value_search($req_id, $expanded)) {
                    echo "<a href='?collapse={$req_id}#{$req_id}'>" . $img_tree_minus_b . $img_tree_folder_b . "</a>";
                    # if last node has children and the node is not in the expanded array
                } else {
                    echo "<a href='?expand={$req_id}#{$req_id}'>" . $img_tree_plus_b . $img_tree_folder . "</a>";
                }
            }
            $column_type = array(" ");
            # if not the last node
        } else {
            # if not the last node and the node has no children
            if (empty($tree_array[$i]["children"])) {
                echo $img_tree_T;
            } else {
                # if not the last node and the node is in the expanded array
                if (util_array_value_search($req_id, $expanded)) {
                    echo "<a href='?collapse={$req_id}#{$req_id}'>" . $img_tree_minus . $img_tree_folder_b . "</a>";
                    # if not the last node and the node is not in the expanded array
                } else {
                    echo "<a href='?expand={$req_id}#{$req_id}'>" . $img_tree_plus . $img_tree_folder . "</a>";
                }
            }
            $column_type = array("|");
        }
        # prints a closed folder if node has no children and $root_node is set to true
        if (empty($tree_array[$i]["children"]) && $root_node) {
            echo $img_tree_folder;
        }
        # formatting for highlighted node
        $style = "";
        if ($req_id == $highlighted) {
            $style = "style='font-weight: bold; font-size: 120%;'";
        }
        # print the node name
        echo " <a {$style} name={$req_id} href='requirement_detail_page.php?req_id={$req_id}&req_version_id={$req_version_id}'>" . $tree_array[$i]['name'] . "</a>";
        echo "<br>" . NEWLINE;
        # display this nodes children
        if (util_array_value_search($req_id, $expanded)) {
            html_dynamic_tree($session_variable, $tree_array[$i]['children'], false, $highlighted, array_merge($column_map, $column_type));
        }
    }
}
function requirement_add_version($project_id, $req_id, $req_defect_id, $area_covered, $type, $record_or_file, $version, $status, $filename, $detail = "", $reason_for_change = "", $assign_to, $upload_by, $functionality, $priority, $release_id)
{
    global $db;
    $tbl_req = REQ_TBL;
    $f_req_id = $tbl_req . "." . REQ_ID;
    $f_req_filename = $tbl_req . "." . REQ_FILENAME;
    $f_req_area_covered = $tbl_req . "." . REQ_AREA_COVERED;
    $f_req_type = $tbl_req . "." . REQ_TYPE;
    $f_req_parent = $tbl_req . "." . REQ_PARENT;
    $f_req_label = $tbl_req . "." . REQ_LABEL;
    $f_req_unique_id = $tbl_req . "." . REQ_UNIQUE_ID;
    $f_req_functionality = $tbl_req . "." . REQ_FUNCTIONALITY;
    $f_req_locked_by = $tbl_req . "." . REQ_LOCKED_BY;
    $f_req_locked_date = $tbl_req . "." . REQ_LOCKED_DATE;
    $f_req_priority = $tbl_req . "." . REQ_PRIORITY;
    $f_req_last_updated = $tbl_req . "." . REQ_LAST_UPDATED;
    $tbl_req_ver = REQ_VERS_TBL;
    $f_req_ver_uid = $tbl_req_ver . "." . REQ_VERS_UNIQUE_ID;
    $f_req_ver_req_id = $tbl_req_ver . "." . REQ_VERS_REQ_ID;
    $f_req_ver_version = $tbl_req_ver . "." . REQ_VERS_VERSION;
    $f_req_ver_timestamp = $tbl_req_ver . "." . REQ_VERS_TIMESTAMP;
    $f_req_ver_uploaded_by = $tbl_req_ver . "." . REQ_VERS_UPLOADED_BY;
    $f_req_ver_filename = $tbl_req_ver . "." . REQ_VERS_FILENAME;
    $f_req_ver_comments = $tbl_req_ver . "." . REQ_VERS_COMMENTS;
    $f_req_ver_status = $tbl_req_ver . "." . REQ_VERS_STATUS;
    $f_req_ver_shed_release = $tbl_req_ver . "." . REQ_VERS_SCHEDULED_RELEASE_IMP;
    $f_req_ver_shed_build = $tbl_req_ver . "." . REQ_VERS_SCHEDULED_BUILD_IMP;
    $f_req_ver_actual_release = $tbl_req_ver . "." . REQ_VERS_ACTUAL_RELEASE_IMP;
    $f_req_ver_actual_build = $tbl_req_ver . "." . REQ_VERS_ACTUAL_BUILD_IMP;
    $f_req_ver_detail = $tbl_req_ver . "." . REQ_VERS_DETAIL;
    $f_req_ver_release = $tbl_req_ver . "." . REQ_VERS_ASSIGN_RELEASE;
    $f_req_ver_latest = $tbl_req_ver . "." . REQ_VERS_LATEST;
    $f_req_ver_reason_change = $tbl_req_ver . "." . REQ_VERS_REASON_CHANGE;
    $f_req_ver_assigned = $tbl_req_ver . "." . REQ_VERS_ASSIGNED_TO;
    $f_req_ver_defect_id = $tbl_req_ver . "." . REQ_VERS_DEFECT_ID;
    $last_updated = date_get_short_dt();
    if ($area_covered == '') {
        $area_covered = 0;
    }
    if ($type == '') {
        $type = 0;
    }
    $q = "\tUPDATE {$tbl_req_ver}\n\t\t\tSET\n\t\t\t\t{$f_req_ver_latest} = 'N'\n\t\t\tWHERE\n\t\t\t\t{$f_req_ver_req_id} = {$req_id}";
    db_query($db, $q);
    $q = "\tUPDATE {$tbl_req}\n\t\t\tSET\n\t\t\t\t{$f_req_area_covered} = '{$area_covered}',\n\t\t\t\t{$f_req_type} = '{$type}',\n\t\t\t\t{$f_req_priority} = '{$priority}',\n\t\t\t\t{$f_req_last_updated} = '{$last_updated}'\n\t\t\tWHERE\n\t\t\t\t{$f_req_id} = {$req_id}";
    db_query($db, $q);
    $q = "\tINSERT INTO {$tbl_req_ver}\n\t\t\t\t(\t{$f_req_ver_req_id},\n\t\t\t\t\t{$f_req_ver_defect_id},\n\t\t\t\t\t{$f_req_ver_version},\n\t\t\t\t\t{$f_req_ver_timestamp},\n\t\t\t\t\t{$f_req_ver_uploaded_by},\n\t\t\t\t\t{$f_req_ver_filename},\n\t\t\t\t\t{$f_req_ver_status},\n\t\t\t\t\t{$f_req_ver_detail},\n\t\t\t\t\t{$f_req_ver_reason_change},\n\t\t\t\t\t{$f_req_ver_assigned},\n\t\t\t\t\t{$f_req_ver_latest} )\n\t\t\tVALUES\n\t\t\t\t(\t{$req_id},\n\t\t\t\t    '{$req_defect_id}',\n\t\t\t\t\t'{$version}',\n\t\t\t\t\t'{$last_updated}',\n\t\t\t\t\t'{$upload_by}',\n\t\t\t\t\t'{$filename}',\n\t\t\t\t\t'{$status}',\n\t\t\t\t\t'{$detail}',\n\t\t\t\t\t'{$reason_for_change}',\n\t\t\t\t\t'{$assign_to}',\n\t\t\t\t\t'Y' )";
    db_query($db, $q);
    requirement_edit_functionality($req_id, $functionality);
    # update related tests statuses to "Review Requirement"
    $req_test_relationships = requirement_get_test_relationships($req_id);
    foreach ($req_test_relationships as $row_req_test_rels) {
        $test_id = $row_req_test_rels[TEST_ID];
        test_update_field($project_id, $test_id, TEST_STATUS, "Review Requirement");
    }
    # Get the req_version_id just inserted.
    $req_version_id = requirement_get_latest_version($req_id);
    # update requirment_release_assoc
    requirement_edit_release($req_version_id, $release_id);
}
$req_assigned_to = session_validate_form_get_field('req_assigned_to');
$req_author = session_validate_form_get_field('req_author');
$req_functionality = session_validate_form_get_field("req_functionality");
$assigned_release = session_validate_form_get_field("assigned_release");
$req_defect_id = session_validate_form_get_field("defect_id");
if ($req_defect_id == '') {
    $req_defect_id = 0;
}
# return the user to the previous page if the new_bug_id doesn't exist in the bug table
if (!bug_exists($req_defect_id) && $req_defect_id != 0) {
    html_redirect($redirect_on_error);
}
requirement_add_version($project_id, $req_id, $req_defect_id, $req_area, $req_type, $req_record_or_file, $req_version, $req_status, $uploaded_filename, $detail, $reason_for_change, $req_assigned_to, $req_author, $req_functionality, $req_priority, $assigned_release);
session_validate_form_reset();
# GET THE NEW REQUIREMENT VERSION NUMBER
$req_version_id = requirement_get_latest_version($req_id);
############################################################################
# EMAIL NOTIFICATION
############################################################################
$recipients = requirement_get_notify_users($project_id, $req_id);
requirement_email($project_id, $req_id, $recipients, $action = "new_version");
############################################################################
############################################################################
html_print_operation_successful('req_edit_page', "requirement_detail_page.php?req_version_id={$req_version_id}");
# ------------------------------------
# $Log: requirement_add_new_version_action.php,v $
# Revision 1.7  2006/12/05 05:24:18  gth2
# fixing bug 1608519 - gth
#
# Revision 1.6  2006/09/27 23:58:33  gth2
# Adding functionality to link a change request (defect_id) to a requirement - gth
         print "<tr class='{$row_style}' align=left>" . NEWLINE;
         print "<td class='tbl-c'>{$rel_type} <a href='requirement_detail_page.php?req_id={$req_parent}&amp;req_version_id={$req_parent_version}'>{$rel_parent_id}</a></td>" . NEWLINE;
         print "<td class='tbl-l'>{$req_parent_name}</td>" . NEWLINE;
         if ($user_has_delete_rights) {
             print "<td class='tbl-c'></td>" . NEWLINE;
         }
         print "</tr>" . NEWLINE;
     }
     # PRINT CHILDREN RECORDS
     if (!empty($rows_children)) {
         foreach ($rows_children as $row_child) {
             $rel_req_id = util_pad_id($row_child['req_id']);
             $child_id = $rel_req_id;
             $parent_id = $s_req_id;
             $rel_req_name = $row_child['req_name'];
             $req_child_version = requirement_get_latest_version($child_id);
             $row_style = html_tbl_alternate_bgcolor($row_style);
             print "<tr class='{$row_style}' align=left>" . NEWLINE;
             print "<td class='tbl-c'><a href='requirement_detail_page.php?req_id={$rel_req_id}&amp;req_version_id={$req_child_version}'>{$rel_req_id}</a></td>" . NEWLINE;
             print "<td class='tbl-l'>{$rel_req_name}</td>" . NEWLINE;
             if ($user_has_delete_rights) {
                 print "<td class='tbl-c'><a href='requirement_delete_assoc_action.php?assoc=req&amp;parent_id={$parent_id}&amp;assoc_id={$child_id}'>" . lang_get('delete') . "</a></td>" . NEWLINE;
             }
             print "</tr>";
         }
     }
     print "</table>";
 } else {
     print "<div align=center>" . NEWLINE;
     print lang_get('no_related_reqs');
     print "</div>" . NEWLINE;
$filter_doc_type = $display_options['filter']['doc_type'];
$filter_status = $display_options['filter']['status'];
$filter_area_covered = $display_options['filter']['area_covered'];
$filter_functionality = $display_options['filter']['functionality'];
$filter_assign_release = $display_options['filter']['assign_release'];
$filter_per_page = $display_options['filter']['per_page'];
$filter_show_versions = $display_options['filter']['show_versions'];
$filter_search = $display_options['filter']['requirement_search'];
$filter_priority = $display_options['filter']['priority'];
$display_options = session_set_display_options("requirements", array_merge($_POST, $_GET));
$s_tab = $display_options['tab'];
$s_properties = session_set_properties("requirements", $_GET);
$s_req_id = $s_properties['req_id'];
$s_req_version_id = $s_properties['req_version_id'];
if (empty($_GET['req_version_id'])) {
    $_GET['req_version_id'] = requirement_get_latest_version($s_req_id);
    $s_req_version_id = $_GET['req_version_id'];
}
html_window_title();
html_print_body();
html_page_title($project_name . " - " . lang_get("req_folder_view_page"));
html_page_header($db, $project_name);
html_print_menu();
requirement_menu_print($page);
error_report_check($_GET);
print "<br>" . NEWLINE;
print "<form action='{$page}' method=post>" . NEWLINE;
print "<div align=center>" . NEWLINE;
html_print_requirements_filter($project_id, $filter_doc_type, $filter_status, $filter_area_covered, $filter_functionality, $filter_assign_release, $filter_per_page = null, $filter_show_versions = null, $filter_search, $filter_priority);
print "<br>" . NEWLINE;
print "</div>";