<?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__);
$s_project_properties	= session_get_project_properties();
$s_project_id			= $s_project_properties['project_id'];
$s_project_name			= $s_project_properties['project_name'];
$history_detail_page	= 'requirement_version_view_history_page.php';
$req_detail_page		= 'requirement_detail_page.php';

$row_style = '';

$s_properties 		= session_set_properties("requirements", $_GET);
$s_req_id		= $s_properties['req_id'];
$s_req_version_id	= $s_properties['req_version_id'];

html_window_title();
html_print_body();
html_page_title($s_project_name ." - REQUIREMENTS");
html_page_header( $db, $s_project_name );
html_print_menu();

#### Change to api submenu function for this page type ####
requirement_menu_print ($page);

error_report_check( $_GET );


$rows = requirement_get_detail( $s_project_id, $s_req_id );
$row_requirement = $rows[0];

$req_name		= $row_requirement[REQ_FILENAME];
$record_or_file		= $row_requirement[REQ_REC_FILE];
$req_version_num	= requirement_get_version_number( $s_req_id, $s_req_version_id );

print"<br>\n";

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

print"<table class=width100 rules=cols>\n";
print"<tr>\n";
print"<td width='33%' nowrap class=grid-header-c>".lang_get('req_id')."</td>\n";
print"<td width='33%' nowrap class=grid-header-c>".lang_get('req_name')."</td>\n";
print"<td width='33%' nowrap class=grid-header-c>".lang_get('req_version')."</td>\n";
print"</tr>\n";

print"<tr>\n";
print"<td width='33%' class=grid-data-c><a href='$req_detail_page?req_id=$s_req_id'>".sprintf( "%05s",trim( $s_req_id ) )."</a></td>\n";
print"<td width='33%'class=grid-data-c>$req_name</td>\n";
print"<td width='33%' class=grid-data-c>$req_version_num</td>\n";
print"</tr>\n";
print"</table>\n";

print"</div>\n";

print"<br>\n";
/*
print"<table class=width100 rules=all>\n";
print"<tr>\n";
print"<td width='25%' nowrap  class=grid-header-l>".lang_get('req_area')."</td>\n";
print"<td width='25%' class=grid-data-l>".$row_requirement[REQ_AREA_SPECD]."</td>\n";

print"<td width='25%' nowrap class=grid-header-l>".lang_get('req_locked_date')."</td>\n";
print"<td width='25%' class=grid-data-l>".$row_requirement[REQ_LOCKED_DATE]."</td>\n";
print"</tr>\n";

$rows_functions = requirement_get_functionality($s_req_id);

print"<tr>\n";
print"<td width='25%' nowrap class=grid-header-l>".lang_get('functionality')."</td>\n";
print"<td width='25%' class=grid-data-l>";
	foreach($rows_functions as $key => $value) {

		print$value."<br>";
	}
print"</td>\n";

print"<td width='25%' nowrap class=grid-header-l>".lang_get('req_locked_by')."</td>\n";
print"<td width='25%' class=grid-data-l>".$row_requirement[REQ_LOCKED_BY]."</td>\n";
print"</tr>\n";

print"<tr>\n";
print"<td width='25%' nowrap class=grid-header-l>".lang_get('req_type')."</td>\n";
print"<td width='25%' class=grid-data-l>".$row_requirement[REQ_TYPE]."</td>\n";

print"<td width='25%' nowrap class=grid-header-l></td>\n";
print"<td width='25%' class=grid-data-l></td>\n";
print"</tr>\n";

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

if( !empty($rows) ) {

	print"<br><br>";
	print"<table class=width100 rules=cols>\n";
	print"<tr>\n";
	html_tbl_print_header( lang_get("version") );
	html_tbl_print_header( lang_get("status") );
	html_tbl_print_header( lang_get("author") );
	html_tbl_print_header( lang_get("created") );
	html_tbl_print_header( lang_get("req_assign_release") );
	html_tbl_print_header( lang_get("assigned_to") );
	html_tbl_print_header( lang_get("view") );
	print"</tr>\n";

	foreach($rows as $row ) {

		$req_version_id			= $row[REQ_VERS_UNIQUE_ID];
		$req_version			= $row[REQ_VERS_VERSION];
		$req_status				= $row[REQ_VERS_STATUS];
		$author					= $row[REQ_VERS_AUTHOR];
		$timestamp				= $row[REQ_VERS_TIMESTAMP];
		$assigned_to			= $row[REQ_VERS_ASSIGNED_TO];
		$req_last_updated	= $row[REQ_LAST_UPDATED];


		$row_style = html_tbl_alternate_bgcolor( $row_style );
		$file_name = "";

		print"<tr class=$row_style>\n";
		print"<td>$req_version</td>\n";
		print"<td>$req_status</td>\n";
		print"<td>$author</td>\n";
		print"<td>$timestamp</td>\n";
		print"<td>\n";
		$assoc_releases = requirement_get_assoc_releases($req_version_id);
		foreach($assoc_releases as $row) {

			print$row[RELEASE_NAME]."<br>\n";
		}
		print"</td>\n";
		print"<td>$assigned_to</td>\n";
		if( $record_or_file == 'F' ) {

			$file_name	= $row[REQ_VERS_FILENAME];
			print"<td><a href='download.php?upload_filename=". $s_project_properties['req_upload_path'] . $file_name ."'>". lang_get('download') ."</a></td>\n";
		}
		else {
			print"<td><a href='$history_detail_page?req_version_id=$req_version_id'>". lang_get('view') ."</a></td>\n";
		}
		print"</tr>\n";

	}

	print"</table>\n";

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

}

html_print_footer();
?>