This commit is contained in:
2026-06-19 04:52:59 -04:00
parent ce1408f90c
commit f6c3dbafe7

View File

@@ -38,26 +38,30 @@ function dsc01_handle_post($association_slug, $access) {
return $out;
}
// Build spool envelope
// Load association config
$cfg_raw = @file_get_contents('addon/vs01/config.json');
$cfg = $cfg_raw ? json_decode($cfg_raw, true) : [];
$assoc = $cfg['associations'][$association_slug] ?? [];
// Load dsc01 config for receiver_url and node_token
$dsc_config = dsc01_load_config();
$envelope = dsc01_build_spool_envelope(
$codes,
$narrative,
$association_slug,
$assoc['channel_id'] ?? '',
$access
$access,
$dsc_config['node_token'] ?? ''
);
$result = dsc01_post_to_orchestrator($envelope);
$result = dsc01_post_to_orchestrator($envelope, $dsc_config);
if ($result === true) {
$assoc_name = dsc01_h($assoc['name'] ?? $association_slug);
return '<div class="dsc01-content">
<div class="alert alert-success">
Your checklist for ' . $assoc_name . ' has been submitted.
Your checklist for ' . $assoc_name . ' has been saved.
<a href="' . z_root() . '/vs01/' . dsc01_h($association_slug) . '">
Return to ' . $assoc_name . '
</a>
@@ -75,27 +79,56 @@ function dsc01_handle_post($association_slug, $access) {
// ---------------------------------------------------------------------------
// SPOOL ENVELOPE
// Matches contracts/dsc01/record-v1.json — _header / _payload shape.
// ---------------------------------------------------------------------------
function dsc01_build_spool_envelope($dsc_codes, $narrative, $association_slug, $channel_id, $standing) {
function dsc01_build_spool_envelope($dsc_codes, $narrative, $association_slug, $channel_id, $standing, $node_token) {
return [
'_header' => [
'addon' => 'dsc01',
'contract_version' => '1.0',
'association_slug' => $association_slug,
'association_channel_id' => (string) $channel_id,
'participant_id' => dsc01_get_participant_id(),
'submitted_at' => date('c'),
'standing' => $standing,
'node_token_hash' => hash('sha256', $node_token),
],
'_payload' => [
'fields' => [
'dsc_codes' => $dsc_codes,
'narrative' => $narrative,
],
],
];
}
// ---------------------------------------------------------------------------
// PARTICIPANT ID
// ---------------------------------------------------------------------------
function dsc01_get_participant_id() {
$observer = get_observer_hash();
if (!$observer) return '';
$r = q("SELECT xchan_addr FROM xchan WHERE xchan_hash = '%s' LIMIT 1",
dbesc($observer)
);
if (!$r) return '';
$addr = $r[0]['xchan_addr'] ?? '';
$parts = explode('@', $addr);
return $parts[0] ?? '';
}
// ---------------------------------------------------------------------------
// ORCHESTRATOR POST
// ---------------------------------------------------------------------------
function dsc01_post_to_orchestrator($envelope) {
function dsc01_post_to_orchestrator($envelope, $config = null) {
if ($config === null) {
$config = dsc01_load_config();
}
$receiver_url = $config['receiver_url'] ?? '';
$node_token = $config['node_token'] ?? '';