<?php
	include('lock.php');
	include('smtp/PHPMailerAutoload.php');
	
$task_id = decryptId($_GET['task_id']);
$task_status=$_POST['task_status'];
$updatesql ="UPDATE `task_master` SET `task_deleted`='Yes' WHERE task_id='$task_id'";	
$updatesqlres = mysqli_query($con, $updatesql);	

////// MAIL FORMAT //////
$taskgetquery=mysqli_query($con,"select * from task_master where task_id='$task_id'");
$taskgetdata=mysqli_fetch_assoc($taskgetquery);
$task_cby = $taskgetdata['task_cby'];
$task_title = $taskgetdata['task_title'];
$task_status = $taskgetdata['task_status'];

$taskuserqry=mysqli_query($con,"select * from user_master where user_id='$task_cby'");
$taskuserdata=mysqli_fetch_array($taskuserqry);
$taskusername=$taskuserdata['user_name'];
$taskuseremail=$taskuserdata['user_email'];

$message  ='
<p>Dear <strong>'.$taskusername.',</strong> </p>
<p>This is to inform you that the following task has been <strong style="color:red;">cancelled</strong> :</p>
<p><strong>Task Name: </strong> '.$task_title.' </p>
<p><strong>Task Status: </strong> '.$task_status.'</p>
<p><strong>Cancelled By: </strong> '.$user_name.'</p>
<p>Please review the update and take any necessary action if required.</p>

<p><br>Best Regards,,</p>
<p><strong>'.$user_name.'</strong></p>
<p><strong> SNA Associates </strong></p>
';

//$message;
$subject ='Task Cancelled: '.$task_title;
$mail = new PHPMailer();
$mail->SMTPDebug  = false;
$mail->isSMTP();
$mail->SMTPAuth   = true;
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 587; // TLS port
$mail->SMTPSecure = 'tls';
$mail->Username   = "notifications@snassociates.org.in";
$mail->Password   = "unjn wqld wlut cmzm"; // ❗ normal password नहीं चलेगा
$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
$mail->setFrom("notifications@snassociates.org.in", "SNA Associates");
$mail->Subject = $subject;
$mail->Body    = $message;
$mail->addAddress($taskuseremail);
// Optional
$mail->SMTPOptions = [
    'ssl' => [
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => false
    ]
];

if(!$mail->send()){
    //echo "Mail Error: " . $mail->ErrorInfo;
}else{
    //echo "Mail Sent Successfully";
}

///////// MAIL FORMAT END ////////////

//////// LOGS CREATE START
$cdate=date('Y-m-d H:i:s');
$cby=$_SESSION['user_id'];
$logs_remark='Task Cancelled';
$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
	
echo '<script> window.location="task-list"; </script>';
?>