<?php 
include("../db.php");

header('Content-Type: application/json');
date_default_timezone_set("Asia/Kolkata");

    $class = $_POST['class'];
    $uid   = $_POST['uid'];
    $current_date = date('d-m-Y');
    
    $status = 0;

    $liveclassArray = array();
    
    $array = array();

    $section = $db->getVal("select section from student where idno='$uid' ");

	$allLiveclass = $db->getRows("select * from liveclass_meet where  class='$class'  and date = '$current_date'");
    if(count($allLiveclass) > 0){
        $status = 1;

    	foreach($allLiveclass as $liveclass){
    	    
    	    $teacher=$db->getVal("select name from staff where idno='$liveclass[teacher_id]' ");
    	    
    	   // $sec = json_decode($liveclass['section']);
    	   // if(in_array($section, $sec)){
    	    
    	    $edate = date_create($liveclass['date']);
							    
		    $examdate = date_format($edate,"m-d-Y");
    	    
                array_push($liveclassArray,["id"=>"$liveclass[id]","chapter"=>"$liveclass[chapter]","topic"=>"$liveclass[topic]", "date"=>"$examdate", "time"=>"$liveclass[time]", "endtime"=>"$liveclass[endtime]", "tname"=>"$teacher", "url"=>"$liveclass[url]" ]);
    	   // }
    	}

    }
 
 $array['status'] = $status;
 $array['liveclasses'] = $liveclassArray;
 
 echo json_encode($array);
?>