<?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
#----------------------------------------------------------------------
# ---------------------------------------------------------------------
# Test Set Page
#
# $RCSfile: testset_page.php,v $  $Revision: 1.3 $
# ---------------------------------------------------------------------

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


$page                   		= basename(__FILE__);
$form_name						= 'add_testset';
$action_page					= 'testset_add_action.php';
$testset_edit_page				= 'testset_edit_page.php';
$testset_add_tests_page			= 'testset_add_tests_page.php';
$delete_page 					= 'delete_page.php';
$testset_copy_page				= 'testset_copy_page.php';
$testset_edit_description_page	= 'testset_edit_description_page.php';
$s_project_properties   		= session_get_project_properties();
$project_name           		= $s_project_properties['project_name'];
$project_id 					= $s_project_properties['project_id'];
$row_style              		= '';

$s_release_properties	= session_set_properties( "release", $_GET );
$release_id				= $s_release_properties['release_id'];
$release_name			= admin_get_release_name($release_id);
$build_id				= $s_release_properties['build_id'];
$build_name				= admin_get_build_name($build_id);

$redirect_url			= $page ."?build_id=". $build_id;

$display_options	= session_set_display_options( "testset", $_POST );
$order_by			= $display_options['order_by'];
$order_dir			= $display_options['order_dir'];

html_window_title();
html_print_body( $form_name, 'testset_name_required');
html_page_title($project_name ." - ". lang_get('testset_page') );
html_page_header( $db, $project_name );
html_print_menu();

html_release_map(	Array(	"release_link",
							"build_link",
							lang_get("testsets") ) );


error_report_check( $_GET );

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"<form method=post name=$form_name action=$action_page>\n";
print"<table class=inner>\n";

print"<tr>\n";
print"<td colspan='2'><h4>". lang_get('add_testset') ." - $build_name</h4></td>\n";
print"</tr>\n";


# TESTSET NAME
print"<tr>\n";
print"<td class='form-lbl-r'>". lang_get('testset_name') ." <span class='required'>*</span></td>\n";
print"<td class='form-data-l'><input type='text' maxlength='20' name='testset_name_required' size=30 value='". session_validate_form_get_field("testset_name_required"). "'></td>\n";
print"</tr>\n";

# DESCRIPTION
print"<tr>\n";
print"<td class='form-lbl-r'>". lang_get('description') ."</td>\n";
print"<td class='form-data-l'><textarea name='testset_description' rows=5 cols=30 >". session_validate_form_get_field("testset_description").	"</textarea></td>\n";
print"</tr>\n";

# SUBMIT BUTTON
print"<tr>\n";
print"<td colspan='2' class='form-data-c'><input type='submit' value='". lang_get('add') ."'></td>\n";
print"</tr>\n";

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

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

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

################################################################################
# TESTSET TABLE
$testset_details = testset_get_details_by_build( $build_id, null, $order_by, $order_dir );

if( !empty( $testset_details ) ) {

	print"<table class=width100 rules=cols>\n";

	print"<tr>\n";
	html_tbl_print_header( lang_get('testset_name'), TS_NAME, $order_by, $order_dir, $page );
	html_tbl_print_header( lang_get('edit_add_tests') );
	html_tbl_print_header( lang_get('testset_date_received'), TS_DATE_CREATED, $order_by, $order_dir, $page );
	html_tbl_print_header( lang_get('description') );
	html_tbl_print_header( lang_get("copy") );
	html_tbl_print_header( lang_get('edit') );
	html_tbl_print_header( lang_get('delete') );
	print"</tr>\n";

	for( $i=0; $i < sizeof( $testset_details ); $i++ ) {

		extract( $testset_details[$i], EXTR_PREFIX_ALL, 'v' );

		$testset_id				= ${'v_' . TS_ID};
		$testset_name			= ${'v_' . TS_NAME};
		$testset_date_created	= ${'v_' . TS_DATE_CREATED};
		$testset_description	= ${'v_' . TS_DESCRIPTION};

		$row_style = html_tbl_alternate_bgcolor( $row_style );
		print"<tr class='$row_style'>\n";
		print"<td class='tbl-l'>$testset_name</td>\n";

		if( testset_number_of_tests($testset_id) ) { # edit tests in testset
			$edit_add_link_name = lang_get('edit_testset');
			$edit_add_link_href = $testset_edit_page;
		}
		else { # add tests to testset
			$edit_add_link_name = lang_get('add_tests');
			$edit_add_link_href = $testset_add_tests_page;
		}

		print"<td class='tbl-c'><a href='$edit_add_link_href?testset_id=$testset_id'>$edit_add_link_name</a></td>\n";
		print"<td class='tbl-c'>$testset_date_created</td>\n";
		print"<td class='tbl-c'>$testset_description</td>\n";
		print"<td class='tbl-c'><a href='$testset_copy_page?testset_id=$testset_id'>". lang_get('copy') ."</a></td>\n";
		print"<td class='tbl-c'><a href='$testset_edit_description_page?testset_id=$testset_id'>". lang_get('edit') ."</a></td>\n";
		print"<td class='tbl-c'>";
		print "<form 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_testset'>\n";
			print"<input type='hidden' name='id' value=$testset_id>\n";
			print"<input type='hidden' name='msg' value='40'>\n";
			print"</form>";
			print"</td>\n";
		print"</tr>\n";

		/*
		print"<td class='tbl-c'><a href='$delete_page?r_page=$page&f=delete_testset&id=$testset_id&msg=40'>". lang_get('delete') ."</a></td>\n";
		*/

	}
	print"</table>\n";
} else {
	html_no_records_found_message( lang_get('no_testsets') );
}

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

