Add website-type TFE support: URLs stored as thesis_files rows, HTMX-toggle on Site web format

This commit is contained in:
Pontoporeia
2026-05-07 21:24:46 +02:00
parent 9dc7ea98f2
commit ac0008df6c
10 changed files with 399 additions and 39 deletions

View File

@@ -204,6 +204,11 @@
}
/* ── Jury fieldset ──────────────────────────────────────────────────────── */
/* ── Website-URL inline fieldset (shown/hidden via HTMX) ────────────────── */
/* The fieldset is shown/hidden via outerHTML swap — no CSS needed */
/* ── Jury fieldset (continued) ──────────────────────────────────────────── */
.admin-body fieldset fieldset.admin-jury-lecteurs,
.student-body fieldset fieldset.admin-jury-lecteurs {
border: none;

View File

@@ -0,0 +1,66 @@
<?php
/**
* format-website-fragment.php (partage)
*
* HTMX fragment for the student share form: returns the website URL input fields
* if "Site web" is among the currently selected format checkboxes.
*
* Regular PHP include inside partage/index.php routing — no separate bootstrap.
* The parent partage/index.php already handles boot + session.
*
* Expected POST:
* - formats[]: array of selected format_type IDs
* - website_url: current website_url value (for repopulation)
* - website_label: current website_label value (for repopulation)
*/
// Find the "Site web" format ID
$stmt = Database::getInstance()->getConnection()->prepare(
'SELECT id FROM format_types WHERE name = ? LIMIT 1'
);
$stmt->execute(['Site web']);
$websiteFormatId = $stmt->fetchColumn();
if (!$websiteFormatId) {
echo '';
exit;
}
$selectedFormats = isset($_POST['formats']) && is_array($_POST['formats'])
? array_map('intval', $_POST['formats'])
: [];
if (!in_array((int)$websiteFormatId, $selectedFormats, true)) {
echo '';
exit;
}
$websiteUrl = htmlspecialchars($_POST['website_url'] ?? '');
$websiteLabel = htmlspecialchars($_POST['website_label'] ?? '');
?>
<fieldset id="website-url-fieldset">
<legend>Site web</legend>
<div class="admin-form-group">
<label for="website_url">URL du site :</label>
<div class="admin-file-input">
<input type="url"
id="website_url"
name="website_url"
value="<?= $websiteUrl ?>"
placeholder="https://mon-tfe.erg.be">
<small>Si le TFE est un site web, entrez son URL ici. Il sera affiché comme un site embarqué sur la page du TFE.</small>
</div>
</div>
<div class="admin-form-group">
<label for="website_label">Légende :</label>
<input type="text"
id="website_label"
name="website_label"
value="<?= $websiteLabel ?>"
placeholder="Description du site (optionnel)"
class="admin-file-label-input"
style="max-width:400px;">
</div>
</fieldset>

View File

@@ -21,6 +21,13 @@ $parts = explode('/', $path);
$slug = $parts[0] ?? '';
$action = $parts[1] ?? '';
// Special route: /partage/format-website-fragment (HTMX fragment, no auth needed)
if ($slug === 'format-website-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once __DIR__ . '/format-website-fragment.php';
exit;
}
// Special route: /partage/recapitulatif?id=N
if ($slug === 'recapitulatif' || $slug === 'recapitulatif.php') {
App::boot();
@@ -265,6 +272,7 @@ function renderShareLinkForm(string $slug, array $link): void
<link rel="stylesheet" href="<?= App::assetV('/assets/css/form.css') ?>">
<script src="<?= App::assetV('/assets/js/sortable.min.js') ?>" defer></script>
<script src="<?= App::assetV('/assets/js/file-upload-queue.js') ?>" defer></script>
<script src="<?= App::assetV('/assets/js/htmx.min.js') ?>" defer></script>
</head>
<body class="student-body">
<main id="main-content">
@@ -319,12 +327,6 @@ function renderShareLinkForm(string $slug, array $link): void
<?php $name = 'language_autre'; $label = 'Autre(s) langue(s) :'; $value = old($formData, 'language_autre'); $hint = 'Si votre TFE contient une langue absente de la liste, précisez-la ici.'; include APP_ROOT . '/templates/partials/form/text-field.php'; ?>
</fieldset>
<!-- ═══════════════════ Format(s) ═══════════════════ -->
<fieldset>
<legend>Format(s)</legend>
<?php $name = 'formats'; $label = 'Format(s) du TFE :'; $options = $formatTypes; $checked = $formData['formats'] ?? []; $required = true; include APP_ROOT . '/templates/partials/form/checkbox-list.php'; ?>
</fieldset>
<!-- ═══════════════════ Mots-clés ═══════════════════ -->
<fieldset>
<legend>Mots-clés</legend>
@@ -368,6 +370,19 @@ function renderShareLinkForm(string $slug, array $link): void
require APP_ROOT . '/templates/partials/form/jury-fieldset.php';
?>
<!-- ═══════════════════ Format(s) ═══════════════════ -->
<fieldset>
<legend>Format(s)</legend>
<?php
$name = 'formats'; $label = 'Format(s) du TFE :'; $options = $formatTypes; $checked = $formData['formats'] ?? []; $required = true;
$hxPost = '/partage/format-website-fragment';
$hxTarget = '#website-url-fieldset';
// Capture before include unsets it
$_checkedFormatsForSiteWeb = $checked;
include APP_ROOT . '/templates/partials/form/checkbox-list.php';
?>
</fieldset>
<!-- ═══════════════════ Fichiers ═══════════════════ -->
<?php
$helpContent = $helpFn('fieldset_files');
@@ -375,6 +390,43 @@ function renderShareLinkForm(string $slug, array $link): void
include APP_ROOT . '/templates/partials/form/fieldset-files.php';
?>
<!-- Website URL fieldset — shown/hidden via HTMX when "Site web" checked -->
<fieldset id="website-url-fieldset" style="display:none">
<legend>Site web</legend>
<div class="admin-form-group">
<label for="website_url">URL du site :</label>
<div class="admin-file-input">
<input type="url"
id="website_url"
name="website_url"
value="<?= htmlspecialchars($formData['website_url'] ?? '') ?>"
placeholder="https://mon-tfe.erg.be">
<small>Si le TFE est un site web, entrez son URL ici. Il sera affiché comme un site embarqué sur la page du TFE.</small>
</div>
</div>
<div class="admin-form-group">
<label for="website_label">Légende :</label>
<input type="text"
id="website_label"
name="website_label"
value="<?= htmlspecialchars($formData['website_label'] ?? '') ?>"
placeholder="Description du site (optionnel)"
class="admin-file-label-input"
style="max-width:400px;">
</div>
</fieldset>
<?php
// Server-side: show if Site web already checked (e.g. on error redirect)
$_stmt = Database::getInstance()->getConnection()->prepare('SELECT id FROM format_types WHERE name = ? LIMIT 1');
$_stmt->execute(['Site web']);
$_siteWebId = $_stmt->fetchColumn();
if ($_siteWebId && in_array((string)$_siteWebId, array_map('strval', $_checkedFormatsForSiteWeb), true)) {
echo '<script>document.getElementById("website-url-fieldset").style.display=""</script>';
}
?>
<!-- ═══════════════════ Métadonnées complémentaires ═══════════════════ -->
<?php
$oldFn = $shareOldFn;