<?php

require_once __DIR__ . '/db_config.php';

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

if ( isset($_POST["mail"]) && isset($_POST["role"]) ) {
 
$mail= $_POST['mail'];
$cname=$_POST["cname"];
$role=$_POST["role"];
$id=$_POST["id"];

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

$taskQuery="SELECT employee,COUNT(*) as counts FROM tm_all_tasks WHERE t_project_id='$id' AND employee IS NOT NULL AND a_deleted='no' AND t_deleted='no' AND m_deleted='no' AND p_deleted='no' AND l_deleted='no' GROUP BY employee";
$taskResult=mysqli_query($con,$taskQuery);
if(!empty($taskResult) && mysqli_num_rows($taskResult) > 0){
    while ($row = mysqli_fetch_array($taskResult,MYSQLI_ASSOC)) {
        array_push($response["peoples"], $row);
        array_push($employess,$row["employee"]);
    }
}

$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);
    }
}

}

echo json_encode($response);


?>