<?php
// ajax/time_spent.ajax.php
// Returns JSON: { RIEMING: {seconds, hours, label}, DRILLING: {...}, CASING: {...}, BLASTING: {...} }
// Query param: user_id (required)
include $_SERVER['DOCUMENT_ROOT'] . "/root.class.php";
include $_SERVER['DOCUMENT_ROOT'] . "/app/test/classes/dashboard.class.php";

header('Content-Type: application/json');

$user_id = intval($_GET['user_id'] ?? 0);

if (!$user_id) {
    echo json_encode([]);
    exit;
}

$db   = new db_safeguard();
$dash = new DashboardData($db);

echo json_encode($dash->timeSpentByActivity($user_id));