<?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();
$step_action="";
$step_expected="";

$page						= basename(__FILE__);
$update_action_page			= 'test_detail_update_page.php';
$add_version_page			= 'test_add_version_page.php';
$delete_page				= 'delete_page.php';
$new_upload_action_page		= 'test_detail_new_upload_action.php';
$row_test_step_add_action_page  = 'test_step_add_action.php';
$row_test_step_renumber_page    = 'test_step_renumber_action.php';
$row_test_step_edit_page		= 'test_step_edit_page.php';
$active_version_page		= 'test_version_make_active_action.php';
$test_page					= 'test_page.php';
#$row_test_step_delete_page		= 'delete_page.php';

$num                    = 0;
$bg_color               = '';
$row_style				= '';

$s_user_properties		= session_get_user_properties();
$s_project_properties   = session_get_project_properties();
$s_show_options 		= session_get_show_options();
$s_test_details			= session_set_properties("test", $_GET);

$s_user_id				= $s_user_properties['user_id'];
$s_username				= $s_user_properties['username'];
$s_tempest_admin		= $s_user_properties['tempest_admin'];
$s_project_rights		= $s_user_properties['project_rights'];
$s_delete_rights		= $s_user_properties['delete_rights'];
$s_email				= $s_user_properties['email'];

$project_name           = $s_project_properties['project_name'];
$project_id				= $s_project_properties['project_id'];

$show_priority 			= $s_show_options['show_priority'];

$test_id				= $s_test_details['test_id'];
//$test_version_id		= $s_test_details['test_version_id'];

function RemoveFirstFromArray($array) {
   foreach ($array as $index => $value) {
       unset($array[$index]);
       return $array;
   }
   return $array;
}

function array_top($array) {
   foreach ($array as $index => $value) {
       return $array[$index];
   }
   return false;
}

$way=array();
if (!empty($_GET['way'])) {
  $way=explode('-',$_GET['way']);
  if (isset($way[0]) && $way[0]=="") $way=RemoveFirstFromArray($way);
}

if (!empty($_GET['time'])) $version_control_time=session_validate_form_get_field('time', $_GET['time']); else
   $version_control_time=0;

if ($version_control_time!=0) $redirect_url			= $page . "?test_id=". $test_id.'&amp;time='.$version_control_time;
else
$redirect_url			= $page . "?test_id=". $test_id;

//$test_name 			= test_get_name( $test_id );

session_set_display_options('test_detail', $_POST);
$s_test_detail_options 	= session_set_display_options('test_detail', $_GET);
$s_tab					= $s_test_detail_options['tab'];
$s_page_number			= $s_test_detail_options['page_number'];

if( isset($_GET['test_id']) ) {

	$s_page_number = 1;
}


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

$project_manager		= user_has_rights( $project_id, $s_user_id, MANAGER );
$user_has_delete_rights	= ($s_delete_rights==="Y" || $project_manager);

# LOCK REQUIREMENT
if( isset($_POST['submit_usecase_lock']) ) {

	usecase_lock($test_id, $s_username);

	############################################################################
	# EMAIL NOTIFICATION
	############################################################################
//	$recipients	= requirement_get_notify_users($project_id, $s_req_id);
//	requirement_email($project_id, $s_req_id, $recipients, $action="lock");
	############################################################################
	############################################################################
}

# UNLOCK REQUIREMENT
if( isset($_POST['submit_usecase_unlock']) ) {

	usecase_unlock($test_id);

	############################################################################
	# EMAIL NOTIFICATION
	############################################################################
//	$recipients	= requirement_get_notify_users($project_id, $s_req_id);
//	requirement_email($project_id, $s_req_id, $recipients, $action="unlock");
	############################################################################
	############################################################################
}

html_window_title();
html_print_body();

$row = test_get_detail( $test_id, $version_control_time);

$test_name       	= $row[TEST_NAME];

