<?php

$user_id=$_SESSION['user_id']; 
$company_id=$_SESSION['company_id'];
$department_id = $_SESSION['dept_id'];
$project_id =$_SESSION['project_id'];

if ($_SESSION['id_group'] == -1) { // Group Admin 
$sql_1 = "
Select  GROUP_CONCAT(T.task_id) tasks
from (
    SELECT task_id FROM tasks where projects_project_id = $project_id
     ) T";
} else { // Groups Not Admin
$sql_1 = "
select  GROUP_CONCAT(T.task_id) tasks
from (
    SELECT task_id FROM tasks
    WHERE projects_project_id = $project_id
    AND access = 0
  UNION
    SELECT task_id FROM tasks join projects on (projects_project_id = project_id)
    WHERE projects_project_id = $project_id
    AND access = 1
    AND companies_company_id = $company_id
  UNION
    SELECT task_id FROM tasks join projects on (projects_project_id = project_id)
    WHERE projects_project_id = $project_id
    AND access = 2
    AND departments_dept_id = $department_id
  UNION
    SELECT task_id FROM tasks join projects on (projects_project_id = project_id)
    WHERE projects_project_id = $project_id
    AND ( access = 3 or access = 4)
    AND projects.creator = $user_id
  UNION
    SELECT task_id FROM tasks
    WHERE projects_project_id = $project_id
    AND access = 4
    AND creator = $user_id ) T 
";
}
$rs = DB::Query($sql_1);
$_SESSION['task_access']= $rs->value("tasks"); 

if ($_SESSION['task_access'] == '') {
		$_SESSION['task_access']="0"; // 0,  In case you do not have any authorized
}

?>