Refactor HTMX fragment architecture: DRY split into auth endpoints + shared templates

- Created templates/partials/form/_licence.php (shared HTML, no auth logic)
- Created templates/partials/form/_format-website.php (shared HTML, no auth logic)
- Created src/FragmentRenderer.php helper for clean fragment rendering
- Created public/{admin,partage}/fragments/ subdirectories
- Created thin fragment endpoint files: auth guard + data fetch + render template
- Updated all hx-post references in templates to new fragments/ paths
- Updated partage/index.php routing for new fragments subdirectory
- Kept old fragment files as thin delegates for backward compat
- Updated nginx config: added PHP handler in /partage/ location block
This commit is contained in:
Pontoporeia
2026-05-12 15:01:17 +02:00
parent 2632730fa0
commit da153fc604
38 changed files with 503 additions and 527 deletions

View File

@@ -1,17 +1,6 @@
<?php
/**
* fichiers-fragment.php (admin)
*
* Admin-gated HTMX fragment: returns the combined Format(s) + Fichiers block
* for the admin add/edit forms. Wraps the shared logic in fichiers-fragment.php
* after enforcing authentication.
* Admin fragment: Format(s) + Fichiers block (HTMX partial).
* @deprecated Use /admin/fragments/fichiers.php instead.
*/
require_once __DIR__ . '/../../bootstrap.php';
require_once __DIR__ . '/../../src/AdminAuth.php';
App::boot();
AdminAuth::requireLogin();
$_POST['admin_mode'] = '1';
require_once APP_ROOT . '/templates/partials/form/fichiers-fragment.php';
require_once __DIR__ . '/fragments/fichiers.php';

View File

@@ -1,57 +1,6 @@
<?php
/**
* format-website-fragment.php (admin)
*
* Admin-gated HTMX fragment: returns the Site web URL fieldset for the
* admin edit form when "Site web" is among the selected format checkboxes.
* Uses id="edit-website-url-fieldset" to avoid collision with the partage form.
* Admin fragment: Site web format fieldset (HTMX partial).
* @deprecated Use /admin/fragments/format-website.php instead.
*/
require_once __DIR__ . '/../../bootstrap.php';
require_once __DIR__ . '/../../src/AdminAuth.php';
App::boot();
AdminAuth::requireLogin();
$db = Database::getInstance()->getConnection();
$stmt = $db->prepare('SELECT id FROM format_types WHERE name = ? LIMIT 1');
$stmt->execute(['Site web']);
$websiteFormatId = $stmt->fetchColumn();
if (!$websiteFormatId) {
echo '<fieldset id="edit-website-url-fieldset" style="display:none"></fieldset>';
exit;
}
$selectedFormats = isset($_POST['formats']) && is_array($_POST['formats'])
? array_map('intval', $_POST['formats'])
: [];
if (!in_array((int)$websiteFormatId, $selectedFormats, true)) {
echo '<fieldset id="edit-website-url-fieldset" style="display:none"></fieldset>';
exit;
}
$websiteUrl = htmlspecialchars($_POST['website_url'] ?? '');
$websiteLabel = htmlspecialchars($_POST['website_label'] ?? '');
?>
<fieldset id="edit-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>
require_once __DIR__ . '/fragments/format-website.php';

View File

