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

# if $parent_req==0, then the requirement is not a child of any other requirement
if( isset($_POST["parent_req"]) ) {

	$parent_req = $_POST["parent_req"];
} else {

	$parent_req = 0;
}

$add_req_page	= "requirement_add_page.php?type=".$_POST['req_record_or_file']."&parent_req=$parent_req";

session_validate_form_set($_POST, $add_req_page);

# if requirement is a file
if( $_POST['req_record_or_file'] == "F" ) {

	$uploaded_filename = file_add_requirement( $add_req_page );
	$detail = "";
} else {

	$uploaded_filename = "";
	$detail = session_validate_form_get_field('req_detail_required', "", session_use_FCKeditor());
}

$req_reason_for_change	= session_validate_form_get_field("req_reason_change");
$project_id				= $_POST['project_id'];
$req_name				= session_validate_form_get_field('req_name_required');
$req_area				= session_validate_form_get_field('req_area_covered');
$req_type				= session_validate_form_get_field('req_type');
$req_rec_or_file		= $_POST['req_record_or_file'];
$req_version			= session_validate_form_get_field('req_version');
$req_status				= session_validate_form_get_field('req_status');
$req_priority			= session_validate_form_get_field('req_priority');
$req_assigned_to		= session_validate_form_get_field('req_assigned_to');
$req_assign_release		= session_validate_form_get_field('req_assign_release');
$req_author				= session_validate_form_get_field('req_author');
$req_functionality		= session_validate_form_get_field('req_functionality');


//$req_untestable			= session_validate_form_get_field('chk_untestable');

if( requirement_name_exists($project_id, $req_name) ) {

	error_report_show($add_req_page, DUPLICATE_REQ_NAME);
}


list($req_id,$vers_id)=requirement_add(	$project_id,
					$req_name,
					$req_area,
					$req_type,
					$req_rec_or_file,
					$req_version,
					$req_status,
					$req_priority,
					$uploaded_filename,
					$detail,
					$req_reason_for_change,
					$req_assigned_to,
					$req_assign_release,
					$req_author,
					$req_functionality,
					$parent_req );


session_validate_form_reset();

$s_user_properties		= session_get_user_properties();
$s_user_id				= $s_user_properties['user_id'];
$project_manager		= user_has_rights( $project_id, $s_user_id, MANAGER );

$user_has_delete_rights	= ($s_user_properties['delete_rights']==="Y" || $project_manager);
if ($user_has_delete_rights) html_print_operation_successful( 'req_add_page', "requirement_releases_assoc_page.php?req_id=".$req_id."&req_version_id=".$vers_id );
	else html_print_operation_successful( 'req_add_page', "requirement_detail_page.php?req_id=".$req_id."&req_version_id=".$vers_id );
?>