<?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";

$page						= basename(__FILE__);
$update_action_page			= 'test_detail_page.php';
$test_step_edit_page		= 'test_step_edit_action.php';

$project_properties     = session_get_project_properties();
$project_name           = $project_properties['project_name'];
$project_id 			= $project_properties['project_id'];
//$test_id				= $_GET['test_id'];
//$test_version_id		= $_GET['test_version_id'];
$test_step_id			= $_GET['test_step_id'];

$s_test_detail			= session_get_properties('test');
$test_id			    = $s_test_detail['test_id'];
$test_data			    = test_get_detail($test_id);
$test_name=$test_data[TEST_NAME];
//$test_version_id		= $s_test_detail['test_version_id'];

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

        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;
       }


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

html_window_title();
auth_authenticate_user();

html_page_title($project_name ." - UC#".$test_id." ".$test_name." - Edit Use Case Step");
html_page_header( $db, $project_name );

html_print_menu();
test_menu_print ($page);
html_print_body();
print"<br><br>";

$ts_detail 	= test_get_test_step_detail( $test_step_id );

$step 		= $ts_detail[TEST_STEP_NO];
$action 	= $ts_detail[TEST_STEP_ACTION];
$expected 	= $ts_detail[TEST_STEP_EXPECTED];
$inputs		= $ts_detail[TEST_STEP_TEST_INPUTS];
$info_step 	= $ts_detail[TEST_STEP_INFO_STEP];
$parent_step 	= $ts_detail[TEST_STEP_PARENT];
$checked	= "";

error_report_check( $_GET );

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


		print"<form method=post name='test_step_add' action=$test_step_edit_page>\n";
		print"<input type='hidden' name='test_step_id' value='$test_step_id'>";
		//print"<td><input type='hidden' name='test_version_id' value='$test_version_id'></td>";

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

		print"<tr>\n";
			print"<td colspan=2 align=left class='form-lbl-l'>". lang_get('step') ." $step</td>\n";
		print"</tr>";

		$test_step_tbl  = TEST_STEP_TBL;
		$f_test_id		= TEST_STEP_TEST_ID;
		$f_test_step_no	= TEST_STEP_NO;
/*
		# MOVE STEP
		print"<tr>\n";
			print"<td class='form-lbl-r'>". lang_get('move_step') ."</td>\n";
			print"<td align=left>\n";
			print"<select name='location'>\n";
			print"<option value='none'></option>\n";
			print"<option value='end'>At end of table</option>\n";
				$q = "SELECT * FROM $test_step_tbl WHERE $f_test_id = '$test_id' ORDER BY $f_test_step_no";
				$rs = db_query( $db, $q );
				while($rw = db_fetch_row( $db, $rs ) ){
					print"<option value=$rw[$f_test_step_no]";
                                        print">After Step $rw[$f_test_step_no]</option>\n";
				}
			print"</select>\n";
		print"</td>\n";
		print"</tr>";
*/
		# PARENT STEP
			print"<td class='form-lbl-r'>ParentStep</td>\n";

			$test_step_tbl  = TEST_STEP_TBL;
			$f_test_id		= TEST_STEP_TEST_ID;
			$f_test_step_no	= TEST_STEP_NO;
			$f_test_step_id = TEST_STEP_ID;

			print"<td align=left>\n";
			print"<select name='parent_step'>";
			print"<option value='0'>-</option>";
				$q = "SELECT * FROM $test_step_tbl WHERE $f_test_id = '$test_id' ORDER BY $f_test_step_no";
				$rs = db_query( $db, $q );
				while($rw = db_fetch_row( $db, $rs ) ) if ($rw[$f_test_step_id]!=$test_step_id){
					print"<option value=$rw[$f_test_step_id]";
					if ($parent_step==$rw[$f_test_step_id]) echo ' selected';
					print">".substr($rw[TEST_STEP_ACTION], 0, 25);
					if (strlen($rw[TEST_STEP_ACTION])>25) print '...';
                                        print"</option>";
				}
			print"</select>\n";
			print"</td>\n";


		# ACTOR
		print"<tr>\n";
			print"<td class='form-lbl-r'>". lang_get('info_step') ."</td>\n";
			print"<td align=left>";

//                        print"<input type=checkbox name=info_step $checked>";
                        $checked = "";
			if( $info_step=="Y" ) { $checked = "selected"; }
                        print'<select name=info_step><option value="Y" '.$checked.'>'.lang_get('by_system').'</option>';
                        $checked = "selected";
			if( $info_step=="Y" ) { $checked = ""; }
                        print'<option value="N" '.$checked.'>'.lang_get('by_user').'</option>';
                        print'</select>';
                        print"</td>";
		print"</tr>";

		# ACTION
		$action = session_validate_form_get_field("step_action_required", $action, session_use_FCKeditor());
		print"<tr>";
			print"<td class='form-lbl-r'>". lang_get('step_action') ." <span class='required'>*</span></td>\n";
			print"<td align=left>";
			html_FCKeditor("step_action_required", 600, 200, $action);
			print"</td>\n";
		print"</tr>";


		# EXPTECTED RESULT
		$expected_result = session_validate_form_get_field("step_expected_required", $expected, session_use_FCKeditor());
		print"<tr>";
			print"<td class='form-lbl-r'>". lang_get('step_expected') ." <span class='required'>*</span></td>\n";
			print"<td align=left>";
			html_FCKeditor("step_expected_required", 600, 200, $expected_result);
			print"</td>\n";
		print"</tr>\n";

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

		util_add_spacer();

		# SUBMIT BUTTON
		print"<tr>\n";
		print"<td colspan='3' class=center><input type='submit' value='". lang_get('edit_step') ."'></td>\n";
		print"</tr>\n";

		util_add_spacer();

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

print"</td>\n";
print"</tr>\n";
print"</table>\n";
print"</div>";
?>