<?php
# ---------------------------------------------------------------------
# rth is a requirement, test, and bugtracking system
# Copyright (C) 2005 George Holbrook - rth@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
#----------------------------------------------------------------------
# ---------------------------------------------------------------------
# Results Continue Manual Test Page
#
# $RCSfile: results_continue_manual_test_page.php,v $  $Revision: 1.3 $
# ---------------------------------------------------------------------

if( isset($_POST['submit_button']) ) {

	require_once("results_continue_manual_test_action.php");
	exit;
}

include"./api/include_api.php";
auth_authenticate_user();

if( sizeof($_POST) ) {
	session_validate_form_set($_POST);
} else {
	session_validate_form_reset();
}

$page                   = basename(__FILE__);
$project_properties     = session_get_project_properties();
$project_name           = $project_properties['project_name'];
$project_id				= $project_properties['project_id'];

$s_results 				= session_set_properties( "results", $_GET );
$testset_id 			= $s_results['testset_id'];
$test_id 				= $s_results['test_id'];
$test_run_id 			= $s_results['test_run_id'];

$redirect_url			= $page ."?test_id=$test_id&amp;testset_id=$testset_id";
$results_page			= 'results_page.php';
$form_name				= 'run_test';
$row_style              = '';
$time					= results_get_time_started();

$order_by		= TEST_STEP_NO;
$order_dir		= "ASC";
$page_number	= 1;

util_set_order_by($order_by, $_POST);
util_set_order_dir($order_dir, $_POST);
util_set_page_number($page_number, $_POST);

/*
$test_run_options		= session_set_display_options( 'test_run_details', $_POST );
$s_page_number			= $test_run_options['page_number'];
*/

#error_report_check( $_GET );
/*

if( isset($_GET['testset_id']) && isset($_GET['test_id']) ) {
    $testset_id = $_GET['testset_id'];
    $test_id = $_GET['test_id'];
} else {   # coming from redirect etc, get stored testset_id and test_run_id
    $s_results = session_get_properties("results");
    $testset_id = $s_results['testset_id'];
    $test_id = $s_results['test_id'];
}
*/

$test_name = test_get_name( $test_id );

html_window_title();
html_print_body();
html_page_title($project_name ." - ". lang_get('run_manual_test_page') );
html_page_header( $db, $project_name );
html_print_menu();
html_test_results_menu( $db, $results_page, $project_id, session_get_properties("results", $_GET) );

error_report_check( $_GET );

$test_results_details = results_get_test_results_detail( $test_run_id );

$row_test_name			= $test_results_details[TEST_RESULTS_TEST_SUITE];
$row_test_id			= $test_results_details[TEST_RESULTS_TEMPEST_TEST_ID];
$row_time_started		= $test_results_details[TEST_RESULTS_TIME_STARTED];
$row_time_finished		= $test_results_details[TEST_RESULTS_TIME_FINISHED];
$row_finished			= $test_results_details[TEST_RESULTS_FINISHED];
$row_test_run_status	= $test_results_details[TEST_RESULTS_TEST_STATUS];
$row_comments			= $test_results_details[TEST_RESULTS_COMMENTS];
$row_os					= $test_results_details[TEST_RESULTS_OS];
$row_env				= $test_results_details[TEST_RESULTS_ENVIRONMENT];
$row_root_cause			= $test_results_details[TEST_RESULTS_ROOT_CAUSE];
$row_cvs				= $test_results_details[TEST_RESULTS_CVS_VERSION];

print"<form method=post enctype='multipart/form-data' name='run_manual_test' action='$page?test_id=$test_id&amp;testset_id=$testset_id&amp;test_run_id=$test_run_id'>\n";
print"<input type=hidden name=test_run_id value='$test_run_id'>";

print"<div align=center>\n";

print"<span class='required'>*</span> <span class='print'>" . lang_get('must_complete_field') . "</span>\n";
print"<table class=width60>\n";
print"<tr>\n";
print"<td>\n";

print"<table class=inner>\n";

print"<tr>\n";
print"<td class=form-header-l colspan=2>". lang_get('run_test') ." - $test_name</td>\n";
print"</tr>\n";

#util_add_spacer();
/*
print"<tr>\n";
print"<td class=form-lbl-r>". lang_get('test_name') ."</td>\n";
print"<td class=left>$test_name</td>\n";
print "</td>\n";
*/

