false,'error'=>'Invalid ID']); exit; } $sessionId = trim($_GET['DUMMYSESSID'] ?? ($_POST['DUMMYSESSID'] ?? '')); if ($sessionId === '') { echo json_encode(['ok'=>false,'error'=>'Not authenticated']); exit; } $Request = ['SESSION' => ['PHPSESSID' => $sessionId, 'REMOTE_ADDR' => $_SERVER['REMOTE_ADDR'] ?? '']]; $Response = []; PAWebAdminSessionInfo($Request, $Response); if (($Response['SESSION']['Active'] ?? 0) != 1) { echo json_encode(['ok'=>false,'error'=>'Session expired']); exit; } // Full registration record $q = "SELECT PIRegistrationID, PIID, PIType, FirstName, LastName, Email, Telephone, Address1, Address2, City, State, CountryCode, ZipCode, Age, CompanyName, Website, VehicleMake, VehicleModel, VehicleYear, VehicleColor, LicensePlate, CoverageZipCodes, EmailConfirmed, EmailConfirmedDateTime, LifecycleStatus, ContactStatus, CurrentStatus, AdminNotes, InsertDateTime, UpdateDateTime FROM PIRegistration WHERE PIRegistrationID=$id LIMIT 1"; $row = []; $cnt = 0; $err = ''; $st = ''; PACommonDBSelectRecord($q, $row, $cnt, $err, $st); if ($cnt <= 0 || !is_array($row)) { echo json_encode(['ok'=>false,'error'=>'Not found']); exit; } // Documents $qd = "SELECT DocumentType, S3BucketName, S3ObjectKey FROM PIRegistrationDocuments WHERE PIRegistrationID=$id AND IsActive=1 AND RecordStatus=0 ORDER BY PIRegistrationDocumentID DESC"; $docs = []; $dcnt = 0; PACommonDBSelectMultipleRecords($qd, $docs, $dcnt, $err, $st); if (!is_array($docs)) $docs = []; elseif (isset($docs['DocumentType'])) $docs = [$docs]; $seen = []; $seenSigned = []; foreach ($docs as $d) { $type = $d['DocumentType']; if (isset($seen[$type])) continue; // keep only first (most recent) $seen[$type] = paPiRegistrationS3Url($d['S3BucketName'], $d['S3ObjectKey']); $seenSigned[$type] = paPiRegistrationSignedS3Url($d['S3BucketName'], $d['S3ObjectKey']); } $row['ProfilePictureUrl'] = $seen['PROFILE_PICTURE'] ?? ''; $row['DriversLicenseFrontUrl'] = $seen['DRIVERS_LICENSE_FRONT'] ?? ''; $row['DriversLicenseBackUrl'] = $seen['DRIVERS_LICENSE_BACK'] ?? ''; $row['ProfilePictureNewS3Url'] = $seenSigned['PROFILE_PICTURE'] ?? ''; $row['DriversLicenseFrontNewS3Url'] = $seenSigned['DRIVERS_LICENSE_FRONT'] ?? ''; $row['DriversLicenseBackNewS3Url'] = $seenSigned['DRIVERS_LICENSE_BACK'] ?? ''; $row['DriversLicenseImageNewS3Url'] = $row['DriversLicenseFrontNewS3Url'] !== '' ? $row['DriversLicenseFrontNewS3Url'] : $row['DriversLicenseBackNewS3Url']; echo json_encode(['ok'=>true,'data'=>$row]);