['label' => 'All', 'icon' => 'fa-list', 'where' => '1 = 1'], 'signins' => ['label' => 'Signing in', 'icon' => 'fa-sign-in-alt', 'where' => "log_type = 'Client Login'"], 'changes' => ['label' => 'Changes', 'icon' => 'fa-pen', 'where' => "log_type <> 'Client Login'"], ]; $tab = isset($tabs[$_GET['tab'] ?? '']) ? $_GET['tab'] : 'all'; $scope = "log_user_id = $session_user_id AND log_client_id = $session_client_id AND $session_user_id > 0"; $counts = []; foreach ($tabs as $key => $info) { $counts[$key] = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM logs WHERE $scope AND {$info['where']}"))[0]); } $total = $counts[$tab]; $pages = max(1, (int) ceil($total / $per_page)); $page = min(max(1, intval($_GET['page'] ?? 1)), $pages); $offset = ($page - 1) * $per_page; $sql = mysqli_query($mysqli, "SELECT log_type, log_action, log_description, log_ip, log_user_agent, log_created_at FROM logs WHERE $scope AND {$tabs[$tab]['where']} ORDER BY log_id DESC LIMIT $offset, $per_page"); /** What a row was, in words, with its icon. */ function activityLabel(array $row) { $sign_in = [ 'Success' => ['Signed in', 'fa-sign-in-alt'], 'MFA Failed' => ['Wrong two-step code', 'fa-exclamation-triangle'], 'Reset Requested' => ['Asked for a password link', 'fa-envelope'], 'Reset Sent' => ['Password link emailed', 'fa-envelope'], 'Password Reset' => ['Set a password from a link', 'fa-key'], 'Failed' => ['Sign-in refused', 'fa-ban'], ]; if ($row['log_type'] === 'Client Login') { return $sign_in[$row['log_action']] ?? ['Signing in', 'fa-sign-in-alt']; } return [trim($row['log_type'] . ' ' . strtolower((string) $row['log_action'])), 'fa-pen']; } function activityUrl(array $changes) { global $tab; $params = array_filter(array_merge(['tab' => $tab !== 'all' ? $tab : null], $changes), function ($v) { return $v !== null && $v !== ''; }); return 'activity.php' . ($params ? '?' . http_build_query($params) : ''); } ?> Your account
Every time you signed in, and what you did here