feat: refactor licence fragment — Libre→CC2r+licence, Interne→opt-in want_license, Interdit→none, add details/summary to license UI

This commit is contained in:
Pontoporeia
2026-05-11 14:19:44 +02:00
parent 927ee2fe2a
commit 8bf95f4e14
10 changed files with 809 additions and 109 deletions

View File

@@ -79,20 +79,19 @@ $websiteLabel = htmlspecialchars($_POST['website_label'] ?? '');
if ($editMode && (!empty($_efiles) || $_cover)):
?>
<div class="admin-form-group">
<ul id="existing-files-sortable" class="admin-file-list">
<ul id="existing-files-sortable" class="admin-file-list" role="list">
<?php if ($_cover): ?>
<li class="admin-file-list-item">
<span class="admin-file-icon-col">🖼️</span>
<span class="admin-file-info">
<span class="admin-file-name">Couverture</span>
<span class="admin-file-meta-row">
<img src="/media?path=<?= urlencode($_cover) ?>"
alt="Couverture actuelle" style="max-height:120px;border-radius:var(--radius);margin-top:var(--space-3xs);">
</span>
<label class="admin-checkbox-label" style="margin-top:var(--space-3xs);">
<input type="checkbox" name="remove_cover" value="1"> Supprimer
</label>
</span>
<figure class="admin-file-figure">
<img src="/media?path=<?= urlencode($_cover) ?>"
alt="Couverture actuelle" class="admin-file-thumb">
<figcaption class="admin-file-caption">
<span class="admin-file-name">Couverture</span>
<label class="admin-checkbox-label" style="margin-top:var(--space-3xs);">
<input type="checkbox" name="remove_cover" value="1"> Supprimer
</label>
</figcaption>
</figure>
</li>
<?php endif; ?>
<?php
@@ -118,27 +117,31 @@ $websiteLabel = htmlspecialchars($_POST['website_label'] ?? '');
?>
<li class="admin-file-list-item" data-file-id="<?= (int)$_f["id"] ?>">
<input type="hidden" name="file_sort_order[]" value="<?= (int)$_f["id"] ?>">
<span class="admin-file-icon-col"><?= $_fIcon ?></span>
<span class="admin-file-info">
<a href="<?= $_fLinkHref ?>" target="_blank" rel="noopener" class="admin-file-name">
<?= htmlspecialchars($_f["file_name"] ?? basename($_f["file_path"])) ?>
</a>
<span class="admin-file-meta-row">
<span class="admin-file-type-badge"><?= htmlspecialchars($_fType) ?></span>
<?php if (!empty($_f["file_size"]) && $_f["file_size"] > 0): ?>
<span class="admin-file-size"><?= number_format($_f["file_size"] / 1024 / 1024, 2) ?> MB</span>
<figure class="admin-file-figure">
<span class="admin-file-icon"><?= $_fIcon ?></span>
<figcaption class="admin-file-caption">
<a href="<?= $_fLinkHref ?>" target="_blank" rel="noopener" class="admin-file-name">
<?= htmlspecialchars($_f["file_name"] ?? basename($_f["file_path"])) ?>
</a>
<?php if ($_fIsPeerTube): ?>
<span class="admin-file-peertube-id">ID: <?= htmlspecialchars(substr($_fPath, strlen("peertube_ids:"))) ?></span>
<?php endif; ?>
</span>
<input type="text" name="file_label[<?= (int)$_f["id"] ?>]"
value="<?= htmlspecialchars($_f["display_label"] ?? "") ?>"
placeholder="Légende / description (optionnel)"
class="admin-file-label-input">
</span>
<span class="admin-file-meta-row">
<span class="admin-file-type-badge"><?= htmlspecialchars($_fType) ?></span>
<?php if (!empty($_f["file_size"]) && $_f["file_size"] > 0): ?>
<span class="admin-file-size"><?= number_format($_f["file_size"] / 1024 / 1024, 2) ?> MB</span>
<?php endif; ?>
</span>
<input type="text" name="file_label[<?= (int)$_f["id"] ?>]"
value="<?= htmlspecialchars($_f["display_label"] ?? "") ?>"
placeholder="Légende / description (optionnel)"
class="admin-file-label-input">
</figcaption>
</figure>
<input type="hidden" name="delete_files[]" value="<?= (int)$_f["id"] ?>" disabled>
<button type="button"
class="admin-btn-remove fq-remove"
onclick="this.previousElementSibling.disabled=false;this.closest('li').style.opacity='0.4';this.disabled=true;"
aria-label="Supprimer <?= htmlspecialchars($_f["file_name"] ?? basename($_f["file_path"])) ?>">&#x2715;</button>
class="btn btn--danger btn--sm"
onclick="this.previousElementSibling.previousElementSibling.disabled=false;this.closest('li').style.opacity='0.4';this.disabled=true;">Supprimer</button>
</li>
<?php endforeach; ?>
</ul>

View File

@@ -1,21 +1,21 @@
<?php
/**
* HTMX fragment: renders the licence section with conditional required states.
* HTMX fragment (partage): renders the licence section with conditional options.
*
* POST: access_type_id, license_id, license_custom, cc2r, admin_mode
* POST: access_type_id, license_id, license_custom, cc2r, want_license, admin_mode
*
* When access_type_id=1 (Libre): licence fields are required.
* When access_type_id=2|3 (Interne/Interdit): licence fields are optional.
* 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
*/
require_once __DIR__ . '/../../bootstrap.php';
$accessTypeId = $_POST['access_type_id'] ?? '2';
$licenseId = $_POST['license_id'] ?? '';
$accessTypeId = $_POST['access_type_id'] ?? '';
$licenseId = $_POST['license_id'] ?? '';
$licenseCustom = $_POST['license_custom'] ?? '';
$cc2r = !empty($_POST['cc2r']);
$adminMode = ($_POST['admin_mode'] ?? '0') === '1';
$required = !$adminMode && $accessTypeId === '1';
$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();
@@ -23,25 +23,86 @@ $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 —';
$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...';
$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)
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>