Audit Logs. */ require_once '../../includes/modal_header.php'; $log_id = intval($_GET['id'] ?? 0); $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT logs.*, user_name, user_email, user_avatar, user_type, client_name FROM logs " . auditLogJoinsSql() . " WHERE log_id = $log_id")); if (!$row) { echo json_encode(['error' => 'That audit log entry no longer exists.']); exit; } $type = (string) $row['log_type']; $type_sql = escapeSql($type); $entity_id = intval($row['log_entity_id']); $user_id = intval($row['log_user_id']); $kinds = auditLogKinds(); $who = auditLogWho($row); $style = auditLogActionStyle($row['log_action']); $records = auditLogRecords([$row]); $link = auditLogRecordLink($row, $records); $device = auditLogDevice($row['log_user_agent']); $created = strtotime($row['log_created_at']); $joins = auditLogJoinsSql(); // The record's other entries - its history here (an entry about no one record - a sign-in, a setting - has none) $is_record = $entity_id > 0 && isset($kinds[$type]['table']); $history = []; $history_count = 0; if ($is_record) { $history_where = "log_entity_id = $entity_id AND log_type = '$type_sql' AND log_id <> $log_id"; $history_count = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM logs WHERE $history_where"))[0]); $sql = mysqli_query($mysqli, "SELECT log_id, log_type, log_action, log_description, log_created_at, log_user_id, user_name, user_avatar, user_type FROM logs $joins WHERE $history_where ORDER BY log_created_at DESC, log_id DESC LIMIT 8"); while ($history_row = mysqli_fetch_assoc($sql)) { $history[] = $history_row; } } // What the same person did around then - a quarter hour either side $around = []; $around_count = 0; if ($user_id > 0) { $around_where = "log_user_id = $user_id AND log_id <> $log_id AND log_created_at >= '" . escapeSql($row['log_created_at']) . "' - INTERVAL 15 MINUTE AND log_created_at <= '" . escapeSql($row['log_created_at']) . "' + INTERVAL 15 MINUTE"; $around_count = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM logs WHERE $around_where"))[0]); $sql = mysqli_query($mysqli, "SELECT log_id, log_type, log_action, log_description, log_created_at, log_entity_id, log_user_id, user_name, user_avatar, user_type FROM logs $joins WHERE $around_where ORDER BY log_created_at ASC, log_id ASC LIMIT 10"); while ($around_row = mysqli_fetch_assoc($sql)) { $around[] = $around_row; } } // One line of a list of entries - when, the action and what it says; each opens its own quick look $entry_line = function ($entry, $show_when_as = 'date') { $time = strtotime($entry['log_created_at']); $when = $show_when_as === 'time' ? date('g:i A', $time) : date('M j, Y g:i A', $time); return '' . '' . escapeHtml($when) . '' . '' . auditLogActionPill($entry['log_action']) . '' . '' . escapeHtml($entry['log_description']) . '' . ''; }; ob_start(); ?>