@@ -0,0 +1,13 @@
<?php
/**
* Admin fragment: Format(s) + Fichiers block (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
require_once __DIR__ . '/../../../src/AdminAuth.php';
App::boot();
AdminAuth::requireLogin();
$_POST['admin_mode'] = '1';
require_once APP_ROOT . '/templates/partials/form/fichiers-fragment.php';

View File

@@ -0,0 +1,29 @@
<?php
/**
* Admin fragment: Site web format fieldset (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
require_once __DIR__ . '/../../../src/AdminAuth.php';
App::boot();
AdminAuth::requireLogin();
require_once APP_ROOT . '/src/FragmentRenderer.php';
$db = Database::getInstance()->getConnection();
$stmt = $db->prepare('SELECT id FROM format_types WHERE name = ? LIMIT 1');
$stmt->execute(['Site web']);
$websiteFormatId = $stmt->fetchColumn();
$selectedFormats = isset($_POST['formats']) && is_array($_POST['formats'])
? array_map('intval', $_POST['formats'])
: [];
FragmentRenderer::render('form/_format-website', [
'fieldsetId' => 'edit-website-url-fieldset',
'selectedFormats' => $selectedFormats,
'websiteFormatId' => $websiteFormatId,
'websiteUrl' => $_POST['website_url'] ?? '',
'websiteLabel' => $_POST['website_label'] ?? '',
]);

View File

@@ -0,0 +1,9 @@
<?php
/**
* Admin fragment: language-autre asterisk toggle (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
require_once __DIR__ . '/../../../src/AdminAuth.php';
AdminAuth::requireLogin();
require_once APP_ROOT . '/public/partage/language-autre-fragment.php';

View File

@@ -0,0 +1,10 @@
<?php
/**
* Admin fragment: language search (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
require_once __DIR__ . '/../../../src/AdminAuth.php';
AdminAuth::requireLogin();
App::boot();
require_once APP_ROOT . '/public/partage/language-search-fragment.php';

View File

@@ -0,0 +1,23 @@
<?php
/**
* Admin fragment: licence section (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
require_once __DIR__ . '/../../../src/AdminAuth.php';
AdminAuth::requireLogin();
require_once APP_ROOT . '/src/Database.php';
require_once APP_ROOT . '/src/FragmentRenderer.php';
$licenseTypes = Database::getInstance()->getAllLicenseTypes();
FragmentRenderer::render('form/_licence', [
'adminMode' => true,
'accessTypeId' => $_POST['access_type_id'] ?? '',
'licenseId' => $_POST['license_id'] ?? '',
'licenseCustom' => $_POST['license_custom'] ?? '',
'cc2r' => !empty($_POST['cc2r']),
'wantLicense' => !empty($_POST['want_license']),
'hxPost' => '/admin/fragments/licence.php',
'licenseTypes' => $licenseTypes,
]);

View File

@@ -0,0 +1,10 @@
<?php
/**
* Admin fragment: tag search (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
require_once __DIR__ . '/../../../src/AdminAuth.php';
AdminAuth::requireLogin();
App::boot();
require_once APP_ROOT . '/public/partage/tag-search-fragment.php';

View File

@@ -0,0 +1,9 @@
<?php
/**
* Admin fragment: file validation (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
require_once __DIR__ . '/../../../src/AdminAuth.php';
AdminAuth::requireLogin();
require_once APP_ROOT . '/src/Controllers/validate-file-fragment-shared.php';

View File

@@ -1,17 +1,6 @@
<?php
/**
* language-autre-fragment.php (admin)
*
* HTMX fragment: returns the "Autre(s) langue(s)" input row.
* Called from the shared form partial when a language checkbox changes.
*
* Expected POST:
* languages[] — selected language IDs (may be absent)
* language_autre — current free-text value (for repopulation)
* Admin fragment: language-autre asterisk toggle (HTMX partial).
* @deprecated Use /admin/fragments/language-autre.php instead.
*/
require_once __DIR__ . '/../../bootstrap.php';
require_once __DIR__ . '/../../src/AdminAuth.php';
AdminAuth::requireLogin();
require_once APP_ROOT . '/public/partage/language-autre-fragment.php';
require_once __DIR__ . '/fragments/language-autre.php';

View File

@@ -1,14 +1,6 @@
<?php
/**
* language-search-fragment.php (admin)
*
* HTMX fragment: returns matching language suggestions for the
* "Autre(s) langue(s)" interactive search input. Admin-auth gated wrapper.
* Admin fragment: language search (HTMX partial).
* @deprecated Use /admin/fragments/language-search.php instead.
*/
require_once __DIR__ . '/../../bootstrap.php';
require_once __DIR__ . '/../../src/AdminAuth.php';
AdminAuth::requireLogin();
App::boot();
require_once APP_ROOT . '/public/partage/language-search-fragment.php';
require_once __DIR__ . '/fragments/language-search.php';

View File

