<?php

require_once '../../core/api_bootstrap.php';
require_once '../../core/employee_auth.php';

EmployeeAuth::check('view_analytics');

try {

$db = new Database();
$conn = $db->connect();

$stmt = $conn->prepare("

SELECT
a.id,
e.name AS employee,
a.action,
a.module,
a.record_id,
a.ip_address,
a.created_at

FROM activity_logs a

LEFT JOIN employees e
ON a.employee_id = e.id

ORDER BY a.created_at DESC
LIMIT 100

");

$stmt->execute();

$logs = $stmt->fetchAll();

Response::success($logs);

}
catch(Exception $e){

Logger::log("system.log",$e->getMessage());

Response::error("Server error",500);

}
