<?php
# ---------------------------------------------------------------------
# truc is a tool for requirement and use case tracking
# Copyright (C) 2006 ASDIS - http://sf.net/projects/truc
#
# (rth) Initial truc version based on rth
#       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
#----------------------------------------------------------------------

include"./api/include_api.php";

auth_authenticate_user();

$page                   = basename(__FILE__);
$action_page            = 'test_detail_update_action.php';
$s_project_properties   = session_get_project_properties();
$project_name           = $s_project_properties['project_name'];
$project_id             = $s_project_properties['project_id'];

$user_properties		= session_get_user_properties();
$user_id				= $user_properties['user_id'];
$username				= $user_properties['username'];

# Check to see if test_id is in GET (the user has clicked the pencil to go straight to update)
if( isset($_GET['test_id']) ) {
	$s_test_details		= session_set_properties("test", $_GET);
}

$s_test_details		= session_get_properties("test");
$test_id			= $s_test_details['test_id'];
//$test_version_id	= $s_test_details['test_version_id'];

        if (usecase_locked($project_id,$test_id,$username)) {
                 html_print_operation_failed( 'usecase_edit_page',error_report_msg(CAN_NOT_MODIFY_USECASE_LOCKED,usecase_locked_by($project_id,$test_id)), "test_detail_page.php?test_id=".$test_id);
                 exit;
       }


$s_show_options = session_get_show_options();
$show_priority = $s_show_options['show_priority'];

if(isset($_GET['failed'])) {
    $is_validation_failure = $_GET['failed'];
}
else
    $is_validation_failure = false;


#global $db;

html_window_title();
html_page_title($project_name ." - ". lang_get('update_test_page') );
html_page_header( $db, $project_name );
html_print_menu();
test_menu_print ($page);
html_print_body();

error_report_check( $_GET );

$row = test_get_detail( $test_id  );

if(!empty($row)) {

	$test_name       = $row[TEST_NAME];
	$ba_owner        = $row[TEST_BA_OWNER];
	$qa_owner        = $row[TEST_QA_OWNER];
	$tester			 = $row[TEST_TESTER];
	$test_type       = $row[TEST_TESTTYPE];
	$manual          = $row[TEST_MANUAL];
	$automated       = $row[TEST_AUTOMATED];
	$area_tested     = $row[TEST_AREA_TESTED];
	$autopass        = $row[TEST_AUTO_PASS];
	$test_purpose    = $row[TEST_PURPOSE];
	$test_comments   = $row[TEST_COMMENTS];
	$test_priority   = $row[TEST_PRIORITY];
	$performance     = $row[TEST_LR];
	$assigned_to     = $row[TEST_ASSIGNED_TO];
	$assigned_by     = $row[TEST_ASSIGNED_BY];
	$dateassigned    = $row[TEST_DATE_ASSIGNED];
	$dateexpcomplete = $row[TEST_DATE_EXPECTED];
	$dateactcomplete = $row[TEST_DATE_COMPLETE];
	$duration		 = $row[TEST_DURATION];
	$test_status     = $row[TEST_STATUS];
	$signoff_date    = $row[TEST_SIGNOFF_DATE];
	$signoff_by		 = $row[TEST_SIGNOFF_BY];
	//$test_status     = ${'v_' . TEST_VERS_STATUS};
	//$signoff_date    = ${'v_' . TEST_VERS_SIGNOFF_DATE};
	//$signoff_by		 = ${'v_' . TEST_VERS_SIGNOFF_BY};
	$pre        = $row[USECASE_PRE_CONDITION];
	$post        = $row[USECASE_POST_CONDITION];

	print"<br>";

	print"<div align=center>";
	print"<span class='required'>*</span><span class='print'>" . lang_get('must_complete_field') . "</span><br>";
	print"<div align='center'>";
	print"<table class=width75>";
	print"<tr>";
	print"<td>";
		print"<table class=inner rules=none border=0>";
		print"<form method=post action=$action_page?test_id=$test_id>";

		print"<tr>";
		print"<td class=print-category colspan=2>".lang_get('update_test')."</td>";
		print"</tr>";

		print"<tr>";
		print"<td class=form-lbl-r>". lang_get('test_name') ."<span class='required'>*</span></td>";
		print"<td class=left>";
			print"<input type=text size=67 name=testname_required value='" . session_validate_form_get_field('testname_required', $test_name);
			print"'>";
		print"</td>";
		print"</tr>";

		print"<tr>";
		print"<td class=form-lbl-r>". lang_get('usecase_pre') ."</td>";
		print"<td class=left>";
				print"<textarea rows='4' cols='50' name='testpre'>" .
				session_validate_form_get_field('testpre', $pre) ;
				print"</textarea>";
		print"</td>";
		print"</tr>";

		print"<tr>";
		print"<td class=form-lbl-r>". lang_get('usecase_post') ."</td>";
		print"<td class=left>";
				print"<textarea rows='4' cols='50' name='testpost'>" .
				session_validate_form_get_field('testpost', $post) ;
				print"</textarea>";
		print"</td>";
		print"</tr>";
		print"<tr>";
		print"<td class=form-lbl-r>". lang_get('test_purpose') ."</td>";
		print"<td class=left>";
				print"<textarea rows='4' cols='50' name='testpurpose'>" .
				session_validate_form_get_field('testpurpose', $test_purpose) ;
				print"</textarea>";
		print"</td>";
		print"</tr>";


		print"<tr>";
		print"<td class=form-lbl-r>". lang_get('test_comments') ."</td>";
		print"<td class=left>";
			print"<textarea rows='2' cols='50' name='testcomments'>" .
				   session_validate_form_get_field('testcomments', $test_comments);
			print"</textarea>";
		print"</td>";
		print"</tr>";


		# TEST STATUS
		print"<tr>";
		print"<td class=form-lbl-r>". lang_get('test_status') ."</td>";
		print"<td class=left>";
			$selected_value = session_validate_form_get_field('teststatus', $test_status);
			$statuses = test_get_status( $blank=false );
			print"<select name='teststatus' size=1>";
			html_print_list_box_from_array( $statuses, $selected_value);
			#html_print_list_box( $db, TEST_STATUS_TBL, TEST_STATUS_STATUS, $project_id, $selected_value);
			print"</select>";
		print"</td>";
		print"</tr>";


		print"<tr><td class=center colspan=2><input type=submit name='save' value='Update'> <input type=submit name='save' value='Upgrade'><br><br></td></tr>";

		print"</form>";
		print"</table>";
	print"</td>";
	print"</tr>";
	print"</table>";
	print"<br>";
	print"</div>";
	print"</div>";

}

html_print_footer();
?>