diff --git a/js/admin.js b/js/admin.js
index b938962..ed6f219 100644
--- a/js/admin.js
+++ b/js/admin.js
@@ -1,6 +1,6 @@
const API_URL = '../api.php';
let allItems = [];
-let currentAdminTab = 'videotheque'; // Défaut sur vidéothèque
+let currentAdminTab = 'videotheque'; // ✅ CORRIGÉ : Défaut sur vidéothèque
let currentPage = 1;
const itemsPerPage = 12;
let selectedIds = new Set();
@@ -56,7 +56,7 @@ function parseCSV(text) {
document.addEventListener('DOMContentLoaded', () => {
loadDashboardData();
initEventListeners();
- updateImportInterface(); // Mise à jour initiale de l'interface d'import
+ updateImportInterface();
const confirmBtn = document.getElementById('confirm-btn');
if (confirmBtn) {
@@ -389,6 +389,62 @@ async function saveFilmForm(e) {
} catch (err) { console.error(err); }
}
+// ✅ NOUVELLE FONCTION : Recherche par EAN pour la vidéothèque
+async function searchByEan() {
+ const eanInput = document.getElementById('f-ean');
+ const ean = eanInput ? eanInput.value.trim() : '';
+
+ if (!ean) {
+ alert('Veuillez entrer un code EAN/UPC');
+ return;
+ }
+
+ const searchBtn = document.getElementById('search-ean-btn');
+ if (searchBtn) {
+ searchBtn.disabled = true;
+ searchBtn.innerHTML = ' Recherche...';
+ }
+
+ try {
+ const res = await fetch(`${API_URL}?action=search_by_ean&ean=${encodeURIComponent(ean)}`, {
+ headers: { 'Authorization': localStorage.getItem('token') }
+ });
+
+ if (!res.ok) throw new Error(`Erreur HTTP ${res.status}`);
+
+ const data = await res.json();
+
+ if (!data.success) {
+ alert('❌ ' + (data.error || 'Film non trouvé'));
+ return;
+ }
+
+ // Remplir le formulaire avec les données trouvées
+ if (data.title) document.getElementById('f-title').value = data.title;
+ if (data.year) document.getElementById('f-year').value = data.year;
+ if (data.director) document.getElementById('f-director').value = data.director;
+ if (data.poster) document.getElementById('f-poster').value = data.poster;
+ if (data.format) document.getElementById('f-format').value = data.format;
+ if (data.length) document.getElementById('f-length').value = data.length;
+ if (data.publisher) document.getElementById('f-publisher').value = data.publisher;
+ if (data.number_of_discs) document.getElementById('f-discs').value = data.number_of_discs;
+ if (data.aspect_ratio) document.getElementById('f-aspect').value = data.aspect_ratio;
+ if (data.actors) document.getElementById('f-actors').value = data.actors;
+ if (data.description) document.getElementById('f-description').value = data.description;
+
+ alert('✅ Film trouvé ! Les informations ont été remplies.');
+
+ } catch (err) {
+ console.error(err);
+ alert('❌ Erreur lors de la recherche : ' + err.message);
+ } finally {
+ if (searchBtn) {
+ searchBtn.disabled = false;
+ searchBtn.innerHTML = ' Rechercher';
+ }
+ }
+}
+
async function handleCritiqueUpload(input) {
if (!input.files || input.files.length === 0) return;
let allData = [];
@@ -414,7 +470,7 @@ async function handleCritiqueUpload(input) {
loadDashboardData();
}
-// ✅ CORRECTION : Extrait TOUTES les métadonnées du CSV pour ne rien perdre
+// ✅ CORRECTION : Retourne TOUTES les données du CSV
function normalizeVideothequeRow(row) {
let ean = row['ean_isbn13'] || row['EAN'] || row['ean'] || row['Barcode'] || row['UPC'] || row['upc_isbn10'] || '';
if (ean) ean = String(ean).replace(/[^0-9]/g, '');
@@ -434,7 +490,7 @@ function normalizeVideothequeRow(row) {
length: row['length'] || '',
number_of_discs: row['number_of_discs'] || 1,
aspect_ratio: row['aspect_ratio'] || '',
- actors: row['creators'] || row['ensemble'] || '' // 'creators' contient le casting dans votre CSV
+ actors: row['creators'] || row['ensemble'] || ''
};
}
@@ -454,7 +510,6 @@ function handleVideothequeUpload(input) {
let processed = 0, totalImp = 0, totalSkp = 0;
try {
- // ✅ Envoi par lots de 5 pour que le throttle PHP fonctionne au sein du même script
const BATCH_SIZE = 5;
for (let i = 0; i < items.length; i += BATCH_SIZE) {
const batch = items.slice(i, i + BATCH_SIZE);
@@ -472,7 +527,7 @@ function handleVideothequeUpload(input) {
totalSkp += data.skipped || 0;
processed += batch.length;
updateImportModal(processed, items.length);
- await new Promise(r => setTimeout(r, 500)); // Petit délai réseau
+ await new Promise(r => setTimeout(r, 500));
}
input.value = '';
@@ -530,7 +585,6 @@ async function saveNewPassword() {
} catch (err) { console.error(err); }
}
-// ✅ SÉPARATION CLAIRE DES IMPORTS
function updateImportInterface() {
const title = document.getElementById('import-title');
const desc = document.getElementById('import-desc');