mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
Extract FormBootstrap helper to eliminate bootstrap duplication across add/edit form pages
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
<?php
|
||||
require_once __DIR__ . "/../../bootstrap.php";
|
||||
require_once __DIR__ . '/../../bootstrap.php';
|
||||
require_once __DIR__ . '/../../src/AdminAuth.php';
|
||||
require_once __DIR__ . '/../../src/Form/FormBootstrap.php';
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
if (empty($_SESSION["csrf_token"])) {
|
||||
$_SESSION["csrf_token"] = bin2hex(random_bytes(32));
|
||||
if (empty($_SESSION['csrf_token'])) {
|
||||
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
|
||||
}
|
||||
|
||||
$pageTitle = "Ajouter un TFE";
|
||||
$pageTitle = 'Ajouter un TFE';
|
||||
|
||||
require_once __DIR__ . '/../../src/Controllers/ThesisCreateController.php';
|
||||
|
||||
@@ -19,44 +20,32 @@ try {
|
||||
die('Erreur lors du chargement du formulaire.');
|
||||
}
|
||||
|
||||
$formData = $_SESSION['form_data'] ?? [];
|
||||
// Form data (flash repopulation)
|
||||
$formData = $_SESSION['form_data'] ?? [];
|
||||
unset($_SESSION['form_data']);
|
||||
$autofocusField = App::consumeAutofocus();
|
||||
|
||||
// Site settings for licence / access type toggles
|
||||
$siteSettings = Database::getInstance()->getAllSettings();
|
||||
// Form help blocks
|
||||
$helpBlocks = Database::getInstance()->getAllFormHelpBlocks();
|
||||
$helpFn = fn(string $key) => empty($helpBlocks[$key]['enabled']) ? '' : ($helpBlocks[$key]['content'] ?? '');
|
||||
$helpBlocks = Database::getInstance()->getAllFormHelpBlocks();
|
||||
|
||||
function withAutofocus(string $fieldName, array $attrs = []): array {
|
||||
global $autofocusField;
|
||||
if ($autofocusField === $fieldName) {
|
||||
$attrs['autofocus'] = true;
|
||||
}
|
||||
return $attrs;
|
||||
}
|
||||
// Shared form variables from the bootstrap helper
|
||||
extract(FormBootstrap::adminFormVariables(
|
||||
mode: 'add',
|
||||
formAction: 'actions/formulaire.php',
|
||||
hiddenFields: '<input type="hidden" name="csrf_token" value="' . htmlspecialchars($_SESSION['csrf_token']) . '">',
|
||||
formData: $formData,
|
||||
siteSettings: $siteSettings,
|
||||
helpBlocks: $helpBlocks,
|
||||
options: [
|
||||
'existingWebsiteUrl' => $formData['website_url'] ?? '',
|
||||
'existingWebsiteLabel' => $formData['website_label'] ?? '',
|
||||
'checkedFormats' => $formData['formats'] ?? [],
|
||||
],
|
||||
));
|
||||
|
||||
function old($key, $default = "") {
|
||||
global $formData;
|
||||
if (!isset($formData[$key])) return $default;
|
||||
if (is_array($formData[$key])) return $formData[$key]; // Return raw array for callers that handle it
|
||||
if ($formData[$key] === null) return $default;
|
||||
return htmlspecialchars((string)$formData[$key]);
|
||||
}
|
||||
|
||||
function wasSelected($key, $value) {
|
||||
global $formData;
|
||||
if (!isset($formData[$key])) return false;
|
||||
if (is_array($formData[$key])) return in_array($value, $formData[$key]);
|
||||
return $formData[$key] == $value;
|
||||
}
|
||||
|
||||
$isAdmin = true;
|
||||
$bodyClass = 'admin-body';
|
||||
$extraCss = ['/assets/css/form-base.css'];
|
||||
$extraCssAdmin = ['/assets/css/form-admin.css', '/assets/css/filepond.min.css', '/assets/css/filepond-plugin-image-preview.min.css'];
|
||||
$extraJs = ['/assets/js/vendor/filepond.min.js', '/assets/js/vendor/filepond-plugin-file-validate-type.min.js', '/assets/js/vendor/filepond-plugin-file-validate-size.min.js', '/assets/js/vendor/filepond-plugin-image-preview.min.js', '/assets/js/vendor/filepond-plugin-image-exif-orientation.min.js', '/assets/js/app/file-upload-filepond.js', '/assets/js/app/beforeunload-guard.js', '/assets/js/app/pill-search.js', '/assets/js/app/jury-autocomplete.js'];
|
||||
// Asset arrays and page chrome
|
||||
$isAdmin = true;
|
||||
$bodyClass = 'admin-body';
|
||||
extract(FormBootstrap::adminAssetArrays());
|
||||
require_once APP_ROOT . '/templates/head.php';
|
||||
include APP_ROOT . '/templates/header.php';
|
||||
include APP_ROOT . '/templates/admin/add.php';
|
||||
|
||||
Reference in New Issue
Block a user