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

error_reporting(E_ALL);
header("Access-Control-Allow-Origin: * ");

$tid = $_REQUEST['teacher_id'];
$session = $_REQUEST['session'];
$type = $_REQUEST['type'];

$status = 0;
$msg = "Unknown error...!";

$current_date = date('Y-m-d');

$check_qry = $db->getRows("SELECT * FROM attendance_new WHERE teacher_id = '$tid' AND att_type = '$type' AND session = '$session' AND timestamp LIKE '$current_date%'");

if (count($check_qry) == 0) {

    $aryData = array("teacher_id" => $tid, "att_type" => $type, "session" => $session);

    $insert_complain = $db->insertAry("attendance_new", $aryData);

    if ($insert_complain > 0) {
        $status = 1;
        $msg = "Attendance marked successfully";
    } else {
        $msg = "Failed to marked attendance..! Please try again later";
    }

} else {
    $msg = "Attendance is already marked";
}

echo json_encode(array('status' => $status, 'msg' => $msg));