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

session_clear_form_values();
$redirect_page = 'test_page.php';
$test_add_page = "test_add_page.php";

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

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

	$assoc_req = 0;
}

session_validate_form_set($_POST, $test_add_page);

$project_id 	= session_get_project_id();
$testname 		= session_validate_form_get_field('testname_required');
$testpurpose 	= session_validate_form_get_field('testpurpose');
$testpre 	= session_validate_form_get_field('testpre');
$testpost 	= session_validate_form_get_field('testpost');
$testcomments 	= session_validate_form_get_field('testcomments');
$testpriority 	= session_validate_form_get_field('testpriority');
$teststatus 	= session_validate_form_get_field('teststatus');
$testareatested = session_validate_form_get_field('testareatested');
$testtype 		= session_validate_form_get_field('testtype');
$ba_owner 		= session_validate_form_get_field('ba_owner');
$qa_owner 		= session_validate_form_get_field('qa_owner');
$tester			= session_validate_form_get_field('tester');
$assigned_to	= session_validate_form_get_field('assigned_to');
$assigned_by	= session_validate_form_get_field('assigned_by');
$dateassigned 	= session_validate_form_get_field('dateassigned');
$dateexpcomplete= session_validate_form_get_field('dateexpcomplete');
$dateactcomplete= session_validate_form_get_field('dateactcomplete');
$datebasignoff 	= session_validate_form_get_field('datebasignoff');
$duration	 	= session_validate_form_get_field('test_duration');
$autopass 		= session_validate_form_get_field('chk_autopass');
$steps 			= session_validate_form_get_field('chk_steps');
$auto 			= session_validate_form_get_field('chk_auto');
$performance 	= session_validate_form_get_field('chk_performance');

if (!util_date_isvalid($dateassigned)    ||
    !util_date_isvalid($dateexpcomplete) ||
    !util_date_isvalid($dateactcomplete) ||
    !util_date_isvalid($datebasignoff)) {

    error_report_show("test_add_page.php", INVALID_DATE );
}


if (test_name_exists( $project_id, $testname )) {

    error_report_show("test_add_page.php", DUPLICATE_TESTNAME );
}


test_add_test_version(
			$project_id,
			$testname,
			$testpurpose,
			$testcomments,
			$testpriority,
			$teststatus,
			$testareatested,
			$testtype,
			$ba_owner,
			$qa_owner,
			$tester,
			$assigned_to,
			$assigned_by,
			$dateassigned,
			$dateexpcomplete,
			$dateactcomplete,
			$datebasignoff,
			$duration,
			$autopass,
			$steps,
			$auto,
			$performance,
			$assoc_req,
                        $testpre,
                        $testpost );

# Add entry into the log table for the project
$page_name = "CREATE TEST";
$deletion = 'N';
$creation = 'Y';
$upload = 'N';
$action = "ADDED TEST $testname";

log_activity_log( $page_name, $deletion, $creation, $upload, $action );

session_validate_form_reset();

# validation succeeded
html_print_operation_successful( 'create_test_page', $redirect_page );
?>