@@ -1,109 +1,6 @@
<?php
/**
* HTMX fragment (admin): renders the licence section with conditional options.
*
* POST: access_type_id, license_id, license_custom, cc2r, want_license
*
* Libre (1): CC2r checkbox + licence select/custom (at least one required)
* Interne (2): opt-in "Je souhaite appliquer une licence" → CC2r + licence select/custom
* Interdit (3): no licence options
* Admin fragment: licence section (HTMX partial).
* @deprecated Use /admin/fragments/licence.php instead.
*/
require_once __DIR__ . '/../../bootstrap.php';
require_once __DIR__ . '/../../src/AdminAuth.php';
AdminAuth::requireLogin();
$accessTypeId = $_POST['access_type_id'] ?? '';
$licenseId = $_POST['license_id'] ?? '';
$licenseCustom = $_POST['license_custom'] ?? '';
$cc2r = !empty($_POST['cc2r']);
$wantLicense = !empty($_POST['want_license']);
require_once APP_ROOT . '/src/Database.php';
$db = Database::getInstance();
$licenseTypes = $db->getAllLicenseTypes();
?>
<div class="licence-license-choice">
<?php if ($accessTypeId === '1'): ?>
<fieldset class="licence-options-fieldset">
<legend>Options de licence</legend>
<p class="licence-note">J'autorise que mon TFE soit disponible en libre accès. Je suis conscient·e des responsabilités légales.</p>
<div class="admin-form-group">
<label class="admin-checkbox-label">
<input type="checkbox" name="cc2r" value="1"
<?= $cc2r ? 'checked' : '' ?>>
J'accepte les conditions collectives de réutilisation (CC2r)
</label>
<small><a href="https://cc2r.net/" target="_blank" rel="noopener">En savoir plus sur la CC2r ↗</a></small>
</div>
<div class="licence-or-separator"><span>et / ou</span></div>
<?php
$name = 'license_id'; $label = 'Licence :'; $options = $licenseTypes;
$selected = $licenseId; $placeholder = '— Sélectionner —'; $required = false;
include APP_ROOT . '/templates/partials/form/select-field.php';
?>
<?php
$name = 'license_custom'; $label = 'Ou précisez une autre licence :';
$value = htmlspecialchars($licenseCustom);
$hint = 'Ex: CC BY-NC 4.0, Tous droits réservés…';
include APP_ROOT . '/templates/partials/form/text-field.php';
?>
</fieldset>
<?php elseif ($accessTypeId === '2'): ?>
<fieldset class="licence-options-fieldset">
<legend>Options de licence</legend>
<p class="licence-note">Mon TFE est accessible sur place et sur la plateforme xamxam par la communauté erg. J'autorise une (ré-)utilisation dans un contexte académique au sein de l'erg.</p>
<div class="admin-form-group">
<label class="admin-checkbox-label">
<input type="checkbox" name="want_license" value="1"
hx-post="/admin/licence-fragment.php"
hx-target=".licence-license-choice"
hx-swap="outerHTML"
hx-include="closest fieldset"
<?= $wantLicense ? 'checked' : '' ?>>
<strong>Je souhaite appliquer une licence sur mon TFE</strong>
</label>
<small>Par défaut, aucune licence spécifique n'est appliquée. Cochez pour en choisir une.</small>
</div>
<?php if ($wantLicense): ?>
<div class="admin-form-group">
<label class="admin-checkbox-label">
<input type="checkbox" name="cc2r" value="1"
<?= $cc2r ? 'checked' : '' ?>>
J'accepte les conditions collectives de réutilisation (CC2r)
</label>
<small><a href="https://cc2r.net/" target="_blank" rel="noopener">En savoir plus sur la CC2r ↗</a></small>
</div>
<?php
$name = 'license_id'; $label = 'Licence :'; $options = $licenseTypes;
$selected = $licenseId; $placeholder = '— Sélectionner —'; $required = false;
include APP_ROOT . '/templates/partials/form/select-field.php';
?>
<?php
$name = 'license_custom'; $label = 'Ou précisez une autre licence :';
$value = htmlspecialchars($licenseCustom);
$hint = 'Ex: CC BY-NC 4.0, Tous droits réservés…';
include APP_ROOT . '/templates/partials/form/text-field.php';
?>
<p class="licence-note"><em>Je suis conscient·e des obligations légales venant avec la licence choisie et acquiesce avoir lu la documentation prévue à cet effet par l'erg, ainsi qu'avoir discuté des enjeux des licences avec l'équipe pédagogique.</em></p>
<?php endif; ?>
</fieldset>
<?php elseif ($accessTypeId === '3'): ?>
<fieldset class="licence-options-fieldset">
<legend>Options de licence</legend>
<p class="licence-note">Mon TFE n'est pas disponible en physique ni sur le site. Une note descriptive est visible publiquement.</p>
<p class="licence-note"><em>Aucune licence n'est applicable.</em></p>
</fieldset>
<?php endif; ?>
</div>
require_once __DIR__ . '/fragments/licence.php';

