<?php  if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } RBAC::enforce('view.crm'); $userId = (int)($_GET['user_id'] ?? 0); if ($userId <= 0) { echo "<div class=\"empty-state\"><span>No user selected.</span></div>"; return; } $user = Database::fetchOne("SELECT id, username, encrypted_username, status, is_verified, created_at, last_login FROM users WHERE id=:id", [':id'=>$userId]); if (!$user) { echo "<div class=\"empty-state\"><span>User not found.</span></div>"; return; } $username = $user['username']; $msgCount = (int)Database::scalar("SELECT COUNT(*) FROM support_messages WHERE user_id=:id", [':id'=>$userId]); $orderCount = (int)Database::scalar("SELECT COUNT(*) FROM orders WHERE user_id=:id", [':id'=>$userId]); $devices = Database::fetchAll("SELECT device_token, ip_address, last_seen FROM device_bindings WHERE user_id=:id ORDER BY last_seen DESC LIMIT 5", [':id'=>$userId]); ?> <div class="intelligence-panel"> <span class="section-label">Customer Intelligence:<?= UI::e($username) ?> </span> <div class="detail-grid"> <div><span class="kpi-label">Status</span><span><?= UI::e($user['status']) ?> </span></div> <div><span class="kpi-label">Verified</span><span><?= $user['is_verified'] ? 'Yes' : 'No' ?> </span></div> <div><span class="kpi-label">Messages</span><span><?= $msgCount ?> </span></div> <div><span class="kpi-label">Orders</span><span><?= $orderCount ?> </span></div> <div><span class="kpi-label">Last Login</span><span><?= UI::e($user['last_login'] ?? 'Never') ?> </span></div> </div> <span class="section-label">Known Devices</span><?php foreach ($devices as $d): ?> <div class="event-row"><span><?= UI::e(substr($d['device_token'] ?? '', 0, 16)) ?> ...</span><span><?= UI::e($d['ip_address'] ?? '') ?> </span><span><?= UI::e($d['last_seen'] ?? '') ?> </span></div><?php endforeach; ?> </div>