<?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 = '';
          if($loggedInUserDepartment==TL_DEPARTMENT){
               $getEmpId = $this->db->prepare("SELECT DISTINCT `ENGINEER_EMP_ID` FROM `normal_site_visit_2` WHERE `TL_EMP_ID`=$loggedInUserEmployeID");
          }elseif($loggedInUserDepartment==FINANCE_DEPARTMENT){

               $getEmpId = $this->db->prepare("SELECT DISTINCT `ENGINEER_EMP_ID` FROM `normal_site_visit_2`");
          }

          $getEmpId->execute();
          $getEmpId->bind_result($empId);
          $getEmpId->store_result();

          if ($getEmpId->num_rows() > 0) {
               while ($getEmpId->fetch()) {

                    $empIdarry[] = array(
                         "empId" => $empId
                    );
               }



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



