mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
refactor: Admin index — replace emoji buttons with Phosphor SVG icons, add back buttons + row click navigation, minimal JS, move export DB to Exporter modal, color stats, bulk bar anti-shift, credits reorder, tags icons
This commit is contained in:
98
app/public/admin/actions/export.php
Normal file
98
app/public/admin/actions/export.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Unified export dispatcher.
|
||||
*
|
||||
* Query params:
|
||||
* csv=1 — export CSV
|
||||
* files=1 — export ZIP of files
|
||||
*
|
||||
* If both are requested, CSV is streamed first (as a download) then the ZIP.
|
||||
* In practice, browsers handle this as two sequential downloads.
|
||||
*/
|
||||
require_once __DIR__ . "/../../../bootstrap.php";
|
||||
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
require_once APP_ROOT . '/src/Controllers/ExportController.php';
|
||||
require_once APP_ROOT . '/src/AdminLogger.php';
|
||||
|
||||
$doCsv = !empty($_GET['csv']);
|
||||
$doFiles = !empty($_GET['files']);
|
||||
$doDb = !empty($_GET['db']);
|
||||
|
||||
if (!$doCsv && !$doFiles && !$doDb) {
|
||||
$doCsv = true;
|
||||
}
|
||||
|
||||
$controller = ExportController::create();
|
||||
|
||||
if ($doCsv) {
|
||||
AdminLogger::make()->logCsvExport();
|
||||
|
||||
$filename = 'xamxam-export-' . date('Y-m-d') . '.csv';
|
||||
|
||||
header('Content-Type: text/csv; charset=UTF-8');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
|
||||
echo "\xEF\xBB\xBF";
|
||||
|
||||
$out = fopen('php://output', 'w');
|
||||
fputcsv($out, ExportController::CSV_HEADERS, ',', '"', '');
|
||||
$rows = $controller->exportAllTheses();
|
||||
foreach ($rows as $csvLine) {
|
||||
fputcsv($out, $csvLine, ',', '"', '');
|
||||
}
|
||||
fclose($out);
|
||||
|
||||
// If only CSV, we're done
|
||||
if (!$doFiles) {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ($doFiles) {
|
||||
try {
|
||||
$zipPath = $controller->createExportZip();
|
||||
$fileSize = filesize($zipPath);
|
||||
$fileCount = count($controller->getAllThesisFiles());
|
||||
|
||||
AdminLogger::make()->logFilesExport($fileCount, (int)$fileSize);
|
||||
|
||||
$filename = 'xamxam-files-' . date('Y-m-d') . '.zip';
|
||||
|
||||
header('Content-Type: application/zip');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
header('Content-Length: ' . $fileSize);
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
|
||||
readfile($zipPath);
|
||||
@unlink($zipPath);
|
||||
} catch (Exception $e) {
|
||||
error_log('Files export error: ' . $e->getMessage());
|
||||
http_response_code(500);
|
||||
exit('Erreur lors de la création de l\'archive : ' . htmlspecialchars($e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
if ($doDb) {
|
||||
$dbPath = $controller->getDatabasePath();
|
||||
|
||||
if (!file_exists($dbPath)) {
|
||||
http_response_code(500);
|
||||
exit('Base de données introuvable.');
|
||||
}
|
||||
|
||||
$filename = 'xamxam-db-' . date('Y-m-d') . '.sqlite';
|
||||
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
header('Content-Length: ' . filesize($dbPath));
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
|
||||
AdminLogger::make()->logDbExport();
|
||||
|
||||
readfile($dbPath);
|
||||
}
|
||||
|
||||
exit;
|
||||
@@ -403,14 +403,8 @@ try {
|
||||
$filters['sort'] = $sortCol;
|
||||
$filters['dir'] = $sortDir;
|
||||
|
||||
$perPage = 25;
|
||||
$page = isset($_GET['page']) ? max(1, intval($_GET['page'])) : 1;
|
||||
$totalCount = $db->getThesesListCount($filters);
|
||||
$totalPages = $totalCount > 0 ? (int) ceil($totalCount / $perPage) : 1;
|
||||
$page = min($page, $totalPages);
|
||||
$offset = ($page - 1) * $perPage;
|
||||
|
||||
$theses = $db->getThesesList($filters, $perPage, $offset);
|
||||
$theses = $db->getThesesList($filters, 0, 0);
|
||||
$totalCount = count($theses);
|
||||
$stats = $db->getThesesStats();
|
||||
$years = $db->getAllYears();
|
||||
$orientations = $db->getAllOrientations();
|
||||
@@ -420,9 +414,14 @@ try {
|
||||
die("Erreur lors du chargement de la liste.");
|
||||
}
|
||||
|
||||
$isHtmx = ($_SERVER['HTTP_HX_REQUEST'] ?? '') === 'true';
|
||||
$isAdmin = true; $bodyClass = 'admin-body';
|
||||
require_once APP_ROOT . '/templates/head.php';
|
||||
include APP_ROOT . '/templates/header.php';
|
||||
include APP_ROOT . '/templates/admin/index.php';
|
||||
require_once APP_ROOT . '/templates/admin/footer.php';
|
||||
if ($isHtmx) {
|
||||
include APP_ROOT . '/templates/admin/index-table.php';
|
||||
} else {
|
||||
require_once APP_ROOT . '/templates/head.php';
|
||||
include APP_ROOT . '/templates/header.php';
|
||||
include APP_ROOT . '/templates/admin/index.php';
|
||||
require_once APP_ROOT . '/templates/admin/footer.php';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user