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

$status = 0;
$msg = "Unable to fetch data..! Please retry later";
$data = array();
$attList = array();

if (isset($_GET['date']) && isset($_GET['bus_id']) && isset($_GET['session'])){

    $date    = $_GET["date"];
    $bus_id  = $_GET['bus_id'];
    $session = $_GET['session'];

    $result = $db->getRows("select idno,name,admissionno,fname,class,section,mobile,fincome,bus from student where old_school = '$bus_id' and session = '$session' and status = 1 and issue_TC = 0 order by class,name");

    if ($result){
        $status = 1;

        foreach ($result as $row){
            $row['pickup_point'] = $db->getVal("select root from bus where id='$row[bus]' ");

            $checkvalue = $db->getVal("select id from bus_attendance where idno='".$row['idno']."' and bus='$bus_id' and date='$date' and session='".$session."' ");
            if ($checkvalue != '') $attList[] = $row['idno'];

            $data[] = $row;
        }

        $msg = "Record found";
    }else{
        $msg = "Record not found";
    }

}

echo json_encode(array("status" => $status, "data" => $data, "msg" => $msg, "att_list" => $attList));