<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");

include_once '../config/database.php'; 
include_once '../objects/staff.php'; 

$database = new Database();
$db = $database->getConnection();

$staff = new Staff($db);

$data = json_decode(file_get_contents("php://input"));

if (isset($data->id)) {
    $staff->id = $data->id;
    $staff->getOneRow();
    $staff_data = array(
        "id" => $staff->id,
        "name" => $staff->name, 
        "position" => $staff->position,
        "phone" => $staff->phone,
        "email" => $staff->email,
        "nrc" => $staff->nrc,
        "gender" => $staff->gender,
        "dob" => $staff->dob,
        "join_date" => $staff->join_date,
        "resign_date" => $staff->resign_date,
        "address" => $staff->address,
    );
    echo json_encode($staff_data);
} else {
    echo json_encode(array("message" => "staff is missing."));
}
?>
