<?php
if(isset($_POST['s_date'])){
   require_once('../../assets/config/config.php');
   $obj=new Database();
   $id=$_POST['name'];
   $b=[];   
   if($_POST['s_date']=='multi')
   {
      $id="shift_time='".$id."'";
      $date=date("d-M-Y",strtotime($_POST['date']));
      $obj->select('students_course','*',null,$id,'id DESC',null);
      $result=$obj->getResult();                              
      foreach($result as $row)
      {   
         if(attendence_checker($row['batch_no'],$date))
         {
            $row['present']='1';
         }
         array_push($b,$row);                
      }
   }
   if($_POST['s_date']=='single')
   {
      
      $date=date("d-M-Y",strtotime($_POST['date']));
      $id="batch_no='".$id."' and attendence_date='".$date."'";
      $obj->select('students_attendence','*',null,$id,null,null);
      $result=$obj->getResult();                             
                  foreach($result as $row)
                  {
                     array_push($b,$row);                
                  }
   }

         
         header('Content-type:application/json');
         echo json_encode($b);


         
}
function attendence_checker($batch_no,$date)
         {
            $obj=new Database();
            $id="batch_no='".$batch_no."' and attendence_date='".$date."'";
            $obj->select('students_attendence','*',null,$id,null,null);
            $result1=$obj->getResult(); 
            if($result1)
            {
               return true;
            } 
         }
?>