Updated
This commit is contained in:
@@ -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';
|
||||
}
|
||||
|
||||
return 'public';
|
||||
}
|
||||
|
||||
function vs01_access_wall() {
|
||||
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
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if ($access === 'public' || $access === 'denied') {
|
||||
return vs01_access_wall();
|
||||
}
|
||||
// TODO: handle POST submission
|
||||
return vs01_access_wall();
|
||||
// Index — list registered associations
|
||||
if (!$association_slug) {
|
||||
return vs01_render_index();
|
||||
}
|
||||
|
||||
return vs01_render_main($access);
|
||||
$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') {
|
||||
return vs01_access_wall($association_slug);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
// 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
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user