<?php

require_once __DIR__ . '/db_config.php';

$response = array();
$response["list"] = array();

if ( isset($_POST["mail"]) && isset($_POST["cname"]) && isset($_POST["role"]) ) {
 
$mail= $_POST['mail'];
$cname=$_POST["cname"];
$role=$_POST["role"];
$projectId=$_POST["id"];
$tid=$_POST["tid"];
$list=json_decode($_POST["list"],true);

$responsible=$_POST["responsible"];

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


$tasklsitQuery="SELECT * FROM tm_all_tasklists WHERE projectid='$projectId'";

if(!empty($tid)){
    $tasklsitQuery=$tasklsitQuery." AND tasklistid='$tid' ";
}else if($role!="admin" && $responsible == "no" ){
    $tasklsitQuery=$tasklsitQuery." AND employee='$mail'";
}

if(count($list)!=0){
$taskQuery=$taskQuery." AND (l_deleted='no' OR (tasklistid='".implode("' OR  tasklistid='",$list)."'))";
}

$tasklsitQuery=$tasklsitQuery." GROUP BY tasklistid";
$tasklsitResult=mysqli_query($con,$tasklsitQuery);

if(!empty($tasklsitResult) && mysqli_num_rows($tasklsitResult) > 0){
    while ($row = mysqli_fetch_array($tasklsitResult,MYSQLI_ASSOC)) {
        array_push($response["list"], $row);
    }
}

}

echo json_encode($response);


?>