$test_purpose    	= $row[TEST_PURPOSE];
$test_comments		= $row[TEST_COMMENTS];
$ba_owner        	= $row[TEST_BA_OWNER];
$qa_owner        	= $row[TEST_QA_OWNER];
$tester	        	= $row[TEST_TESTER];
$test_type       	= $row[TEST_TESTTYPE];
$area_tested     	= $row[TEST_AREA_TESTED];
$test_priority   	= $row[TEST_PRIORITY];
$manual          	= $row[TEST_MANUAL];
$automated       	= $row[TEST_AUTOMATED];
$performance	 	= $row[TEST_LR];
$autopass        	= $row[TEST_AUTO_PASS];
$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_by		 	= $row[TEST_SIGNOFF_BY];
$signoff_date    	= $row[TEST_SIGNOFF_DATE];
$last_updated_date 	= $row[TEST_LAST_UPDATED];
$last_updated_by 	= $row[TEST_LAST_UPDATED_BY];
$test_versioncounter 	= $row[TEST_VERSIONCOUNTER];
$locked_by		= $row[USECASE_LOCKED_BY];
$locked_date		= $row[USECASE_LOCKED_DATE];
$post_condition         = $row[USECASE_POST_CONDITION];
$pre_condition         = $row[USECASE_PRE_CONDITION];
$locked=usecase_locked($project_id,$test_id,$s_username);

$user_has_delete_rights	= ((($s_delete_rights==="Y") || $project_manager));


//html_page_title($project_name ." - #".$test_id." ".$test_name." <small>(". lang_get('test_detail_page'). ")</small>");
html_page_title($project_name ." - UC#".$test_id." ".$test_name."");
html_page_header( $db, $project_name );
html_print_menu();

test_menu_print($page);

error_report_check( $_GET );




# $test_version_id = $row[TEST_VERS_ID]; It's in the session
//$version_no		 = $row[TEST_VERS_NUMBER];
//$latest_version	 = $row[TEST_VERS_LATEST];
//$active_version  = $row[TEST_VERS_ACTIVE];
//$test_comments   = $row[TEST_VERS_COMMENTS];
//$test_status     = $row[TEST_VERS_STATUS];
//$signoff_by		 = $row[TEST_VERS_SIGNOFF_BY];
//$signoff_date    = $row[TEST_VERS_SIGNOFF_DATE];
//$author			 = $row[TEST_AUTHOR];
$date_created	 = $row[TEST_DATE_CREATED];

print"<br>";
print"<div align=center>";
if ($version_control_time!=0) {
	print"<table class=width95>\n";
		print"<tr>\n";
				print"<td style='background-color:#F8A302;color:#FFFFFF;text-align:center' width='25%'><br/> <b>Test #".$test_id.", Version from ";
				print strftime("%d.%m.%y, %H:%S",$version_control_time);
                                print"</b>:: <a href='test_detail_page.php?test_id=".$test_id."'>Current Version</a><br/><br/></td>\n";
			print"</tr>\n";


	print"</table>\n";


print"<br>";
}