View File

@@ -1,14 +1,6 @@
<?php
/**
* tag-search-fragment.php (admin)
*
* HTMX fragment: returns matching tag suggestions for the mot-clé
* interactive search input. Admin-auth gated wrapper.
* Admin fragment: tag search (HTMX partial).
* @deprecated Use /admin/fragments/tag-search.php instead.
*/
require_once __DIR__ . '/../../bootstrap.php';
require_once __DIR__ . '/../../src/AdminAuth.php';
AdminAuth::requireLogin();
App::boot();
require_once APP_ROOT . '/public/partage/tag-search-fragment.php';
require_once __DIR__ . '/fragments/tag-search.php';

View File

@@ -1,12 +1,6 @@
<?php
/**
* validate-file-fragment.php (admin)
*
* Admin-gated HTMX fragment: validates uploaded file MIME type and size.
* Wraps the shared validation logic.
* Admin fragment: file validation (HTMX partial).
* @deprecated Use /admin/fragments/validate-file.php instead.
*/
require_once __DIR__ . '/../../bootstrap.php';
require_once __DIR__ . '/../../src/AdminAuth.php';
AdminAuth::requireLogin();
require_once APP_ROOT . '/src/Controllers/validate-file-fragment-shared.php';
require_once __DIR__ . '/fragments/validate-file.php';

View File

@@ -1,66 +1,6 @@
<?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)
* Partagé fragment: Site web format fieldset (HTMX partial).
* @deprecated Use /partage/fragments/format-website.php instead.
*/
// 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>
require_once __DIR__ . '/fragments/format-website.php';

View File

@@ -0,0 +1,8 @@
<?php
/**
* Partagé fragment: Format(s) + Fichiers block (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
App::boot();
require_once APP_ROOT . '/templates/partials/form/fichiers-fragment.php';

View File

@@ -0,0 +1,26 @@
<?php
/**
* Partagé fragment: Site web format fieldset (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
App::boot();
require_once APP_ROOT . '/src/FragmentRenderer.php';
$db = Database::getInstance()->getConnection();
$stmt = $db->prepare('SELECT id FROM format_types WHERE name = ? LIMIT 1');
$stmt->execute(['Site web']);
$websiteFormatId = $stmt->fetchColumn();
$selectedFormats = isset($_POST['formats']) && is_array($_POST['formats'])
? array_map('intval', $_POST['formats'])
: [];
FragmentRenderer::render('form/_format-website', [
'fieldsetId' => 'website-url-fieldset',
'selectedFormats' => $selectedFormats,
'websiteFormatId' => $websiteFormatId,
'websiteUrl' => $_POST['website_url'] ?? '',
'websiteLabel' => $_POST['website_label'] ?? '',
]);

View File

@@ -0,0 +1,8 @@
<?php
/**
* Partagé fragment: language-autre asterisk toggle (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
App::boot();
require_once APP_ROOT . '/public/partage/language-autre-fragment.php';

View File

@@ -0,0 +1,8 @@
<?php
/**
* Partagé fragment: language search (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
App::boot();
require_once APP_ROOT . '/public/partage/language-search-fragment.php';

View File

@@ -0,0 +1,22 @@
<?php
/**
* Partagé fragment: licence section (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
App::boot();
require_once APP_ROOT . '/src/Database.php';
require_once APP_ROOT . '/src/FragmentRenderer.php';
$licenseTypes = Database::getInstance()->getAllLicenseTypes();
FragmentRenderer::render('form/_licence', [
'adminMode' => false,
'accessTypeId' => $_POST['access_type_id'] ?? '',
'licenseId' => $_POST['license_id'] ?? '',
'licenseCustom' => $_POST['license_custom'] ?? '',
'cc2r' => !empty($_POST['cc2r']),
'wantLicense' => !empty($_POST['want_license']),
'hxPost' => '/partage/fragments/licence.php',
'licenseTypes' => $licenseTypes,
]);

View File

@@ -0,0 +1,8 @@
<?php
/**
* Partagé fragment: tag search (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
App::boot();
require_once APP_ROOT . '/public/partage/tag-search-fragment.php';

View File

@@ -0,0 +1,8 @@
<?php
/**
* Partagé fragment: file validation (HTMX partial).
*/
require_once __DIR__ . '/../../../bootstrap.php';
App::boot();
require_once APP_ROOT . '/src/Controllers/validate-file-fragment-shared.php';

