0 && (int)($auditStep['dashID'] ?? 0) === $auditDashID) { $auditCase = $auditStep['dash']['caseName'] ?? ('Case ' . $auditDashID); break; } } if ($auditCase !== null) { $auditRows = array(); $auditCount = 0; $auditError = ''; PACommonDBSelectMultipleRecords( 'SELECT DashAuditID, DashStepID, Action, PerformedBy, PerformedByType, Details, OldValue, NewValue, Insert_DateTime ' . 'FROM PART_Dash_Audit WHERE DashID = ' . $auditDashID . ' AND RecordStatus = 0 ' . 'ORDER BY Insert_DateTime DESC, DashAuditID DESC LIMIT 500', $auditRows, $auditCount, $auditError, $auditStatus ); // A nearby event is context for an older notice row, not a stored causal link. $nearbyByStep = array(); for ($eventIndex = count((array)$auditRows) - 1; $eventIndex >= 0; $eventIndex--) { $event = $auditRows[$eventIndex]; $stepID = (int)($event['DashStepID'] ?? 0); if ($stepID < 1) continue; $action = (string)($event['Action'] ?? ''); $eventTime = strtotime((string)$event['Insert_DateTime'] . ' UTC'); if (in_array($action, array('STEP_CREATED', 'STEP_SUBMITTED', 'DETECTIVE_REQUEST_LOCATION_SNAPSHOT', 'TIMER_REMINDER_RECORDED', 'TIMER_ACTION_CREATED', 'TIMER_INFO_CREATED', 'NO_PI_RESPONSE_INFO_CREATED'), true) && trim((string)($event['Details'] ?? '')) !== '') { $nearbyByStep[$stepID] = $event; } elseif (preg_match('/^(EMAIL|SMS)_/', $action) || $action === 'TIMER_NOTICE_RESULT') { $nearby = $nearbyByStep[$stepID] ?? null; $nearbyTime = $nearby ? strtotime((string)$nearby['Insert_DateTime'] . ' UTC') : false; if ($eventTime !== false && $nearbyTime !== false && $eventTime >= $nearbyTime && $eventTime - $nearbyTime <= 10) { $auditRows[$eventIndex]['NearbyStepEventID'] = (int)$nearby['DashAuditID']; $auditRows[$eventIndex]['NearbyStepEventDetails'] = (string)$nearby['Details']; } } } $auditStepTitles = array(); $auditStepParents = array(); $auditStepTemplateIDs = array(); $auditStepIDs = array(); foreach ((array)$auditRows as $auditRow) { $stepID = (int)$auditRow['DashStepID']; if ($stepID > 0) $auditStepIDs[$stepID] = $stepID; } if ($auditStepIDs) { $idList = implode(',', $auditStepIDs); $stepRows = array(); $stepCount = 0; $stepError = ''; $stepStatus = ''; PACommonDBSelectMultipleRecords( 'SELECT s.DashStepID, s.DashStepTemplateID, s.ParentDashStepID, ' . 'COALESCE(NULLIF(c.Title, \'\'), t.Title) AS StepTitle, ' . 'COALESCE(NULLIF(pc.Title, \'\'), pt.Title) AS ParentStepTitle ' . 'FROM PART_DashSteps s ' . 'LEFT JOIN PART_DashStepTemplates t ON t.DashStepTemplateID = s.DashStepTemplateID ' . 'LEFT JOIN PART_DashStepTagCache c ON c.DashStepID = s.DashStepID AND c.RecordStatus = 0 ' . 'LEFT JOIN PART_DashSteps p ON p.DashStepID = s.ParentDashStepID AND p.DashID = s.DashID ' . 'LEFT JOIN PART_DashStepTemplates pt ON pt.DashStepTemplateID = p.DashStepTemplateID ' . 'LEFT JOIN PART_DashStepTagCache pc ON pc.DashStepID = p.DashStepID AND pc.RecordStatus = 0 ' . 'WHERE s.DashID = ' . $auditDashID . ' AND s.DashStepID IN (' . $idList . ')', $stepRows, $stepCount, $stepError, $stepStatus ); if ((int)$stepStatus === 0) { foreach ($stepRows as $stepRow) { $stepID = (int)$stepRow['DashStepID']; $title = trim((string)($stepRow['StepTitle'] ?? '')); if ($title !== '') $auditStepTitles[$stepID] = $title; $parentTitle = trim((string)($stepRow['ParentStepTitle'] ?? '')); if ((int)$stepRow['ParentDashStepID'] > 0 && $parentTitle !== '') { $auditStepParents[$stepID] = array('id' => (int)$stepRow['ParentDashStepID'], 'title' => $parentTitle); } $auditStepTemplateIDs[$stepID] = (int)$stepRow['DashStepTemplateID']; } } } $auditEscape = function ($value) { return htmlspecialchars((string)$value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); }; $auditFormat = function ($value) { $decoded = json_decode((string)$value, true); return json_last_error() === JSON_ERROR_NONE ? json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : (string)$value; }; $auditButtonHTML = '
'; ?>