function test_add_new_version($test_id, $test_version_id, $comments, $status, $assigned_to)
{
    global $db;
    $version_tbl = TEST_VERS_TBL;
    $f_test_id = TEST_VERS_TEST_ID;
    $f_version_id = TEST_VERS_ID;
    $f_version_no = TEST_VERS_NUMBER;
    $f_latest = TEST_VERS_LATEST;
    $f_active_version = TEST_VERS_ACTIVE;
    $f_test_comments = TEST_VERS_COMMENTS;
    $f_test_status = TEST_VERS_STATUS;
    $f_assigned_to = TEST_VERS_ASSIGNED_TO;
    $f_version_author = TEST_VERS_AUTHOR;
    $f_date_created = TEST_VERS_DATE_CREATED;
    $ts_tbl = TEST_STEP_TBL;
    $f_ts_id = TEST_STEP_ID;
    $f_ts_version_id = TEST_STEP_VERSION_ID;
    $f_step_no = TEST_STEP_NO;
    $f_action = TEST_STEP_ACTION;
    $f_expected = TEST_STEP_EXPECTED;
    # SELECT THE MAX VERSION AND ADD ONE
    $q_version = "SELECT {$f_version_no}\n\t\t\t\t FROM {$version_tbl}\n\t\t\t\t WHERE {$f_test_id} = '{$test_id}'\n\t\t\t\t AND {$f_latest} = 'Y'";
    #print"$q_version<br>";
    $current_version = db_get_one($db, $q_version);
    #print"current_version = $current_version<br>";
    $new_version = util_increment_version($current_version);
    #print"new_version = $new_version<br>";
    # SET THE LATEST FLAG TO 'N' FOR THE LAST VERSION THAT EQUALED 'Y'
    test_reset_latest($test_id);
    # INSERT INTO VERSION TABLE
    $created_date = date_get_short_dt();
    $author = session_get_username();
    $q = "INSERT INTO {$version_tbl}\n\t\t  ( {$f_test_id}, {$f_version_no}, {$f_latest}, {$f_active_version}, {$f_test_comments},\n\t\t\t{$f_test_status}, {$f_assigned_to}, {$f_version_author}, {$f_date_created} )\n\t\t  VALUES\n\t\t  ( '{$test_id}', '{$new_version}', 'Y', 'N', '{$comments}', '{$status}', '{$assigned_to}',\n\t\t\t'{$author}', '{$created_date}')";
    db_query($db, $q);
    $new_version_id = test_get_latest_version($test_id);
    # COPY TEST STEPS INTO NEW VERSION
    $q_steps = "SELECT {$f_step_no}, {$f_action}, {$f_expected}\n\t\t\t\tFROM {$ts_tbl}\n\t\t\t\tWHERE {$f_ts_version_id} = {$test_version_id}";
    $rs_steps = db_query($db, $q_steps);
    $num_steps = db_num_rows($db, $rs_steps);
    if ($num_steps > 0) {
        while ($row_steps = db_fetch_row($db, $rs_steps)) {
            $q_insert = "INSERT INTO {$ts_tbl}\n\t\t\t\t\t\t({$f_ts_version_id}, {$f_step_no}, {$f_action}, {$f_expected})\n\t\t\t\t\t\t VALUES\n\t\t\t\t\t\t('{$new_version_id}', '{$row_steps[$f_step_no]}', '{$row_steps[$f_action]}',\n\t\t\t\t\t\t '{$row_steps[$f_expected]}')";
            //print"$q_insert<br>";
            db_query($db, $q_insert);
        }
    }
}
print "<td>" . NEWLINE;
print "<table class=inner>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td colspan=2><h4>" . lang_get('new_version') . "</h4></td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "<tr>" . NEWLINE;
print "<td class=center>" . NEWLINE;
# NAME
print "<tr>" . NEWLINE;
print "<td class=form-lbl-r nowrap>" . lang_get('req_name') . "</td>" . NEWLINE;
print "<td class=form-data-l>{$req_name}</td>" . NEWLINE;
print "</tr>" . NEWLINE;
# VERSION
print "<tr>" . NEWLINE;
print "<td class=form-lbl-r nowrap>" . lang_get('version') . "</td>" . NEWLINE;
print "<td class=form-data-l><input type=text name=req_version value='" . session_validate_form_get_field('req_version', util_increment_version($version_num)) . "' size=5 maxlength=10></td>" . NEWLINE;
print "</tr>" . NEWLINE;
# STATUS
print "<tr>" . NEWLINE;
print "<td class=form-lbl-r nowrap>" . lang_get('req_status') . "</td>" . NEWLINE;
print "<td class=form-data-l>" . NEWLINE;
print "<select name=req_status size=1>" . NEWLINE;
$list_box = requirement_get_statuses();
html_print_list_box_from_array($list_box, session_validate_form_get_field('req_status', $status));
print "</select>" . NEWLINE;
print "</td>" . NEWLINE;
print "</tr>" . NEWLINE;
# PRIORITY
print "<tr>" . NEWLINE;
print "<td class=form-lbl-r nowrap>" . lang_get('req_priority') . "</td>" . NEWLINE;
print "<td class=form-data-l>" . NEWLINE;
function file_add_supporting_test_doc_version($file_temp_name, $file_name, $test_id, $manual_test_id, $comments, $file_type)
{
    global $db;
    $project_properties = session_get_project_properties();
    $file_upload_path = $project_properties['test_upload_path'];
    $project_id = $project_properties['project_id'];
    $redirect_page = "test_detail_page.php?test_id={$test_id}&project_id={$project_id}&tab=2";
    $redirect_on_error = "test_add_doc_version_page.php?test_id={$test_id}&manual_test_id={$manual_test_id}";
    $file_db_name = "";
    # Check to make sure the file name is the same as the previous version
    if (IGNORE_VERSION_FILENAME_VALIDATION || file_name_exists($test_id, $file_name)) {
        # create a unique name for the file using the time function
        $file_db_name = "SupportingTestDoc" . time() . "-{$file_name}";
        # Get the current file version and increment it by one
        $current_file_version = test_get_max_file_version($manual_test_id);
        $file_version = util_increment_version($current_file_version);
        # Make sure the temp file was uploaded successfully
        if (move_uploaded_file($file_temp_name, $file_upload_path . $file_db_name)) {
            $current_date = date("Y-m-d H:i:s");
            $s_user = session_get_user_properties();
            $username = $s_user['username'];
            $td_vers_tbl = MAN_TD_VER_TBL;
            $f_man_test_id = MAN_TD_VER_MANUAL_TEST_ID;
            $f_file_name = MAN_TD_VER_FILENAME;
            $f_timestamp = MAN_TD_VER_TIME_STAMP;
            $f_version = MAN_TD_VER_VERSION;
            $f_username = MAN_TD_VER_UPLOADED_BY;
            $f_comments = MAN_TEST_DOCS_VERS_COMMENTS;
            $f_file_type = MAN_TEST_DOCS_VERS_MANUAL_DOC_TYPE_NAME;
            $q = "INSERT INTO {$td_vers_tbl} \n\t\t\t\t({$f_man_test_id}, {$f_file_name}, {$f_timestamp}, {$f_version}, {$f_username}, {$f_comments}, {$f_file_type}) \n\t\t\t\tVALUES ('{$manual_test_id}', '{$file_db_name}', '{$current_date}', '{$file_version}', '{$username}', '{$comments}', '{$file_type}')";
            //print"$q<br>";
            $db->Execute($q);
        } else {
            # The file wasn't uploaded to the temp directory successfully
            error_report_show($redirect_page, FAILED_FILE_UPLOAD);
        }
    } else {
        # The file name of the new version doesn't match the old
        error_report_show($redirect_on_error, NO_MATCHING_FILE_NAME);
    }
}
print "\t\t<td class=left><h4>" . lang_get("uploading_new_version") . " {$test_plan_name}</h4></td>" . NEWLINE;
print "\t</tr>" . NEWLINE;
print "\t<tr>" . NEWLINE;
print "\t\t<td>" . NEWLINE;
print "\t\t<table>" . NEWLINE;
print "\t\t<tr>" . NEWLINE;
print "\t\t\t<td class=right>" . lang_get("file_name") . " <span class='required'>*</span></td>" . NEWLINE;
print "\t\t\t<td class=left><input type=file name=upload_file size=90></td>" . NEWLINE;
print "\t\t</tr>" . NEWLINE;
print "\t\t<tr>" . NEWLINE;
print "\t\t\t<td class=right>" . lang_get("comments") . "</td>" . NEWLINE;
print "\t\t\t<td class=left><textarea name=comments rows=6 cols=80></textarea></td>" . NEWLINE;
print "\t\t</tr>" . NEWLINE;
print "\t\t<tr>" . NEWLINE;
print "\t\t\t<td class=right>" . lang_get("version") . " <span class='required'>*</span></td>" . NEWLINE;
print "\t\t\t<td class=left><input type=text name=version value='" . util_increment_version($test_plan_version) . "' size=10></td>" . NEWLINE;
print "\t\t</tr>" . NEWLINE;
print "\t\t<tr>" . NEWLINE;
print "\t\t\t<td></td>" . NEWLINE;
print "\t\t\t<td><input type=submit value=" . lang_get("upload") . "></td>" . NEWLINE;
print "\t\t</tr>" . NEWLINE;
print "\t\t</table>" . NEWLINE;
print "\t\t</td>" . NEWLINE;
print "\t</tr>" . NEWLINE;
print "\t</table>" . NEWLINE;
print "\t</td>" . NEWLINE;
print "</tr>" . NEWLINE;
print "</table>" . NEWLINE;
print "</form>";
print "</div>" . NEWLINE;
html_print_footer();