View File

@@ -22,54 +22,59 @@ $parts = explode('/', $path);
$slug = $parts[0] ?? '';
$action = $parts[1] ?? '';
// Special route: /partage/language-autre-fragment (HTMX fragment, no auth needed)
if ($slug === 'language-autre-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
// Special route: /partage/fragments/* (HTMX fragments under fragments/ subdirectory)
if (str_starts_with($slug, 'fragments/') && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once __DIR__ . '/language-autre-fragment.php';
$fragmentFile = __DIR__ . '/' . basename($slug);
if (file_exists($fragmentFile)) {
require_once $fragmentFile;
} else {
http_response_code(404);
exit;
}
exit;
}
// Special route: /partage/format-website-fragment (HTMX fragment, legacy — kept for safety)
if ($slug === 'format-website-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once __DIR__ . '/format-website-fragment.php';
exit;
}
// Special route: /partage/validate-file-fragment (HTMX fragment — file MIME/size validation)
if ($slug === 'validate-file-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once __DIR__ . '/../../src/Controllers/validate-file-fragment-shared.php';
exit;
}
// Special route: /partage/fichiers-fragment (HTMX fragment — format-aware fichiers block)
if ($slug === 'fichiers-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once APP_ROOT . '/templates/partials/form/fichiers-fragment.php';
exit;
}
// Special route: /partage/licence-fragment (HTMX fragment — licence section with conditional required)
// Legacy routes — kept for backward compatibility, delegate to fragments/
if ($slug === 'licence-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once __DIR__ . '/licence-fragment.php';
require_once __DIR__ . '/fragments/licence.php';
exit;
}
// Special route: /partage/tag-search-fragment (HTMX fragment — interactive tag search)
if ($slug === 'tag-search-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
if ($slug === 'language-autre-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once __DIR__ . '/tag-search-fragment.php';
require_once __DIR__ . '/fragments/language-autre.php';
exit;
}
// Special route: /partage/language-search-fragment (HTMX fragment — interactive language search)
if ($slug === 'language-search-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once __DIR__ . '/language-search-fragment.php';
require_once __DIR__ . '/fragments/language-search.php';
exit;
}
if ($slug === 'tag-search-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once __DIR__ . '/fragments/tag-search.php';
exit;
}
if ($slug === 'format-website-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once __DIR__ . '/fragments/format-website.php';
exit;
}
if ($slug === 'fichiers-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once __DIR__ . '/fragments/fichiers.php';
exit;
}
if ($slug === 'validate-file-fragment' && $_SERVER['REQUEST_METHOD'] === 'POST') {
App::boot();
require_once __DIR__ . '/fragments/validate-file.php';
exit;
}

View File

@@ -1,33 +1,6 @@
<?php
/**
* language-autre-fragment.php
*
* Shared HTMX fragment include: returns the requirement asterisk for the
* "Autre(s) langue(s)" label. When no standard language checkbox is checked,
* an asterisk is rendered to signal the field is required (server-side validated).
*
* Included by:
* - /admin/language-autre-fragment.php (AdminAuth gated)
* - partage/index.php special route (public, session already booted)
*
* Expected POST:
* languages[] — selected language IDs (may be absent)
* Partagé fragment: language-autre asterisk toggle (HTMX partial).
* @deprecated Use /partage/fragments/language-autre.php instead.
*/
$selectedIds = isset($_POST['languages']) && is_array($_POST['languages'])
? $_POST['languages']
: [];
$anyChecked = !empty($selectedIds);
// Also check if any "autre" language pills are present (posted as language_autre[])
$hasLangAutre = isset($_POST['language_autre']) && is_array($_POST['language_autre'])
&& count(array_filter($_POST['language_autre'], fn($l) => is_string($l) && trim($l) !== '')) > 0;
// The "Autre(s) langue(s)" label is required if no standard language is checked.
// The "Langue(s) du TFE" checkbox list is required if neither standard languages
// nor "autre" languages are set.
$langAutreRequired = !$anyChecked;
$checkboxesRequired = !$anyChecked && !$hasLangAutre;
?>
<span id="language-autre-required"><?= $langAutreRequired ? ' <span class="asterisk">*</span>' : '' ?></span>
<span id="languages-required-asterisk" hx-swap-oob="true"><?= $checkboxesRequired ? ' <span class="asterisk">*</span>' : '' ?></span>
require_once __DIR__ . '/fragments/language-autre.php';

View File

@@ -1,108 +1,6 @@
<?php
/**
* HTMX fragment (partage): renders the licence section with conditional options.
*
* POST: access_type_id, license_id, license_custom, cc2r, want_license, admin_mode
*
* Libre (1): CC2r checkbox + licence select/custom (au moins une des deux)
* Interne (2): opt-in "Je souhaite appliquer une licence" → CC2r + licence
* Interdit (3): no licence options
* Partagé fragment: licence section (HTMX partial).
* @deprecated Use /partage/fragments/licence.php instead.
*/
require_once __DIR__ . '/../../bootstrap.php';
$accessTypeId = $_POST['access_type_id'] ?? '';
$licenseId = $_POST['license_id'] ?? '';
$licenseCustom = $_POST['license_custom'] ?? '';
$cc2r = !empty($_POST['cc2r']);
$wantLicense = !empty($_POST['want_license']);
$adminMode = ($_POST['admin_mode'] ?? '0') === '1';
require_once APP_ROOT . '/src/Database.php';
$db = Database::getInstance();
$licenseTypes = $db->getAllLicenseTypes();
?>
<div class="licence-license-choice">
<?php if ($accessTypeId === '1'): ?>
<fieldset class="licence-options-fieldset">
<legend>Options de licence</legend>
<p class="licence-note">J'autorise que mon TFE soit disponible en libre accès. Je suis conscient·e des responsabilités légales.</p>
<div class="admin-form-group">
<label class="admin-checkbox-label">
<input type="checkbox" name="cc2r" value="1"
<?= $cc2r ? 'checked' : '' ?>>
J'accepte les conditions collectives de réutilisation (CC2r)
</label>
<small><a href="https://cc2r.net/" target="_blank" rel="noopener">En savoir plus sur la CC2r ↗</a></small>
</div>
<div class="licence-or-separator"><span>et / ou</span></div>
<?php
$name = 'license_id'; $label = 'Licence :'; $options = $licenseTypes;
$selected = $licenseId; $placeholder = '— Sélectionner —'; $required = false;
include APP_ROOT . '/templates/partials/form/select-field.php';
?>
<?php
$name = 'license_custom'; $label = 'Ou précisez une autre licence :';
$value = htmlspecialchars($licenseCustom);
$hint = 'Ex: CC BY-NC 4.0, Tous droits réservés…';
include APP_ROOT . '/templates/partials/form/text-field.php';
?>
</fieldset>
<?php elseif ($accessTypeId === '2'): ?>
<fieldset class="licence-options-fieldset">
<legend>Options de licence</legend>
<p class="licence-note">Mon TFE est accessible sur place et sur la plateforme xamxam par la communauté erg. J'autorise une (ré-)utilisation dans un contexte académique au sein de l'erg.</p>
<div class="admin-form-group">
<label class="admin-checkbox-label">
<input type="checkbox" name="want_license" value="1"
hx-post="/partage/licence-fragment"
hx-target=".licence-license-choice"
hx-swap="outerHTML"
hx-include="closest fieldset"
<?= $wantLicense ? 'checked' : '' ?>>
<strong>Je souhaite appliquer une licence sur mon TFE</strong>
</label>
<small>Par défaut, aucune licence spécifique n'est appliquée. Cochez pour en choisir une.</small>
</div>
<?php if ($wantLicense): ?>
<div class="admin-form-group">
<label class="admin-checkbox-label">
<input type="checkbox" name="cc2r" value="1"
<?= $cc2r ? 'checked' : '' ?>>
J'accepte les conditions collectives de réutilisation (CC2r)
</label>
<small><a href="https://cc2r.net/" target="_blank" rel="noopener">En savoir plus sur la CC2r ↗</a></small>
</div>
<?php
$name = 'license_id'; $label = 'Licence :'; $options = $licenseTypes;
$selected = $licenseId; $placeholder = '— Sélectionner —'; $required = false;
include APP_ROOT . '/templates/partials/form/select-field.php';
?>
<?php
$name = 'license_custom'; $label = 'Ou précisez une autre licence :';
$value = htmlspecialchars($licenseCustom);
$hint = 'Ex: CC BY-NC 4.0, Tous droits réservés…';
include APP_ROOT . '/templates/partials/form/text-field.php';
?>
<p class="licence-note"><em>Je suis conscient·e des obligations légales venant avec la licence choisie et acquiesce avoir lu la documentation prévue à cet effet par l'erg, ainsi qu'avoir discuté des enjeux des licences avec l'équipe pédagogique.</em></p>
<?php endif; ?>
</fieldset>
<?php elseif ($accessTypeId === '3'): ?>
<fieldset class="licence-options-fieldset">
<legend>Options de licence</legend>
<p class="licence-note">Mon TFE n'est pas disponible en physique ni sur le site. Une note descriptive est visible publiquement.</p>
<p class="licence-note"><em>Aucune licence n'est applicable.</em></p>
</fieldset>
<?php endif; ?>
</div>
require_once __DIR__ . '/fragments/licence.php';

View File

@@ -1,67 +1,6 @@
<?php
/**
* tag-search-fragment.php
*
* Shared HTMX fragment: returns matching tag suggestions for the mot-clé
* interactive search input.
*
* Included by:
* - /admin/tag-search-fragment.php (AdminAuth gated)
* - partage/index.php special route (public, session already booted)
*
* Expected POST:
* q — search query string (partial tag name)
* tag[] — already selected tag names (sent via hx-include, to exclude from suggestions)
* Partagé fragment: tag search (HTMX partial).
* @deprecated Use /partage/fragments/tag-search.php instead.
*/
require_once __DIR__ . '/../../src/Database.php';
$query = trim(preg_replace('/\s+/', ' ', strtolower($_POST['tag_search_q'] ?? '')));
$currentTags = isset($_POST['tag']) && is_array($_POST['tag'])
? array_map(function($t) { return trim(preg_replace('/\s+/', ' ', strtolower($t))); }, $_POST['tag'])
: [];
$db = Database::getInstance();
$results = $db->searchTags($query);
// Deduplicate results by lowercase name
$seen = [];
$results = array_values(array_filter($results, function($tag) use (&$seen) {
$key = strtolower($tag['name']);
if (isset($seen[$key])) return false;
$seen[$key] = true;
return true;
}));
// Filter out already-selected tags (case-insensitive)
$results = array_values(array_filter($results, function($tag) use ($currentTags) {
return !in_array(strtolower($tag['name']), $currentTags, true);
}));
// Check if query exactly matches an existing tag (case-insensitive)
$exactExists = false;
foreach ($results as $tag) {
if (strcasecmp($tag['name'], $query) === 0) {
$exactExists = true;
break;
}
}
// If no exact match and query non-empty, suggest creation
$canCreate = ($query !== '' && !$exactExists && !in_array($query, $currentTags, true));
?>
<?php if (empty($results) && !$canCreate): ?>
<div class="tag-search-empty">Aucun mot-clé trouvé.</div>
<?php endif; ?>
<?php foreach ($results as $tag): ?>
<button type="button" class="tag-search-item" data-tag-id="<?= (int)$tag['id'] ?>" data-tag-name="<?= htmlspecialchars($tag['name']) ?>">
<span class="tag-search-item-name"><?= htmlspecialchars($tag['name']) ?></span>
<span class="tag-search-item-count">(<?= (int)$tag['thesis_count'] ?>)</span>
</button>
<?php endforeach; ?>
<?php if ($canCreate): ?>
<button type="button" class="tag-search-item tag-search-item--create" data-tag-name="<?= htmlspecialchars($query) ?>">
<span class="tag-search-item-name">Créer «&nbsp;<?= htmlspecialchars($query) ?>&nbsp;»</span>
</button>
<?php endif; ?>
require_once __DIR__ . '/fragments/tag-search.php';