Updated
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
function dsc01_handle_post($association_slug, $access) {
|
function dsc01_handle_post($association_slug, $access) {
|
||||||
$categories = dsc01_load_categories();
|
$categories = dsc01_load_categories();
|
||||||
$valid_codes = array_keys($categories);
|
$valid_codes = array_keys($categories);
|
||||||
|
|
||||||
$raw_codes = $_POST['dsc_codes'] ?? [];
|
$raw_codes = $_POST['dsc_codes'] ?? [];
|
||||||
@@ -38,26 +38,30 @@ function dsc01_handle_post($association_slug, $access) {
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build spool envelope
|
// Load association config
|
||||||
$cfg_raw = @file_get_contents('addon/vs01/config.json');
|
$cfg_raw = @file_get_contents('addon/vs01/config.json');
|
||||||
$cfg = $cfg_raw ? json_decode($cfg_raw, true) : [];
|
$cfg = $cfg_raw ? json_decode($cfg_raw, true) : [];
|
||||||
$assoc = $cfg['associations'][$association_slug] ?? [];
|
$assoc = $cfg['associations'][$association_slug] ?? [];
|
||||||
|
|
||||||
|
// Load dsc01 config for receiver_url and node_token
|
||||||
|
$dsc_config = dsc01_load_config();
|
||||||
|
|
||||||
$envelope = dsc01_build_spool_envelope(
|
$envelope = dsc01_build_spool_envelope(
|
||||||
$codes,
|
$codes,
|
||||||
$narrative,
|
$narrative,
|
||||||
$association_slug,
|
$association_slug,
|
||||||
$assoc['channel_id'] ?? '',
|
$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) {
|
if ($result === true) {
|
||||||
$assoc_name = dsc01_h($assoc['name'] ?? $association_slug);
|
$assoc_name = dsc01_h($assoc['name'] ?? $association_slug);
|
||||||
return '<div class="dsc01-content">
|
return '<div class="dsc01-content">
|
||||||
<div class="alert alert-success">
|
<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) . '">
|
<a href="' . z_root() . '/vs01/' . dsc01_h($association_slug) . '">
|
||||||
Return to ' . $assoc_name . '
|
Return to ' . $assoc_name . '
|
||||||
</a>
|
</a>
|
||||||
@@ -75,29 +79,58 @@ function dsc01_handle_post($association_slug, $access) {
|
|||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// SPOOL ENVELOPE
|
// 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 [
|
return [
|
||||||
'addon' => 'dsc01',
|
'_header' => [
|
||||||
'contract_version' => '1.0',
|
'addon' => 'dsc01',
|
||||||
'association_slug' => $association_slug,
|
'contract_version' => '1.0',
|
||||||
'association_channel_id' => (string) $channel_id,
|
'association_slug' => $association_slug,
|
||||||
'submitted_at' => date('c'),
|
'association_channel_id' => (string) $channel_id,
|
||||||
'standing' => $standing,
|
'participant_id' => dsc01_get_participant_id(),
|
||||||
'dsc_codes' => $dsc_codes,
|
'submitted_at' => date('c'),
|
||||||
'narrative' => $narrative,
|
'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
|
// ORCHESTRATOR POST
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
function dsc01_post_to_orchestrator($envelope) {
|
function dsc01_post_to_orchestrator($envelope, $config = null) {
|
||||||
$config = dsc01_load_config();
|
if ($config === null) {
|
||||||
|
$config = dsc01_load_config();
|
||||||
|
}
|
||||||
$receiver_url = $config['receiver_url'] ?? '';
|
$receiver_url = $config['receiver_url'] ?? '';
|
||||||
$node_token = $config['node_token'] ?? '';
|
$node_token = $config['node_token'] ?? '';
|
||||||
|
|
||||||
if (!$receiver_url) {
|
if (!$receiver_url) {
|
||||||
logger('dsc01_spool: receiver_url not configured');
|
logger('dsc01_spool: receiver_url not configured');
|
||||||
|
|||||||
Reference in New Issue
Block a user