Updated
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Name: SCN01 Vital Signs
|
||||
* Description: Public civic diagnostic — the ten structural preconditions of an HOA association.
|
||||
* Version: 0.1.0
|
||||
* Name: SCN01 Scenarios
|
||||
* Description: Public civic diagnostic — browse and submit diagnostic scenarios.
|
||||
* Version: 0.2.0
|
||||
* MinVersion: 11.0
|
||||
* MaxVersion: 12.0
|
||||
*/
|
||||
@@ -32,46 +32,92 @@ function scn01_load_pdl(&$b) {
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// HELPERS
|
||||
// ----------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function scn01_h($value) {
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// ACCESS
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
function scn01_access_state() {
|
||||
if (!local_channel()) {
|
||||
return 'public';
|
||||
}
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function scn01_access_state($association_slug = '') {
|
||||
// Operator check — association channel owner (local channel only)
|
||||
if (local_channel()) {
|
||||
$channel = App::get_channel();
|
||||
|
||||
if (local_channel() === intval($channel['channel_id'])) {
|
||||
return 'operator';
|
||||
}
|
||||
|
||||
$config = scn01_load_config();
|
||||
$gid = intval($config['corpus_builder_group_id'] ?? 0);
|
||||
|
||||
if ($gid && in_array(get_observer_hash(), group_get_members_xchan($gid))) {
|
||||
return 'participant';
|
||||
}
|
||||
|
||||
return 'denied';
|
||||
if (!$association_slug) {
|
||||
return 'public';
|
||||
}
|
||||
|
||||
function scn01_access_wall() {
|
||||
// Load association config from vs01 — the single source of truth.
|
||||
$raw = @file_get_contents('addon/vs01/config.json');
|
||||
if ($raw === false) return 'public';
|
||||
$cfg = json_decode($raw, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) return 'public';
|
||||
|
||||
$assoc = $cfg['associations'][$association_slug] ?? null;
|
||||
if (!$assoc) return 'public';
|
||||
|
||||
// get_observer_hash() works for both local channels and guest token visitors.
|
||||
$observer = get_observer_hash();
|
||||
if (!$observer) return 'public';
|
||||
|
||||
$groups = $assoc['groups'] ?? [];
|
||||
|
||||
// Direct pgrp_member query — does not call local_channel(), works for guest tokens.
|
||||
|
||||
// Corpus Builder — highest participant tier
|
||||
$cb_gid = intval($groups['corpus_builder'] ?? 0);
|
||||
if ($cb_gid) {
|
||||
$r = q("SELECT xchan FROM pgrp_member WHERE gid = %d AND xchan = '%s' LIMIT 1",
|
||||
intval($cb_gid),
|
||||
dbesc($observer)
|
||||
);
|
||||
if ($r) return 'participant';
|
||||
}
|
||||
|
||||
// SASE Participant
|
||||
$sase_gid = intval($groups['sase_participant'] ?? 0);
|
||||
if ($sase_gid) {
|
||||
$r = q("SELECT xchan FROM pgrp_member WHERE gid = %d AND xchan = '%s' LIMIT 1",
|
||||
intval($sase_gid),
|
||||
dbesc($observer)
|
||||
);
|
||||
if ($r) return 'participant';
|
||||
}
|
||||
|
||||
// Civic Professional
|
||||
$prof_gid = intval($groups['civic_professional'] ?? 0);
|
||||
if ($prof_gid) {
|
||||
$r = q("SELECT xchan FROM pgrp_member WHERE gid = %d AND xchan = '%s' LIMIT 1",
|
||||
intval($prof_gid),
|
||||
dbesc($observer)
|
||||
);
|
||||
if ($r) return 'participant';
|
||||
}
|
||||
|
||||
return 'public';
|
||||
}
|
||||
|
||||
function scn01_access_wall($association_slug = '') {
|
||||
$raw = @file_get_contents('addon/vs01/config.json');
|
||||
$cfg = $raw ? json_decode($raw, true) : [];
|
||||
$assoc = $association_slug ? ($cfg['associations'][$association_slug] ?? null) : null;
|
||||
$name = $assoc ? scn01_h($assoc['name']) : 'this association';
|
||||
return '
|
||||
<div class="scn01-content">
|
||||
<div class="alert alert-info" role="alert">
|
||||
<strong>HOA_MEMBER standing required to submit.</strong>
|
||||
Vital Signs are public and readable by anyone.
|
||||
To submit a Vital Signs record for your association, you must complete the SASE process.
|
||||
<strong>HOA_MEMBER standing required to submit a record for ' . $name . '.</strong>
|
||||
Scenarios are public and readable by anyone.
|
||||
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.
|
||||
@@ -80,9 +126,9 @@ function scn01_access_wall() {
|
||||
';
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// CONTENT
|
||||
// ----------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function scn01_content() {
|
||||
if (function_exists('head_add_css')) {
|
||||
@@ -92,23 +138,25 @@ function scn01_content() {
|
||||
head_add_js('/addon/scn01/view/js/scn01.js');
|
||||
}
|
||||
|
||||
$access = scn01_access_state();
|
||||
$association_slug = argv(1) ?? '';
|
||||
|
||||
$access = scn01_access_state($association_slug);
|
||||
|
||||
// scn01 is public — access wall only gates submission, not reading
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
if ($access === 'public' || $access === 'denied') {
|
||||
return scn01_access_wall();
|
||||
if ($access === 'public') {
|
||||
return scn01_access_wall($association_slug);
|
||||
}
|
||||
// TODO: handle POST submission
|
||||
return scn01_access_wall();
|
||||
return scn01_access_wall($association_slug);
|
||||
}
|
||||
|
||||
return scn01_render_main($access);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// RENDER
|
||||
// ----------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function scn01_render_main($access) {
|
||||
$out = '<div class="scn01-content">';
|
||||
@@ -117,7 +165,7 @@ function scn01_render_main($access) {
|
||||
$out .= '<p class="text-muted">Browse diagnostic scenarios. When you find one close to your situation, submit your account in your own words.</p>';
|
||||
$out .= '</div>';
|
||||
|
||||
// TODO: render the ten Vital Signs
|
||||
// TODO: render scenarios
|
||||
|
||||
$out .= '<div class="scn01-placeholder text-muted fst-italic">Content forthcoming.</div>';
|
||||
$out .= '</div>';
|
||||
@@ -125,9 +173,9 @@ function scn01_render_main($access) {
|
||||
return $out;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// CONFIG
|
||||
// ----------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function scn01_load_config() {
|
||||
$path = 'addon/scn01/config.json';
|
||||
@@ -137,9 +185,9 @@ function scn01_load_config() {
|
||||
return (json_last_error() === JSON_ERROR_NONE) ? $data : [];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
// CSRF
|
||||
// ----------------------------------------------------------------------------
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function scn01_csrf_token() {
|
||||
if (empty($_SESSION['scn01_csrf'])) {
|
||||
|
||||
Reference in New Issue
Block a user