<?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();


session_validate_form_reset();

$page                   = basename(__FILE__);
$action_page            = 'requirement_action.php';
$num                    = 0;
$row_style				= '';

$s_project_properties   = session_get_project_properties();
$s_user_properties		= session_get_user_properties();
$s_display_options 		= session_set_display_options( "requirements", array_merge($_POST, $_GET) );
$s_properties			= session_set_properties("requirements", $_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'];
$s_project_id				= $s_project_properties['project_id'];

$s_tab 					= $s_display_options['tab'];
$s_req_id				= $s_properties['req_id'];
$s_req_version_id		= $s_properties['req_version_id'];


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

	requirement_lock($s_req_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_req_unlock']) ) {

	requirement_unlock($s_req_id);

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

# get requirement details
if( empty($_GET['req_version_id']) ) {

	$s_req_version_id = requirement_get_latest_version( $s_req_id );
}

$row_requirement 	= requirement_get_detail( $project_id, $s_req_id, $s_req_version_id );
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
                $reason_for_change	= $row_detail[REQ_VERS_REASON_CHANGE];
		$req_parent			= $row_detail[REQ_PARENT];
		$req_priority		= $row_detail[REQ_PRIORITY];
		$req_last_updated	= $row_detail[REQ_LAST_UPDATED];
}

$assigned_to_release	= requirement_get_release( $req_version_id );
$project_manager		= user_has_rights( $project_id, $s_user_id, MANAGER );
$user_has_delete_rights	= ($s_delete_rights==="Y" || $project_manager);
$user_has_edit_rights	= (empty($locked_by) || $locked_by==$s_username || $project_manager);


# Redirect back to the requirements page if no requirement returned.
# This is useful when a requirement is deleted, because the user get redirected
# back to this page.
if( empty($row_requirement) ) {

	html_redirect("requirement_page.php");
}

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

requirement_menu_print($page);

error_report_check( $_GET );

print"<br>\n";

print"<form method=post action='$page?req_id=$s_req_id'>\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 valign=top>".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 valign=top>".lang_get('req_created')."</td>\n";
print"<td class=grid-data-l valign=top>$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>".lang_get('create_child')."</td>\n";
print"<td class=grid-data-l><a href='test_add_page.php?assoc_req=$s_req_id'>".lang_get('test')."</a> / <a href='requirement_add_page.php?type=R&amp;parent_req=$s_req_id'>".lang_get('record')."</a></td>\n";
print"<td nowrap class=grid-header-l></td>\n";
print"<td class=grid-data-l></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";

if ($reason_for_change!="") {
	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>$reason_for_change</td>\n";
	print"</tr>\n";
}

print"</table>\n";

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

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

} # if locked and current user did not lock it
else {
	$lock = "disabled";
	$unlock = "disabled";
}

# disable new version and update if user does not have the rights
if( $user_has_edit_rights ) {
	$update_disabled = "";
} else {
	$update_disabled = "disabled";
}

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

print"<table class=hide100>\n";
print"<tr>\n";
print"<td width='20%' align=center><input type=submit name=submit_req_add_ver value='".lang_get('req_add_ver')."' $update_disabled></td>\n";
print"<td width='20%' align=center><input type=submit name=submit_req_update value='".lang_get('req_update')."' $update_disabled></td>\n";
print"<td width='20%' align=center>\n";
	print"<input type=submit name=submit_req_delete value='".lang_get('req_delete')."' $delete_disabled>\n";
	print"<input type='hidden' name='r_page' value='requirement_page.php'>\n";
	print"<input type='hidden' name='f' value='delete_requirement'>\n";
	print"<input type='hidden' name='id' value='$s_req_id'>\n";
	print"<input type='hidden' name='project_id' value='$project_id'>\n";
	print"<input type='hidden' name='msg' value='". DEL_REQUIREMENT ."'>\n";
	print"<input type='hidden' name='req_version_id' value='$s_req_version_id'>\n";
print"</td>\n";
print"<td width='20%' align=center><input type=submit name=submit_req_lock $lock value='".lang_get('req_lock')."'></td>\n";
print"<td width='20%' align=center><input type=submit name=submit_req_unlock $unlock value='".lang_get('req_unlock')."'></td>\n";
print"</tr>\n";

print"</table>\n";

print"</form>\n";

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

print"<table class=hide100>\n";
print"<tr>\n";
print"<td>\n";
req_sub_menu_print( $s_req_id, $s_req_version_id, $page, $s_tab  );
//html_print_tabs($tabs, $s_tab);
print"</td>\n";
print"</tr>\n";

