<?php
include 'dbconnect.php';

if (isset($_POST['project_ids']) && is_array($_POST['project_ids'])) {
    $projectIds = $_POST['project_ids'];

    $ids = array_map('intval', $projectIds); 
    $idList = implode(',', $ids);

    $sql = mysqli_query($conn, "
        SELECT DISTINCT tu.id, tu.name 
        FROM tbl_invite_user tu
        JOIN tbl_lead_user_access_projects pum ON pum.tbl_lead_user_access_projects_user_id = tu.id
        WHERE pum.tbl_lead_user_access_projects_project_id IN ($idList) AND tu.flag = 0
    ");

    echo '<option value="">Select Assigned User</option>';
    while ($row = mysqli_fetch_array($sql)) {
        echo '<option value="' . $row['id'] . '">' . $row['name'] . '</option>';
    }
}
?>
