mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
feat: fix file deletion on save + trash policy + documents/ prefix + relink browser
1. note_intention: Delete old file only when a genuinely new upload arrives
(32-char hex file_id), not when the FilePond pool preserves an existing
file by sending its DB integer ID. Previously the DB integer ID
triggered $hasNewNote=true, which deleted the existing note_intention
from disk+DB, then handleFilePondSingleFile couldn't re-process it
because the regex requires a hex pattern. Same fix applied to cover.
2. All file deletions now use deleteThesisFileToTrash() which renames
files to tmp/_trash/ instead of unlinking. The trash preserves
original filenames prefixed with DB id for traceability. Skips
website URLs and PeerTube refs (no disk file).
3. Storage prefix changed from theses/ to documents/ to reflect that
the folder holds all document types (determined by file_type in DB).
MediaController visibility gate supports both prefixes for backward
compat with existing files.
4. File browser + relink feature for orphaned files:
- /admin/fragments/file-browser.php — HTMX tree browser for
storage/documents/ and storage/theses/
- /admin/actions/filepond/relink.php — POST endpoint that inserts
a thesis_files row pointing to existing on-disk file
- Per-pool "📂 Relier" buttons (edit mode only)
- JS: XamxamOpenFileBrowser / XamxamRelinkFile with FilePond integration
- CSS: .relink-modal dialog + .file-browser tree styles
This commit is contained in:
@@ -84,6 +84,14 @@ $websiteLabel = htmlspecialchars($_POST['website_label'] ?? '');
|
||||
data-existing-files='<?= htmlspecialchars(json_encode($existingFilesJsonForCover ?? []), ENT_QUOTES) ?>'>
|
||||
<small>JPG, PNG ou WEBP. Format 4:3 recommandé. Max 20 MB.</small>
|
||||
</div>
|
||||
<?php if ($editMode): ?>
|
||||
<button type="button" class="btn btn--sm btn--ghost file-browser-trigger"
|
||||
data-queue-type="cover"
|
||||
data-thesis-id="<?= htmlspecialchars((string)($thesisId ?? $_GET['id'] ?? '')) ?>"
|
||||
onclick="XamxamOpenFileBrowser(this)">
|
||||
📂 Relier un fichier existant
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- ── 2. Note d'intention ── -->
|
||||
@@ -98,6 +106,14 @@ $websiteLabel = htmlspecialchars($_POST['website_label'] ?? '');
|
||||
<?= !$adminMode ? 'required' : '' ?>>
|
||||
<small>PDF uniquement. Max 100 MB. Si votre fichier est trop lourd, compressez-le avec <a href="https://www.bentopdf.com" target="_blank" rel="noopener">bentopdf.com</a>.</small>
|
||||
</div>
|
||||
<?php if ($editMode): ?>
|
||||
<button type="button" class="btn btn--sm btn--ghost file-browser-trigger"
|
||||
data-queue-type="note_intention"
|
||||
data-thesis-id="<?= htmlspecialchars((string)($thesisId ?? $_GET['id'] ?? '')) ?>"
|
||||
onclick="XamxamOpenFileBrowser(this)">
|
||||
📂 Relier un fichier existant
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- ── 3. TFE (all files: PDF, images, video, audio, VTT, archives) ── -->
|
||||
@@ -122,6 +138,14 @@ $websiteLabel = htmlspecialchars($_POST['website_label'] ?? '');
|
||||
<?php endif; ?>
|
||||
</small>
|
||||
</div>
|
||||
<?php if ($editMode): ?>
|
||||
<button type="button" class="btn btn--sm btn--ghost file-browser-trigger"
|
||||
data-queue-type="tfe"
|
||||
data-thesis-id="<?= htmlspecialchars((string)($thesisId ?? $_GET['id'] ?? '')) ?>"
|
||||
onclick="XamxamOpenFileBrowser(this)">
|
||||
📂 Relier un fichier existant
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- ── 4. Annexes ── -->
|
||||
@@ -138,6 +162,14 @@ $websiteLabel = htmlspecialchars($_POST['website_label'] ?? '');
|
||||
data-existing-files='<?= htmlspecialchars(json_encode($existingFilesJsonForAnnexe ?? []), ENT_QUOTES) ?>'>
|
||||
<small class="admin-file-hint">PDF ou archives ZIP/TAR. Max 500 MB. Glissez pour réordonner.</small>
|
||||
</div>
|
||||
<?php if ($editMode): ?>
|
||||
<button type="button" class="btn btn--sm btn--ghost file-browser-trigger"
|
||||
data-queue-type="annexe"
|
||||
data-thesis-id="<?= htmlspecialchars((string)($thesisId ?? $_GET['id'] ?? '')) ?>"
|
||||
onclick="XamxamOpenFileBrowser(this)">
|
||||
📂 Relier un fichier existant
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -154,3 +186,19 @@ $websiteLabel = htmlspecialchars($_POST['website_label'] ?? '');
|
||||
|
||||
</fieldset><!-- /Fichiers -->
|
||||
</div><!-- #format-fichiers-block -->
|
||||
|
||||
<!-- ═══════════════════ File Browser Modal (edit mode only) ═══════════════════ -->
|
||||
<?php if ($editMode): ?>
|
||||
<dialog id="relink-modal" class="relink-modal">
|
||||
<div class="relink-modal-header">
|
||||
<h3>Relier un fichier existant</h3>
|
||||
<button type="button" class="btn btn--sm btn--ghost" onclick="document.getElementById('relink-modal').close()" aria-label="Fermer">✕</button>
|
||||
</div>
|
||||
<div id="relink-modal-body">
|
||||
<p class="file-browser-loading">Chargement du navigateur de fichiers…</p>
|
||||
</div>
|
||||
<div class="relink-modal-footer">
|
||||
<small>Seuls les fichiers déjà présents dans storage/documents/ ou storage/theses/ sont listés.</small>
|
||||
</div>
|
||||
</dialog>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -233,7 +233,7 @@ $checkedFormatsForSiteWeb = $checkedFormatsForSiteWeb ?? [];
|
||||
$hint = "Si votre TFE contient une langue absente de la liste, précisez-la ici.";
|
||||
$selectedLanguages = $_selectedOtherLangs;
|
||||
$required = $_langAutreRequired && !$adminMode;
|
||||
$hxPost = ($mode === 'partage') ? "/partage/fragments/language-search.php" : "/admin/fragments/language-search.php";
|
||||
$hxPost = ($mode === 'partage') ? "/partage/fragments/pill-search.php" : "/admin/fragments/pill-search.php";
|
||||
include APP_ROOT . "/templates/partials/form/language-search.php";
|
||||
unset($_langAutreRequired, $_selectedOtherLangs, $_langRaw, $_l, $name, $label, $placeholder, $hint, $selectedLanguages, $required, $hxPost);
|
||||
?>
|
||||
@@ -279,7 +279,7 @@ $checkedFormatsForSiteWeb = $checkedFormatsForSiteWeb ?? [];
|
||||
$selectedTags = $_selectedTags;
|
||||
$required = !$adminMode;
|
||||
$minTags = ($mode === 'partage') ? 3 : 0;
|
||||
$hxPost = ($mode === 'partage') ? "/partage/fragments/tag-search.php" : "/admin/fragments/tag-search.php";
|
||||
$hxPost = ($mode === 'partage') ? "/partage/fragments/pill-search.php" : "/admin/fragments/pill-search.php";
|
||||
include APP_ROOT . "/templates/partials/form/tag-search.php";
|
||||
unset($_tagsRaw, $_selectedTags, $_t, $name, $label, $placeholder, $hint, $selectedTags, $hxPost, $minTags, $required);
|
||||
?>
|
||||
|
||||
@@ -67,13 +67,13 @@ if ($addMode) {
|
||||
<legend>Composition du jury</legend>
|
||||
|
||||
<!-- Promoteur·ice(s) interne -->
|
||||
<fieldset class="admin-jury-lecteurs">
|
||||
<fieldset class="admin-jury-lecteurs" data-jury-autocomplete data-jury-hx-post="<?= $adminMode ? '/admin/fragments/pill-search.php' : '/partage/fragments/pill-search.php' ?>" data-jury-role="promoteur_interne">
|
||||
<legend>Promoteur·ice(s) interne<?= $adminMode ? '' : ' <span class="asterisk">*</span>' ?></legend>
|
||||
<div id="jury-promoteur-interne-list" class="admin-jury-list">
|
||||
<?php if (empty($juryPromoteurs) && $juryPromoteur === null): ?>
|
||||
<div class="admin-jury-entry">
|
||||
<input type="text" name="jury_promoteur[]" placeholder="Nom" <?= $adminMode ? '' : 'required' ?>
|
||||
id="jury_promoteur" aria-label="Promoteur·ice interne 1 — nom">
|
||||
id="jury_promoteur" aria-label="Promoteur·ice interne 1 — nom" autocomplete="off">
|
||||
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
|
||||
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
@@ -83,7 +83,7 @@ if ($addMode) {
|
||||
<input type="text" name="jury_promoteur[]"
|
||||
value="<?= htmlspecialchars($pm['name']) ?>" placeholder="Nom"
|
||||
<?= (!$adminMode && $pi === 0) ? 'required' : '' ?>
|
||||
aria-label="Promoteur·ice interne <?= $pi + 1 ?> — nom">
|
||||
aria-label="Promoteur·ice interne <?= $pi + 1 ?> — nom" autocomplete="off">
|
||||
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
|
||||
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
@@ -92,7 +92,7 @@ if ($addMode) {
|
||||
<div class="admin-jury-entry">
|
||||
<input type="text" name="jury_promoteur[]"
|
||||
value="<?= htmlspecialchars($juryPromoteur ?? '') ?>" placeholder="Nom" <?= $adminMode ? '' : 'required' ?>
|
||||
aria-label="Promoteur·ice interne 1 — nom">
|
||||
aria-label="Promoteur·ice interne 1 — nom" autocomplete="off">
|
||||
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
|
||||
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
@@ -106,13 +106,13 @@ if ($addMode) {
|
||||
|
||||
<?php if ($showPromoteurUlb): ?>
|
||||
<!-- Promoteur·ice(s) ULB -->
|
||||
<fieldset class="admin-jury-lecteurs" id="jury-promoteur-ulb-row"<?= $promoteurUlbConditional ? ' style="display:none"' : '' ?>>
|
||||
<fieldset class="admin-jury-lecteurs" id="jury-promoteur-ulb-row"<?= $promoteurUlbConditional ? ' style="display:none"' : '' ?> data-jury-autocomplete data-jury-hx-post="<?= $adminMode ? '/admin/fragments/pill-search.php' : '/partage/fragments/pill-search.php' ?>" data-jury-role="promoteur_externe">
|
||||
<legend>Promoteur·ice(s) ULB<span id="jury-ulb-asterisk" style="display:none"> <span class="asterisk">*</span></span></legend>
|
||||
<div id="jury-promoteur-ulb-list" class="admin-jury-list">
|
||||
<?php if (empty($juryPromoteursUlb) && $juryPromoteurUlb === null): ?>
|
||||
<div class="admin-jury-entry">
|
||||
<input type="text" name="jury_promoteur_ulb_name[]" placeholder="Nom"
|
||||
aria-label="Promoteur·ice ULB 1 — nom">
|
||||
aria-label="Promoteur·ice ULB 1 — nom" autocomplete="off">
|
||||
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
|
||||
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
@@ -121,7 +121,7 @@ if ($addMode) {
|
||||
<div class="admin-jury-entry">
|
||||
<input type="text" name="jury_promoteur_ulb_name[]"
|
||||
value="<?= htmlspecialchars($pm['name']) ?>" placeholder="Nom"
|
||||
aria-label="Promoteur·ice ULB <?= $pi + 1 ?> — nom">
|
||||
aria-label="Promoteur·ice ULB <?= $pi + 1 ?> — nom" autocomplete="off">
|
||||
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
|
||||
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
@@ -130,7 +130,7 @@ if ($addMode) {
|
||||
<div class="admin-jury-entry">
|
||||
<input type="text" name="jury_promoteur_ulb_name[]"
|
||||
value="<?= htmlspecialchars($juryPromoteurUlb ?? '') ?>" placeholder="Nom"
|
||||
aria-label="Promoteur·ice ULB 1 — nom">
|
||||
aria-label="Promoteur·ice ULB 1 — nom" autocomplete="off">
|
||||
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
|
||||
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
@@ -144,23 +144,20 @@ if ($addMode) {
|
||||
<?php if ($promoteurUlbConditional): ?>
|
||||
<script>
|
||||
(function() {
|
||||
var finalitySelect = document.querySelector('select[name="finality"]');
|
||||
var ulbRow = document.getElementById('jury-promoteur-ulb-row');
|
||||
var ulbInput = ulbRow ? ulbRow.querySelector('input') : null;
|
||||
var ulbAsterisk = document.getElementById('jury-ulb-asterisk');
|
||||
function isApprofondiSelected() {
|
||||
if (!finalitySelect) return false;
|
||||
var selected = finalitySelect.options[finalitySelect.selectedIndex];
|
||||
var text = (selected && selected.text) ? selected.text.toLowerCase() : '';
|
||||
return text.includes('approfondi');
|
||||
}
|
||||
function toggleUlb() {
|
||||
if (!ulbRow) return;
|
||||
var show = isApprofondiSelected();
|
||||
ulbRow.style.display = show ? '' : 'none';
|
||||
if (ulbAsterisk) ulbAsterisk.style.display = show ? '' : 'none';
|
||||
// Mark first ULB input required when finality is Approfondi
|
||||
if (ulbRow) {
|
||||
try {
|
||||
var finalitySelect = document.querySelector('select[name="finality"]');
|
||||
var ulbRow = document.getElementById('jury-promoteur-ulb-row');
|
||||
if (!finalitySelect || !ulbRow) return;
|
||||
var ulbAsterisk = document.getElementById('jury-ulb-asterisk');
|
||||
function isApprofondiSelected() {
|
||||
var opt = finalitySelect.options[finalitySelect.selectedIndex];
|
||||
if (!opt) return false;
|
||||
return (opt.textContent || opt.text || '').toLowerCase().includes('approfondi');
|
||||
}
|
||||
function toggleUlb() {
|
||||
var show = isApprofondiSelected();
|
||||
ulbRow.style.display = show ? '' : 'none';
|
||||
if (ulbAsterisk) ulbAsterisk.style.display = show ? '' : 'none';
|
||||
var inputs = ulbRow.querySelectorAll('input[name="jury_promoteur_ulb_name[]"]');
|
||||
inputs.forEach(function(inp, idx) {
|
||||
inp.required = <?= $adminMode ? 'false' : 'show && idx === 0' ?>;
|
||||
@@ -168,24 +165,22 @@ if ($addMode) {
|
||||
if (!show) inp.value = '';
|
||||
});
|
||||
}
|
||||
}
|
||||
if (finalitySelect) {
|
||||
finalitySelect.addEventListener('change', toggleUlb);
|
||||
toggleUlb();
|
||||
}
|
||||
} catch(e) { console.error('jury ULB toggle:', e); }
|
||||
})();
|
||||
</script>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Lecteur·ice(s) interne -->
|
||||
<fieldset class="admin-jury-lecteurs">
|
||||
<fieldset class="admin-jury-lecteurs" data-jury-autocomplete data-jury-hx-post="<?= $adminMode ? '/admin/fragments/pill-search.php' : '/partage/fragments/pill-search.php' ?>" data-jury-role="lecteur_interne">
|
||||
<legend>Lecteur·ice(s) interne<?= $adminMode ? '' : ' <span class="asterisk">*</span>' ?></legend>
|
||||
<div id="jury-lecteurs-internes-list" class="admin-jury-list">
|
||||
<?php if (empty($lecteursInternes)): ?>
|
||||
<div class="admin-jury-entry">
|
||||
<input type="text" name="jury_lecteur_interne[]" placeholder="Nom" <?= $adminMode ? '' : 'required' ?>
|
||||
aria-label="Lecteur·ice interne 1 — nom">
|
||||
aria-label="Lecteur·ice interne 1 — nom" autocomplete="off">
|
||||
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
|
||||
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
@@ -195,7 +190,7 @@ if ($addMode) {
|
||||
<input type="text" name="jury_lecteur_interne[]"
|
||||
value="<?= htmlspecialchars($lm['name']) ?>" placeholder="Nom"
|
||||
<?= (!$adminMode && $li === 0) ? 'required' : '' ?>
|
||||
aria-label="Lecteur·ice interne <?= $li + 1 ?> — nom">
|
||||
aria-label="Lecteur·ice interne <?= $li + 1 ?> — nom" autocomplete="off">
|
||||
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
|
||||
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
@@ -209,13 +204,13 @@ if ($addMode) {
|
||||
</fieldset>
|
||||
|
||||
<!-- Lecteur·ice(s) externe -->
|
||||
<fieldset class="admin-jury-lecteurs">
|
||||
<fieldset class="admin-jury-lecteurs" data-jury-autocomplete data-jury-hx-post="<?= $adminMode ? '/admin/fragments/pill-search.php' : '/partage/fragments/pill-search.php' ?>" data-jury-role="lecteur_externe">
|
||||
<legend>Lecteur·ice(s) externe<?= $adminMode ? '' : ' <span class="asterisk">*</span>' ?></legend>
|
||||
<div id="jury-lecteurs-externes-list" class="admin-jury-list">
|
||||
<?php if (empty($lecteursExternes)): ?>
|
||||
<div class="admin-jury-entry">
|
||||
<input type="text" name="jury_lecteur_externe[]" placeholder="Nom" <?= $adminMode ? '' : 'required' ?>
|
||||
aria-label="Lecteur·ice externe 1 — nom">
|
||||
aria-label="Lecteur·ice externe 1 — nom" autocomplete="off">
|
||||
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
|
||||
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
@@ -225,7 +220,7 @@ if ($addMode) {
|
||||
<input type="text" name="jury_lecteur_externe[]"
|
||||
value="<?= htmlspecialchars($lm['name']) ?>" placeholder="Nom"
|
||||
<?= (!$adminMode && $li === 0) ? 'required' : '' ?>
|
||||
aria-label="Lecteur·ice externe <?= $li + 1 ?> — nom">
|
||||
aria-label="Lecteur·ice externe <?= $li + 1 ?> — nom" autocomplete="off">
|
||||
<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"
|
||||
onclick="removeJuryRow(this)" aria-label="Supprimer"><span aria-hidden="true">✕</span></button>
|
||||
</div>
|
||||
@@ -247,7 +242,7 @@ function addJuryRow(listId, inputName, roleLabel) {
|
||||
var n = list.querySelectorAll('.admin-jury-entry').length + 1;
|
||||
var div = document.createElement('div');
|
||||
div.className = 'admin-jury-entry';
|
||||
div.innerHTML = '<input type="text" name="' + inputName + '" placeholder="Nom"'
|
||||
div.innerHTML = '<input type="text" name="' + inputName + '" placeholder="Nom" autocomplete="off"'
|
||||
+ ' aria-label="' + roleLabel + ' ' + n + ' \u2014 nom">'
|
||||
+ '<button type="button" class="btn btn--sm btn--ghost admin-btn-remove"'
|
||||
+ ' onclick="removeJuryRow(this)" aria-label="Supprimer">'
|
||||
|
||||
@@ -24,7 +24,7 @@ $name = $name ?? 'language_autre';
|
||||
$label = $label ?? 'Autre(s) langue(s)';
|
||||
$placeholder = $placeholder ?? 'Rechercher une langue…';
|
||||
$hint = $hint ?? null;
|
||||
$hxPost = $hxPost ?? '/admin/fragments/language-search.php';
|
||||
$hxPost = $hxPost ?? '/admin/fragments/pill-search.php';
|
||||
$selectedLanguages = $selectedLanguages ?? [];
|
||||
$id = $id ?? $name;
|
||||
$maxLanguages = $maxLanguages ?? 10;
|
||||
@@ -71,6 +71,7 @@ $langCount = count($selectedLanguages);
|
||||
hx-trigger="input changed delay:200ms, focus"
|
||||
hx-target="#<?= htmlspecialchars($id) ?>-suggestions"
|
||||
hx-swap="innerHTML"
|
||||
hx-vals='{"pill_type":"language"}'
|
||||
hx-include="#<?= htmlspecialchars($id) ?>-pills">
|
||||
</div>
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ $name = $name ?? 'tag';
|
||||
$label = $label ?? 'Mots-clés';
|
||||
$placeholder = $placeholder ?? 'Rechercher un mot-clé…';
|
||||
$hint = $hint ?? null;
|
||||
$hxPost = $hxPost ?? '/admin/fragments/tag-search.php';
|
||||
$hxPost = $hxPost ?? '/admin/fragments/pill-search.php';
|
||||
$selectedTags = $selectedTags ?? [];
|
||||
$id = $id ?? $name;
|
||||
$maxTags = $maxTags ?? 10;
|
||||
@@ -74,6 +74,7 @@ $belowMin = $required && $tagCount < $minTags;
|
||||
hx-trigger="input changed delay:200ms, focus"
|
||||
hx-target="#<?= htmlspecialchars($id) ?>-suggestions"
|
||||
hx-swap="innerHTML"
|
||||
hx-vals='{"pill_type":"tag"}'
|
||||
hx-include="#<?= htmlspecialchars($id) ?>-pills">
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user