<?php
	include('lock.php');
	
	if(isset($_POST['taskadd']))
	{
	$task_id=$_POST['task_id'];
	$remarks=addslashes($_POST['remarks']);
	
	$cdate=date('Y-m-d H:i:s');
	$cby=$_SESSION['user_id'];
	
	//////// IMAGE UPLOAD SECTION 
	$category_img = $_FILES["category_img"]["name"];
	if($category_img)
	{
	$randomno	=  rand(9999, 999999);
	$target_dir = "./task-image/";
	$categoryimg =$randomno.'-'.$category_img;
	$target_categoryimg = $target_dir . basename($categoryimg);

	if(move_uploaded_file($_FILES["category_img"]["tmp_name"], $target_categoryimg)){
    $categoryimgdata=$categoryimg;
	}
	else
	{
	$categoryimgdata='';
	}	
	}
	else{
    $categoryimgdata='';	
	}
	
	$sql ="INSERT INTO `task_tracking`(`tt_taskid`, `tt_userid`, `tt_remark`,`tt_ctime`,`tt_file`) 
	VALUES ('$task_id','$cby','$remarks','$cdate','$categoryimgdata')";	
    mysqli_query($con, $sql);	
	
	//////// LOGS CREATE START
	$logs_remark=$remarks;
	$logsql ="INSERT INTO `task_log`(`logs_taskid`, `logs_remark`, `logs_ctime`, `logs_cby`) 
	VALUES ('$task_id','$logs_remark','$cdate','$cby')";	
	$logsqlres = mysqli_query($con, $logsql);
	//////// LOGS CREATE END

	}
	
	$encrypted = encryptId($task_id);
	echo '<script> window.location="task-track?task_id='.$encrypted.'"; </script>';
?>