<?php

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

if ($_SESSION['id_group'] == -1) { // Group Admin 
$sql_1 = "
Select  GROUP_CONCAT(P.project_id) project
from (
    SELECT project_id FROM projects
     ) P";
} else { // Groups Not Admin
$sql_1 = "
Select  GROUP_CONCAT(P.project_id) project
from (
    SELECT project_id FROM projects
    WHERE private = 0
  UNION
    SELECT project_id FROM projects
    WHERE private = 1 AND companies_company_id = $company_id
  UNION
    SELECT project_id FROM projects
    WHERE private = 2 AND departments_dept_id = $department_id
  UNION
    SELECT project_id FROM projects
    WHERE (private = 3 or private = 4) AND creator = $user_id
  UNION
    SELECT project_id FROM projects
    WHERE private = 4 AND project_id In (
      SELECT distinct projects_project_id FROM tasks
      WHERE creator = $user_id ) ) P";
}
$rs = DB::Query($sql_1);
$_SESSION['project_access']= $rs->value("project");
if ($_SESSION['project_access'] == '') {
		$_SESSION['project_access']="0"; // 0,  In case you do not have any authorized
}
?>