Audit Logs. * Record pages link here for all of one record's history (type, entity). */ // Default Column Sortby Filter $sort = "log_id"; $order = "DESC"; if (!isset($_GET['client_id'])) { // Every client's is Admin > Audit Logs require_once $_SERVER['DOCUMENT_ROOT'] . '/config.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/functions.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/check_login.php'; redirect($session_is_admin ? '/admin/audit_logs.php' : '/agent/clients.php'); } require_once "includes/inc_all_client.php"; $page_title = 'Audit Log'; $sortable_columns = [ 'log_id' => "log_id $order", 'log_created_at' => "log_created_at $order, log_id $order", 'user_name' => "user_name IS NULL, user_name $order, log_id DESC", 'log_type' => "log_type $order, log_action $order, log_id DESC", 'log_action' => "log_action $order, log_id DESC", 'log_ip' => "log_ip IS NULL, log_ip $order, log_id DESC", ]; if (!isset($sortable_columns[$sort])) { $sort = 'log_id'; } // Security is sign-ins, users and settings - an admin's, and in Admin > Audit Logs $views = auditLogViews(); unset($views['security']); $views['signins']['title'] = 'Their contacts signing in to the client portal'; $view = isset($_GET['view']) && is_string($_GET['view']) && isset($views[$_GET['view']]) ? $_GET['view'] : ''; $scope = "log_client_id = $client_id AND " . auditLogRoleSql(); $filter_src = array_merge($_GET, ['client' => $client_id, 'dtf' => $dtf, 'dtt' => $dtt, 'view' => $view]); $joins = auditLogJoinsSql(); $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS log_id, log_type, log_action, log_description, log_ip, log_user_agent, log_created_at, log_client_id, log_user_id, log_entity_id, user_name, user_avatar, user_type, client_name FROM logs $joins WHERE $scope AND " . auditLogFiltersSql($filter_src) . " ORDER BY {$sortable_columns[$sort]} LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $rows = []; while ($row = mysqli_fetch_assoc($sql)) { $rows[] = $row; } $records = auditLogRecords($rows); $new_ips = signInNewIpIds($rows); $kinds = auditLogKinds(); // Each view counted for the rest of the filters $count_sql = []; foreach ($views as $definition) { $count_sql[] = 'COALESCE(SUM(' . ($definition['where'] === '' ? '1' : $definition['where']) . '), 0)'; } $counts = array_combine(array_keys($views), array_map('intval', mysqli_fetch_row(mysqli_query($mysqli, "SELECT " . implode(', ', $count_sql) . " FROM logs $joins WHERE $scope AND " . auditLogFiltersSql(array_merge($filter_src, ['view' => ''])))))); $user_filter = is_string($_GET['user'] ?? null) ? $_GET['user'] : ''; $type_filter = is_string($_GET['type'] ?? null) ? $_GET['type'] : ''; $action_filter = is_string($_GET['action'] ?? null) ? $_GET['action'] : ''; $entity_filter = is_scalar($_GET['entity'] ?? null) ? intval($_GET['entity']) : 0; $more_filters = $action_filter !== '' || $entity_filter; $any_filter = $q !== '' || $user_filter !== '' || $type_filter !== '' || $action_filter !== '' || $entity_filter || $dtf !== '1970-01-01' || $dtt !== '2099-12-31'; $sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) { return '' . $label . ($sort === $column ? " $order_icon" : '') . ''; }; $view_url = function ($key) { $query = $_GET; unset($query['page']); $query['view'] = $key; return '?' . http_build_query(array_filter($query, function ($value) { return $value !== '' && $value !== null && $value !== []; })); }; $view_empty = [ 'changes' => 'No changes yet', 'deletions' => 'Nothing deleted yet', 'signins' => 'No portal sign-ins yet', 'data' => 'Nothing looked at or taken out yet', ]; ?>
| = $sort_link('log_created_at', 'When') ?> | = $sort_link('user_name', 'Who') ?> | = $sort_link('log_type', 'What') ?> | Description | = $sort_link('log_ip', 'From') ?> | |
|---|---|---|---|---|---|
|
= escapeHtml(date('M j, Y g:i A', strtotime($row['log_created_at']))) ?>
= escapeHtml(timeAgo($row['log_created_at'])) ?>
|
= $who['html'] ?> |
= escapeHtml($type) ?>
= auditLogActionPill($row['log_action']) ?>= isset($new_ips[intval($row['log_id'])]) ? ' ' . signInNewIpBadge() : '' ?>
|
= escapeHtml(auditLogDescription($row)) ?>
= $link ?>
No longer here
= escapeHtml($from) ?>
|
= escapeHtml((string) $row['log_ip']) ?>
= escapeHtml($device) ?>
|