<?php
session_start();
if(isset($_SESSION['teamLeads'])){

$loggedInUserDepartment=$_SESSION['teamLeads'];
$loggedInUserEmployeID=$_SESSION["userId"];
$obj=new FetchEmpId();
$obj->getEmpId($loggedInUserDepartment,$loggedInUserEmployeID);

}else {
  header('location: ../login.php');
}
class FetchEmpId
{


     function __construct()
     {
          require_once dirname(__DIR__) . '/php/DB_Connect.php';
          $DBclassObject = new DB_conncect(); //encapsulation
          $this->db = $DBclassObject->connectToDB();
     }

     function getEmpId($loggedInUserDepartment,$loggedInUserEmployeID)
     {
          $empId = $empName='';
          if($loggedInUserDepartment==TL_DEPARTMENT){
               $getEmpId = $this->db->prepare("SELECT  `EMP_ID`,`EMP_NAME` FROM `empCircle` WHERE `TL_EMP_ID`=$loggedInUserEmployeID");
          }elseif($loggedInUserDepartment==FINANCE_DEPARTMENT){

               $getEmpId = $this->db->prepare("SELECT  `EMP_ID`,`EMP_NAME` FROM `empCircle`");
          }
          $getEmpId->execute();
          $getEmpId->bind_result($empId,$empName);
          $getEmpId->store_result();

          if ($getEmpId->num_rows() > 0) {
               while ($getEmpId->fetch()) {
                    $empIdarry[] = array(
                         "empId" => $empId,
                         "empName"=>$empName
                    );
               }



               echo  json_encode($empIdarry);
          } else {
               echo json_encode("query having no data");
          }
     }
}


$object = new FetchEmpId();
