<?php
include("../../db.php");
header('Content-Type: application/json');

    $date   = $_REQUEST['date'];
    $month  = $_REQUEST['month'];
    $year   = $_REQUEST['year'];

    $fdate  = $year."-".$month."-".$date;

    $session    = $_REQUEST['session'];

	$array  = array();
	$status = 1;
	
    $staffArray = array();

    $cdate = $_GET["date"]+1;
    $todate = $year."-".$month."-".$cdate;

    $records = $db->getRows("SELECT * FROM staff WHERE session='$session' and status='1' ");

    foreach($records as $rec){
        $result = $db->getRow("Select * from attendance_new where teacher_id='$rec[idno]' and (timestamp>='$fdate' and timestamp<='$todate') and session='$session' and att_type='IN' ");

        $out = "";
        if(count($result)>1){
            $out = $db->getVal("select timestamp from attendance_new where teacher_id='$rec[idno]' and (timestamp>='$fdate' and timestamp<='$todate') and session='$session' and att_type='OUT' ");
            if (!$out){
                $out = "";
            }
        }

        $remarks = "";
        if($result['att_type']=="IN"){
            $remarks = "Present";
        } else {
            $remarks = "Absent";
        }

            array_push($staffArray, [ 
                                    "idno"      =>  $rec['idno'],
                                    "name"      =>  $rec['name'],
                                    "In"        =>  "$result[timestamp]",
                                    "Out"       =>  $out,
                                    "Remarks"   =>  $remarks
                                ]);
                                
    }


    //$array['data'] = $staffArray;

   echo json_encode(array("status"=>"$status", "data"=>$staffArray));
?>