print"<tr>\n";
print"<td align=center>\n";

# EDIT LINKS
# if requirement not locked OR current user locked requirement OR current user is a manager
# display edit links

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


print"<tr>\n";
print"<td>\n";
switch( $s_tab ) {
# REQUIREMENTS ASSOC
case 1:

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

	# GET CHILDREN OF THIS REQUIREMENT
	$rows_children = requirement_get_related($s_req_id);


	# if this requirement has children OR a parent
	if( !empty($rows_children) || $req_parent != 0 ) {

		$row_style = html_tbl_alternate_bgcolor($row_style);
		
		print"<table rules=cols align=center class=width90>";
		print"<tr>";
		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) {
				print"<th width='10%' class=grid-header-c>". lang_get('delete') ."</th>";
			}
		print"</tr>";

		# PRINT PARENT RECORD
		if( $req_parent != 0 ) {
			$assoc_id			= $s_req_id;
			$rel_parent_id 		= util_pad_id( $req_parent );
			$req_parent_name 	= requirement_get_name($req_parent);
			$rel_type = 'child of';

			print"<tr class='$row_style' align=left>\n";
			print"<td class='tbl-c'>$rel_type <a href='requirement_detail_page.php?req_id=$req_parent'>$rel_parent_id</a></td>\n";
			print"<td class='tbl-l'>$req_parent_name</td>\n";
			if( $user_has_delete_rights ) {
				print"<td class='tbl-c'></td>\n";
			}
			print"</tr>\n";
		}

		# PRINT CHILDREN RECORDS
		if( !empty($rows_children) ) {

			foreach($rows_children as $row_child) {

				$rel_req_id 	= util_pad_id( $row_child['req_id'] );
				$child_id		= $rel_req_id;
				$parent_id		= $s_req_id;
				$rel_req_name 	= $row_child['req_name'];


				$row_style = html_tbl_alternate_bgcolor($row_style);
				print"<tr class='$row_style' align=left>\n";

				print"<td class='tbl-c'><a href='requirement_detail_page.php?req_id=$rel_req_id'>$rel_req_id</a></td>\n";

				print"<td class='tbl-l'>$rel_req_name</td>\n";
				if( $user_has_delete_rights ) {
					print"<td class='tbl-c'><a href='requirement_delete_assoc_action.php?assoc=req&amp;parent_id=$parent_id&amp;assoc_id=$child_id'>".lang_get('delete')."</a></td>\n";
				}
				print"</tr>";
			}
		}

		print"</table>";


	}
	else {
		print"<div align=center>\n";
		print lang_get('no_related_reqs');
		print"</div>\n";
	}

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

	break;
