function test_import_excel($test_id, $name)
{
    global $db;
    $ts_tbl = TEST_STEP_TBL;
    $f_ts_id = TEST_STEP_ID;
    $f_ts_test_id = TEST_STEP_TEST_ID;
    $f_ts_step_no = TEST_STEP_NO;
    $f_ts_action = TEST_STEP_ACTION;
    $f_ts_input = TEST_STEP_TEST_INPUTS;
    $f_ts_expected = TEST_STEP_EXPECTED;
    $f_info_step = TEST_STEP_INFO_STEP;
    $s_project_properties = session_get_project_properties();
    $project_name = $s_project_properties['project_name'];
    $redirect_on_error = "test_step_import_csv_page.php?test_id={$test_id}";
    $uploaded_file = $_FILES[$name];
    $file_name = $_FILES[$name]['name'];
    $file_temp_name = $_FILES[$name]['tmp_name'];
    $file_size = $_FILES[$name]['size'];
    /*
    print"file_name = $file_name<br>";
    print"file_temp_name = $uploaded_file[tmp_name]<br>";
    print"file_size = $uploaded_file[size]<br>";
    */
    if ($file_size != '0' && is_uploaded_file($file_temp_name)) {
        require_once './Excel/reader.php';
        // ExcelFile($filename, $encoding);
        $data = new Spreadsheet_Excel_Reader();
        // Set output Encoding.
        $data->setOutputEncoding('CP1251');
        /***
         * if you want you can change 'iconv' to mb_convert_encoding:
         * $data->setUTFEncoder('mb');
         *
         **/
        /***
         * By default rows & cols indeces start with 1
         * For change initial index use:
         * $data->setRowColOffset(0);
         *
         **/
        /***
         *  Some function for formatting output.
         * $data->setDefaultFormat('%.2f');
         * setDefaultFormat - set format for columns with unknown formatting
         *
         * $data->setColumnFormat(4, '%.3f');
         * setColumnFormat - set format for column (apply only to number fields)
         *
         **/
        $data->read($uploaded_file['tmp_name']);
        //error_reporting(E_ALL ^ E_NOTICE);
        $debug = false;
        if (!$debug) {
            $q = "DELETE FROM {$ts_tbl} WHERE {$f_ts_test_id} = '{$test_id}'";
            db_query($db, $q);
        }
        for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
            $step_no = '';
            $action = '';
            $test_input = '';
            $expected = '';
            $info = '';
            //for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
            //echo "\"".$data->sheets[0]['cells'][$i][1]."\",";
            /*
            print"i = $i<br>";
            	print"j = $j<br>";
            */
            # Get record from CSV file
            $step_no = @util_html_special_chars_string($data->sheets[0]['cells'][$i][1]);
            $action = @util_html_special_chars_string($data->sheets[0]['cells'][$i][2]);
            $test_input = @util_html_special_chars_string($data->sheets[0]['cells'][$i][3]);
            $expected = @util_html_special_chars_string($data->sheets[0]['cells'][$i][4]);
            $info = @util_html_special_chars_string($data->sheets[0]['cells'][$i][5]);
            # We don't need to insert the column headers
            if ($i > 1) {
                # Insert into the Test Set table
                $q = "\tINSERT INTO {$ts_tbl}\n\t\t\t\t\t\t( {$f_ts_test_id}, {$f_ts_step_no}, {$f_ts_action}, {$f_ts_input}, {$f_ts_expected}, {$f_info_step} )\n\t\t\t\t\tVALUES\n\t\t\t\t\t\t( '{$test_id}', '{$step_no}', '{$action}', '{$test_input}', '{$expected}', '{$info}' )";
                if ($debug) {
                    print "{$q};<br>";
                } else {
                    db_query($db, $q);
                }
            }
        }
        # Create a version of the file in Test Doc Version table if the upload was successful
        if (file_name_exists($test_id, $file_name)) {
            # Get the manual_test_id from the Manual Test Doc table and add a new file version
            $manual_test_id = test_get_manual_test_id($test_id, $file_name);
            file_add_supporting_test_doc_version($file_temp_name, $file_name, $test_id, $manual_test_id, $comments = "", $file_type = "");
        } else {
            # Add a new file
            file_add_supporting_test_doc($file_temp_name, $file_name, $test_id, $comments = "", $file_type = "");
        }
    } else {
        # The user tried to upload and empty file
        error_report_show($redirect_on_error, NO_FILE_SPECIFIED);
    }
}
    $manual_test_id = $_GET['manual_test_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}";
session_validate_form_set($_POST, $redirect_page);
# Make sure the user entered a file name
$file_temp_name = $_FILES['uploadfile_required']['tmp_name'];
$file_name = str_replace(" ", "_", $_FILES['uploadfile_required']['name']);
$file_size = $_FILES['uploadfile_required']['size'];
# Make sure the user filled in the file name.
if (!isset($file_temp_name) || !is_uploaded_file($file_temp_name)) {
    error_report_show($redirect_on_error, REQUIRED_FIELD_MISSING);
}
if ($file_size != '0' && is_uploaded_file($file_temp_name)) {
    //print"manual_test_id = $manual_test_id<br>";
    file_add_supporting_test_doc_version($file_temp_name, $file_name, $test_id, $manual_test_id, $comments, $doc_type);
} else {
    error_report_show($redirect_on_error, FAILED_FILE_UPLOAD);
}
html_print_operation_successful('file_upload_page', $redirect_page);
# ---------------------------------------------------------------------
# $Log: test_add_doc_version_action.php,v $
# Revision 1.6  2008/08/07 10:57:51  peter_thal
# Now blanks are replaced with underscores by adding a new supporting doc
#
# Revision 1.5  2008/08/05 07:22:33  peter_thal
# fixed save bug for comment and doc type field
#
# Revision 1.4  2008/07/23 14:53:50  peter_thal
# delete supporting docs feature added (linux/unix)
#