################################################################################
# Test Plan File Upload

print"<h2>";
print lang_get("test_plan_file_upload");
print"</h2>\n";

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

$rows = testset_get_test_plans($build_id);

if( !empty($rows) ) {
	print"<table class=width100 rules=cols>\n";
	print"<tr>\n";
					html_tbl_print_header( lang_get("file_type") );
					html_tbl_print_header( lang_get("file_name") );
					html_tbl_print_header( lang_get("version") );
					html_tbl_print_header( lang_get("view") );
					html_tbl_print_header( lang_get("download") );
					html_tbl_print_header( lang_get("show_log") );
					html_tbl_print_header( lang_get("add_version") );
					html_tbl_print_header( lang_get("uploaded_by") );
					html_tbl_print_header( lang_get("date_added") );
					html_tbl_print_header( lang_get("info") );
					html_tbl_print_header( lang_get("delete") );
	print"</tr>\n";

	foreach($rows as $row) {

		$test_plan_id 	= $row[TEST_PLAN_ID];
		$upload_path	= $s_project_properties['test_plan_upload_path'];
		$file_name 		= $upload_path . $row[TEST_PLAN_VERSION_FILENAME];
		$row_style 		= html_tbl_alternate_bgcolor( $row_style );

		print"<tr class=$row_style>\n";
		print"<td>".html_file_type( $row[TEST_PLAN_NAME] )."</td>\n";
		print"<td>". $row[TEST_PLAN_NAME]. "</td>\n";
		print"<td>". $row[TEST_PLAN_VERSION_VERSION]. "</td>\n";
		print"<td><a href='$file_name' target='_blank'>". lang_get('view') ."</a></td>\n";
		print"<td><a href='download.php?upload_filename=$file_name'>". lang_get('download') ."</a></td>\n";
		print"<td><a href=\"testset_show_test_plan_history_page.php?test_plan_id=$test_plan_id\">". lang_get('show') ."</a></td>\n";
		print"<td><a href=\"testset_upload_new_test_plan_version_page.php?test_plan_id=$test_plan_id\">". lang_get('add') ."</a></td>\n";
		print"<td>". $row[TEST_PLAN_VERSION_UPLOADEDBY]. "</td>\n";
		print"<td>". $row[TEST_PLAN_VERSION_UPLOADEDDATE]. "</td>\n";
		print"<td>". html_info_icon( $row[TEST_PLAN_VERSION_COMMMENTS] ). "</td>\n";
		print"<td>";
				print"<form 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_testplan'>\n";
				print"<input type='hidden' name='id' value=$test_plan_id>\n";
				print"<input type='hidden' name='msg' value=".DEL_TEST_PLAN.">\n";
				print"</form>";
		print"</td>\n";
				
		print"</tr>\n";

	}

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

}

################################################################################
# File Upload Form
print"<form enctype=\"multipart/form-data\" name=\"upload\" action=\"testset_plan_file_upload_action.php\" method=\"post\">\n";
print"<input type=hidden name=MAX_FILE_SIZE  value=25000000>\n";
print"<input type=hidden name=build_id  value=$build_id>\n";
print"<table class=width70>\n";
print"<tr>\n";
print"<td>\n";
print"<table class=inner>\n";
print"<tr>\n";
print"<td class=left><h4>". lang_get("upload_test_plan") ."</h4></td>\n";
print"</tr>\n";
print"<tr>\n";
print"<td>";
print"<table>\n";
print"<tr>\n";
print"<td class=right>". lang_get("file_name") ." <span class='required'>*</span></td>\n";
print"<td class=left><input type=file name=upload_file size=90></td>\n";
print"</tr>\n";
print"<tr>\n";
print"<td class=right>". lang_get("comments") ."</td>\n";
print"<td class=left><textarea name=comments rows=2 cols=80></textarea></td>\n";
print"</tr>\n";
print"<tr>\n";
print"<td></td>\n";
print"<td><input type=submit value=". lang_get("upload") ."></td>\n";
print"</tr>\n";
print"</table>\n";
print"</td>";
print"</tr>\n";
print"</table>\n";
print"</td>\n";
print"</tr>\n";
print"</table>\n";
print"</form>";
print"</div>\n";

html_print_footer();

session_validate_form_reset();

# ---------------------------------------------------------------------
# $Log: testset_page.php,v $
# Revision 1.3  2006/02/24 11:36:04  gth2
# update to div - class=div-c not working in firefox - gth
#
# Revision 1.2  2006/01/09 02:02:14  gth2
# fixing some defects found while writing help file
#
# Revision 1.1.1.1  2005/11/30 23:00:58  gth2
# importing initial version - gth
#
# ---------------------------------------------------------------------

?>