Files
WebGis_UAS_Project/05/api/log.php
T
2026-06-10 19:23:50 +07:00

28 lines
1.1 KiB
PHP

<?php
// api/log.php — Log Aktivitas
require_once __DIR__ . '/../config.php';
requireRole(['superadmin', 'pimpinan']);
$db = getDB();
$limit = min((int)($_GET['limit'] ?? 100), 500);
$offset = (int)($_GET['offset'] ?? 0);
$tabel = $_GET['tabel'] ?? '';
$uid = (int)($_GET['user_id'] ?? 0);
$where = []; $params = [];
if ($tabel) { $where[] = "l.tabel=?"; $params[] = $tabel; }
if ($uid) { $where[] = "l.user_id=?"; $params[] = $uid; }
$w = $where ? 'WHERE '.implode(' AND ',$where) : '';
$st = getDB()->prepare("SELECT l.id, l.aksi, l.tabel, l.record_id, l.keterangan, l.ip_address, l.created_at,
u.username, u.nama_lengkap, r.kode as role
FROM log_aktivitas l
LEFT JOIN user u ON u.id=l.user_id
LEFT JOIN role r ON r.id=u.role_id
$w ORDER BY l.created_at DESC LIMIT ? OFFSET ?");
$params[] = $limit; $params[] = $offset;
$st->execute($params);
$total = (int)getDB()->query("SELECT COUNT(*) FROM log_aktivitas $w")->fetchColumn();
jsonOk(['rows' => $st->fetchAll(), 'total' => $total, 'limit' => $limit, 'offset' => $offset]);