add file
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
include 'koneksi.php';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$action = $_GET['action'] ?? 'list';
|
||||
|
||||
// ===== LIST LOG =====
|
||||
if ($action === 'list') {
|
||||
$limit = (int)($_GET['limit'] ?? 100);
|
||||
$q = $conn->query("
|
||||
SELECT l.*, u.nama_lengkap AS nama_user, u.username
|
||||
FROM log_aktivitas l
|
||||
LEFT JOIN user u ON l.user_id = u.id
|
||||
ORDER BY l.created_at DESC
|
||||
LIMIT $limit
|
||||
");
|
||||
$rows = [];
|
||||
while ($r = $q->fetch_assoc()) $rows[] = $r;
|
||||
echo json_encode($rows, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
// ===== TAMBAH LOG =====
|
||||
elseif ($action === 'tambah') {
|
||||
$uid = (int)$_POST['user_id'];
|
||||
$aksi = $_POST['aksi'] ?? '';
|
||||
$tabel = $_POST['tabel'] ?? '';
|
||||
$rid = (int)($_POST['record_id'] ?? 0);
|
||||
$detail = $_POST['detail'] ?? '';
|
||||
$ip = $_SERVER['REMOTE_ADDR'] ?? '';
|
||||
|
||||
$stmt = $conn->prepare("INSERT INTO log_aktivitas (user_id,aksi,tabel,record_id,detail,ip) VALUES (?,?,?,?,?,?)");
|
||||
$stmt->bind_param("ississs", $uid, $aksi, $tabel, $rid, $detail, $ip);
|
||||
$stmt->execute()
|
||||
? print json_encode(['status'=>'success'])
|
||||
: print json_encode(['status'=>'error','msg'=>$stmt->error]);
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user