First cut of Add / Edit / Active / Answered pages

- Centralized UI between UI and Layout classes
This commit is contained in:
2024-06-22 16:58:33 -04:00
parent 0b7fa77247
commit b759c3494e
20 changed files with 528 additions and 96 deletions

View File

@@ -14,9 +14,9 @@ const MPJ_VERSION = '4.0.0-alpha1';
if (php_sapi_name() != 'cli') {
session_start();
$auth0_session = Auth::client()->getCredentials();
if (!is_null($auth0_session)) {
$_SESSION['user_id'] = $auth0_session->user['sub'];
$auth0_user = Auth::user();
if (!is_null($auth0_user)) {
$_SESSION['user_id'] = $auth0_user['sub'];
}
}
@@ -24,31 +24,14 @@ Configuration::$pdoDSN = 'sqlite:' . implode(DIRECTORY_SEPARATOR, [__DIR__, 'dat
Configuration::$mode = Mode::SQLite;
Definition::ensureTable(Table::REQUEST);
$_PATCH = [];
if ($_SERVER['REQUEST_METHOD'] ?? '' == 'PATCH') parse_str(file_get_contents('php://input'), $_PATCH);
/**
* Is this an htmx request?
*
* @return bool True if this is an htmx request, false if not
* Return a 404 and exit
*/
function is_htmx(): bool
function not_found(): never
{
return key_exists('HTTP_HX_REQUEST', $_SERVER) && !key_exists('HTTP_HX_HISTORY_RESTORE_REQUEST', $_SERVER);
}
function page_head(string $title): void
{
Layout::htmlHead($title);
echo '<body>';
if (!is_htmx()) echo '<section id=top aria-label="Top navigation">';
Layout::navBar();
echo '<main role=main>';
}
function page_foot(): void
{
echo '</main>';
if (!is_htmx()) {
echo '</section>';
Layout::htmlFoot();
}
echo '</body></html>';
http_response_code(404);
die('Not found');
}