<?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
#----------------------------------------------------------------------

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

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

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

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

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

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

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

$page                   = basename(__FILE__);
$action_page            = 'requirement_action.php';
$num                    = 0;
$s_project_properties     = session_get_project_properties();
$project_name           = $s_project_properties['project_name'];
$project_id				= $s_project_properties['project_id'];
$username				= session_get_username();
$row_style				= '';

$display_options 	= session_set_display_options( "requirements", array_merge($_POST, $_GET) );
$s_tab 				= $display_options['tab'];

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

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

	global $db;

	$q = "	Update
				Requirement
			Set
				LockedBy = '$username',
				LockedDate = '".date("Y-m-d H:i:s")."'
			WHERE
				ReqID = '$s_req_id'";
	db_query($db, $q);
}

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

	global $db;

	$q = "	Update
				Requirement
			Set
				LockedBy = '',
				LockedDate = ''
			WHERE
				ReqID = '$s_req_id'";
	db_query($db, $q);
}

html_window_title();
html_print_body();

$row_requirement = requirement_get_detail( $project_id, $s_req_id, $s_req_version_id );
//$row_requirement = $row_requirements[0];

foreach( $row_requirement as $row_detail ) {



		$req_name			= $row_detail[REQ_FILENAME];
		$req_version_id		= $row_detail[REQ_VERS_UNIQUE_ID];
		$req_version_num	= $row_detail[REQ_VERS_VERSION];
		$req_status			= $row_detail[REQ_VERS_STATUS];
		$area_covered		= $row_detail[REQ_AREA_COVERAGE];
		$req_author			= $row_detail[REQ_VERS_UPLOADED_BY];
		$req_doc_type		= $row_detail[REQ_DOC_TYPE_NAME];
		$date_created		= $row_detail[REQ_VERS_TIMESTAMP];
		$locked_by			= $row_detail[REQ_LOCKED_BY];
		$locked_date		= $row_detail[REQ_LOCKED_DATE];
		$assigned_to		= $row_detail[REQ_VERS_ASSIGNED_TO];
		$record_or_file		= $row_detail[REQ_REC_FILE];
		$req_file_name		= $row_detail[REQ_VERS_FILENAME]; # Blank if record based
		$req_detail			= $row_detail[REQ_VERS_DETAIL]; # Blank if file based
                $req_reason_for_change	= $row_detail[REQ_VERS_REASON_CHANGE];
		$req_priority		= $row_detail[REQ_PRIORITY];
		$req_last_updated	= $row_detail[REQ_LAST_UPDATED];

}


html_page_title($project_name ." - Req#".$s_req_id." ".$req_name." ".$req_version_num."");
//html_page_title($project_name ." - ". lang_get("req_detail_page"));
html_page_header( $db, $project_name );
html_print_menu();

requirement_menu_print($page);

error_report_check( $_GET );
$assigned_to_release	= requirement_get_release( $req_version_id );

print"<br>\n";
	print"<table class=width95>\n";
		print"<tr>\n";
				print"<td style='background-color:#F8A302;color:#FFFFFF;text-align:center' width='25%'><br/> <b>Req #".$s_req_id.", Version from ";
				print strftime("%d.%m.%y, %H:%S",strtotime($req_last_updated));
                                print"</b>:: <a href='requirement_detail_page.php?test_id=".$s_req_id."'>Current Version</a><br/><br/></td>\n";
			print"</tr>\n";


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


print"<form method=post action='$page'>\n";

print"<table class=width100 rules=all>\n";
print"<tr>\n";
print"<td width='25%' nowrap class=grid-header-l>".lang_get('status')."</td>\n";
print"<td width='25%' class=grid-data-l>$req_status</td>\n";
print"<td width='25%' nowrap  class=grid-header-l>".lang_get('req_priority')."</td>\n";
print"<td width='25%' class=grid-data-l>$req_priority</td>\n";
print"</tr>\n";

print"<tr>\n";
print"<td nowrap class=grid-header-l>".lang_get('author')."</td>\n";
print"<td class=grid-data-l>$req_author</td>\n";
print"<td width='25%' nowrap  class=grid-header-l>".lang_get('req_area')."</td>\n";
print"<td width='25%' class=grid-data-l>$area_covered</td>\n";
print"</tr>\n";

$rows_functions = requirement_get_functionality($project_id, $s_req_id);

print"<tr>\n";
print"<td nowrap class=grid-header-l>".lang_get('assigned_to')."</td>\n";
print"<td class=grid-data-l>$assigned_to</td>\n";
print"<td nowrap class=grid-header-l>".lang_get('req_type')."</td>\n";
print"<td class=grid-data-l>$req_doc_type</td>\n";
print"</tr>\n";

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

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

print"<tr>\n";
print"<td nowrap class=grid-header-l>".lang_get('req_created')."</td>\n";
print"<td class=grid-data-l>$date_created</td>\n";
print"<td nowrap class=grid-header-l>".lang_get('req_locked_by')."</td>\n";
print"<td class=grid-data-l>$locked_by</td>\n";
print"</tr>\n";

print"<tr>\n";
print"<td nowrap class=grid-header-l>".lang_get('last_updated')."</td>\n";
print"<td class=grid-data-l>$req_last_updated</td>\n";
print"<td nowrap class=grid-header-l>".lang_get('req_locked_date')."</td>\n";
print"<td class=grid-data-l>$locked_date</td>\n";
print"</tr>\n";

print"<tr>\n";
print"<td nowrap class=grid-header-l></td>\n";
print"<td class=grid-data-l></td>\n";
print"<td nowrap class=grid-header-l>".lang_get('show_history')."</td>\n";
print"<td class=grid-data-l><a href='requirement_version_history_page.php?req_id=$s_req_id'>".lang_get('history')."</a></td>\n";
print"</tr>\n";


	print"<tr>\n";
	print"<td nowrap class=grid-header-l>".lang_get('detail')."</td>\n";
	print"<td colspan=3 class=grid-data-l>$req_detail</td>\n";
	print"</tr>\n";
	print"<tr>\n";
	print"<td nowrap class=grid-header-l>".lang_get('why_we_upgraded')."</td>\n";
	print"<td colspan=3 class=grid-data-l>$req_reason_for_change</td>\n";
	print"</tr>\n";


print"</table>\n";

html_print_footer();
?>