Updated
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
{
|
||||
"_note": "Copy to config.json. Do not commit config.json — it contains secrets and installation-specific values.",
|
||||
"corpus_builder_group_id": 0,
|
||||
"listings_file": "REPLACE — absolute path to listings.json on the host",
|
||||
"directory_default_tab": "core"
|
||||
"receiver_url": "REPLACE — orchestrator receiver endpoint, e.g. https://orchestrator1.internal.diagnostics.kane-il.us/receive",
|
||||
"node_token": "REPLACE — shared secret for node-to-orchestrator authentication",
|
||||
"listings_file": "REPLACE — absolute path to listings.json on the host, e.g. /var/www/hubzilla/addon/vs01/listings.json",
|
||||
"directory_default_tab": "core",
|
||||
"associations": {
|
||||
"REPLACE-SLUG": {
|
||||
"_note": "Key is the URL slug — lowercase, hyphens only, matches argv(1) in the route",
|
||||
"name": "REPLACE — association legal name",
|
||||
"address": "REPLACE — association street address",
|
||||
"channel_id": 0,
|
||||
"channel_address": "REPLACE — channel@node address",
|
||||
"groups": {
|
||||
"public": 0,
|
||||
"sase_participant": 0,
|
||||
"corpus_builder": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,16 @@
|
||||
/**
|
||||
* Name: VS-01 Vital Signs
|
||||
* Description: Public civic diagnostic — the ten structural preconditions of an HOA association.
|
||||
* Version: 0.1.0
|
||||
* Version: 0.2.0
|
||||
* MinVersion: 11.0
|
||||
* MaxVersion: 12.0
|
||||
*/
|
||||
|
||||
use Zotlabs\Extend\Widget;
|
||||
|
||||
require_once 'addon/vs01/vs01_renderer.php';
|
||||
require_once 'addon/vs01/vs01_spool.php';
|
||||
|
||||
function vs01_module() {}
|
||||
|
||||
function vs01_load() {
|
||||
@@ -44,34 +47,71 @@ function vs01_h($value) {
|
||||
// ACCESS
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_access_state() {
|
||||
function vs01_access_state($association_slug = '') {
|
||||
if (!local_channel()) {
|
||||
return 'public';
|
||||
}
|
||||
|
||||
$channel = App::get_channel();
|
||||
$config = vs01_load_config();
|
||||
|
||||
// Operator check — site owner, not association channel owner
|
||||
$channel = App::get_channel();
|
||||
if (local_channel() === intval($channel['channel_id'])) {
|
||||
return 'operator';
|
||||
}
|
||||
|
||||
$config = vs01_load_config();
|
||||
$gid = intval($config['corpus_builder_group_id'] ?? 0);
|
||||
if (!$association_slug) {
|
||||
return 'public';
|
||||
}
|
||||
|
||||
if ($gid && in_array(get_observer_hash(), group_get_members_xchan($gid))) {
|
||||
$assoc = $config['associations'][$association_slug] ?? null;
|
||||
if (!$assoc) return 'public';
|
||||
|
||||
$observer = get_observer_hash();
|
||||
$groups = $assoc['groups'] ?? [];
|
||||
|
||||
// Corpus Builder — highest participant tier
|
||||
$cb_gid = intval($groups['corpus_builder'] ?? 0);
|
||||
if ($cb_gid && in_array($observer, group_get_members_xchan($cb_gid))) {
|
||||
return 'participant';
|
||||
}
|
||||
|
||||
return 'denied';
|
||||
// SASE Participant
|
||||
$sase_gid = intval($groups['sase_participant'] ?? 0);
|
||||
if ($sase_gid && in_array($observer, group_get_members_xchan($sase_gid))) {
|
||||
return 'participant';
|
||||
}
|
||||
|
||||
function vs01_access_wall() {
|
||||
return 'public';
|
||||
}
|
||||
|
||||
function vs01_is_professional() {
|
||||
if (!local_channel()) return false;
|
||||
$observer = get_observer_hash();
|
||||
$listings = vs01_load_listings();
|
||||
foreach (['tier1', 'tier2'] as $tier) {
|
||||
foreach ($listings[$tier] ?? [] as $entry) {
|
||||
if (($entry['xchan'] ?? '') === $observer
|
||||
&& ($entry['status'] ?? '') === 'active') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function vs01_access_wall($association_slug = '') {
|
||||
$config = vs01_load_config();
|
||||
$assoc = $association_slug
|
||||
? ($config['associations'][$association_slug] ?? null)
|
||||
: null;
|
||||
$name = $assoc ? vs01_h($assoc['name']) : 'this association';
|
||||
return '
|
||||
<div class="vs01-content">
|
||||
<div class="alert alert-info" role="alert">
|
||||
<strong>HOA_MEMBER standing required to submit.</strong>
|
||||
<strong>HOA_MEMBER standing required to submit a record for ' . $name . '.</strong>
|
||||
Vital Signs are public and readable by anyone.
|
||||
To submit a Vital Signs record for your association, you must complete the SASE process.
|
||||
To submit a record, you must complete the SASE process.
|
||||
Visit <a href="https://directory.diagnostics.kane-il.us/channel/theron">
|
||||
directory.diagnostics.kane-il.us
|
||||
</a> to begin.
|
||||
@@ -81,7 +121,7 @@ function vs01_access_wall() {
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CONTENT
|
||||
// CONTENT ROUTER
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_content() {
|
||||
@@ -92,39 +132,279 @@ function vs01_content() {
|
||||
head_add_js('/addon/vs01/view/js/vs01.js');
|
||||
}
|
||||
|
||||
$access = vs01_access_state();
|
||||
$association_slug = argv(1) ?? '';
|
||||
$vs_code = strtoupper(argv(2) ?? '');
|
||||
|
||||
// vs01 is public — access wall only gates submission, not reading
|
||||
// Index — list registered associations
|
||||
if (!$association_slug) {
|
||||
return vs01_render_index();
|
||||
}
|
||||
|
||||
$config = vs01_load_config();
|
||||
if (!isset($config['associations'][$association_slug])) {
|
||||
return vs01_render_not_found();
|
||||
}
|
||||
|
||||
$access = vs01_access_state($association_slug);
|
||||
if (vs01_is_professional()) {
|
||||
$access = 'professional';
|
||||
}
|
||||
|
||||
// Manage route — operator only
|
||||
if ($vs_code === 'MANAGE') {
|
||||
if ($access !== 'operator') {
|
||||
return vs01_access_wall($association_slug);
|
||||
}
|
||||
return vs01_render_manage($association_slug);
|
||||
}
|
||||
|
||||
// VS form route
|
||||
if ($vs_code && preg_match('/^VS-\d{2}$/', $vs_code)) {
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if ($access === 'public' || $access === 'denied') {
|
||||
return vs01_access_wall();
|
||||
if ($access === 'public') {
|
||||
return vs01_access_wall($association_slug);
|
||||
}
|
||||
// TODO: handle POST submission
|
||||
return vs01_access_wall();
|
||||
if (!vs01_verify_csrf()) {
|
||||
return '<div class="alert alert-danger">Invalid form token. Please reload and try again.</div>';
|
||||
}
|
||||
return vs01_handle_post($association_slug, $vs_code, $access);
|
||||
}
|
||||
return vs01_render_vs_form($association_slug, $vs_code, $access);
|
||||
}
|
||||
|
||||
return vs01_render_main($access);
|
||||
// Association landing
|
||||
return vs01_render_landing($association_slug, $access);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// RENDER
|
||||
// RENDER — INDEX
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_main($access) {
|
||||
function vs01_render_index() {
|
||||
$config = vs01_load_config();
|
||||
$associations = $config['associations'] ?? [];
|
||||
|
||||
if (empty($associations)) {
|
||||
return '<div class="vs01-content"><p class="text-muted">No associations registered.</p></div>';
|
||||
}
|
||||
|
||||
$out = '<div class="vs01-content">';
|
||||
$out .= '<h2>Vital Signs</h2>';
|
||||
$out .= '<p class="text-muted">Select an association to view or submit its diagnostic record.</p>';
|
||||
$out .= '<ul class="vs01-association-list list-group">';
|
||||
foreach ($associations as $slug => $assoc) {
|
||||
$name = vs01_h($assoc['name'] ?? $slug);
|
||||
$address = vs01_h($assoc['address'] ?? '');
|
||||
$out .= '<li class="list-group-item">';
|
||||
$out .= '<a href="' . z_root() . '/vs01/' . vs01_h($slug) . '">' . $name . '</a>';
|
||||
if ($address) {
|
||||
$out .= ' <span class="text-muted small">— ' . $address . '</span>';
|
||||
}
|
||||
$out .= '</li>';
|
||||
}
|
||||
$out .= '</ul></div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// RENDER — ASSOCIATION LANDING
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_landing($association_slug, $access) {
|
||||
$config = vs01_load_config();
|
||||
$assoc = $config['associations'][$association_slug];
|
||||
$name = vs01_h($assoc['name'] ?? $association_slug);
|
||||
$schemas = vs01_load_schemas();
|
||||
|
||||
$out = '<div class="vs01-content">';
|
||||
$out .= '<div class="vs01-header mb-3">';
|
||||
$out .= '<h2>Vital Signs</h2>';
|
||||
$out .= '<p class="text-muted">The ten structural preconditions of an HOA association.</p>';
|
||||
$out .= '<h2>' . $name . '</h2>';
|
||||
$out .= '<p class="text-muted">Vital Signs diagnostic record.</p>';
|
||||
$out .= '</div>';
|
||||
|
||||
// TODO: render the ten Vital Signs
|
||||
// VS navigation
|
||||
$out .= '<nav class="vs01-vs-nav" aria-label="Vital Signs">';
|
||||
$out .= '<ul class="list-group list-group-flush">';
|
||||
foreach ($schemas as $code => $schema) {
|
||||
$title = vs01_h($schema['_meta']['title'] ?? $code);
|
||||
$dq = vs01_h($schema['_meta']['diagnostic_question'] ?? '');
|
||||
$url = z_root() . '/vs01/' . vs01_h($association_slug) . '/' . vs01_h($code);
|
||||
$out .= '<li class="list-group-item">';
|
||||
$out .= '<a href="' . $url . '"><strong>' . vs01_h($code) . '</strong> — ' . $title . '</a>';
|
||||
if ($dq) {
|
||||
$out .= '<p class="small text-muted mb-0">' . $dq . '</p>';
|
||||
}
|
||||
$out .= '</li>';
|
||||
}
|
||||
$out .= '</ul></nav>';
|
||||
|
||||
if ($access === 'operator') {
|
||||
$manage_url = z_root() . '/vs01/' . vs01_h($association_slug) . '/manage';
|
||||
$out .= '<div class="mt-3"><a href="' . $manage_url . '" class="btn btn-sm btn-outline-secondary">Manage TMP</a></div>';
|
||||
}
|
||||
|
||||
$out .= '<div class="vs01-placeholder text-muted fst-italic">Content forthcoming.</div>';
|
||||
$out .= '</div>';
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// RENDER — VS FORM
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_vs_form($association_slug, $vs_code, $access) {
|
||||
$schemas = vs01_load_schemas();
|
||||
if (!isset($schemas[$vs_code])) {
|
||||
return '<div class="alert alert-warning">VS code ' . vs01_h($vs_code) . ' not found.</div>';
|
||||
}
|
||||
|
||||
$schema = $schemas[$vs_code];
|
||||
$config = vs01_load_config();
|
||||
$assoc = $config['associations'][$association_slug];
|
||||
$name = vs01_h($assoc['name'] ?? $association_slug);
|
||||
|
||||
// Determine perspective from access state
|
||||
$perspective_map = [
|
||||
'participant' => 'homeowner',
|
||||
'professional' => 'professional',
|
||||
'operator' => 'public_record',
|
||||
'public' => 'homeowner',
|
||||
];
|
||||
$perspective_key = $perspective_map[$access] ?? 'homeowner';
|
||||
$perspective = $schema['perspectives'][$perspective_key] ?? null;
|
||||
|
||||
if (!$perspective) {
|
||||
return '<div class="alert alert-warning">No perspective defined for access state: ' . vs01_h($access) . '</div>';
|
||||
}
|
||||
|
||||
$form_url = z_root() . '/vs01/' . vs01_h($association_slug) . '/' . vs01_h($vs_code);
|
||||
$meta = $schema['_meta'];
|
||||
|
||||
$out = '<div class="vs01-content">';
|
||||
|
||||
// Breadcrumb
|
||||
$out .= '<nav aria-label="breadcrumb"><ol class="breadcrumb">';
|
||||
$out .= '<li class="breadcrumb-item"><a href="' . z_root() . '/vs01/' . vs01_h($association_slug) . '">' . $name . '</a></li>';
|
||||
$out .= '<li class="breadcrumb-item active">' . vs01_h($vs_code) . ' — ' . vs01_h($meta['title'] ?? '') . '</li>';
|
||||
$out .= '</ol></nav>';
|
||||
|
||||
// VS header
|
||||
$out .= '<div class="vs01-vs-header mb-3">';
|
||||
$out .= '<h3>' . vs01_h($vs_code) . ' — ' . vs01_h($meta['title'] ?? '') . '</h3>';
|
||||
$out .= '<p class="vs01-diagnostic-question">' . vs01_h($meta['diagnostic_question'] ?? '') . '</p>';
|
||||
$out .= '</div>';
|
||||
|
||||
// Compound condition banners
|
||||
$out .= vs01_render_compound_banners($association_slug);
|
||||
|
||||
// Verification sources
|
||||
$out .= vs01_render_verification_sources($meta);
|
||||
|
||||
// Perspective note for VS-07 and VS-09 homeowner slot
|
||||
$out .= vs01_render_perspective_note($schema, $perspective_key);
|
||||
|
||||
// Public access — show read-only content, no form
|
||||
if ($access === 'public') {
|
||||
$out .= '<div class="alert alert-info mt-3">';
|
||||
$out .= 'Vital Signs are public. ';
|
||||
$out .= '<a href="https://directory.diagnostics.kane-il.us/channel/theron">Complete the SASE process</a> ';
|
||||
$out .= 'to submit a record for this association.';
|
||||
$out .= '</div>';
|
||||
$out .= '</div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
// Immutable check for public record perspective
|
||||
if ($perspective_key === 'public_record'
|
||||
&& ($perspective['immutable_after_submit'] ?? false)
|
||||
&& vs01_public_record_exists($vs_code, $association_slug)) {
|
||||
$out .= '<div class="vs01-immutable-notice alert alert-secondary">';
|
||||
$out .= 'Public record — immutable. Contact the operator to correct spelling or citation errors.';
|
||||
$out .= '</div>';
|
||||
$out .= vs01_render_public_record_readonly($perspective, []);
|
||||
$out .= '</div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
// Form
|
||||
$out .= '<p class="vs01-instruction">' . vs01_h($perspective['instruction'] ?? '') . '</p>';
|
||||
$out .= '<form method="post" action="' . $form_url . '" class="vs01-form" novalidate>';
|
||||
$out .= vs01_csrf_token();
|
||||
$out .= '<input type="hidden" name="vs_code" value="' . vs01_h($vs_code) . '">';
|
||||
$out .= '<input type="hidden" name="perspective" value="' . vs01_h($perspective_key) . '">';
|
||||
|
||||
foreach ($perspective['fields'] ?? [] as $field) {
|
||||
$field_html = vs01_render_field($field, []);
|
||||
if (!empty($field['depends_on'])) {
|
||||
$field_html = vs01_wrap_depends_on($field, $field_html);
|
||||
}
|
||||
$out .= $field_html;
|
||||
}
|
||||
|
||||
// THROWAWAY — bare minimum confirmation target; replace with full TMP workflow
|
||||
$out .= '<div class="mt-3">';
|
||||
$out .= '<button type="submit" class="btn btn-primary">Submit</button>';
|
||||
$out .= '</div>';
|
||||
$out .= '</form>';
|
||||
|
||||
// VS navigation — previous / next
|
||||
$out .= vs01_render_vs_nav($association_slug, $vs_code);
|
||||
|
||||
$out .= '</div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// RENDER — VS NAVIGATION
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_vs_nav($association_slug, $current_code) {
|
||||
$schemas = vs01_load_schemas();
|
||||
$codes = array_keys($schemas);
|
||||
$idx = array_search($current_code, $codes, true);
|
||||
$base = z_root() . '/vs01/' . vs01_h($association_slug) . '/';
|
||||
|
||||
$out = '<nav class="vs01-vs-nav-arrows mt-4 d-flex justify-content-between">';
|
||||
if ($idx > 0) {
|
||||
$prev = $codes[$idx - 1];
|
||||
$out .= '<a href="' . $base . vs01_h($prev) . '" class="btn btn-sm btn-outline-secondary">← ' . vs01_h($prev) . '</a>';
|
||||
} else {
|
||||
$out .= '<span></span>';
|
||||
}
|
||||
if ($idx !== false && $idx < count($codes) - 1) {
|
||||
$next = $codes[$idx + 1];
|
||||
$out .= '<a href="' . $base . vs01_h($next) . '" class="btn btn-sm btn-outline-secondary">' . vs01_h($next) . ' →</a>';
|
||||
} else {
|
||||
$out .= '<span></span>';
|
||||
}
|
||||
$out .= '</nav>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// RENDER — MANAGE (TMP REVIEW)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_manage($association_slug) {
|
||||
$config = vs01_load_config();
|
||||
$assoc = $config['associations'][$association_slug];
|
||||
$name = vs01_h($assoc['name'] ?? $association_slug);
|
||||
|
||||
$out = '<div class="vs01-content">';
|
||||
$out .= '<h2>Manage — ' . $name . '</h2>';
|
||||
// TODO: load TMP submissions from orchestrator and render review interface
|
||||
$out .= '<p class="text-muted fst-italic">TMP review forthcoming.</p>';
|
||||
$out .= '</div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// RENDER — NOT FOUND
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_not_found() {
|
||||
return '<div class="vs01-content"><div class="alert alert-warning">Association not found.</div></div>';
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CONFIG
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -137,6 +417,24 @@ function vs01_load_config() {
|
||||
return (json_last_error() === JSON_ERROR_NONE) ? $data : [];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// LISTINGS
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_load_listings() {
|
||||
$config = vs01_load_config();
|
||||
$path = $config['listings_file'] ?? 'addon/vs01/listings.json';
|
||||
$raw = @file_get_contents($path);
|
||||
if ($raw === false) {
|
||||
return ['core' => [], 'tier1' => [], 'tier2' => [], 'other' => []];
|
||||
}
|
||||
$data = json_decode($raw, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
return ['core' => [], 'tier1' => [], 'tier2' => [], 'other' => []];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CSRF
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
328
hubzilla/addon/vs01/vs01_renderer.php
Normal file
328
hubzilla/addon/vs01/vs01_renderer.php
Normal file
@@ -0,0 +1,328 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* VS-01 Renderer
|
||||
* Reads VS JSON schemas and produces form HTML.
|
||||
* This file knows nothing about what a Vital Sign is.
|
||||
* It only knows how to render what the schema describes.
|
||||
* See VS-RENDERER-SPEC.md for the full contract.
|
||||
*/
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SCHEMA LOADER
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_load_schemas() {
|
||||
$dir = 'addon/vs01/vital-signs/';
|
||||
$files = glob($dir . 'VS-*.json');
|
||||
if (!$files) return [];
|
||||
sort($files);
|
||||
$schemas = [];
|
||||
foreach ($files as $file) {
|
||||
$raw = @file_get_contents($file);
|
||||
if (!$raw) {
|
||||
logger('vs01_renderer: could not read schema file: ' . $file);
|
||||
continue;
|
||||
}
|
||||
$data = json_decode($raw, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
logger('vs01_renderer: malformed schema file: ' . $file);
|
||||
continue;
|
||||
}
|
||||
$code = $data['_meta']['code'] ?? null;
|
||||
if ($code) $schemas[$code] = $data;
|
||||
}
|
||||
return $schemas;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// FIELD TYPE RENDERERS
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_field_text($field, $value = '') {
|
||||
$id = vs01_h($field['id']);
|
||||
$out = '<div class="vs01-field vs01-field-text mb-3" data-field-id="' . $id . '">';
|
||||
$out .= '<label class="form-label" for="' . $id . '">' . vs01_h($field['label']) . '</label>';
|
||||
$out .= '<input type="text" class="form-control" id="' . $id . '"
|
||||
name="fields[' . $id . ']"
|
||||
value="' . vs01_h($value) . '"
|
||||
placeholder="' . vs01_h($field['placeholder'] ?? '') . '"
|
||||
' . (!empty($field['required']) ? 'required' : '') . '>';
|
||||
$out .= '</div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
function vs01_render_field_number($field, $value = '') {
|
||||
$id = vs01_h($field['id']);
|
||||
$out = '<div class="vs01-field vs01-field-number mb-3" data-field-id="' . $id . '">';
|
||||
$out .= '<label class="form-label" for="' . $id . '">' . vs01_h($field['label']) . '</label>';
|
||||
$out .= '<input type="number" class="form-control" id="' . $id . '"
|
||||
name="fields[' . $id . ']"
|
||||
value="' . vs01_h($value) . '"
|
||||
placeholder="' . vs01_h($field['placeholder'] ?? '') . '"
|
||||
' . (!empty($field['required']) ? 'required' : '') . '>';
|
||||
$out .= '</div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
function vs01_render_field_date($field, $value = '') {
|
||||
$id = vs01_h($field['id']);
|
||||
$out = '<div class="vs01-field vs01-field-date mb-3" data-field-id="' . $id . '">';
|
||||
$out .= '<label class="form-label" for="' . $id . '">' . vs01_h($field['label']) . '</label>';
|
||||
$out .= '<input type="date" class="form-control" id="' . $id . '"
|
||||
name="fields[' . $id . ']"
|
||||
value="' . vs01_h($value) . '"
|
||||
' . (!empty($field['required']) ? 'required' : '') . '>';
|
||||
$out .= '</div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
function vs01_render_field_boolean($field, $value = '') {
|
||||
$id = vs01_h($field['id']);
|
||||
$yes = ($value === 'true') ? 'checked' : '';
|
||||
$no = ($value === 'false') ? 'checked' : '';
|
||||
$req = !empty($field['required']) ? 'required' : '';
|
||||
$out = '<div class="vs01-field vs01-field-boolean mb-3" data-field-id="' . $id . '">';
|
||||
$out .= '<fieldset class="vs01-boolean-group">';
|
||||
$out .= '<legend class="form-label">' . vs01_h($field['label']) . '</legend>';
|
||||
$out .= '<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="radio" id="' . $id . '_yes"
|
||||
name="fields[' . $id . ']" value="true" ' . $yes . ' ' . $req . '>
|
||||
<label class="form-check-label" for="' . $id . '_yes">Yes</label>
|
||||
</div>';
|
||||
$out .= '<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="radio" id="' . $id . '_no"
|
||||
name="fields[' . $id . ']" value="false" ' . $no . '>
|
||||
<label class="form-check-label" for="' . $id . '_no">No</label>
|
||||
</div>';
|
||||
$out .= '</fieldset></div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
function vs01_render_field_select($field, $value = '') {
|
||||
$id = vs01_h($field['id']);
|
||||
$options = $field['options'] ?? [];
|
||||
$out = '<div class="vs01-field vs01-field-select mb-3" data-field-id="' . $id . '">';
|
||||
$out .= '<label class="form-label" for="' . $id . '">' . vs01_h($field['label']) . '</label>';
|
||||
$out .= '<select class="form-select" id="' . $id . '" name="fields[' . $id . ']"
|
||||
' . (!empty($field['required']) ? 'required' : '') . '>';
|
||||
$out .= '<option value="">— select —</option>';
|
||||
foreach ($options as $opt) {
|
||||
$v = vs01_h($opt['value']);
|
||||
$l = vs01_h($opt['label']);
|
||||
$sel = ($value === $opt['value']) ? 'selected' : '';
|
||||
$out .= '<option value="' . $v . '" ' . $sel . '>' . $l . '</option>';
|
||||
}
|
||||
$out .= '</select></div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
function vs01_render_field_textarea($field, $value = '') {
|
||||
$id = vs01_h($field['id']);
|
||||
$out = '<div class="vs01-field vs01-field-textarea mb-3" data-field-id="' . $id . '">';
|
||||
$out .= '<label class="form-label" for="' . $id . '">' . vs01_h($field['label']) . '</label>';
|
||||
$out .= '<textarea class="form-control" id="' . $id . '"
|
||||
name="fields[' . $id . ']"
|
||||
placeholder="' . vs01_h($field['placeholder'] ?? '') . '"
|
||||
rows="5"
|
||||
' . (!empty($field['required']) ? 'required' : '') . '>'
|
||||
. vs01_h($value) . '</textarea>';
|
||||
$out .= '</div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
function vs01_render_field_multiselect($field, $value = '') {
|
||||
$id = vs01_h($field['id']);
|
||||
$options = $field['options'] ?? [];
|
||||
$selected = $value ? json_decode($value, true) : [];
|
||||
if (!is_array($selected)) $selected = [];
|
||||
$out = '<div class="vs01-field vs01-field-multiselect mb-3" data-field-id="' . $id . '">';
|
||||
$out .= '<fieldset><legend class="form-label">' . vs01_h($field['label']) . '</legend>';
|
||||
foreach ($options as $opt) {
|
||||
$v = vs01_h($opt['value']);
|
||||
$l = vs01_h($opt['label']);
|
||||
$chk = in_array($opt['value'], $selected) ? 'checked' : '';
|
||||
$out .= '<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox"
|
||||
id="' . $id . '_' . $v . '"
|
||||
name="fields[' . $id . '][]"
|
||||
value="' . $v . '" ' . $chk . '>
|
||||
<label class="form-check-label" for="' . $id . '_' . $v . '">' . $l . '</label>
|
||||
</div>';
|
||||
}
|
||||
$out .= '</fieldset></div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// FIELD DISPATCHER
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_field($field, $submitted_values = []) {
|
||||
$id = $field['id'] ?? '';
|
||||
$type = $field['type'] ?? 'text';
|
||||
$value = $submitted_values[$id] ?? '';
|
||||
|
||||
switch ($type) {
|
||||
case 'text': $html = vs01_render_field_text($field, $value); break;
|
||||
case 'number': $html = vs01_render_field_number($field, $value); break;
|
||||
case 'date': $html = vs01_render_field_date($field, $value); break;
|
||||
case 'boolean': $html = vs01_render_field_boolean($field, $value); break;
|
||||
case 'select': $html = vs01_render_field_select($field, $value); break;
|
||||
case 'textarea': $html = vs01_render_field_textarea($field, $value); break;
|
||||
case 'multiselect': $html = vs01_render_field_multiselect($field, $value); break;
|
||||
default:
|
||||
$html = '<div class="alert alert-danger">Unknown field type: ' . vs01_h($type) . '</div>';
|
||||
}
|
||||
|
||||
$html .= vs01_render_diagnostic_flag($field, $value);
|
||||
return $html;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CONDITIONAL DISPLAY
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_wrap_depends_on($field, $html) {
|
||||
if (empty($field['depends_on'])) return $html;
|
||||
$dep_field = vs01_h($field['depends_on']['field']);
|
||||
$dep_value = $field['depends_on']['value'];
|
||||
$dep_value = is_array($dep_value)
|
||||
? vs01_h(json_encode($dep_value))
|
||||
: vs01_h((string) $dep_value);
|
||||
return '<div class="vs01-conditional"
|
||||
data-depends-on="' . $dep_field . '"
|
||||
data-depends-value="' . $dep_value . '"
|
||||
style="display:none;">'
|
||||
. $html .
|
||||
'</div>';
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// DIAGNOSTIC FLAGS
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_diagnostic_flag($field, $value) {
|
||||
if (empty($field['diagnostic_flag'])) return '';
|
||||
$condition = $field['flag_condition'] ?? null;
|
||||
if ($condition === null) return '';
|
||||
|
||||
$triggered = false;
|
||||
if (is_array($condition)) {
|
||||
$triggered = in_array($value, $condition);
|
||||
} elseif (is_bool($condition)) {
|
||||
$triggered = ($value === ($condition ? 'true' : 'false'));
|
||||
} else {
|
||||
$triggered = ($value === (string) $condition);
|
||||
}
|
||||
|
||||
if (!$triggered) return '';
|
||||
|
||||
$severity = vs01_flag_severity($field);
|
||||
$label = vs01_h($field['flag_label'] ?? 'Diagnostic condition');
|
||||
$note = isset($field['flag_note'])
|
||||
? '<p class="vs01-flag-note mb-0 mt-1 small">' . vs01_h($field['flag_note']) . '</p>'
|
||||
: '';
|
||||
|
||||
return '<div class="vs01-flag vs01-flag-' . $severity . ' mb-2" role="alert">
|
||||
<strong>' . $label . '</strong>' . $note . '
|
||||
</div>';
|
||||
}
|
||||
|
||||
function vs01_flag_severity($field) {
|
||||
$id = $field['id'] ?? '';
|
||||
if (in_array($id, ['pro_selfdealing_verified', 'pro_standing_verified', 'pro_incumbent_perpetuation_risk'])) {
|
||||
return 'critical';
|
||||
}
|
||||
if (str_starts_with($id, 'pro_')) return 'high';
|
||||
return 'standard';
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// COMPOUND CONDITION BANNERS
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_compound_banners($association_slug) {
|
||||
// TODO: query stored VS records for this association from orchestrator
|
||||
// and evaluate the three compound conditions defined in VS-RENDERER-SPEC.md.
|
||||
// Returns empty string until orchestrator query is implemented.
|
||||
return '';
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// CROSS-VS REFERENCE NOTES
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_cross_reference($vs_code, $label, $association_slug) {
|
||||
$url = z_root() . '/vs01/' . vs01_h($association_slug) . '/' . vs01_h($vs_code);
|
||||
return '<div class="vs01-cross-ref small text-muted mt-1">
|
||||
See also: <a href="' . $url . '">' . vs01_h($label) . '</a>
|
||||
</div>';
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// VERIFICATION SOURCES PANEL
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_verification_sources($meta) {
|
||||
$sources = $meta['verification_sources'] ?? [];
|
||||
if (empty($sources)) return '';
|
||||
$code = vs01_h($meta['code'] ?? 'vs');
|
||||
$out = '<div class="vs01-verification-sources mb-3">';
|
||||
$out .= '<button type="button" class="btn btn-sm btn-outline-secondary"
|
||||
data-bs-toggle="collapse"
|
||||
data-bs-target="#vs01-sources-' . $code . '"
|
||||
aria-expanded="false">
|
||||
Where to verify this
|
||||
</button>';
|
||||
$out .= '<div class="collapse mt-2" id="vs01-sources-' . $code . '">';
|
||||
foreach ($sources as $source) {
|
||||
$label = vs01_h($source['label'] ?? '');
|
||||
$url = vs01_h($source['url'] ?? '');
|
||||
$instruction = vs01_h($source['instruction'] ?? '');
|
||||
$out .= '<div class="vs01-source mb-2">';
|
||||
$out .= '<a href="' . $url . '" target="_blank" rel="noopener" class="fw-semibold">' . $label . '</a>';
|
||||
$out .= '<p class="small text-muted mb-0">' . $instruction . '</p>';
|
||||
$out .= '</div>';
|
||||
}
|
||||
$out .= '</div></div>';
|
||||
return $out;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// PERSPECTIVE NOTE (VS-07 and VS-09 homeowner slot)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_perspective_note($schema, $perspective_key) {
|
||||
if ($perspective_key !== 'homeowner') return '';
|
||||
$code = $schema['_meta']['code'] ?? '';
|
||||
if (!in_array($code, ['VS-07', 'VS-09'])) return '';
|
||||
$notes = $schema['_meta']['renderer_notes'] ?? '';
|
||||
if (!$notes) return '';
|
||||
return '<div class="vs01-perspective-note alert alert-light small mb-3">'
|
||||
. vs01_h($notes) . '</div>';
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// IMMUTABLE PUBLIC RECORD
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_public_record_exists($vs_code, $association_slug) {
|
||||
// TODO: query orchestrator for existing promoted public record
|
||||
return false;
|
||||
}
|
||||
|
||||
function vs01_render_public_record_readonly($perspective, $values) {
|
||||
$out = '<div class="vs01-readonly">';
|
||||
foreach ($perspective['fields'] ?? [] as $field) {
|
||||
$id = vs01_h($field['id'] ?? '');
|
||||
$label = vs01_h($field['label'] ?? '');
|
||||
$value = vs01_h($values[$field['id'] ?? ''] ?? '—');
|
||||
$out .= '<div class="vs01-readonly-field mb-2">';
|
||||
$out .= '<span class="fw-semibold">' . $label . '</span> ';
|
||||
$out .= '<span class="text-muted">' . $value . '</span>';
|
||||
$out .= '</div>';
|
||||
}
|
||||
$out .= '</div>';
|
||||
return $out;
|
||||
}
|
||||
233
hubzilla/addon/vs01/vs01_spool.php
Normal file
233
hubzilla/addon/vs01/vs01_spool.php
Normal file
@@ -0,0 +1,233 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* VS-01 Spool Handler
|
||||
* Validates POST submissions, builds the spool envelope,
|
||||
* and POSTs to the orchestrator receiver.
|
||||
* See VS-RENDERER-SPEC.md — Spool POST Handler section.
|
||||
*/
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// POST HANDLER
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_handle_post($association_slug, $vs_code, $access) {
|
||||
$schemas = vs01_load_schemas();
|
||||
if (!isset($schemas[$vs_code])) {
|
||||
return '<div class="alert alert-danger">Unknown VS code: ' . vs01_h($vs_code) . '</div>';
|
||||
}
|
||||
|
||||
$schema = $schemas[$vs_code];
|
||||
|
||||
// Determine perspective
|
||||
$perspective_map = [
|
||||
'participant' => 'homeowner',
|
||||
'professional' => 'professional',
|
||||
'operator' => 'public_record',
|
||||
];
|
||||
$perspective_key = $perspective_map[$access] ?? null;
|
||||
if (!$perspective_key) {
|
||||
return '<div class="alert alert-danger">Invalid access state for submission.</div>';
|
||||
}
|
||||
|
||||
$perspective = $schema['perspectives'][$perspective_key] ?? null;
|
||||
if (!$perspective) {
|
||||
return '<div class="alert alert-danger">No perspective defined for this access state.</div>';
|
||||
}
|
||||
|
||||
// Collect and sanitize submitted fields
|
||||
$raw_fields = $_POST['fields'] ?? [];
|
||||
$fields = [];
|
||||
foreach ($perspective['fields'] ?? [] as $field_def) {
|
||||
$id = $field_def['id'] ?? '';
|
||||
if (!$id) continue;
|
||||
$type = $field_def['type'] ?? 'text';
|
||||
if ($type === 'multiselect') {
|
||||
$val = isset($raw_fields[$id]) && is_array($raw_fields[$id])
|
||||
? array_map('strval', $raw_fields[$id])
|
||||
: [];
|
||||
$fields[$id] = json_encode($val);
|
||||
} else {
|
||||
$fields[$id] = isset($raw_fields[$id])
|
||||
? substr(strip_tags((string) $raw_fields[$id]), 0, 8192)
|
||||
: '';
|
||||
}
|
||||
}
|
||||
|
||||
// Validate required fields
|
||||
$errors = vs01_validate_required($perspective, $fields);
|
||||
if ($errors) {
|
||||
$out = '<div class="alert alert-danger"><strong>Please complete the required fields:</strong><ul>';
|
||||
foreach ($errors as $e) {
|
||||
$out .= '<li>' . vs01_h($e) . '</li>';
|
||||
}
|
||||
$out .= '</ul></div>';
|
||||
// Re-render form with submitted values and errors
|
||||
$out .= vs01_render_vs_form_with_values($association_slug, $vs_code, $access, $fields);
|
||||
return $out;
|
||||
}
|
||||
|
||||
// Build spool envelope
|
||||
$config = vs01_load_config();
|
||||
$assoc = $config['associations'][$association_slug] ?? [];
|
||||
$envelope = vs01_build_spool_envelope(
|
||||
$vs_code,
|
||||
$perspective_key,
|
||||
$fields,
|
||||
$association_slug,
|
||||
$assoc['channel_id'] ?? ''
|
||||
);
|
||||
|
||||
// POST to orchestrator
|
||||
$result = vs01_post_to_orchestrator($envelope);
|
||||
|
||||
if ($result === true) {
|
||||
// THROWAWAY — replace with TMP review redirect or confirmation page
|
||||
return '<div class="vs01-content">
|
||||
<div class="alert alert-success">
|
||||
Your record for ' . vs01_h($vs_code) . ' has been submitted.
|
||||
<a href="' . z_root() . '/vs01/' . vs01_h($association_slug) . '">
|
||||
Return to ' . vs01_h($assoc['name'] ?? $association_slug) . '
|
||||
</a>
|
||||
</div>
|
||||
</div>';
|
||||
}
|
||||
|
||||
return '<div class="alert alert-danger">
|
||||
Submission failed. Please try again or contact the operator.
|
||||
<br><small>' . vs01_h($result) . '</small>
|
||||
</div>';
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// VALIDATION
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_validate_required($perspective, $fields) {
|
||||
$errors = [];
|
||||
foreach ($perspective['fields'] ?? [] as $field_def) {
|
||||
if (empty($field_def['required'])) continue;
|
||||
$id = $field_def['id'] ?? '';
|
||||
$value = trim($fields[$id] ?? '');
|
||||
if ($value === '' || $value === '[]') {
|
||||
$errors[] = $field_def['label'] ?? $id;
|
||||
}
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// SPOOL ENVELOPE
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_build_spool_envelope($vs_code, $perspective, $fields, $association_slug, $channel_id) {
|
||||
return [
|
||||
'addon' => 'vs01',
|
||||
'contract_version' => '1.0',
|
||||
'vs_code' => $vs_code,
|
||||
'perspective' => $perspective,
|
||||
'association_slug' => $association_slug,
|
||||
'association_channel_id' => (string) $channel_id,
|
||||
'submitted_at' => date('c'),
|
||||
'standing' => vs01_access_state($association_slug),
|
||||
'fields' => $fields,
|
||||
];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ORCHESTRATOR POST
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_post_to_orchestrator($envelope) {
|
||||
$config = vs01_load_config();
|
||||
$receiver_url = $config['receiver_url'] ?? '';
|
||||
$node_token = $config['node_token'] ?? '';
|
||||
|
||||
if (!$receiver_url) {
|
||||
logger('vs01_spool: receiver_url not configured');
|
||||
return 'Orchestrator receiver URL not configured.';
|
||||
}
|
||||
|
||||
$payload = json_encode($envelope);
|
||||
if ($payload === false) {
|
||||
logger('vs01_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('vs01_spool: curl error: ' . $curl_error);
|
||||
return 'Network error: ' . $curl_error;
|
||||
}
|
||||
|
||||
if ($http_code === 200 || $http_code === 201) {
|
||||
return true;
|
||||
}
|
||||
|
||||
logger('vs01_spool: orchestrator returned HTTP ' . $http_code . ': ' . $response);
|
||||
return 'Orchestrator error (HTTP ' . $http_code . ').';
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// RE-RENDER FORM WITH SUBMITTED VALUES
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function vs01_render_vs_form_with_values($association_slug, $vs_code, $access, $submitted_values) {
|
||||
$schemas = vs01_load_schemas();
|
||||
if (!isset($schemas[$vs_code])) return '';
|
||||
|
||||
$schema = $schemas[$vs_code];
|
||||
$config = vs01_load_config();
|
||||
$assoc = $config['associations'][$association_slug];
|
||||
|
||||
$perspective_map = [
|
||||
'participant' => 'homeowner',
|
||||
'professional' => 'professional',
|
||||
'operator' => 'public_record',
|
||||
];
|
||||
$perspective_key = $perspective_map[$access] ?? 'homeowner';
|
||||
$perspective = $schema['perspectives'][$perspective_key] ?? null;
|
||||
if (!$perspective) return '';
|
||||
|
||||
$form_url = z_root() . '/vs01/' . vs01_h($association_slug) . '/' . vs01_h($vs_code);
|
||||
$meta = $schema['_meta'];
|
||||
|
||||
$out = '<div class="vs01-content">';
|
||||
$out .= '<h3>' . vs01_h($vs_code) . ' — ' . vs01_h($meta['title'] ?? '') . '</h3>';
|
||||
$out .= vs01_render_verification_sources($meta);
|
||||
$out .= '<p class="vs01-instruction">' . vs01_h($perspective['instruction'] ?? '') . '</p>';
|
||||
$out .= '<form method="post" action="' . $form_url . '" class="vs01-form" novalidate>';
|
||||
$out .= vs01_csrf_token();
|
||||
$out .= '<input type="hidden" name="vs_code" value="' . vs01_h($vs_code) . '">';
|
||||
$out .= '<input type="hidden" name="perspective" value="' . vs01_h($perspective_key) . '">';
|
||||
|
||||
foreach ($perspective['fields'] ?? [] as $field) {
|
||||
$field_html = vs01_render_field($field, $submitted_values);
|
||||
if (!empty($field['depends_on'])) {
|
||||
$field_html = vs01_wrap_depends_on($field, $field_html);
|
||||
}
|
||||
$out .= $field_html;
|
||||
}
|
||||
|
||||
$out .= '<div class="mt-3"><button type="submit" class="btn btn-primary">Submit</button></div>';
|
||||
$out .= '</form>';
|
||||
$out .= vs01_render_vs_nav($association_slug, $vs_code);
|
||||
$out .= '</div>';
|
||||
return $out;
|
||||
}
|
||||
Reference in New Issue
Block a user