if ( !empty($row) ) {


	print"<table class=width100>\n";
		print"<tr>\n";
				print"<td class=grid-header-l width='25%'>\n";
				print lang_get('last_updated_by');
				print"</td>\n";
				print"<td class=grid-data-l width='75%'>\n";
				print $last_updated_by.", ".$last_updated_date;
				print"</td>\n";
			print"</tr>\n";
			print"<tr>\n";
				print"<td class=grid-header-l>". lang_get('test_status') ."</td>\n";
				print"<td class=grid-data-l>$test_status</td>\n";
			print"</tr>\n";
	#---------------
if(!empty($locked_by)) {
			print"<tr>\n";
				print"<td class=grid-header-l>". lang_get('locked_by') ."</td>\n";
				print"<td class=grid-data-l>$locked_by, $locked_date</td>\n";
			print"</tr>\n";
}

			print"<tr>\n";
				print"<td class=grid-header-l>". lang_get('usecase_pre') ."</td>\n";
				print"<td class=grid-data-l>";
				print nl2br($pre_condition);
				print"</td>\n";
			print"</tr>\n";
			print"<tr>\n";
				print"<td class=grid-header-l>". lang_get('usecase_post') ."</td>\n";
				print"<td class=grid-data-l>";
				print nl2br($post_condition);
				print"</td>\n";
			print"</tr>\n";

			print"<tr>\n";
				print"<td class=grid-header-l>". lang_get('test_purpose') ."</td>\n";
				print"<td class=grid-data-l>";
				print nl2br($test_purpose);
				print"</td>\n";
			print"</tr>\n";
	#----------------
			print"<tr>\n";
				print"<td class=grid-header-l>\n";
				print lang_get('test_comments');
				print"</td>\n";
				print"<td class=grid-data-l >\n";
				print nl2br($test_comments);
				print"</td>\n";
			print"</tr>\n";


	print"</table>\n";
if ($version_control_time==0) {

# enable/disable lock buttons
# if not locked
$can_edit="disabled";
if( $locked) {

	$lock = "disabled";
	$unlock = "disabled";
	if ($locked_by==$s_username) $unlock="";

} # if locked and current user locked it, or current user a manager
else {
        $can_edit="";
	$lock = "";
	$unlock = "disabled";
	if ($locked_by==$s_username) {
          $lock = "disabled";
          $unlock="";
        }

}

     // Show only if not in history
	print"<div style='text-align:left'><table>\n";
	print"<tr>\n";
		# UPDATE TEST
		print"<td>\n";
		print"<form method=post action='$update_action_page?test_id=$test_id'>\n";
		print"<input type='submit' $can_edit value='". lang_get('update_test') ."'>\n";
		print"</form>\n";
		print"</td>\n";



		# DELETE TEST

		# disable delete button if user does not have the rights
		if( $user_has_delete_rights && (!$locked)) {
			$delete_disabled = "";
		} else {
			$delete_disabled = "disabled";
		}

		print"<td>\n";
		print"<form method=post action='$delete_page'>\n";
		print"<input  style='margin-left:30px;margin-right:30px'type='submit' value='". lang_get('delete_test_btn') ."' $delete_disabled>\n";
		print"<input type='hidden' name='r_page' value='$test_page'>";
		print"<input type='hidden' name='f' value='delete_test'>";
		print"<input type='hidden' name='id' value='$test_id'>";
		print"<input type='hidden' name='msg' value='210'>";

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

		print"<td>\n";
		print"<form method=post action='$page?test_id=$test_id'>\n";
		print"<input type='submit' name='submit_usecase_lock' $lock value='". lang_get('lock_test') ."'>\n";
		print"</form>\n";
		print"</td>\n";
		print"<td>\n";
		if ($user_has_delete_rights && $locked) $unlock="";
		print"<form method=post action='$page?test_id=$test_id'>\n";
		print"<input type='submit' name='submit_usecase_unlock' $unlock value='". lang_get('unlock_test') ."'>\n";
		print"</form>\n";
		print"</td>\n";
	print"</tr>\n";
	print"</table></div>\n";
  }

} else {
    print"<br><span class='print'>" . lang_get('no_test_suites') . $project_name . "</span>";
}


# Begin section for Test Steps - Documentation - Requirement Association
print"<br>";

print"<table class=hide100>\n";
print"<tr>\n";
print"<td>\n";
test_sub_menu_print( $test_id, $page, $s_tab,$version_control_time);
print"</td>\n";
print"</tr>\n";

//error_report_check( $_GET );

