<?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_once"./api/include_api.php";
auth_authenticate_user();

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

	if( $_POST['submit_btn']==lang_get('edit') ) {

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

	if( $_POST['submit_btn']==lang_get('delete') ) {

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

	if( $_POST['submit_btn']==lang_get("new_post") ) {

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

session_validate_form_reset();

$project_name 		= session_get_project_name();
$page				= basename(__FILE__);
$row_style			= '';

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

$test_detail_page		= 'test_detail_page.php';
$req_detail_page		= 'requirement_detail_page.php';
$results_page			= 'results_page.php';

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

html_window_title();
html_print_body();
html_page_title($project_name ." - MyTRUC");
html_page_header( $db, $project_name );
html_print_menu();
//html_print_sub_menu( $page, array() );

error_report_check( $_GET );


//print"<h3>".lang_get("news")."</h3>\n";

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

print"<table width=95% border=0>\n";
print"<tr>\n";
print"<td align=left><font size=3><b>". lang_get('news') ."</b></font></td>\n";
print"</tr>\n";
print"</table>\n";


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

$rows_news = news_get($project_id);

if($rows_news) {

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

	foreach($rows_news as $row_news) {

		$news_id		= $row_news[NEWS_ID];
		$subject 		= $row_news[NEWS_SUBJECT];
		$body			= $row_news[NEWS_BODY];
		$poster			= $row_news[NEWS_POSTER];
		$news_modified	= $row_news[NEWS_MODIFIED];

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

		# NEWS TITLE
		print"<tr class='tbl-header-l'>\n";
		print"<td><b>$subject - $news_modified - ".user_get_display_name($project_id, $poster)."</b></td>\n";
		print"</tr>\n";

		# NEWS
		print"<tr>\n";
		print"<td align=left class=news-body>".util_html_encode_string($body)."</td>\n";
		print"</tr>\n";

	}

} else { # The default news if there isn't any

		# DEFAULT NEWS
		print"<tr class='tbl-header-l'>\n";
		print"<td><b>". lang_get('home_welcome') ."</b></td>\n";
		print"</tr>\n";

		# NEWS
		print"<tr>\n";
		print"<td align=left class=news-body>".lang_get('home_notes')."</td>\n";
		print"</tr>\n";

}

print"</table>\n";
print"</div>";
print"<br>\n";
   */
/*
# LATEST TEST SETS
print"<div align=center>\n";

print"<table width=95% border=0>\n";
print"<tr>\n";
print"<td align=left><font size=3><b>". lang_get('testsets_last_five') ."</b></font></td>\n";
print"</tr>\n";
print"</table>\n";

$release_id		= admin_get_max_release_id_from_build_tbl( $project_id );
$build_id		= admin_get_max_build_id( $release_id );
$testset_id		= admin_get_max_testset( $build_id );
$statuses		= results_get_teststatus_by_project( $project_id );
$results_url	= $results_page ."?release_id=$release_id&amp;build_id=$build_id&amp;testset_id=$testset_id";

// testset_get_last_5: function that returns an array with last 5 testsets created
$rows_testsets = testset_get_last_5($project_id); 


if($rows_testsets) {

	print"<table rules=cols class=width95>\n";
	print"<tr>\n";
	html_tbl_print_header( lang_get('testset_id') );
	html_tbl_print_header( lang_get('testset_name') );
	html_tbl_print_header( lang_get('build_name') );
	html_tbl_print_header( lang_get('release_name') );
	html_tbl_print_header( lang_get('tests') );
	# Display table headers based on the statuses of the project
	foreach( $statuses as $status ) {
		html_tbl_print_header( $status );
	}
	html_tbl_print_header( lang_get('testset_date_received') );
	print"</tr>\n";
	
	foreach($rows_testsets as $row_testset) {

		$testset_id	= $row_testset[TS_ID];
		$num_tests = admin_count_tests_in_testset( $testset_id );
		$testset_name = admin_get_testset_name( $testset_id );
		$testset_build_id = admin_get_build_id_from_testset_id( $testset_id );
		$testset_build_name = admin_get_build_name($testset_build_id);
		$testset_release_id = admin_get_release_id_from_build_id( $testset_build_id ); 
		$testset_release_name = admin_get_release_name($testset_release_id);
		$testset_date_created = $row_testset[TS_DATE_CREATED];

		$display_test_id = util_pad_id( $testset_id );
		$results_url = $results_page ."?release_id=$testset_release_id&amp;build_id=$testset_build_id&amp;testset_id=$testset_id";

		$row_style = html_tbl_alternate_bgcolor($row_style);
		print"<tr class=$row_style>\n";
		if ($num_tests>0) {
		print"<td class='tbl-data-c'><a href='$results_url'>$display_test_id</a></td>";
		}
		else {
		print"<td class='tbl-data-c'>$display_test_id</td>";
		}
		print"<td class='tbl-data-c'>$testset_name</td>";
		print"<td class='tbl-data-c'>$testset_build_name</td>";
		print"<td class='tbl-data-c'>$testset_release_name</td>";
		print"<td class='tbl-data-c'>$num_tests</td>";
		# Display table data based on the statuses of the project as well
		foreach( $statuses as $status ) {
			$num = results_get_num_tests_by_status( $testset_id, $status );
			print"<td class='tbl-data-c'>$num</td>\n";
		
		} 
		print"<td class='tbl-data-c'>$testset_date_created</td>";
		print"</tr>";
	}   
}
else {

	print lang_get('no_testsets_in_project');
}


print"</table>\n";

print"</div>\n";
print"<br>";
*/


  abox_header('My Requirement Locks');
    $lockslinks=array();
    $locks=requirement_get_locks($project_id,$username);
    foreach ($locks as $lock) {
      $lockslinks[]="<span title='".$lock[REQ_VERS_STATUS]."'><img border=0 src='images/icons/RStatus/".$lock[REQ_VERS_STATUS].".png' alt='".$lock[REQ_VERS_STATUS]."'></span> ".abox_link('#'.$lock[REQ_ID].' '.$lock[REQ_NAME],"requirement_detail_page.php?req_id=".$lock[REQ_ID])." <small>(".$lock[REQ_LOCKED_DATE].")</small>";
    }
    abox_list($lockslinks);
  abox_footer();

  abox_header('My Use Case Locks');
    $lockslinks=array();
    $locks=usecase_get_locks($project_id,$username);
    foreach ($locks as $lock) {
      $lockslinks[]="<span title='".$lock[TEST_STATUS]."'><img border=0 src='images/icons/RStatus/".$lock[TEST_STATUS].".png' alt='".$lock[TEST_STATUS]."'></span> ".abox_link('#'.$lock[TEST_ID].' '.$lock[TEST_NAME],"test_detail_page.php?test_id=".$lock[TEST_ID])." <small>(".$lock[USECASE_LOCKED_DATE].")</small>";
    }
    abox_list($lockslinks);
  abox_footer();

  abox_header('Requirements - Last modified');
    $lockslinks=array();
    $rows_tests = requirement_get_last_updated($project_id);
    foreach($rows_tests as $row_test) {
      $lockslinks[]="<span title='".$row_test[REQ_VERS_STATUS]."'><img border=0 src='images/icons/RStatus/".$row_test[REQ_VERS_STATUS].".png' alt='".$row_test[REQ_VERS_STATUS]."'></span> ".abox_link("#".$row_test[REQ_ID].' '.$row_test[REQ_NAME],"requirement_detail_page.php?req_id=".$row_test[REQ_ID])." ".$row_test[REQ_VERS_VERSION]." <small>(".$row_test[REQ_VERS_LAST_UPDATED]." by ".$row_test[REQ_VERS_LAST_UPDATED_BY].")</small>";
    }
    abox_list($lockslinks);
  abox_footer();

  abox_header('Use Cases - Last modified');
    $lockslinks=array();
    $rows_tests = test_get_last_modified($project_id);
    foreach($rows_tests as $row_test) {
      $lockslinks[]="<span title='".$row_test[TEST_STATUS]."'><img border=0 src='images/icons/RStatus/".$row_test[TEST_STATUS].".png' alt='".$row_test[TEST_STATUS]."'></span> ".abox_link('#'.$row_test[TEST_ID].' '.$row_test[TEST_NAME],"test_detail_page.php?test_id=".$row_test[TEST_ID])."      <small>(".$row_test[TEST_LAST_UPDATED]." by ".$row_test[TEST_LAST_UPDATED_BY].")</small>";
    }
    abox_list($lockslinks);
  abox_footer();

/*
# LATEST CHANGES TO TESTS
print"<div align=center>";

print"<table width=95% border=0>\n";
print"<tr>\n";
print"<td align=left><font size=3><b>". lang_get('latest_tests') ."</b></font></td>\n";
print"</tr>\n";
print"</table>\n";
#print"<h3>".lang_get("latest_tests")."</h3>\n";

$rows_tests = test_get_last_modified($project_id);

if($rows_tests) {

	print"<table rules=cols class=width95>\n";
	print"<tr>";
	html_tbl_print_header( lang_get('test_id') );
	html_tbl_print_header( lang_get('test_name') );
	html_tbl_print_header( lang_get('last_updated_by') );
	html_tbl_print_header( lang_get('last_updated') );
	print"</tr>";

	foreach($rows_tests as $row_test) {

		$test_id				= $row_test[TEST_ID];
		$test_name 				= $row_test[TEST_NAME];
		$test_last_updated		= $row_test[TEST_LAST_UPDATED];
		$test_last_updated_by	= $row_test[TEST_LAST_UPDATED_BY];

		$display_test_id = util_pad_id( $test_id );

		$row_style = html_tbl_alternate_bgcolor($row_style);

		print"<tr class=$row_style>\n";
		print"<td class='tbl-l'  ><a href='$test_detail_page?test_id=$test_id'>$display_test_id</a></td>\n";
		print"<td class='tbl-l'>$test_name</td>\n";
		print"<td class='tbl-l'>$test_last_updated_by</td>\n";
		print"<td class='tbl-l'>$test_last_updated</td>\n";
		print"</tr>\n";
	}
	print"</table>\n";

} else {

	print lang_get('no_tests_in_project');
}

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

# LATEST CHANGES TO REQUIREMENTS
print"<div align=center>\n";

print"<table width=95% border=0>\n";
print"<tr>\n";
print"<td align=left><font size=3><b>". lang_get('latest_requirements') ."</b></font></td>\n";
print"</tr>\n";
print"</table>\n";
#print"<h3>".lang_get("latest_requirements")."</h3>\n";

$rows_reqs = requirement_get_last_updated($project_id);

if($rows_reqs) {

	print"<table rules=cols class=width95>\n";
	print"<tr>";
	html_tbl_print_header( lang_get('req_id') );
	html_tbl_print_header( lang_get('req_version') );
	html_tbl_print_header( lang_get('req_name') );
	html_tbl_print_header( lang_get('last_updated_by') );
	html_tbl_print_header( lang_get('last_updated') );
	print"</tr>";

	foreach($rows_reqs as $rows_req) {

		$req_id					= $rows_req[REQ_ID];
		$req_version_id			= $rows_req[REQ_VERS_UNIQUE_ID];
		$req_name 				= $rows_req[REQ_FILENAME];
		$req_last_updated		= $rows_req[REQ_VERS_LAST_UPDATED];
		$req_last_updated_by	= $rows_req[REQ_VERS_LAST_UPDATED_BY];
		$req_version			= $rows_req[REQ_VERS_VERSION];

		$display_req_id = util_pad_id( $req_id );

		$row_style = html_tbl_alternate_bgcolor($row_style);

		print"<tr class=$row_style>\n";
		print"<td class='tbl-l'><a href='$req_detail_page?req_id=$req_id&amp;req_version_id=$req_version_id'>$display_req_id</a></td>\n";
		print"<td class='tbl-l'>$req_version</td>\n";
		print"<td class='tbl-l'>$req_name</td>\n";
		print"<td class='tbl-l'>$req_last_updated_by</td>\n";
		print"<td class='tbl-l'>$req_last_updated</td>\n";
		print"</tr>\n";
	}
	print"</table>\n";

} else {

	print lang_get('no_requirements_in_project');
}

print"</div>";
*/
html_print_footer();
?>