print"<tr>\n";
print"<td class='form-lbl-r'>". lang_get('test_comments') ."</td>\n";
print"<td class='form-data-l'>\n";
	print"<textarea rows='5' cols='40' name='test_run_comments'>". session_validate_form_get_field("test_run_comments", $row_comments).	"</textarea>\n";
print"</td>\n";
print"</tr>\n";

# Time Started
/*
Time started doesn't work because of time zones.  The server could be in belfast to record the time finished but the user could be in the States and record a time finished that's later than the time started.  We'll have to figure out how to deal with this.

Could just add a Duration field and calculate the time started.
print"<tr>\n";
print"<td class=form-lbl-r>". lang_get('time_started') ."</td>\n";

	# Hour
	print"<td class='form-data-l'>\n";
	print"<select name='hour' size=1>\n";
	html_print_list_box_from_array( $time['hour'], '');
	print"</select>\n";

	# Minute
	print"<select name='minute' size=1>\n";
	html_print_list_box_from_array( $time['minute'], '');
	print"</select>\n";

	# AM/PM
	print"<select name='am_pm' size=1>\n";
	html_print_list_box_from_array( $time['am_pm'], '');
	print"</select>\n";

print"</td>\n";
print"</tr>" ;
*/

# Duration
print"<tr>\n";
#print"<td class='form-lbl-r'>". lang_get('duration') ."</td>\n";
print"<td class='form-lbl-r'>". lang_get('time_to_run_test') ."</td>\n";
print"<td class='form-data-l'><input type='text' size='3' name='duration' value='".session_validate_form_get_field("duration")."'>&nbsp; ". lang_get('in_minutes') ."</td>\n";
print"</tr>\n";

# Environment
print"<tr>\n";
print"<td class='form-lbl-r'>". lang_get('environment') ."</td>\n";
print"<td class='form-data-l'>\n";
print"<select name='environment' size=1>\n";
	$rows_environments = project_get_environments( $project_id );

	foreach($rows_environments as $row_environment) {

		$list[$row_environment[ENVIRONMENT_NAME]] = $row_environment[ENVIRONMENT_NAME];
	}
	$list[""] = "";

	html_print_list_box_from_key_array( $list, session_validate_form_get_field("environment", $row_env) );
print"</select>\n";
print"</td>\n";
print"</tr>" ;


# OS
print"<tr>\n";
print"<td class=form-lbl-r>". lang_get('os') ."</td>\n";
print"<td class='form-data-l'>\n";
print"<select name='os' size=1>\n";
	$os = results_get_os();
	html_print_list_box_from_array( $os, session_validate_form_get_field("os", $row_os) );
print"</select>\n";
print"</td>\n";
print"</tr>\n";

# Test Run Status
print"<tr>\n";
print"<td class=form-lbl-r>". lang_get('test_run_status') ." <span class='required'>*</span></td>\n";
print"<td class=left>\n";
print"<select name='test_run_status_required' size=1>\n";
	$test_run_status = results_get_teststatus_by_project( $project_id, $blank=true );
	html_print_list_box_from_array( $test_run_status, session_validate_form_get_field("test_run_status_required", $row_test_run_status) );
print"</select>\n";
print"</td>\n";
print"</tr>\n";

# Root Cause for Failure
print"<tr>\n";
print"<td class=form-lbl-r>". lang_get('root_cause') ."</td>\n";
print"<td class=left>\n";
print"<select name='root_cause' size=1>\n";
	$root_cause = results_get_root_cause_values();
	html_print_list_box_from_array( $root_cause, session_validate_form_get_field("root_cause", $row_root_cause) );
print"</select>\n";
print"</td>\n";
print"</tr>\n";

# E-mail user
print"<tr>\n";
print"<td class=form-lbl-r>". lang_get('email_test_run_status') ."</td>\n";
print"<td class=left>\n";
print"<select name='email_users[]' multiple size='3'>\n";
	$users 			= user_get_details_all($project_id);
	$email_users	= array();
	foreach($users as $user) {

		$email_users[$user[USER_EMAIL]] = $user[USER_UNAME];
	}
	$email_users[""] = "";

	html_print_list_box_from_key_array( $email_users, session_validate_form_get_field("email_users") );
print"</select>\n";
print "</td>\n";
print"</tr>\n";

