mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-09-25 01:53:03 +02:00
142 lines
6.9 KiB
PHP
142 lines
6.9 KiB
PHP
<?php
|
|
/**
|
|
* Temp file statistics as an HTML fragment (admin).
|
|
*
|
|
* GET /admin/actions/cleanup-stats-fragment.php
|
|
*
|
|
* Returns an HTML fragment ready for HTMX innerHTML swap into #tmp-cleanup-stats-wrapper.
|
|
*/
|
|
require_once __DIR__ . '/../../../bootstrap.php';
|
|
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
|
AdminAuth::requireLogin();
|
|
|
|
require_once __DIR__ . '/_cleanup-stats-data.php';
|
|
$d = getCleanupStats();
|
|
|
|
// Abandoned FilePond uploads are purged automatically by a cron job, so the
|
|
// cleanup page only surfaces the manually-managed trash (Corbeille).
|
|
$hasTrash = (($d['trash_stale_count'] ?? 0) + ($d['trash_active_count'] ?? 0)) > 0;
|
|
|
|
$trMeta = '';
|
|
if ($hasTrash) {
|
|
$trCount = ($d['trash_stale_count'] ?? 0) + ($d['trash_active_count'] ?? 0);
|
|
$trMeta = $trCount . ' fichier' . ($trCount > 1 ? 's' : '');
|
|
$trTotalSize = ($d['trash_stale_size'] ?? 0) + ($d['trash_active_size'] ?? 0);
|
|
if ($trTotalSize > 0) {
|
|
$trMeta .= ' · ' . humanBytes($trTotalSize);
|
|
}
|
|
}
|
|
?>
|
|
<?php if (!$hasTrash): ?>
|
|
<p style="margin:0;color:var(--accent-green)">✓ Corbeille vide — aucun fichier à nettoyer.</p>
|
|
<?php return; endif; ?>
|
|
|
|
<!-- Bulk actions bar -->
|
|
<div id="cleanup-bulk-actions" class="admin-bulk-actions" style="display:none">
|
|
<strong><span id="cleanup-selected-count">0</span> fichier(s) sélectionné(s)</strong>
|
|
<div class="admin-bulk-btns">
|
|
<button type="button" class="btn btn--sm" onclick="cleanupBulkRestore()" id="cleanup-bulk-restore-btn" style="display:none">
|
|
↺ Restaurer la sélection
|
|
</button>
|
|
<button type="button" class="btn btn--sm btn--red" onclick="cleanupBulkDelete()">
|
|
<?= icon('trash') ?> Supprimer la sélection
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Hidden bulk form (HTMX-powered) -->
|
|
<form id="cleanup-bulk-form" method="post" action="/admin/actions/cleanup-tmp.php"
|
|
hx-post="/admin/actions/cleanup-tmp.php"
|
|
hx-target="#tmp-cleanup-stats-wrapper"
|
|
hx-swap="innerHTML"
|
|
hx-indicator="#tmp-cleanup-stats-wrapper"
|
|
style="display:none">
|
|
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
|
|
<div id="cleanup-bulk-checkboxes"></div>
|
|
</form>
|
|
|
|
<!-- Hidden bulk restore form -->
|
|
<form id="cleanup-bulk-restore-form" method="post" action="/admin/actions/restore-trash.php"
|
|
hx-post="/admin/actions/restore-trash.php"
|
|
hx-target="#tmp-cleanup-stats-wrapper"
|
|
hx-swap="innerHTML"
|
|
hx-indicator="#tmp-cleanup-stats-wrapper"
|
|
style="display:none">
|
|
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
|
|
<div id="cleanup-bulk-restore-checkboxes"></div>
|
|
</form>
|
|
|
|
<?php
|
|
// ── Merge stale + active trash files into a single list for display ─────
|
|
// stale = orphaned (no sidecar, or too old); active = restorable (has sidecar)
|
|
$allTrashFiles = [];
|
|
foreach (($d['trash_active_files'] ?? []) as $f) {
|
|
$f['_restorable'] = true;
|
|
$f['_stale'] = false;
|
|
$allTrashFiles[] = $f;
|
|
}
|
|
foreach (($d['trash_stale_files'] ?? []) as $f) {
|
|
$f['_restorable'] = false;
|
|
$f['_stale'] = true;
|
|
$f['has_sidecar'] = false;
|
|
$f['original_name'] = '';
|
|
$f['file_type'] = '';
|
|
$allTrashFiles[] = $f;
|
|
}
|
|
$hasTrash = !empty($allTrashFiles);
|
|
if ($hasTrash): ?>
|
|
<section aria-labelledby="tmp-trash-heading">
|
|
<h2 id="tmp-trash-heading">Corbeille</h2>
|
|
<p class="cleanup-section-desc">Fichiers retirés d'un TFE. Ceux marqués « Restaurable » peuvent être remis dans le TFE d'origine ; les autres sont orphelins (plus aucun TFE lié). La suppression est définitive et sans retour.</p>
|
|
<p class="cleanup-stat-card"><?= htmlspecialchars($trMeta) ?></p>
|
|
<table class="n-table" aria-labelledby="tmp-trash-heading">
|
|
<thead><tr><th width="1%"><input type="checkbox" onchange="cleanupToggleAll(this, 'trash')" title="Tout sélectionner"></th><th>Nom</th><th>Taille</th><th>Âge</th><th>Statut</th><th width="1%"></th></tr></thead>
|
|
<tbody>
|
|
<?php foreach ($allTrashFiles as $f): ?>
|
|
<tr<?= $f['_restorable'] ? ' class="trash-restorable-row"' : '' ?>>
|
|
<td><input type="checkbox" name="trash_files[]" value="<?= htmlspecialchars($f['name']) ?>" data-cleanup-group="trash"<?= $f['_restorable'] ? ' data-restorable="1"' : '' ?> onchange="cleanupUpdateBulk()"></td>
|
|
<td><strong><?= htmlspecialchars($f['name']) ?></strong></td>
|
|
<td style="white-space:nowrap"><?= htmlspecialchars($f['human']) ?></td>
|
|
<td style="white-space:nowrap">~<?= (int)$f['age_days'] ?> j</td>
|
|
<td>
|
|
<?php if ($f['_restorable']): ?>
|
|
<span style="font-size:0.85em;color:var(--accent-green)" title="<?= htmlspecialchars($f['original_name'] ?? '') ?>">↺ Restaurable</span>
|
|
<?php else: ?>
|
|
<span style="font-size:0.85em;color:var(--text-secondary)">Orphelin</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td style="white-space:nowrap">
|
|
<?php if ($f['_restorable']): ?>
|
|
<button type="button" class="btn btn--sm"
|
|
style="font-size:0.85em;padding:2px var(--space-xs);margin-right:4px"
|
|
title="Restaurer ce fichier vers le TFE associé"
|
|
hx-post="/admin/actions/restore-trash.php"
|
|
hx-confirm="Restaurer ce fichier vers le TFE associé ?"
|
|
hx-vals='{"csrf_token":"<?= htmlspecialchars($_SESSION['csrf_token']) ?>","trash_file":"<?= htmlspecialchars($f['name']) ?>"}'
|
|
hx-target="#tmp-cleanup-stats-wrapper"
|
|
hx-swap="innerHTML"
|
|
hx-indicator="#tmp-cleanup-stats-wrapper">
|
|
↺ Restaurer
|
|
</button>
|
|
<?php endif; ?>
|
|
<button type="button" class="btn btn--sm btn--danger"
|
|
style="font-size:0.85em;padding:2px var(--space-xs)"
|
|
title="Supprimer définitivement ce fichier de la corbeille (irréversible)"
|
|
hx-post="/admin/actions/cleanup-tmp.php"
|
|
hx-confirm="Supprimer définitivement ce fichier de la corbeille ?"
|
|
hx-vals='{"csrf_token":"<?= htmlspecialchars($_SESSION['csrf_token']) ?>","trash_file":"<?= htmlspecialchars($f['name']) ?>"}'
|
|
hx-target="#tmp-cleanup-stats-wrapper"
|
|
hx-swap="innerHTML"
|
|
hx-indicator="#tmp-cleanup-stats-wrapper">
|
|
<?= icon('trash') ?>
|
|
Supprimer
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</section>
|
|
<?php endif; ?>
|
|
|