First commit / commit pertama
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* activity.php — Helper pencatatan log aktivitas (KF-04).
|
||||
*
|
||||
* logActivity($pdo, 'login');
|
||||
* logActivity($pdo, 'create', 'warga_miskin', 12, 'Tambah warga baru');
|
||||
*/
|
||||
|
||||
/**
|
||||
* Catat satu baris aktivitas. Gagal mencatat tidak boleh memutus alur utama,
|
||||
* jadi error ditangkap diam-diam.
|
||||
*/
|
||||
function logActivity(
|
||||
PDO $pdo,
|
||||
string $aksi,
|
||||
?string $tabel = null,
|
||||
?int $recordId = null,
|
||||
?string $keterangan = null
|
||||
): void {
|
||||
try {
|
||||
$stmt = $pdo->prepare(
|
||||
"INSERT INTO activity_log
|
||||
(user_id, username, aksi, tabel_target, record_id, keterangan, ip_address)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)"
|
||||
);
|
||||
$stmt->execute([
|
||||
$_SESSION['user_id'] ?? null,
|
||||
$_SESSION['username'] ?? null,
|
||||
$aksi,
|
||||
$tabel,
|
||||
$recordId,
|
||||
$keterangan,
|
||||
$_SERVER['REMOTE_ADDR'] ?? null,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
// Abaikan — logging tidak boleh menggagalkan request.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user