<?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__);
$project_properties     = session_get_project_properties();
$project_id				= $project_properties['project_id'];
$project_name           = $project_properties['project_name'];
$username				= session_get_username();

$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'];
if( empty($_GET['req_version_id']) ) {

	$s_req_version_id = requirement_get_latest_version( $s_req_id );
} else {
  $s_req_version_id=$_GET['req_version_id'];
}

        if (requirement_locked($project_id,$s_req_id,$username)) {
                 html_print_operation_failed( 'req_edit_page',error_report_msg(CAN_NOT_MODIFY_REQUIREMENT_LOCKED,requirement_locked_by($project_id,$s_req_id)), "requirement_detail_page.php?req_id=".$s_req_id);
                 exit;
       }

html_window_title();
html_print_body();
html_page_title($project_name ." - REQUIREMENT DETAIL");
html_page_header( $db, $project_name );
html_print_menu();

requirement_menu_print($page);

error_report_check( $_GET );

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

$req_version_id			= $row_requirement[REQ_VERS_UNIQUE_ID];
$req_rec_or_file		= $row_requirement[REQ_REC_FILE];
$req_name				= $row_requirement[REQ_FILENAME];
$req_detail				= $row_requirement[REQ_VERS_DETAIL];
$req_reason_for_change	= $row_requirement[REQ_VERS_REASON_CHANGE];
$req_version_status		= $row_requirement[REQ_VERS_STATUS];
$req_area_covered		= $row_requirement[REQ_AREA_COVERAGE];
$req_area_covered_id	= $row_requirement[REQ_AREA_COVERAGE_ID];
$req_doc_type			= $row_requirement[REQ_DOC_TYPE_NAME];
$req_doc_type			= $row_requirement[REQ_DOC_TYPE_ID];
$req_priority			= $row_requirement[REQ_PRIORITY];
$req_assigned_to                = $row_requirement[REQ_VERS_ASSIGNED_TO];
$req_locked_by                  = $row_requirement[REQ_LOCKED_BY];
$selected_release		= requirement_get_release( $req_version_id );
$selected_release_id		= requirement_get_release_id( $req_version_id );
print"<br>";

print"<form method=post action='requirement_edit_action.php'>\n";
print"<input type=hidden name=req_id value=$s_req_id>\n";
print"<input type=hidden name=project_id value=$project_id>\n";
print"<input type=hidden name=req_ver_id value=$req_version_id>\n";
print"<input type=hidden name=record_or_file value='$req_rec_or_file'>\n";
print"<div align=center>\n";
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"<table class=inner>\n";
print"<tr>\n";
print"<td colspan=2><h4>". lang_get('edit_requirement') ."</h4></td>\n";
print"</tr>\n";
print"<tr>\n";
print"<td class=center>\n";

# NAME
print"<tr>\n";
print"<td class=form-lbl-r nowrap>". lang_get('req_name') ." <span class='required'>*</span></td>\n";
print"<td class=form-data-l>\n";
print"<input type='text' maxlength='255' name='req_name_required' size=65 value='".
					session_validate_form_get_field('req_name_required', $req_name).
					"'>\n";
print"</td>\n";
print"</tr>\n";

	# DETAIL
	$detail = session_validate_form_get_field('req_detail_required', $req_detail, session_use_FCKeditor());
	print"<tr>\n";
	print"<td class=form-lbl-r nowrap>". lang_get('req_detail') ." <span class='required'>*</span></td>\n";
	print"<td class=form-data-l>";
	html_FCKeditor("req_detail_required", "100%", 300, $detail);
	print"</td>\n";
//	print"<input type='hidden' name='req_detail_required' value='$detail'>";
	print"</tr>\n";

# REASON FOR CHANGE
$reason_for_change = session_validate_form_get_field('req_reason_change', $req_reason_for_change, session_use_FCKeditor());
print"<tr>\n";
print"<td class=form-lbl-r nowrap>". lang_get('req_reason_change') ."</td>\n";
print"<td class=form-data-l>";
html_FCKeditor("req_reason_change", "100%", 200, $reason_for_change);
print"</td>\n";
print"</tr>\n";

# STATUS
print"<tr>\n";
print"<td class=form-lbl-r nowrap>". lang_get('req_status') ."</td>\n";
print"<td class=form-data-l>\n";

