242 lines
12 KiB
PHP
Executable File
242 lines
12 KiB
PHP
Executable File
<?php
|
|
$pdo = new PDO("pgsql:host=localhost;dbname=adx_system", "admin", "admin123");
|
|
|
|
$dirs = [
|
|
'user' => ['path' => '/opt/wevads/public/uploads/user-uploads/', 'url' => '/uploads/user-uploads/', 'label' => '📤 Mes Uploads'],
|
|
'ia' => ['path' => '/opt/wevads/public/uploads/ia-generated/', 'url' => '/uploads/ia-generated/', 'label' => '🤖 Générés par IA'],
|
|
'commonia' => ['path' => '/opt/wevads/public/uploads/commonia/', 'url' => '/uploads/commonia/', 'label' => '📁 Legacy']
|
|
];
|
|
|
|
foreach ($dirs as $d) { if (!is_dir($d['path'])) @mkdir($d['path'], 0755, true); }
|
|
|
|
$message = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
|
$file = $_FILES['file'];
|
|
$dest = $_POST['destination'] ?? 'user';
|
|
if ($file['error'] === UPLOAD_ERR_OK) {
|
|
$ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
|
|
$allowed = ['pdf','doc','docx','txt','md','csv','json','xml','html','jpg','jpeg','png','gif','webp','svg','zip','py','php','js','css','sql','xlsx','pptx'];
|
|
if (in_array($ext, $allowed)) {
|
|
$newName = date('Ymd_His') . '_' . preg_replace('/[^a-zA-Z0-9._-]/', '_', $file['name']);
|
|
$targetDir = $dest === 'ia' ? $dirs['ia']['path'] : $dirs['user']['path'];
|
|
if (move_uploaded_file($file['tmp_name'], $targetDir . $newName)) {
|
|
$message = "✅ Fichier uploadé: $newName";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (isset($_GET['delete']) && isset($_GET['dir'])) {
|
|
$f = basename($_GET['delete']); $d = $_GET['dir'];
|
|
if (isset($dirs[$d]) && file_exists($dirs[$d]['path'] . $f)) { unlink($dirs[$d]['path'] . $f); $message = "🗑️ Supprimé: $f"; }
|
|
}
|
|
|
|
if (isset($_GET['download']) && isset($_GET['dir'])) {
|
|
$f = basename($_GET['download']); $d = $_GET['dir'];
|
|
if (isset($dirs[$d]) && file_exists($dirs[$d]['path'] . $f)) {
|
|
header('Content-Type: application/octet-stream');
|
|
header('Content-Disposition: attachment; filename="' . $f . '"');
|
|
readfile($dirs[$d]['path'] . $f); exit;
|
|
}
|
|
}
|
|
|
|
function getFiles($dir, $url) {
|
|
$files = [];
|
|
if (is_dir($dir)) {
|
|
foreach (scandir($dir) as $item) {
|
|
if ($item === '.' || $item === '..') continue;
|
|
$fullPath = $dir . $item;
|
|
if (is_file($fullPath)) {
|
|
$ext = strtolower(pathinfo($item, PATHINFO_EXTENSION));
|
|
$files[] = ['name' => $item, 'size' => filesize($fullPath), 'date' => filemtime($fullPath), 'ext' => $ext, 'path' => $url . $item, 'type' => getFileType($ext)];
|
|
}
|
|
}
|
|
}
|
|
usort($files, fn($a, $b) => $b['date'] - $a['date']);
|
|
return $files;
|
|
}
|
|
|
|
function getFileType($ext) {
|
|
$types = ['image' => ['jpg','jpeg','png','gif','webp','svg'], 'document' => ['pdf','doc','docx','txt','md'], 'data' => ['csv','json','xml','xlsx'], 'code' => ['php','js','py','html','css','sql']];
|
|
foreach ($types as $type => $exts) { if (in_array($ext, $exts)) return $type; }
|
|
return 'other';
|
|
}
|
|
|
|
function formatSize($bytes) {
|
|
if ($bytes >= 1048576) return round($bytes / 1048576, 2) . ' MB';
|
|
if ($bytes >= 1024) return round($bytes / 1024, 2) . ' KB';
|
|
return $bytes . ' B';
|
|
}
|
|
|
|
function getIcon($type) { return ['image' => '🖼️', 'document' => '📄', 'data' => '📊', 'code' => '💻'][$type] ?? '📁'; }
|
|
|
|
$userFiles = getFiles($dirs['user']['path'], $dirs['user']['url']);
|
|
$iaFiles = getFiles($dirs['ia']['path'], $dirs['ia']['url']);
|
|
$legacyFiles = getFiles($dirs['commonia']['path'], $dirs['commonia']['url']);
|
|
|
|
$stats = [
|
|
'user' => ['count' => count($userFiles), 'size' => array_sum(array_column($userFiles, 'size'))],
|
|
'ia' => ['count' => count($iaFiles), 'size' => array_sum(array_column($iaFiles, 'size'))],
|
|
'legacy' => ['count' => count($legacyFiles), 'size' => array_sum(array_column($legacyFiles, 'size'))]
|
|
];
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>📁 Documents IA - WEVAL</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
|
|
<link href="/assets/css/ia-theme.css" rel="stylesheet">
|
|
|
|
</head>
|
|
<body>
|
|
<div class="container-fluid py-4">
|
|
<div class="ia-header d-flex justify-content-between align-items-center mb-4">
|
|
<h4 class="mb-0"><i class="fas fa-folder-open"></i> Documents IA</h4>
|
|
<div>
|
|
<a href="/ia-index.php" class="btn btn-outline-light btn-sm">📋 Index</a>
|
|
<a href="/hamid-fullscreen.php" class="btn btn-outline-light btn-sm">💬 Chat</a>
|
|
<a href="/ia-tools-test.php" class="btn btn-outline-light btn-sm">🛠️ Tools</a>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-success"><?= htmlspecialchars($message) ?></div>
|
|
<?php endif; ?>
|
|
|
|
<div class="row g-3 mb-4">
|
|
<div class="col-6 col-md-3">
|
|
<div class="stat-card primary">
|
|
<div class="stat-number" style="color: var(--wevads-accent);"><?= $stats['user']['count'] ?></div>
|
|
<div class="stat-label">📤 Mes Uploads</div>
|
|
<small class="text-muted"><?= formatSize($stats['user']['size']) ?></small>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-3">
|
|
<div class="stat-card success">
|
|
<div class="stat-number" style="color: var(--wevads-secondary);"><?= $stats['ia']['count'] ?></div>
|
|
<div class="stat-label">🤖 Générés par IA</div>
|
|
<small class="text-muted"><?= formatSize($stats['ia']['size']) ?></small>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-3">
|
|
<div class="stat-card purple">
|
|
<div class="stat-number" style="color: var(--wevads-purple);"><?= $stats['legacy']['count'] ?></div>
|
|
<div class="stat-label">📁 Legacy</div>
|
|
<small class="text-muted"><?= formatSize($stats['legacy']['size']) ?></small>
|
|
</div>
|
|
</div>
|
|
<div class="col-6 col-md-3">
|
|
<div class="stat-card accent">
|
|
<div class="stat-number" style="color: var(--wevads-primary);"><?= $stats['user']['count'] + $stats['ia']['count'] + $stats['legacy']['count'] ?></div>
|
|
<div class="stat-label">📊 Total</div>
|
|
<small class="text-muted"><?= formatSize($stats['user']['size'] + $stats['ia']['size'] + $stats['legacy']['size']) ?></small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-lg-3 mb-4">
|
|
<div class="card p-3">
|
|
<h6><i class="fas fa-cloud-upload-alt text-primary"></i> Upload</h6>
|
|
<form method="POST" enctype="multipart/form-data" id="uploadForm">
|
|
<div class="upload-zone" onclick="document.getElementById('fileInput').click()">
|
|
<i class="fas fa-cloud-upload-alt fa-2x mb-2 text-primary"></i>
|
|
<p class="mb-0 small text-muted">Glissez ou cliquez</p>
|
|
<input type="file" name="file" id="fileInput" style="display:none" onchange="this.form.submit()">
|
|
</div>
|
|
<div class="d-flex gap-2 mt-2">
|
|
<button type="button" class="btn btn-sm btn-outline-primary flex-fill dest-btn active" onclick="setDest('user', this)">📤 Upload</button>
|
|
<button type="button" class="btn btn-sm btn-outline-success flex-fill dest-btn" onclick="setDest('ia', this)">🤖 IA</button>
|
|
</div>
|
|
<input type="hidden" name="destination" id="destination" value="user">
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-lg-9">
|
|
<div class="d-flex gap-2 mb-3 flex-wrap">
|
|
<button class="tab-btn active" onclick="showTab('all', this)">📊 Tous</button>
|
|
<button class="tab-btn" onclick="showTab('user', this)">📤 Mes Uploads (<?= $stats['user']['count'] ?>)</button>
|
|
<button class="tab-btn" onclick="showTab('ia', this)">🤖 Générés IA (<?= $stats['ia']['count'] ?>)</button>
|
|
<button class="tab-btn" onclick="showTab('legacy', this)">📁 Legacy (<?= $stats['legacy']['count'] ?>)</button>
|
|
</div>
|
|
|
|
<input type="text" class="search-box mb-3" id="searchInput" placeholder="🔍 Rechercher un fichier..." onkeyup="filterFiles()">
|
|
|
|
<div id="filesList">
|
|
<?php
|
|
$allFiles = [];
|
|
foreach ($userFiles as $f) { $f['source'] = 'user'; $f['dir'] = 'user'; $allFiles[] = $f; }
|
|
foreach ($iaFiles as $f) { $f['source'] = 'ia'; $f['dir'] = 'ia'; $allFiles[] = $f; }
|
|
foreach ($legacyFiles as $f) { $f['source'] = 'legacy'; $f['dir'] = 'commonia'; $allFiles[] = $f; }
|
|
usort($allFiles, fn($a, $b) => $b['date'] - $a['date']);
|
|
|
|
if (empty($allFiles)): ?>
|
|
<div class="empty-state">
|
|
<i class="fas fa-folder-open"></i>
|
|
<h5>Aucun fichier</h5>
|
|
<p>Uploadez des fichiers ou utilisez l'IA pour en générer</p>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($allFiles as $file): ?>
|
|
<div class="file-card source-<?= $file['source'] ?>" data-name="<?= strtolower($file['name']) ?>" data-source="<?= $file['source'] ?>">
|
|
<div class="d-flex align-items-center">
|
|
<div class="me-3" style="font-size: 1.5rem; min-width: 40px; text-align: center;">
|
|
<?php if ($file['type'] === 'image'): ?>
|
|
<img src="<?= htmlspecialchars($file['path']) ?>" style="max-width: 40px; max-height: 40px; border-radius: 4px;" alt="">
|
|
<?php else: ?>
|
|
<?= getIcon($file['type']) ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="flex-grow-1">
|
|
<div class="file-name"><?= htmlspecialchars($file['name']) ?></div>
|
|
<div class="file-meta">
|
|
<span class="badge badge-<?= $file['source'] === 'user' ? 'accent' : ($file['source'] === 'ia' ? 'success' : 'primary') ?>"><?= $file['source'] === 'user' ? '📤 Upload' : ($file['source'] === 'ia' ? '🤖 IA' : '📁 Legacy') ?></span>
|
|
<span class="badge badge-primary"><?= strtoupper($file['ext']) ?></span>
|
|
<?= formatSize($file['size']) ?> • <?= date('d/m/Y H:i', $file['date']) ?>
|
|
</div>
|
|
</div>
|
|
<div class="d-flex gap-1">
|
|
<?php if ($file['type'] === 'image'): ?>
|
|
<a href="<?= htmlspecialchars($file['path']) ?>" target="_blank" class="btn btn-action btn-view"><i class="fas fa-eye"></i></a>
|
|
<?php endif; ?>
|
|
<a href="?download=<?= urlencode($file['name']) ?>&dir=<?= $file['dir'] ?>" class="btn btn-action btn-download"><i class="fas fa-download"></i></a>
|
|
<a href="?delete=<?= urlencode($file['name']) ?>&dir=<?= $file['dir'] ?>" class="btn btn-action btn-delete" onclick="return confirm('Supprimer ?')"><i class="fas fa-trash"></i></a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
function setDest(dest, btn) {
|
|
document.getElementById('destination').value = dest;
|
|
document.querySelectorAll('.dest-btn').forEach(b => b.classList.remove('active'));
|
|
btn.classList.add('active');
|
|
}
|
|
|
|
function showTab(tab, btn) {
|
|
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
|
|
btn.classList.add('active');
|
|
document.querySelectorAll('.file-card').forEach(card => {
|
|
card.style.display = (tab === 'all' || card.dataset.source === tab) ? 'block' : 'none';
|
|
});
|
|
}
|
|
|
|
function filterFiles() {
|
|
const search = document.getElementById('searchInput').value.toLowerCase();
|
|
document.querySelectorAll('.file-card').forEach(card => {
|
|
card.style.display = card.dataset.name.includes(search) ? 'block' : 'none';
|
|
});
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|