/home/techb158/workloadmatch.com/api/routes
Edit: /home/techb158/workloadmatch.com/api/routes/logs.php (3587B)
prepare($sql);
if ($params) $stmt->bind_param($types, ...$params);
$stmt->execute();
$stmt->bind_result($total);
$stmt->fetch();
$stmt->close();
$sql = "SELECT * FROM activity_logs $whereClause ORDER BY $sort $dir LIMIT ? OFFSET ?";
$stmt = $mysqli->prepare($sql);
$bindParams = array_merge($params, [$perPage, $offset]);
$bindTypes = $types . 'ii';
if ($bindParams) $stmt->bind_param($bindTypes, ...$bindParams);
$stmt->execute();
$result = $stmt->get_result();
$items = $result->fetch_all(MYSQLI_ASSOC);
$stmt->close();
Response::paginated($items, $total, $page, $perPage);
}
function getLog(string $id, mysqli $mysqli): void
{
Auth::requireAnyRole(['admin_profile', 'master_profile']);
$stmt = $mysqli->prepare("SELECT * FROM activity_logs WHERE id = ?");
$stmt->bind_param('i', $id);
$stmt->execute();
$result = $stmt->get_result();
$item = $result->fetch_assoc();
$stmt->close();
if (!$item) Response::notFound('Log entry not found');
Response::success($item);
}
function deleteLog(?string $id, mysqli $mysqli): void
{
Auth::requireRole('admin_profile');
if (!$id) Response::error('Log ID required');
$stmt = $mysqli->prepare("DELETE FROM activity_logs WHERE id = ?");
$stmt->bind_param('i', $id);
$stmt->execute();
$stmt->close();
Response::success(null, 'Log entry deleted');
}
function clearLogs(mysqli $mysqli): void
{
Auth::requireRole('admin_profile');
$before = $_GET['before'] ?? date('Y-m-d', strtotime('-30 days'));
$stmt = $mysqli->prepare("DELETE FROM activity_logs WHERE created_at < ?");
$stmt->bind_param('s', $before);
$stmt->execute();
$deleted = $mysqli->affected_rows;
$stmt->close();
Response::success(null, "Deleted $deleted log entries older than $before");
}