$redirect_on_error = "test_detail_page.php?test_id={$test_id}&project_id={$project_id}&tab=2"; session_validate_form_set($_POST, $redirect_page); $project_properties = session_get_project_properties(); $upload_path = $project_properties['test_upload_path']; $s_user = session_get_user_properties(); $username = $s_user['username']; $test_name = test_get_name($test_id); $comments = session_validate_form_get_field('comments'); $doc_type = session_validate_form_get_field('doc_type'); $upload_file_name = $_FILES['uploadfile']['name']; $_FILES['uploadfile']['name'] = str_replace(" ", "_", $upload_file_name); # ------------------------------------------------ # FILE UPLOAD # ------------------------------------------------ if ($_FILES['uploadfile']['size'] != '0' && is_uploaded_file($_FILES['uploadfile']['tmp_name'])) { file_add_supporting_test_doc($_FILES['uploadfile']['tmp_name'], $_FILES['uploadfile']['name'], $test_id, $comments, $doc_type); } else { error_report_show($redirect_on_error, NO_FILE_SPECIFIED); } html_print_operation_successful('file_upload_page', $redirect_page); # --------------------------------------------------------------------- # $Log: test_detail_new_upload_action.php,v $ # Revision 1.8 2008/08/07 10:57:51 peter_thal # Now blanks are replaced with underscores by adding a new supporting doc # # Revision 1.7 2008/07/23 14:53:50 peter_thal # delete supporting docs feature added (linux/unix) # # Revision 1.6 2008/07/09 07:13:24 peter_thal # added direct linking of test detail by adding project_id link parameter # added automated project switching if necessary
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); } }