<?php
include("../../db.php"); 
header("Access-Control-Allow-Origin: * ");

    $class = $_REQUEST['class'];
    $section = $_REQUEST['section'];
    $session = $_REQUEST['session'];

    $data = array();
    
    $Monday = [];
    $Tuesday = [];
    $Wednesday = [];
    $Thursday = [];
    $Friday = [];
    $Saturday = [];

    $result = $db->getRows("select * from time_table where class='$class' and section='$section' and session='$session' ");
    // print_r($result);
    if(count($result)>0 && is_array($result)){
        foreach($result as $res){
            $photo = '';
            $teacher = $db->getRow("select * from staff where idno = '$res[teacher]' ");
                if($teacher['photo'] != ""){
                    $photo = "http://$_SERVER[HTTP_HOST]/media/photo/$teacher[photo]";
                }
            if($res['day'] == "Monday"){
                $Monday []= ["id"=>"$res[id]", "teacher_id"=>"$teacher[idno]", "teacher_name"=>"$teacher[name]", "photo"=>"$photo", "subject"=>"$res[subject]", "period"=>"$res[class_period]" ];
            }
            if($res['day'] == "Tuesday"){
                $Tuesday []= ["id"=>"$res[id]", "teacher_id"=>"$teacher[idno]", "teacher_name"=>"$teacher[name]", "photo"=>"$photo", "subject"=>"$res[subject]", "period"=>"$res[class_period]" ];
            }
            if($res['day'] == "Wednesday"){
                $Wednesday []= ["id"=>"$res[id]", "teacher_id"=>"$teacher[idno]", "teacher_name"=>"$teacher[name]", "photo"=>"$photo", "subject"=>"$res[subject]", "period"=>"$res[class_period]" ];
            }
            if($res['day'] == "Thursday"){
                $Thursday []= ["id"=>"$res[id]", "teacher_id"=>"$teacher[idno]", "teacher_name"=>"$teacher[name]", "photo"=>"$photo", "subject"=>"$res[subject]", "period"=>"$res[class_period]" ];
            }
            if($res['day'] == "Friday"){
                $Friday []= ["id"=>"$res[id]", "teacher_id"=>"$teacher[idno]", "teacher_name"=>"$teacher[name]", "photo"=>"$photo", "subject"=>"$res[subject]", "period"=>"$res[class_period]" ];
            }
            if($res['day'] == "Saturday"){
                $Saturday []= ["id"=>"$res[id]", "teacher_id"=>"$teacher[idno]", "teacher_name"=>"$teacher[name]", "photo"=>"$photo", "subject"=>"$res[subject]", "period"=>"$res[class_period]" ];
            }
            
        }
    }

    $data['Monday'] = $Monday;
    $data['Tuesday'] = $Tuesday;
    $data['Wednesday'] = $Wednesday;
    $data['Thursday'] = $Thursday;
    $data['Friday'] = $Friday;
    $data['Saturday'] = $Saturday;


	if(is_array($data) && count($data)>0)
	{
		echo json_encode(array('status' => 1, 'msg'=>'Record found Successfully..!', "data"=>$data, "current_day"=>date("l")));
			
	}else
	{		
	 	echo json_encode(array('status' => 0, 'msg'=>'No record Found..!'));
	}