Files
xamxam/app/templates/admin/edit.php
Pontoporeia bdd95341b0 Extract shared TFE form partial — single source of truth for add/edit/partage
Created templates/partials/form/form.php as the unified form template driven by
$mode ('add'|'edit'|'partage') and boolean flags for optional sections.

The three calling templates (templates/admin/add.php, templates/admin/edit.php,
partage/index.php renderShareLinkForm) now only set variables then include the
shared partial. ~200 lines of duplicated fieldset HTML eliminated.
2026-05-07 23:39:41 +02:00

111 lines
4.4 KiB
PHP

<main id="main-content">
<h1>Modifier un TFE</h1>
<?php
// ── Build a unified old() callable for the entire edit form ────────────────
$editFormData = array_merge($formData ?? [], [
'titre' => $thesis['title'],
'subtitle' => $thesis['subtitle'] ?? '',
'auteurice' => $thesis['authors'] ?? '',
'mail' => $currentAuthorEmail ?? '',
'synopsis' => $thesis['synopsis'] ?? '',
'tag' => $thesis['keywords'] ?? '',
'année' => $thesis['year'],
'orientation' => $thesis['orientation'],
'ap' => $thesis['ap_program'],
'finality' => $thesis['finality_type'],
'duration_pages' => $currentRaw['duration_pages'] ?? '',
'duration_minutes' => $currentRaw['duration_minutes'] ?? '',
'lien' => $thesis['baiu_link'] ?? '',
'contact_public' => $currentAuthorShowContact ?? false,
]);
$oldFn = fn(string $key, string $default = '') =>
isset($editFormData[$key]) && !is_array($editFormData[$key])
? htmlspecialchars((string)$editFormData[$key]) : $default;
$withAutofocusFn = function (string $field, array $attrs = []) use ($autofocusField) {
if ($autofocusField === $field) $attrs['autofocus'] = true;
return $attrs;
};
// ── Shared form variables ──────────────────────────────────────────────────
$mode = 'edit';
$formAction = '/admin/actions/edit.php';
$hiddenFields = '<input type="hidden" name="csrf_token" value="' . htmlspecialchars($_SESSION['csrf_token']) . '">'
. '<input type="hidden" name="thesis_id" value="' . $thesisId . '">';
$synopsisExtra = '';
$formData = $editFormData;
// Jury data
$juryPromoteur = null;
$juryPromoteurUlb = null;
$lecteursInternes = [];
$lecteursExternes = [];
$juryPresident = null;
foreach ($jury as $jm) {
if ($jm['role'] === 'president') {
$juryPresident = $jm['name'];
} elseif ($jm['role'] === 'promoteur') {
if (($jm['is_ulb'] ?? 0) == 1) {
$juryPromoteurUlb = $jm['name'];
} else {
$juryPromoteur = $jm['name'];
}
} elseif ($jm['role'] === 'lecteur') {
if (($jm['is_external'] ?? 0) == 1) {
$lecteursExternes[] = $jm;
} else {
$lecteursInternes[] = $jm;
}
}
}
$showPresident = true;
$showPromoteurUlb = true;
$promoteurUlbConditional = false;
// Licence / access — always all enabled for admin
$libreEnabled = true;
$interneEnabled = true;
$interditEnabled = true;
$generalitiesHtml = $helpFn('fieldset_generalites');
$defaultAccessTypeId = $currentAccessTypeId ?? 2;
$formData['access_type_id'] = $currentAccessTypeId;
$formData['license_id'] = $currentLicenseId;
$formData['license_custom'] = $currentRaw['license_custom'] ?? '';
$formData['cc2r'] = $currentRaw['cc4r'] ?? false;
// Optional sections
$showContact = true;
$showContextNote = true;
$showBackoffice = true;
$showPublish = true;
// Files: edit mode
$filesMode = 'edit';
$currentCover = $currentCover ?? null;
$currentFiles = $currentFiles ?? [];
$currentBannerPath = $thesis['banner_path'] ?? null;
$currentContextNote = $currentContextNote ?? null;
// Website URL from existing files
$existingWebsiteUrl = '';
$existingWebsiteLabel = '';
foreach ($currentFiles as $f) {
if ($f['file_type'] === 'website') {
$existingWebsiteUrl = $f['file_path'] ?? '';
$existingWebsiteLabel = $f['display_label'] ?? '';
break;
}
}
// Formats — either from flash repopulation or current thesis data
$checkedFormats = $formData['formats'] ?? $currentFormats ?? [];
// Populate formData.formats for checkbox-list partial
$formData['formats'] = $checkedFormats;
$checkedFormatsForSiteWeb = $checkedFormats;
include APP_ROOT . '/templates/partials/form/form.php';
?>
</main>