<?php  if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } function decryptUserPII(int $customerId): array { $user = Database::fetchOne( "SELECT id, first_name, last_name, email, phone FROM users WHERE id = :id", [':id' => $customerId] ); if (!$user) return ['error' => 'User not found']; $fields = ['first_name', 'last_name', 'email', 'phone']; $result = []; foreach ($fields as $f) { if (isset($user[$f]) && $user[$f] !== '') { try { $decrypted = Encryption::render($user[$f]); $result[$f] = ($decrypted === $user[$f]) ? '[Encrypted - key mismatch]' : $decrypted; } catch (\Throwable $e) { $result[$f] = '[Encrypted - key mismatch]'; } } else { $result[$f] = ''; } } return $result; } function renderPIICard(array $pii): string { $html = '<div class="pii-card">'; $html .= '<div class="pii-row"><span>First Name:</span> ' . UI::e($pii['first_name'] ?? '') . '</div>'; $html .= '<div class="pii-row"><span>Last Name:</span> ' . UI::e($pii['last_name'] ?? '') . '</div>'; $html .= '<div class="pii-row"><span>Email:</span> ' . UI::e($pii['email'] ?? '') . '</div>'; $html .= '<div class="pii-row"><span>Phone:</span> ' . UI::e($pii['phone'] ?? '') . '</div>'; $html .= '</div>'; return $html; } function renderDecryptUI(int $customerId): string { $html = '<div class="pii-decrypt">'; $html .= '<div class="section-label">Decrypt PII</div>'; $html .= '<div class="pii-warning"><span>This action is logged and view-once. Decrypted data is never cached.</span></div>'; $html .= '<textarea id="decrypt-reason" class="form-group input" placeholder="Reason for accessing PII..." required rows="2" style="width:100%;margin-bottom:8px"></textarea>'; $html .= '<button class="btn btn-warning" data-action="decryptPII" data-id="' . $customerId . '"><span>Decrypt</span></button>'; $html .= '<div id="pii-result"></div>'; $html .= '</div>'; return $html; } 