<?php

$response = array();

// include db connect class
require_once __DIR__ . '/db_config.php';

    
// check for required fields
if (isset($_POST['data']))  {
    
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());
$json=json_decode($_POST['data'],true);


$mail= $json['mail'];
$cname=$json["cname"];
$role=$json["role"];
$name=$json["name"];
$des=$json["des"];
$project=$json["project"];
$tasklist=$json["tasklist"];
$cat=$json["cat"];
$tag=$json["tag"];
$assignedTo=$json["assignedTo"];
$responsible=$json["responsible"];
$priority=$json["priority"];
$start=$json["start"];
$end=$json["end"];
$milestone=$json["milestone"];
$taskId=$json["taskId"];


date_default_timezone_set('Asia/Calcutta');
$dt=date('Y-m-d H:i:s');

$query="UPDATE task_task SET t_project_id='$project',t_milestone_id='$milestone',listtask_id='$tasklist',task_name='$name',t_description='$des',t_start_date='$start',t_end_date='$end',t_priority='$priority',t_tag='$tag',t_u_created_by_mailid='$mail',t_u_created_by_type='$role' WHERE task_id='$taskId'";
 
    if (mysqli_query($con,$query)) {
        $response["s"] = 1;
        mysqli_query($con,"CALL updateMilestoneDeadline('$milestone','$taskId','$end')");
        mysqli_query($con,"CALL updateProjectDeadline('$project','$milestone','$end')");
    } else {
        $response["s"] = 0;
    }
    mysqli_close($con);
} 
    echo json_encode($response);

?>