<?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__);
$s_test_details		= session_get_properties("test");
$test_id			= $s_test_details['test_id'];
$redirect_page		= "test_detail_page.php?test_id=$test_id";
$redirect_on_error	= "test_detail_page.php?test_id=$test_id&tab=2";

$user_properties		= session_get_user_properties();
$user_id				= $user_properties['user_id'];
$username				= $user_properties['username'];
$project_id=-1;
        if (usecase_locked($project_id,$test_id,$username)) {
                 html_print_operation_failed( 'usecase_edit_page',error_report_msg(CAN_NOT_MODIFY_USECASE_LOCKED,usecase_locked_by($project_id,$test_id)), "test_detail_page.php?test_id=".$test_id);
                 exit;
       }

session_validate_form_set($_POST, $redirect_page);

$project_properties	= session_get_project_properties();
$upload_path		= $project_properties['test_upload_path'];
$s_user				= session_get_user_properties();
$username			= $s_user['username'];
$test_name			= test_get_name( $test_id );
$comments			= session_validate_form_get_field('comments');
$doc_type			= session_validate_form_get_field('doc_type');

# ------------------------------------------------
# FILE UPLOAD
# ------------------------------------------------
if( $_FILES['uploadfile']['size'] != '0' && is_uploaded_file($_FILES['uploadfile']['tmp_name']) ) {

	file_add_supporting_test_doc($_FILES['uploadfile']['tmp_name'], $_FILES['uploadfile']['name'], $test_id, $comments, $doc_type );

}
else{
	error_report_show( $redirect_on_error, NO_FILE_SPECIFIED );
}

html_print_operation_successful( 'file_upload_page', $redirect_page );
?>