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

@@ -1,20 +1,22 @@
<?php
/**
* HTMX fragment (admin): renders the licence section with conditional required states.
* HTMX fragment (admin): 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: never required.
* 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
*/
require_once __DIR__ . '/../../bootstrap.php';
require_once __DIR__ . '/../../src/AdminAuth.php';
AdminAuth::requireLogin();
$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 = true;
$cc2r = !empty($_POST['cc2r']);
$wantLicense = !empty($_POST['want_license']);
require_once APP_ROOT . '/src/Database.php';
$db = Database::getInstance();
@@ -22,6 +24,22 @@ $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;
@@ -31,16 +49,61 @@ $licenseTypes = $db->getAllLicenseTypes();
<?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="/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)
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>

View File

@@ -743,3 +743,18 @@ details > summary::-webkit-details-marker {
audio::-webkit-media-controls-enclosure {
border-radius: var(--radius);
}
details {
padding: var(--space-s);
}
summary {
font-family: var(--font-display);
font-weight: 600;
text-decoration: 1px wavy;
color: var(--accent-secondary);
svg {
fill: var(--accent-secondary);
vertical-align: text-bottom;
height: 1.4em;
}
}

View File

@@ -1362,3 +1362,135 @@ legend {
#format-fichiers-block {
container-type: inline-size;
}
/* ── Licence choice or-separator ─────────────────────────── */
.licence-or-separator {
display: flex;
align-items: center;
gap: var(--space-xs);
margin: var(--space-xs) 0;
color: var(--text-tertiary);
font-size: var(--step--1);
}
.licence-or-separator::before,
.licence-or-separator::after {
content: '';
flex: 1;
height: 1px;
background: var(--accent-muted);
}
/* ── Nested licence fieldset ─────────────────────────────── */
.licence-options-fieldset {
border: 1px solid var(--accent-muted);
border-radius: var(--radius);
padding: var(--space-s);
margin-top: var(--space-xs);
}
.licence-options-fieldset legend {
font-weight: 600;
font-size: var(--step--1);
color: var(--text-secondary);
padding: 0 var(--space-2xs);
}
/* ── File figures (recap + edit existing files) ──────────── */
.admin-file-list,
.recap-files-list {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
gap: var(--space-s);
}
.admin-file-list-item,
.recap-files-list-item {
list-style: none;
}
.admin-file-figure,
.recap-file-figure {
display: flex;
align-items: flex-start;
gap: var(--space-s);
background: var(--bg-secondary, rgba(149, 87, 181, 0.05));
border-radius: var(--radius);
padding: var(--space-s);
margin: 0;
}
.admin-file-icon,
.recap-file-icon {
font-size: 1.5rem;
flex-shrink: 0;
width: 2.5rem;
height: 2.5rem;
display: flex;
align-items: center;
justify-content: center;
background: var(--accent-muted);
border-radius: var(--radius);
}
.admin-file-thumb,
.recap-file-thumb {
max-width: 160px;
max-height: 120px;
object-fit: cover;
border-radius: var(--radius);
flex-shrink: 0;
}
.admin-file-caption,
.recap-file-caption {
flex: 1;
display: flex;
flex-direction: column;
gap: var(--space-3xs);
}
.admin-file-name,
.recap-file-name {
font-weight: 600;
font-size: var(--step--1);
color: var(--text-primary);
}
.admin-file-peertube-id,
.recap-file-peertube-id {
font-size: var(--step--2);
color: var(--text-tertiary);
font-family: monospace;
}
.admin-file-meta-row,
.recap-file-meta-row {
display: flex;
gap: var(--space-xs);
align-items: center;
font-size: var(--step--2);
color: var(--text-tertiary);
}
.recap-file-label {
font-size: var(--step--1);
color: var(--text-secondary);
font-style: italic;
}
.admin-file-label-input {
font-size: var(--step--2);
padding: var(--space-3xs) var(--space-2xs);
border: 1px solid var(--accent-muted);
border-radius: var(--radius);
background: var(--bg-primary);
color: var(--text-primary);
margin-top: var(--space-3xs);
}

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>