<?php
ob_start();
session_start();
require_once("../conn/conn.php");
//include('../utility/chksession.php');
date_default_timezone_set("Asia/Bangkok");


$co_id=$_POST['co_id'];
$co_name=$_POST['co_name'];
$dep_id=$_POST['dep_id'];
$filUpload=$_FILES['filUpload'];
$co_link=$_POST['co_link'];


//exit;


if($co_name == "" || $dep_id == ""){
    ?>
        <script language="JavaScript" type="text/javascript">
			<!--
			alert("กรุณากรอกข้อมูลให้ครบถ้วน !!! ");
			location.href='../admin/add_course.php';
			//-->
		</script>
    <?php 
}else{
	
	if($_FILES['filUpload'] <> ""){
		
		$upload1=$_FILES['filUpload'];
		$pathA = "../file/";
		$nameA = $_FILES['filUpload']['name'];
		$tmpA = $_FILES['filUpload']['tmp_name'];
		
		
		if(strlen($nameA)){
		list($txt, $ext) = explode(".", $nameA);
				$new_file_nameA = $co_id.".".$ext;
				move_uploaded_file($tmpA,$pathA.$new_file_nameA);
		echo $new_file_nameA;
		echo "Copy/Upload Complete<br>";
		}
		
		
    
    $sql = "INSERT INTO `hr_course` (`co_id`, `co_name`, `dep_id`, `co_file`, `co_link`,`co_status`) 
	VALUES ('$co_id', '$co_name', '$dep_id', '$new_file_nameA', '$co_link','1')";
	$query = mysqli_query($con,$sql);
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("บันทึกข้อมูลเรียบร้อย");
                    location.href='../admin/data_traning.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con);
}

}



?>