<?php
include($_SERVER['DOCUMENT_ROOT'] . "/API-Others/connection/conn.php");
header('content-type:application/json');
$staff = $_GET["staff"];
$dateFrom = $_GET["dateFrom"];
$dateTo = $_GET["dateTo"];
if(!empty($staff) && empty($dateFrom) && empty($dateTo)){
  $query = "WHERE users.unique_user_id = '$staff'";
}else if(empty($staff) && !empty($dateFrom) && empty($dateTo)){
    $query = "WHERE staff_attendance.Date = '$dateFrom'";
}else if(empty($staff) && !empty($dateFrom) && !empty($dateTo)){
    $query = "WHERE staff_attendance.Date BETWEEN '$dateFrom' AND '$dateTo'";
}else if(!empty($staff) && !empty($dateFrom) && empty($dateTo)){
    $query = "WHERE users.unique_user_id = '$staff' AND staff_attendance.Date = '$dateFrom'";
}else if(!empty($staff) && !empty($dateFrom) && !empty($dateTo)){
    $query = "WHERE users.unique_user_id = '$staff' AND staff_attendance.Date BETWEEN '$dateFrom' AND '$dateTo'";
}

$query = mysqli_query($conn, "SELECT *,staff_attendance.id AS mainId FROM staff_attendance INNER JOIN users ON staff_attendance.idd = users.unique_user_id $query ORDER BY staff_attendance.Date DESC");
$attendance = array();
while ($spec = mysqli_fetch_assoc($query)) {
    $attendance[] =  $spec;
}


$statusCode = 200;
$statusMessage = "Signed In Successfully";

$resultData = array('code' => $statusCode, 'message' => $statusMessage, 'staff_attendance' => $attendance);
echo json_encode($resultData);
