Your account for ' . $assoc_name . ' has been submitted. Records cannot be edited —
if you want to add more later, submit a new record.
Return to ' . $assoc_name . '
';
}
$out = '
Submission failed. Please try again or contact the operator.
' . scn01_h($result) . '
';
$out .= scn01_render_landing($association_slug, $access);
return $out;
}
// ---------------------------------------------------------------------------
// SPOOL ENVELOPE
// ---------------------------------------------------------------------------
function scn01_build_spool_envelope($narrative, $pinned_scenario_ids, $association_slug, $channel_id, $standing) {
return [
'addon' => 'scn01',
'contract_version' => '1.0',
'association_slug' => $association_slug,
'association_channel_id' => (string) $channel_id,
'submitted_at' => date('c'),
'standing' => $standing,
'pinned_scenario_ids' => $pinned_scenario_ids,
'narrative' => $narrative,
];
}
// ---------------------------------------------------------------------------
// ORCHESTRATOR POST
// ---------------------------------------------------------------------------
function scn01_post_to_orchestrator($envelope) {
$config = scn01_load_config();
$receiver_url = $config['receiver_url'] ?? '';
$node_token = $config['node_token'] ?? '';
if (!$receiver_url) {
logger('scn01_spool: receiver_url not configured');
return 'Orchestrator receiver URL not configured.';
}
$payload = json_encode($envelope);
if ($payload === false) {
logger('scn01_spool: failed to encode envelope');
return 'Failed to encode submission.';
}
$ch = curl_init($receiver_url);
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'X-Node-Token: ' . $node_token,
],
]);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_error = curl_error($ch);
curl_close($ch);
if ($curl_error) {
logger('scn01_spool: curl error: ' . $curl_error);
return 'Network error: ' . $curl_error;
}
if ($http_code === 200 || $http_code === 201) {
return true;
}
logger('scn01_spool: orchestrator returned HTTP ' . $http_code . ': ' . $response);
return 'Orchestrator error (HTTP ' . $http_code . ').';
}
// ---------------------------------------------------------------------------
// CONFIG
// ---------------------------------------------------------------------------
function scn01_load_config() {
$path = 'addon/scn01/config.json';
$raw = @file_get_contents($path);
if ($raw === false) return [];
$data = json_decode($raw, true);
return (json_last_error() === JSON_ERROR_NONE) ? $data : [];
}