print"<select name=req_status size=1>\n";
	$list_box = requirement_get_statuses();

	html_print_list_box_from_array(	$list_box,
									session_validate_form_get_field('req_status',
																	$req_version_status) );
print"</select>\n";
print"</td>\n";
print"</tr>\n";

# PRIORITY
print"<tr>\n";
print"<td class=form-lbl-r nowrap>". lang_get('req_priority') ."</td>\n";
print"<td class=form-data-l>\n";
print"<select name=req_priority size=1>\n";
	
	$list_box = requirement_get_priority();
	html_print_list_box_from_array(	$list_box,
									session_validate_form_get_field('req_priority', $req_priority) );
print"</select>\n";
print"</td>\n";
print"</tr>\n";

# AREA COVERED
print"<tr>\n";
print"<td class=form-lbl-r nowrap>". lang_get('req_area') ."</td>\n";
print"<td class=form-data-l>\n";

print"<select name=req_area size=1>\n";
	$list_box = array();

	$rows_areas = project_get_req_areas_covered($project_id);

	foreach($rows_areas as $row_area) {

		$list_box[$row_area[REQ_AREA_COVERAGE_ID]] = $row_area[REQ_AREA_COVERAGE];
	}
	$list_box[""] = "";

	html_print_list_box_from_key_array(	$list_box,
										session_validate_form_get_field('req_area',
																		$req_area_covered_id) );
print"</select>\n";
print"</td>\n";
print"</tr>\n";

# DOC TYPE
print"<tr>\n";
print"<td class=form-lbl-r nowrap>". lang_get('req_type') ."</td>\n";
print"<td class=form-data-l>\n";

print"<select name=req_type size=1>\n";
	$list_box = array();

	$rows = project_get_req_doc_types($project_id);
	foreach($rows as $row) {
		$list_box[$row[REQ_DOC_TYPE_ID]] = $row[REQ_DOC_TYPE_NAME];
	}

	$list_box[""] = "";

	html_print_list_box_from_key_array(	$list_box,
										session_validate_form_get_field('req_type',
																		$req_doc_type) );
print"</select>\n";
print"</td>\n";
print"</tr>\n";


# ASSIGNED TO
print"<tr>\n";
print"<td class=form-lbl-r nowrap>". lang_get('assigned_to') ."</td>\n";
print"<td class=form-data-l>\n";
print"<select name='req_assigned_to'>\n";

    $rows_users = user_get_usernames_by_project($project_id, true);

    html_print_list_box_from_array( $rows_users, session_validate_form_get_field('req_assigned_to',$req_assigned_to) );

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

# FUNCTIONALITY
$rows_functions = requirement_get_functionality($project_id, $s_req_id);
$function_ids = array();
foreach($rows_functions as $key=>$value) {

	$function_ids[] = $key;
}
print"<tr>\n";
print"<td class=form-lbl-r nowrap>". lang_get('functionality') ."</td>\n";
print"<td class=form-data-l>\n";
print"<select name='req_functionality[]' size=5 multiple>\n";
	$list_box = array();

	$rows = project_get_req_functionality($project_id);
	foreach($rows as $row) {
		$list_box[$row[REQ_FUNCT_ID]] = $row[REQ_FUNCT_NAME];
	}

	html_print_list_box_from_key_array(	$list_box,
										session_validate_form_get_field('req_functionality',
																		$function_ids ) );

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

/*# ASSIGNED TO RELEASE
print"<tr>\n";
print"<td class=form-lbl-r nowrap>". lang_get('assigned_to_release') ."</td>\n";
print"<td class=form-data-l>\n";

	$list_box = array();

	$rows_rel = admin_get_releases($project_id);

	foreach($rows_rel as $row_rel) {

		$list_box[$row_rel[RELEASE_ID]] = $row_rel[RELEASE_NAME];
	}
	$list_box[""] = "";
print"<select name=assigned_release size=1>\n";
	html_print_list_box_from_key_array(	$list_box,session_validate_form_get_field('assigned_release',$selected_release_id));
print"</select>\n";
print"</td>\n";
print"</tr>\n";
*/

# SUBMIT BUTTON
print"<tr>\n";
print"<td colspan='2' class=center><input type='submit' value='". lang_get('submit_btn') ."'></td>\n";

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

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

html_print_footer();
?>