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

$project_id	= session_get_project_id();

$add_page		= 'project_add_page.php';
$redirect_page	= 'admin_page.php';
$proj_properties	= session_get_properties("project_manage");

session_validate_form_set($_POST, $add_page);

$project_name 			= session_validate_form_get_field('project_name_required');
$project_folder_name	= str_replace(" ", "", $project_name);
$project_description 	= session_validate_form_get_field('project_description');

$req_docs		= FILE_UPLOAD_PATH .$project_folder_name."_req_docs/";
$test_docs		= FILE_UPLOAD_PATH .$project_folder_name."_test_docs/";
$test_run_docs	= FILE_UPLOAD_PATH .$project_folder_name."_test_run_docs/";
$test_plan_docs	= FILE_UPLOAD_PATH .$project_folder_name."_test_plan_docs/";


# check username unique
if( !is_null( project_get_id($project_name) ) ) {
	error_report_show( $add_page, PROJECT_NOT_UNIQUE );
}

if ( mkdir($req_docs, 0700) && mkdir($test_docs, 0700) && mkdir($test_run_docs, 0700) && mkdir($test_plan_docs, 0700) ) {

	project_add(	$project_name,
					$project_description,
					$_POST['project_status'],
					isset($_POST['show_custom_1']) ? "Y": "N",
					isset($_POST['show_custom_2']) ? "Y": "N",
					isset($_POST['show_nnumber']) ? "Y": "N",
					isset($_POST['show_custom_4']) ? "Y": "N",
					isset($_POST['show_window']) ? "Y": "N",
					isset($_POST['show_object']) ? "Y": "N",
					isset($_POST['show_memory_stats']) ? "Y": "N",
					isset($_POST['show_custom_5']) ? "Y": "N",
					isset($_POST['show_custom_6']) ? "Y": "N",
					isset($_POST['show_priority']) ? "Y": "N",
					isset($_POST['show_test_input']) ? "Y": "N",
					$req_docs,
					$test_docs,
					$test_run_docs,
					$test_plan_docs );
		
} else {
	error_report_show( $add_page, UNABLE_TO_CREATE_PROJECT_FOLDERS );
}

session_validate_form_reset();

html_print_operation_successful( "project_add_page", $redirect_page );
?>