# TEST ASSOC
case 2:
	print"<table cellpadding=4 width='100%'>\n";
	print"<tr><td colspan=\"3\"><b>Current Use Case associations</b></td></tr>\n";
	print"<tr>\n";
	print"<td>\n";

	$req_test_relationships = requirement_get_test_relationships($s_req_id);

	if( !empty($req_test_relationships) ) {
		print"<table rules=cols class=width100>\n";
		print"<tr>\n";
		print"<th width='10%' class=grid-header-c>". lang_get('id') ."</th>";
                print"<th  width='80%'class=grid-header-c>". lang_get('test_name') ."</th>";
			if( $user_has_delete_rights) {
				print"<th width='10%' class=grid-header-c>". lang_get('delete') ."</th>";
			}
		print"</tr>\n";

		foreach($req_test_relationships as $row_req_test_rels) {

			$test_id		= $row_req_test_rels[TEST_ID];
			$test_id_link	= util_pad_id($test_id);
			$test_name		= $row_req_test_rels[TEST_NAME];
			$assoc_id		= $row_req_test_rels[TEST_REQ_ASSOC_ID];
			$pc_covered		= $row_req_test_rels[TEST_REQ_ASSOC_PERCENT_COVERED];
			$assoc_versioncounter	= $row_req_test_rels[TEST_REQ_ASSOC_USECASE_VERSIONCOUNTER];
			$test_versioncounter    = $row_req_test_rels[TEST_VERSIONCOUNTER];
			$row_style = html_tbl_alternate_bgcolor($row_style);
                        if ($test_versioncounter==$assoc_versioncounter) {
			print"<tr class='$row_style'>\n";
			print"<td class='tbl-c' nowrap><a href='test_detail_page.php?test_id=$test_id&amp;tab=3'>$test_id_link</a></td>\n";
			print"<td  class='tbl-l'nowrap>$test_name</td>\n";
			if( $user_has_delete_rights ) {
				print"<td class='tbl-c' nowrap><a href='requirement_delete_assoc_action.php?assoc=test&amp;assoc_id=$assoc_id'>".lang_get('delete')."</a></td>\n";
			}
			print"</tr>\n";
                        }
		}

		print"</table>\n";

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

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

	$req_test_relationships = requirement_get_test_relationships($s_req_id);

	if( !empty($req_test_relationships) ) {
		print"<table rules=cols class=width100>\n";
		print"<tr>\n";
		print"<th width='10%' class=grid-header-c>". lang_get('id') ."</th>";
                print"<th width='80%' class=grid-header-c>". lang_get('test_name') ."</th>";
			if( $user_has_delete_rights) {
				print"<th width='10%' class=grid-header-c>". lang_get('delete') ."</th>";
			}
		print"</tr>\n";

		foreach($req_test_relationships as $row_req_test_rels) {

			$test_id		= $row_req_test_rels[TEST_ID];
			$test_id_link	= util_pad_id($test_id);
			$test_name		= $row_req_test_rels[TEST_NAME];
			$assoc_id		= $row_req_test_rels[TEST_REQ_ASSOC_ID];
			$pc_covered		= $row_req_test_rels[TEST_REQ_ASSOC_PERCENT_COVERED];
			$assoc_versioncounter	= $row_req_test_rels[TEST_REQ_ASSOC_USECASE_VERSIONCOUNTER];
			$test_versioncounter    = $row_req_test_rels[TEST_VERSIONCOUNTER];
			$row_style = html_tbl_alternate_bgcolor($row_style);
                        if ($test_versioncounter!=$assoc_versioncounter) {
			print"<tr class='$row_style'>\n";
			print"<td class='tbl-c' nowrap><a href='test_detail_page.php?test_id=$test_id&amp;tab=3'>$test_id_link</a></td>\n";
			print"<td class='tbl-l' nowrap>$test_name</td>\n";
			if( $user_has_delete_rights ) {
				print"<td class='tbl-c' nowrap><a href='requirement_delete_assoc_action.php?assoc=test&amp;assoc_id=$assoc_id'>".lang_get('delete')."</a></td>\n";
			}
			print"</tr>\n";
                        }
		}

		print"</table>\n";

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


	break;

# DISCUSSIONS
case 3:

	$rows_discussion = discussion_get($s_req_id);
	if( !empty($rows_discussion) ) {
		print"<table class=width100 rules=cols>\n";
		print"<tr>\n";
		print"<th>".lang_get('subject')."</th>\n";
		print"<th>".lang_get('author')."</th>\n";
		print"<th>".lang_get('date_started')."</th>\n";
		print"<th>".lang_get('num_posts')."</th>\n";
		print"<th>".lang_get('status')."</th>\n";
		print"</tr>\n";

		foreach($rows_discussion as $row_discussion) {
			$row_style = html_tbl_alternate_bgcolor($row_style);
			print"<tr class='$row_style'>\n";
			print"<td><a href='requirement_discussion_page.php?discussion_id=".$row_discussion[DISC_ID]."'>".$row_discussion[DISC_SUBJECT]."</a></td>\n";
			print"<td>".$row_discussion[DISC_AUTHOR]."</td>\n";
			print"<td>".$row_discussion[DISC_DATE]."</td>\n";
			print"<td>".discussion_get_num_posts($row_discussion[DISC_ID])."</td>\n";
			print"<td>".$row_discussion[DISC_STATUS]."</td>\n";
			print"</tr>\n";
		}

		print"</table>\n";
	} else {
		print"<div align=center>\n";
		print lang_get('no_discussions');
		print"</div>\n";
	}


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

	print"<div align=center>";

	print"<span class='required'>*</span> <span class='print'>" . lang_get('must_complete_field') . "</span>\n";

	print"<table class=width90>\n";
	print"<tr>\n";
	print"<td>\n";

	print"<form method=post action='requirement_discussion_action.php'>\n";
	print"<input type=hidden name='req_id' value='$s_req_id'>\n";
	print"<input type=hidden name='status' value='OPEN'>\n";
	print"<input type=hidden name='author' value='$s_username'>\n";
	print"<input type=hidden name='assign_to' value=''>\n";
	print"<table class='inner'>\n";

	# FORM TITLE
	print"<tr>\n";
	print"<td colspan='2'><h4>". lang_get('add_discussion') ."</h4></td>\n";
	print"</tr>\n";


	# SUBJECT
	print"<tr>\n";
	print"<td class='form-lbl-r'>". lang_get('subject') ." <span class='required'>*</span></td>\n";
	print"<td class='form-data-l'><input type='text' maxlength='255' name='subject_required' size=60 value='"
		.session_validate_form_get_field("subject_required")
		."'></td>\n";
	print"</tr>\n";

	# DESCRIPTION
	$add_discussion = session_validate_form_get_field( "discussion", "", session_use_FCKeditor() );
	print"<tr>\n";
	print"<td class='form-lbl-r'>". lang_get('discussion') ."</td>\n";
	print"<td class='form-data-l'>";
	html_FCKeditor("discussion", 360, 200, $add_discussion);
	print"</td>";
	print"</tr>\n";

	# SUBMIT BUTTON
	print"<tr>\n";
	print"<td colspan='2' class='form-data-c'><input type='submit' name=submit_add_discussion 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"</div>";

	break;

# RELEASE ASSOC
case 4:
		print"<table cellpadding=4 width='100%'>\n";
		print"<tr>\n";
		print"<td>\n";

	$req_rel_relationships = requirement_get_assoc_releases($s_req_version_id);

	if( !empty($req_rel_relationships) ) {
		print"<table rules=cols class=width100>\n";
		print"<tr>\n";
		html_tbl_print_header( "&nbsp;".lang_get('release_name')."&nbsp;" );
		if( $user_has_delete_rights ) {
			html_tbl_print_header( "&nbsp;".lang_get('delete')."&nbsp;" );
		}
		print"</tr>\n";

		foreach($req_rel_relationships as $row_req_rel_rels) {

			$release_name	= $row_req_rel_rels[RELEASE_NAME];
			$assoc_id		= $row_req_rel_rels[REQ_VERS_ASSOC_REL_ID];

			$row_style = html_tbl_alternate_bgcolor($row_style);

			print"<tr class='$row_style'>\n";
			print"<td nowrap>$release_name</td>\n";
			if( $user_has_delete_rights ) {
				print"<td nowrap><a href='requirement_delete_assoc_action.php?assoc=release&amp;assoc_id=$assoc_id'>".lang_get('delete')."</a></td>\n";
			}
			print"</tr>\n";
		}

		print"</table>\n";

	} else {
		print"<div align=center>\n";
		print lang_get('no_related_releases');
		print"</div>\n";
	}

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

	break;

# History
case 5:



$rows = requirement_get_detail( $s_project_id, $s_req_id );
$rows = array_reverse($rows);
$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"<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 ) if ($row[REQ_VERS_VERSION]!=$req_version_num){

		$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];

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

		print"<tr class=$row_style>\n";
		print"<td class='tbl-l' >$req_version</td>\n";
		print"<td class='tbl-l' >$req_status</td>\n";
		print"<td class='tbl-l' >$author</td>\n";
		print"<td class='tbl-l' >$timestamp</td>\n";
		print"<td class='tbl-l' >\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";
			print"<td class='tbl-l' ><a href='requirement_version_view_history_page.php?req_version_id=$req_version_id'>". lang_get('view') ."</a></td>\n";
		print"</tr>\n";

	}

	print"</table>\n";

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

}



	break;
}

if( $user_has_delete_rights ) {

  echo '<div style="text-align:center;font-size:15px">';
	switch( $s_tab ) {
	case 1:
		print"<a href='requirement_assoc_page.php?req_id=$s_req_id&amp;req_version_id=$s_req_version_id'>".lang_get("select_children")."</a>\n";
		break;
	case 2:
		print"<a href='requirement_tests_assoc_page.php?req_id=$s_req_id&amp;req_version_id=$s_req_version_id'>".lang_get("edit_assoc")."</a>\n";
		break;
	case 3:
		print"&nbsp;\n";
		break;
	case 4:
		print"<a href='requirement_releases_assoc_page.php?req_id=$s_req_id&amp;req_version_id=$s_req_version_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 2:
		print"You don't got enough rights to modify this section\n";
		break;
	case 3:
		break;
	case 4:
		print"You don't got enough rights to modify this section\n";
		break;
	}
  echo '</div>';

}


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

html_print_footer();

?>