print"<tr>\n";
print"<td align=center>\n";
switch( $s_tab ) {

	case '5':


		print"<form method=post name='test_steps' action='$page'>\n";
		print"<table class=hide100>\n";
		print"<tr>\n";
		print"<td>\n";
		print"</td>\n";
		print"</tr>\n";
		print"</table>\n";
		print"</form>\n";
			$flows=test_get_flows($test_id,null,$version_control_time);
			if (!empty($flows[0]))
			foreach($flows as $flow) {
			print"<table class='width100' rules='cols'>\n";
			print"<tr class='tbl_header'>\n";
			echo'<th width="5%">'.lang_get('step_no').'</th>';
			echo'<th width="5%">'.lang_get('info_step').'</th>';
			echo'<th width="25%">'.lang_get('step_action').'</th>';
			echo'<th width="25%">'.lang_get('step_expected').'</th>';
			if ($version_control_time==0  && $user_has_delete_rights) echo '<th width="5%">'.lang_get('step_edit').'</th>';
			print"</tr>\n";
                          foreach ($flow as $row_test_step) {

                          
				$row_test_step_id	= $row_test_step[TEST_STEP_ID];
				$step_action     	= $row_test_step[TEST_STEP_ACTION];
				$step_number     	= $row_test_step[TEST_STEP_NO];
				$step_expected   	= $row_test_step[TEST_STEP_EXPECTED];
				$info_step 			= $row_test_step[TEST_STEP_INFO_STEP];
				$row_style = html_tbl_alternate_bgcolor( '' );
				$info_step_class = "";
				$step_actor=lang_get('by_user');
				if( $info_step=="Y" ) {
        				$step_actor=lang_get('by_system');
					$info_step_class = "class='test-step-info'";
				}



				print"<tr class='$row_style' style='border-top:1px dashed;'>\n";
				print"<td class='tbl-l' align=left><div $info_step_class>$step_number</div></td>\n";
				print"<td  class='tbl-l' align=center><div $info_step_class>$step_actor</div></td>\n";
				print"<td class='tbl-l' align=left><div $info_step_class>";
                                print " $step_action";
                                print"</div></td>\n";
				print"<td class='tbl-l' align=left><div $info_step_class>$step_expected";
                                print"</div></td>\n";
				if ($version_control_time==0 && $user_has_delete_rights) {
				print"<td class='tbl-c' style='white-space:nowrap'>";
					print"<a href='$row_test_step_edit_page?test_id=$test_id&amp;test_step_id=$row_test_step_id'>[". lang_get('edit_link') ."]</a>&nbsp\n";
					print"<form name='delete_test_step' method=post action='$delete_page'>\n";
					print"<input type='submit' name='delete' value='[". lang_get( 'delete' ) ."]' class='page-numbers'>";
					print"<input type='hidden' name='r_page' value='$redirect_url'>\n";
					print"<input type='hidden' name='f' value='delete_test_step'>\n";
					print"<input type='hidden' name='id' value='$row_test_step_id'>\n";
					print"<input type='hidden' name='msg' value='100'>\n";
					print"</form>\n";
				print"</td>\n";
				}
				print"</tr>\n";
                          }
			print"</table>\n";
		print"<br><br>\n";
                        }



		break;

//test_print_steptree
	case '1':

                if ($version_control_time==0) {
                // Show only if not in history
/*
		if( IMPORT_EXPORT_TO_EXCEL ) {
			print"[ <a href='test_step_import_csv_page.php'>".lang_get('import_teststeps_excel')."</a> ]\n";
			print"[ <a href='csv_export.php?table=test_steps'>".lang_get('export_teststeps_excel')."</a> ]\n";
		}
		else {
			print"[ <a href='test_step_import_csv_page.php'>".lang_get('import_teststeps_csv')."</a> ]\n";
			print"[ <a href='csv_export.php?table=test_steps'>".lang_get('export_teststeps_csv')."</a> ]\n";
		}
                */
		              }


		print"<form method=post name='test_steps' action='$page'>\n";
		print"<table class=hide100>\n";
		print"<tr>\n";
		print"<td>\n";
		print"</td>\n";
		print"</tr>\n";
		print"</table>\n";
		print"</form>\n";
			print"<table class='width100' rules='cols'>\n";
			print"<tr class='tbl_header'>\n";
			echo'<th width="5%">'.lang_get('step_no').'</th>';
			echo'<th width="5%">'.lang_get('info_step').'</th>';
			echo'<th width="25%">'.lang_get('step_action').'</th>';
			echo'<th width="25%">'.lang_get('step_expected').'</th>';
			if ( $user_has_delete_rights && $version_control_time==0 ) echo '<th width="5%">'.lang_get('step_edit').'</th>';
			print"</tr>\n";
                        if( test_print_steptree($test_id,$way,$root=0,$version_control_time,$user_has_delete_rights) != '0' ) {  # Display test steps if they exist
/*
			if ($version_control_time==0) {
			print"<br>\n";
			# RENUMBER TEST STEPS BUTTON
			print"<form action=$row_test_step_renumber_page method=post>\n";
			print"<input type='submit' name=renumber value='". lang_get( 'renumber_steps' ) ."'>\n";
			print"<input type='hidden' name='test_id' value='$test_id'>\n";
			//print"<input type='hidden' name='test_version_id' value='$test_version_id'>";

			print"</form>\n";
			}
			*/

		         }
		print"</table>\n";

		print"<br><br>\n";

                if (( $user_has_delete_rights && $version_control_time==0 )&&(!$locked)) {
                // Show only if not in history


		# ------------------------------------------------------
		# Begin Test Step Form that allows users to add steps
		# ------------------------------------------------------
		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"<a name='steps' id='steps'></a>\n";

		print"<form method=post name='test_step_add' action=$row_test_step_add_action_page>\n";
		//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('add_test_step') ."</td>\n";
		print"</tr>";
		/*
		# ADD STEP AFTER...
		print"<tr>\n";
			print"<td class='form-lbl-r'>Position</td>\n";

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

			print"<td align=left>\n";
			print"<select name='location'>";
			print"<option value='end'>At end of table</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 ) ){
					print"<option value=$rw[$f_test_step_no]>After Step $rw[$f_test_step_no]</option>";
				}
			print"</select>\n";
			print"</td>\n";
		print"</tr>";
                */
		# ADD STEP AFTER...
		print"<tr>\n";
			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 ) ){
					print"<option value=$rw[$f_test_step_id]>".substr(strip_tags($rw[TEST_STEP_ACTION]), 0, 25);
					if (strlen(strip_tags($rw[TEST_STEP_ACTION]))>25) print '...';
                                        print"</option>";
				}
			print"</select>\n";
			print"</td>\n";
		print"</tr>";

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

                        print'<select name=info_step>';
                        print'<option value="N">'.lang_get('by_user').'</option><option value="Y">'.lang_get('by_system').'</option>';
                        print'</select>';
                        print"</td>";
		print"</tr>";

		# ACTION
		$action = session_validate_form_get_field("step_action_required", "", 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", "", 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";
		if (!empty($_GET['way']))	print"<td><input type='hidden' name='way' value='".$_GET['way']."'></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('add_step') ."'></td>\n";
		print"</tr>\n";

		util_add_spacer();

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

		print"</td>\n";
		print"</tr>\n";
		print"</table>\n";
                }
		break;

	# SUPPORTING DOCUMENTATION
	# FILE UPLOAD
	case '2':

		$upload_rows = test_get_uploaded_documents($test_id);

		if( !empty($upload_rows) ) {

			print"<br>";
			print"<table class=width95>";
			print"<tr>";
			print"<td>";
				print"<table class=inner>";
				print"<tr>";
					print"<td class=grid-header-c>". lang_get('file_name') ."</td>";
					print"<td class=grid-header-c>". lang_get('version') ."</td>";
					print"<td class=grid-header-c>". lang_get('view') ."</td>";
					print"<td class=grid-header-c>". lang_get('download') ."</td>";
					print"<td class=grid-header-c>". lang_get('show_history') ."</td>";
if (($version_control_time==0)&&(!$locked))					print"<td class=grid-header-c>". lang_get('add_version') ."</td>";
					//print"<td class=grid-header-c>". lang_get('edit') ."</td>";
					print"<td class=grid-header-c>". lang_get('uploaded_by') ."</td>";
					print"<td class=grid-header-c>". lang_get('date_added') ."</td>";
					print"<td class=grid-header-c>". lang_get('info') ."</td>";
					//print"<td class=grid-header-c>". lang_get('delete_latest') ."</td>";
				print"</tr>";

				foreach($upload_rows as $upload_row) {

					$display_name  = $upload_row[MAN_TD_DISPLAY_NAME];
					$man_test_id   = $upload_row[MAN_TD_MANUAL_TEST_ID];
					$doc_detail_row = test_get_uploaded_document_detail($man_test_id);
					$filename      = $doc_detail_row[MAN_TD_VER_FILENAME];
					$comments      = $doc_detail_row[MAN_TEST_DOCS_VERS_COMMENTS];
					$time_stamp    = $doc_detail_row[MAN_TD_VER_TIME_STAMP];
					$uploaded_by   = $doc_detail_row[MAN_TD_VER_UPLOADED_BY];
					$version       = $doc_detail_row[MAN_TD_VER_VERSION];
					$doc_type      = $doc_detail_row[MAN_TEST_DOCS_VERS_MANUAL_DOC_TYPE_NAME];

					$fname = FILE_UPLOAD_PATH.$s_project_properties['project_id'].'/'. $filename;

					print"<tr>";
						print"<td class=grid-data-c>$display_name</td>";
						print"<td class=grid-data-c>$version</td>";
						print"<td class=grid-data-c>";
						print"<a href='$fname' target='new'>" . lang_get('view') . "</a>";
						print"</td>";
						print"<td class=grid-data-c>";
						print"<a href='download.php?upload_filename=$fname'>" . lang_get('download') . "</a>";
						print"</td>";
						print"<td class=grid-data-c>";
						print"<a href='test_doc_history_page.php?test_id=$test_id&mantestid=$man_test_id'>" . lang_get('show') . "</a>";
						print"</td>";
if (($version_control_time==0)&&(!$locked)) {
						print"<td class=grid-data-c>";
						print"<a href='test_add_doc_version_page.php?test_id=$test_id&manual_test_id=$man_test_id'>" . lang_get('add') . "</a>";
						print"</td>";
}
						//print"<td class=grid-data-c>";
						//print"<a href='test_doc_edit_page.php?mantestid=$man_test_id'>" . lang_get('edit') . "</a>";
						//print"</td>";
						print"<td class=grid-data-c>$uploaded_by</td>";
						print"<td class=grid-data-c>$time_stamp</td>";
						print"<td class=grid-data-c>";

						  if($comments) {
							  print"<img src='". IMG_SRC . "/info.gif' title='$comments'>";
						  }
						  else {
							  print"&nbsp;";
						  }

						print"</td>";
						//print"<td class=grid-data-c>";
						//print"<a href='test_doc_delete_page.php?mantestid=$man_test_id'>" . lang_get('delete') . "</a>";
						//print"</td>";
					print"</tr>";
				}

				print"</table>";
			print"</td>";
			print"</tr>";
			print"</table>";


		}
		else {
			print"<br><span class='print'><div align='center'>" . lang_get('no_documentation') . "</div></span>";
		}

		print"<br>\n";
                if (($version_control_time==0)&&(!$locked)) {

		print"<table class=width95>\n";
		print"<tr>\n";
		print"<td>\n";
			print"<form enctype=multipart/form-data name=upload action='$new_upload_action_page' method=post>\n";
			print"<table class=inner>\n";

			print"<tr class=left>\n";
				print"<td class=form-header-l colspan=2>" . lang_get('upload_heading') . "</td>\n";
			print"</tr>\n";
			print"<tr>\n";
				print"<td class=form-lbl-r>" . lang_get('file_name') . "</td>\n";
				print"<td class=form-data-l><input type='file' name='uploadfile' size='60'></td>\n";
			print"</tr>\n";
			print"<tr>\n";
				print"<td class=form-lbl-r>" . lang_get('comments') . "</td>\n";
				print"<td class=form-data-l><textarea rows='2' cols='45' name='comments'></textarea></td>\n";
			print"</tr>\n";
			print"<tr>\n";
				print"<td colspan=2><input type='hidden' name='MAX_FILE_SIZE' value='25000000'></td>\n";
			print"</tr>\n";
			print"<tr>\n";
				print"<td class=center colspan=2><input type='submit' value='Upload'></td>\n";
			print"</tr>\n";
			print"</table>\n";
			print"</form>\n";
		print"</td>\n";
		print"</tr>\n";
		print"</table>\n";
		print"<br>\n";
		print"<br>\n";
		              }

		break;

	# REQ ASSOC
	case '3':

		/*
		print"<br>";
		print"<b><div align='left'>" . lang_get('req_assoc_section') . "</div></b>";
		print"<hr>";
		print"<br>";
		*/
		if ($version_control_time!=0) $associated_row = test_get_associated_requirements($test_id,$test_versioncounter); else
		$associated_row = test_get_associated_requirements($test_id);

		if (!empty($associated_row)) {

		print"<table cellpadding=4 width='100%'>\n";
		print"<tr><td colspan=\"2\"><b>Current requirement associations</b></td></tr>\n";
		print"<tr>\n";
		print"<td>\n";

		print"<table rules=cols class=width100>\n";
		print"<tr>\n";
			print"<th width='10%' class=grid-header-c>". lang_get('req_id') ."</th>";
			print"<th width='80%' class=grid-header-c>". lang_get('req_name') ."</th>";
			if( $user_has_delete_rights && $version_control_time==0) {
				print"<th width='10%' class=grid-header-c>". lang_get('delete') ."</th>";
			}
		print"</tr>";

		foreach( $associated_row as $row_associated_reqs ) {
			$assoc_id			= $row_associated_reqs[TEST_REQ_ASSOC_ID];
			$req_id				= $row_associated_reqs[REQ_ID];
			$req_filename		= $row_associated_reqs[REQ_FILENAME];
			$req_assoc_covered	= $row_associated_reqs[TEST_REQ_ASSOC_PERCENT_COVERED];
			$req_id_link		= util_pad_id($req_id);

			$row_style = html_tbl_alternate_bgcolor($row_style);

                        $req_to_usecase_version=$row_associated_reqs[TEST_REQ_ASSOC_USECASE_VERSIONCOUNTER];
                        
                        $req_to_usecase_version_message="";
                        if ($test_versioncounter!=$req_to_usecase_version) {
                           $req_to_usecase_version_message="<img src='images/fail.gif' />";
                           $req_to_usecase_version_message="<small>(Prev. Version)</small>";
			} else {

			print"<tr class='$row_style'>\n";
				print"<td class='tbl-c'><a href='requirement_detail_page.php?req_id=$req_id&tab=2'>$req_id_link</a> $req_to_usecase_version_message</td>";
				print"<td class='tbl-l'>$req_filename</td>";
				//print"<td class='tbl-c'><a href='test_req_edit_coverage_page.php?req_id=$req_id&amp;tab=2'>" . lang_get('edit') ."</a></td>";
                     		if( $user_has_delete_rights && $version_control_time==0) {
					print"<td class='tbl-c'><a href='test_delete_assoc_action.php?assoc=req&amp;assoc_id=$assoc_id'>" . lang_get('delete') ."</a></td>";
				}
			print"</tr>";
			}

		}
		print"</table>";
		print"</td>";
		print"</tr>";
		print"</table>";
		}

		if ($version_control_time!=0) $associated_row = test_get_associated_requirements($test_id,$test_versioncounter); else
		$associated_row = test_get_associated_requirements($test_id);
		if (!empty($associated_row)) {

		print"<br/><table cellpadding=4 width='100%'>\n";
		print"<tr><td colspan=\"2\"><b>Not yet confirmed requirement associations of prior Use-Case versions</b></td></tr>\n";
		print"<tr>\n";
		print"<td>\n";

		print"<table rules=cols class=width100>\n";
		print"<tr>\n";
			print"<th width='10%'  class=grid-header-c>". lang_get('req_id') ."</th>";
			print"<th width='80%'  class=grid-header-c>". lang_get('req_name') ."</th>";
			if( $user_has_delete_rights && $version_control_time==0) {
				print"<th  width='10%' class=grid-header-c>". lang_get('delete') ."</th>";
			}
		print"</tr>";

		foreach( $associated_row as $row_associated_reqs ) {
			$assoc_id			= $row_associated_reqs[TEST_REQ_ASSOC_ID];
			$req_id				= $row_associated_reqs[REQ_ID];
			$req_filename		= $row_associated_reqs[REQ_FILENAME];
			$req_assoc_covered	= $row_associated_reqs[TEST_REQ_ASSOC_PERCENT_COVERED];
			$req_id_link		= util_pad_id($req_id);

			$row_style = html_tbl_alternate_bgcolor($row_style);

                        $req_to_usecase_version=$row_associated_reqs[TEST_REQ_ASSOC_USECASE_VERSIONCOUNTER];

                        if ($test_versioncounter!=$req_to_usecase_version) {

			print"<tr class='$row_style'>\n";
				print"<td class='tbl-c'><a href='requirement_detail_page.php?req_id=$req_id&tab=2'>$req_id_link</a></td>";
				print"<td class='tbl-l'>$req_filename</td>";
				//print"<td class='tbl-c'><a href='test_req_edit_coverage_page.php?req_id=$req_id&amp;tab=2'>" . lang_get('edit') ."</a></td>";
				if( $user_has_delete_rights && $version_control_time==0 ) {
					print"<td class='tbl-c'><a href='test_delete_assoc_action.php?assoc=req&amp;assoc_id=$assoc_id'>" . lang_get('delete') ."</a></td>";
				}
			print"</tr>";
			}

		}
		print"</table>";
		print"</td>";
		print"</tr>";
		print"</table>";
		}

		break;
	case '4':

		/*
		print"<br>";
		print"<b><div align='left'>" . lang_get('req_assoc_section') . "</div></b>";
		print"<hr>";
		print"<br>";
		*/
		$associated_row = test_get_history($test_id);
		if (!empty($associated_row)) {

		print"<table cellpadding=4 width='90%'>\n";
		print"<tr>\n";
		print"<td>\n";

		print"<table rules=cols class=width100>\n";
		print"<tr>\n";
			print"<th class=grid-header-c>". lang_get('version_moment') ."</th>";
			print"<th class=grid-header-c>". lang_get('test_name') ."</th>";
			print"<th class=grid-header-c>". lang_get('test_purpose') ."</th>";
		print"</tr>";

		foreach( $associated_row as $row_associated_reqs ) {
			$version_test_name = $row_associated_reqs[TEST_NAME];
			$version_date      = $row_associated_reqs[TEST_VERSIONCONTROL_VERSIONDATE];
			$version_purpose      = $row_associated_reqs[TEST_PURPOSE];

			$row_style = html_tbl_alternate_bgcolor($row_style);
			print"<tr class='$row_style'>\n";
				print"<td class='tbl-c'><a href='test_detail_page.php?test_id=$test_id&amp;time=$version_date'>".strftime("%d.%m.%y, %H:%S",$version_date)."</a></td>";
				print"<td class='tbl-l'>$version_test_name</td>";
				print"<td class='tbl-l'>$version_purpose</td>";

			print"</tr>";

		}
		print"</table>";
		print"</td>";
		print"</tr>";
		print"</table>";
		}
		break;
	/*
	case '4':

	print"<br>";
	print"<table class=width95>";
		print"<tr>";
		print"<td>";
			print"<table class=inner>";
			print"<tr>";
				print"<td class=grid-header-c>". lang_get('test_version') ."</td>";
				print"<td class=grid-header-c>". lang_get('created_by') ."</td>";
				print"<td class=grid-header-c>". lang_get('test_created_date') ."</td>";
				print"<td class=grid-header-c>". lang_get('test_status') ."</td>";
				print"<td class=grid-header-c>". lang_get('signoff_by') ."</td>";
				print"<td class=grid-header-c>". lang_get('signoff_date') ."</td>";
				print"<td class=grid-header-c>". lang_get('signoff') ."</td>";
				print"<td class=grid-header-c>". lang_get('active') ."</td>";
				print"<td class=grid-header-c>". lang_get('make_active') ."</td>";
				print"<td class=grid-header-c>". lang_get('view_test') ."</td>";
			print"</tr>";

		$tst_versions = test_get_all_versions( $test_id );

		foreach( $tst_versions as $tst_version ) {

			$tst_version_id		= $tst_version[TEST_VERS_ID];
			$tst_version_no		= $tst_version[TEST_VERS_NUMBER];
			$tst_created_by		= $tst_version[TEST_VERS_AUTHOR];
			$tst_created_date	= $tst_version[TEST_VERS_DATE_CREATED];
			$tst_version_status = $tst_version[TEST_VERS_STATUS];
			$tst_active			= $tst_version[TEST_VERS_ACTIVE];
			$tst_signoff_by		= $tst_version[TEST_VERS_SIGNOFF_BY];
			$tst_signoff_date	= $tst_version[TEST_VERS_SIGNOFF_DATE];

			$signoff_page = "blah.php";
			$active_url = $active_version_page . "?test_id=$test_id&tst_version_id=$tst_version_id";

			print"<tr>\n";
				print"<td class='grid-data-c'>$tst_version_no</td>\n";
				print"<td class='grid-data-c'>$tst_created_by</td>\n";
				print"<td class='grid-data-c'>$tst_created_date</td>\n";
				print"<td class='grid-data-c'>$tst_version_status</td>\n";
				print"<td class='grid-data-c'>$tst_signoff_by</td>\n";
				print"<td class='grid-data-c'>$tst_signoff_date</td>\n";
				# SIGN OFF
				if( $tst_signoff_by == '' && $tst_signoff_date == '' ) {
					$signoff_page = 'Blah.php';
					print"<td class='grid-data-c'><a href='$signoff_page'>". lang_get('signoff') ."</a></td>\n";
				}
				else {
					print"<td class='grid-data-c'></td>\n";
				}
				# ACTIVE
				if( $tst_active == 'Y' ) {
					print"<td class='grid-data-c'>X</td>\n";
				}
				else {
					print"<td class='grid-data-c'></td>\n";
				}
				# MAKE ACTIVE
				if( $tst_active == 'Y' ) {
					print"<td class='grid-data-c'></td>\n";
				}
				else {
					print"<td class='grid-data-c'><a href='$active_url'>". lang_get('make_active') ."</a></td>\n";
				}
				# VIEW
				if( $tst_version_no == $version_no ) {
					print"<td class='grid-data-c'></td>\n";
				}
				else {
					print"<td class='grid-data-c'><a href='$signoff_page'>". lang_get('view') ."</a></td>\n";
				}
			print"</tr>\n";
		}

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

	break;
	*/
}

if( $user_has_delete_rights && (($version_control_time==0)&&(!$locked))) {
  echo '<div style="text-align:center;font-size:10pt;margin-top:20px">';
	switch( $s_tab ) {
	case 3:
		print"<a href='test_req_assoc_page.php?test_id=$test_id'>".lang_get("edit_assoc")."</a>\n";
		break;
	}
  echo '</div>';
} else {
	
  echo '<div style="text-align:center;font-size:15px">';
	switch( $s_tab ) {
	case 1:
		print"You don't got enough rights to modify this section\n";
		break;
	case 3:
		print"You don't got enough rights to modify this section\n";
		break;
	case 5:
		print"You don't got enough rights to modify this section\n";
		break;
	}
  echo '</div>';

}

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

print"</div>";


session_validate_form_reset();


html_print_footer();
?>