<?php
require "../api.php";

$api = new spamhasiApi();

if (!$api->checkAuth()) {
    die('{"status":500, "error":"Unauthorized"}');
}

$db = $api->getDB();

$sql = "SELECT * FROM users";
$stmt = $db->query($sql);
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

$all_users = [];

if ($result) {
    foreach ($result as $user_res) {
        $user["id"] = $user_res["id"];
        $user["name"] = $user_res["name"];
        $user["mail"] = $user_res["mail"];
        $user["number"] = $user_res["number"];

        $all_opfer[] = $opfer;
    }

    $json["user"] = $all_user;
}else{
    $json["user"] = [];
}

$json["status"] = 200;

die(json_encode($json));
?>