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

$target_dir = "https://cloudsoftonline.com/api_wavoo_rest/employee_images/";

$sql = "SELECT * FROM tblcred WHERE designation IN (1, 2)"; // 1=Supervisor, 2=Delivery Man
$result = mysqli_query($conn, $sql);

$response = [];

if ($result) {
    while ($row = mysqli_fetch_assoc($result)) {
        $response[] = [
            'userid' => $row['userid'],
            'fname' => $row['fname'],
            'lname' => $row['lname'],
            'email' => $row['email'],
            'conno' => $row['conno'],
            'designation' => $row['designation'],
            'join_date' => $row['join_date'],
            'birth_date' => $row['birth_date'],
            'image_url' => $target_dir.$row['image']
        ];
    }

    echo json_encode([
        "success" => true,
        "employees" => $response
    ]);
} else {
    echo json_encode([
        "success" => false,
        "message" => "Query failed."
    ]);
}

mysqli_close($conn);
?>
