<?php

require_once __DIR__ . '/db_config.php';

$response = array();
$response["requests"] = array();
$response["employees"]= array();
$employess=array();

if (isset($_POST["id"]) ) {

$id=$_POST["id"];

$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());

$query="SELECT task_request.id,task_request.increasedays,task_task.task_name,task_request.r_status,r_datetime,reason,response_by,response,updatetime,employee_id,task_milestone.milestone_name,task_task.t_project_id,task_listtask.listtask_name,task_project.project_name,task_request.employee_id FROM `task_request` LEFT JOIN task_task ON task_task.task_id=task_request.task_id  LEFT JOIN task_listtask ON task_listtask.listtask_id=task_task.listtask_id LEFT JOIN task_milestone ON task_listtask.milestone_id=task_milestone.milestone_id LEFT JOIN task_project ON task_project.project_id=task_task.t_project_id WHERE  task_request.id='$id'";
$result=mysqli_query($con,$query);
if(!empty($result) && mysqli_num_rows($result) > 0){
    $response["s"]=true;
    while ($row = mysqli_fetch_array($result)) {
        $response["data"]=$row;
        array_push($employess, $row["response_by"]);
        array_push($employess, $row["employee_id"]);
    }
}else{
    $response["s"]=false;
}




if(count($employess)!=0){
$employess=array_unique($employess);
$employeeQuery="SELECT employeename,emailid FROM signupdetails WHERE (emailid='".implode("' OR  emailid='",$employess)."')";
$employeeResult=mysqli_query($con,$employeeQuery);
if(!empty($employeeResult) && mysqli_num_rows($employeeResult) > 0){
    while ($row = mysqli_fetch_array($employeeResult,MYSQLI_ASSOC)) {
        array_push($response["employees"], $row);
    
    }
    
}
}
    mysqli_close($con);

}


echo json_encode($response);


?>