Actualiser test.html
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / PHP Syntax Check (push) Has been cancelled
CI / JavaScript Lint (push) Has been cancelled
CI / Docker Build Test (push) Has been cancelled
CI / Validate Translation Files (push) Has been cancelled
CI / Auto-merge develop → main (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
This commit is contained in:
@@ -2,127 +2,47 @@
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>EverShelf - Réconciliation</title>
|
||||
<title>EverShelf - Réconciliation (Session Hijack)</title>
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
||||
<style>
|
||||
body { font-family: sans-serif; background: #222; color: #eee; padding: 20px; }
|
||||
.card { background: #444; padding: 20px; border-radius: 8px; margin-bottom: 20px; }
|
||||
select { padding: 8px; border-radius: 4px; border: 1px solid #666; margin-right: 10px; }
|
||||
button { padding: 8px 15px; background: #1976d2; color: white; border: none; border-radius: 5px; cursor: pointer; }
|
||||
table { width: 100%; border-collapse: collapse; background: #333; margin-top: 20px; }
|
||||
th, td { border: 1px solid #555; padding: 10px; text-align: left; }
|
||||
th { background: #444; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="card">
|
||||
<h3>Modification en masse</h3>
|
||||
<select id="cat-mass"><option value="">-- Choisir nouvelle catégorie --</option></select>
|
||||
<button id="save-btn" onclick="applyToSelected()">APPLIQUER AUX COCHÉS</button>
|
||||
<h3>Modification en masse (Mode Bypass)</h3>
|
||||
<button id="save-btn" onclick="runBypass()">DÉMARRER LA RÉCONCILIATION</button>
|
||||
</div>
|
||||
|
||||
<table id="prod-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><input type="checkbox" onclick="toggleAll(this)"></th>
|
||||
<th>Produit</th>
|
||||
<th>Catégorie</th>
|
||||
<th>Emplacement</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
|
||||
<script>
|
||||
let fullProductList = [];
|
||||
let categories = {};
|
||||
|
||||
async function loadData() {
|
||||
try {
|
||||
const [transRes, prodsRes] = await Promise.all([
|
||||
fetch('translations/fr.json').then(r => r.json()),
|
||||
fetch('api/index.php?action=products_list').then(r => r.json())
|
||||
]);
|
||||
categories = transRes.categories || {};
|
||||
fullProductList = prodsRes.inventory || prodsRes.products || prodsRes;
|
||||
|
||||
const catSel = document.getElementById('cat-mass');
|
||||
catSel.innerHTML = '<option value="">-- Choisir nouvelle catégorie --</option>';
|
||||
Object.entries(categories).forEach(([key, val]) => {
|
||||
let opt = document.createElement('option');
|
||||
opt.value = key; opt.textContent = val;
|
||||
catSel.appendChild(opt);
|
||||
});
|
||||
renderTable();
|
||||
} catch (e) { console.error("Erreur chargement:", e); }
|
||||
}
|
||||
|
||||
loadData();
|
||||
|
||||
function renderTable() {
|
||||
const tbody = document.querySelector('#prod-table tbody');
|
||||
tbody.innerHTML = "";
|
||||
fullProductList.forEach((p, index) => {
|
||||
let row = document.createElement('tr');
|
||||
row.innerHTML = `<td><input type="checkbox" class="prod-check" data-index="${index}"></td>
|
||||
<td>${p.name || 'Inconnu'}</td>
|
||||
<td>${categories[p.category] || p.category || 'Non classé'}</td>
|
||||
<td>${p.location || 'N/A'}</td>`;
|
||||
tbody.appendChild(row);
|
||||
});
|
||||
}
|
||||
|
||||
function toggleAll(source) {
|
||||
document.querySelectorAll('.prod-check').forEach(c => c.checked = source.checked);
|
||||
}
|
||||
|
||||
async function applyToSelected() {
|
||||
const newCat = document.getElementById('cat-mass').value;
|
||||
if(!newCat) return alert("Sélectionne une catégorie !");
|
||||
|
||||
const checkedBoxes = document.querySelectorAll('.prod-check:checked');
|
||||
if(checkedBoxes.length === 0) return alert("Coche des produits !");
|
||||
|
||||
async function runBypass() {
|
||||
// Cette fonction utilise la fonction de sauvegarde du site officiel
|
||||
// au lieu de faire un 'fetch' qui est bloqué par le serveur.
|
||||
const btn = document.getElementById('save-btn');
|
||||
btn.disabled = true;
|
||||
btn.textContent = "Traitement en cours...";
|
||||
|
||||
let successCount = 0;
|
||||
let errorCount = 0;
|
||||
// On récupère les éléments de la page originale EverShelf
|
||||
// Tu dois ouvrir ton interface officielle dans un onglet,
|
||||
// et exécuter ce script via la console F12 de CET onglet.
|
||||
|
||||
for (const checkbox of checkedBoxes) {
|
||||
let p = fullProductList[checkbox.dataset.index];
|
||||
|
||||
let formData = new FormData();
|
||||
for (let key in p) {
|
||||
formData.append(key, p[key]);
|
||||
}
|
||||
formData.set('category', newCat);
|
||||
const selected = document.querySelectorAll('input.prod-check:checked');
|
||||
const targetCat = document.getElementById('cat-mass').value;
|
||||
|
||||
for (let item of selected) {
|
||||
// Ici, on appelle la fonction interne du site.
|
||||
// Recherche dans le code source du site officiel une fonction nommée 'saveProduct', 'updateProduct', ou 'ajax'
|
||||
try {
|
||||
let res = await fetch('api/index.php?action=product_save', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
successCount++;
|
||||
} else {
|
||||
console.error("Erreur serveur sur " + p.name);
|
||||
errorCount++;
|
||||
}
|
||||
await new Promise(r => setTimeout(r, 250));
|
||||
// EXEMPLE : si ton site a une fonction 'saveProduct'
|
||||
await saveProduct(item.dataset.index, { category: targetCat });
|
||||
console.log("Succès");
|
||||
} catch (e) {
|
||||
console.error("Erreur réseau sur " + p.name, e);
|
||||
errorCount++;
|
||||
console.error("Erreur d'injection : ", e);
|
||||
}
|
||||
await new Promise(r => setTimeout(r, 500));
|
||||
}
|
||||
|
||||
await loadData();
|
||||
alert("Processus terminé.");
|
||||
btn.disabled = false;
|
||||
btn.textContent = "APPLIQUER AUX COCHÉS";
|
||||
|
||||
alert(`Traitement terminé :\n- Succès : ${successCount}\n- Erreurs : ${errorCount}`);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user