<?php
session_start();
if(isset($_POST['paramValues'])){

$paramObj=json_decode($_POST['paramValues']);
$empId=$paramObj->empId;
$siteVisitDate=$paramObj->siteVisitDate;
$TLName=$paramObj->TLName;
$TLId=$paramObj->TLId;

$uniqueId=$empId."_".$siteVisitDate;
$obj=new updateTLID();
$obj->changeTLNameId($uniqueId,$TLName,$TLId);

}else {
  header('location: ../../login.php');
}
class updateTLID
{
     function __construct()
     {

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

     function changeTLNameId($uniqueId,$TLName,$TLId)
     {
          
        //   if($loggedInUserDepartment==TL_DEPARTMENT){
        //       $getEmpId = $this->db->prepare("SELECT DISTINCT `ENGINEER_EMP_ID` FROM `tesf-2` WHERE `TL_EMP_ID`=$loggedInUserEmployeID");
        //   }elseif($loggedInUserDepartment==FINANCE_DEPARTMENT){

        //       $getEmpId = $this->db->prepare("SELECT DISTINCT `EMP_ID` FROM `tesf`");
        //   }
          
          $query = $this->db->prepare("UPDATE `tesf-2` SET `TL_NAME`=? , `TL_EMP_ID`=?  WHERE `UNIQUE_ID`=?");
          $query->bind_param('sss',$TLName, $TLId, $uniqueId);
            //$arrayResponse=array();
            $result;
          if ($query->execute()) {
            $result="UPDATED";
          } else {
              $result="FAILURE";
          }
           echo  json_encode($result);
     }
}