# File Upload
print"<tr>\n\n";
print"<td><input type='hidden' name=MAX_FILE_SIZE  value='5000000'></td>\n\n";
print"</tr>\n\n";

print"<tr>\n";
print"<td class='form-lbl-r'>". lang_get('upload_file') ."</td>\n";
print"<TD class='form-data-l'><input type='file' name='upload_file' value='". session_validate_form_get_field("upload_file")."' size='40'></td>\n";
print"</tr>\n";

print"<tr><td><input type='hidden' name='test_id' value='$test_id'></td></tr>\n";
print"<tr><td><input type='hidden' name='testset_id' value='$testset_id'></td></tr>\n";

util_add_spacer();

print"<tr><td class=center colspan=2><input type=submit name='submit_button' value='". lang_get( 'save_results' ) ."'></td>\n";

#print"</form>\n";
print"</table>\n";
print"</td>\n";
print"</tr>\n";
print"</table>\n";
print"<br>\n";


# Test Steps
/*print"<form method=post name='test_run' action='$redirect_url'>\n";
print"<table class=hide100>\n";
print"<tr>\n";
print"<td>\n";
$rows_test_steps = test_get_test_steps( $test_id, $s_page_number );
print"</td>\n";
print"</tr>\n";
print"</table>\n";
//print"</form>\n"; */

$rows_test_steps = results_get_verify_results_detail( $test_run_id );

$num_test_steps = sizeof($rows_test_steps);

if( $num_test_steps != '0' ) {  # Display test steps if they exist


	print"<table class='width100' rules='cols'>\n";
	print"<tr class='tbl_header'>\n";
	html_tbl_print_header( lang_get('step_no') );
	html_tbl_print_header( lang_get('step_action') );
	html_tbl_print_header( lang_get('step_expected') );
	html_tbl_print_header( lang_get('actual_result') );
	html_tbl_print_header( lang_get('pass_fail') );
	print"</tr>\n";

	$i = 0;
	$row_style = '';
	foreach($rows_test_steps as $row_test_step ) {

		$verify_results_id  = $row_test_step[VERIFY_RESULTS_ID];
		$step_number     	= $row_test_step[VERIFY_RESULTS_VAL_ID];
		$step_action     	= $row_test_step[VERIFY_RESULTS_ACTION];
		$step_expected   	= $row_test_step[VERIFY_RESULTS_EXPECTED_RESULT];
		$step_actual	   	= $row_test_step[VERIFY_RESULTS_ACTUAL_RESULT];
		$test_status		= $row_test_step[VERIFY_RESULTS_TEST_STATUS];

		$row_style = html_tbl_alternate_bgcolor( $row_style );
		print"<tr class='$row_style'>\n";
		print"<td class='tbl-c' valign=top>$step_number</TD>\n";
		print"<td class='tbl-l' valign=top>$step_action</TD>\n";
		print"<td class='tbl-l' valign=top>$step_expected</TD>\n";
		print"<td><textarea name='actual_result_$verify_results_id' rows='4' cols='30'>".session_validate_form_get_field("actual_result_$verify_results_id", $step_actual)."</textarea></td>\n";
		print"<td>\n";
		print"<select name='step_status_$verify_results_id'>";

			$list_box = array( 	"Pass",
								"Fail",
								"Info",
								"" );

			$list_box_selected 	= session_validate_form_get_field( "step_status_$verify_results_id", $test_status );
			html_print_list_box_from_array(	$list_box,
											$list_box_selected );

		print"</select>\n";
		print"</td>\n";

		print"</tr>\n";

//		print"<td><input type='hidden' name='step_number[{$i}]' value='$step_number'></td>\n";
//		print"<td><input type='hidden' name='step_action[{$i}]' value='$step_action'></td>\n";
//		print"<td><input type='hidden' name='step_expected[{$i}]' value='$step_expected'></td>\n";

		$i++;

	}
	print"</table>\n";
}

print"</div>\n";


print"</form>\n";

html_print_footer();

# ---------------------------------------------------------------------
# $Log: results_continue_manual_test_page.php,v $
# Revision 1.3  2006/02/24 11:35:34  gth2
# update to div - class=div-c not working in firefox - gth
#
# Revision 1.2  2006/01/08 22:00:19  gth2
# bug fixes.  missing some variables - gth
#
# Revision 1.1.1.1  2005/11/30 23:00:58  gth2
# importing initial version - gth
#
# ---------------------------------------------------------------------

?>