FIX DRXGVIOER GIUVDSRGH RSHJGNKJE5NGUIOFNJBDKJBGDSHBGUDS BGJBDSXC VBYNUI?
This commit is contained in:
+22
-14
@@ -1,24 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once 'db.php';
|
require_once 'db.php';
|
||||||
|
session_start(); // Obligatoire si tu veux toucher aux sessions
|
||||||
header('Content-Type: application/json');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
// On récupère l'ID envoyé en POST, sinon on prend la dernière partie créée
|
// 1. Récupérer l'ID envoyé par le JavaScript ($_POST)
|
||||||
$game_id = isset($_SESSION['game_id']) ? $_SESSION['game_id'] : null;
|
$game_id = isset($_POST['game_id']) ? intval($_POST['game_id']) : null;
|
||||||
log("ID de la partie à supprimer : " . $game_id);
|
|
||||||
|
|
||||||
if ($game_id) {
|
if ($game_id) {
|
||||||
|
try {
|
||||||
|
// Supprimer les joueurs associés d'abord (intégrité BDD)
|
||||||
|
$stmt = $db->prepare("DELETE FROM players WHERE game_id = ?");
|
||||||
|
$stmt->execute([$game_id]);
|
||||||
|
|
||||||
|
// Supprimer la partie
|
||||||
$stmt = $db->prepare("DELETE FROM games WHERE id = ?");
|
$stmt = $db->prepare("DELETE FROM games WHERE id = ?");
|
||||||
$stmt->execute([$game_id]);
|
$stmt->execute([$game_id]);
|
||||||
|
|
||||||
// Supprimer les joueurs associés à la partie
|
// Nettoyer la session si besoin
|
||||||
$stmt = $db->prepare("DELETE FROM players WHERE game_id = ?");
|
if (isset($_SESSION['game_id']) && $_SESSION['game_id'] == $game_id) {
|
||||||
$stmt->execute([$game_id]);
|
unset($_SESSION['game_id']);
|
||||||
} else {
|
}
|
||||||
echo "Aucune partie à supprimer.";
|
|
||||||
exit;
|
echo json_encode(['success' => true]);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo json_encode(['success' => false, 'message' => $e->getMessage()]);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
echo "La partie a bien été supprimée de la table poker_paf.";
|
echo json_encode(['success' => false, 'message' => 'ID de partie manquant.']);
|
||||||
|
}
|
||||||
|
exit;
|
||||||
?>
|
?>
|
||||||
+19
-3
@@ -308,11 +308,27 @@ foreach ($players as $p) {
|
|||||||
function deleteGame() {
|
function deleteGame() {
|
||||||
if (confirm("Supprimer la partie ?")) {
|
if (confirm("Supprimer la partie ?")) {
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
|
// On s'assure que actualGameID est bien défini
|
||||||
formData.append('game_id', actualGameID);
|
formData.append('game_id', actualGameID);
|
||||||
console.log("Suppression de la partie ID:", actualGameID);
|
|
||||||
|
|
||||||
fetch('delete_game.php', { method: 'POST', body: formData })
|
fetch('delete_game.php', {
|
||||||
.then(() => window.location.href = 'index.php');
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
})
|
||||||
|
.then(r => r.json()) // On parse la réponse JSON du PHP
|
||||||
|
.then(data => {
|
||||||
|
if (data.success) {
|
||||||
|
console.log("Supprimé !");
|
||||||
|
window.location.href = 'index.php';
|
||||||
|
} else {
|
||||||
|
alert("Erreur lors de la suppression : " + data.message);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error("Erreur réseau :", err);
|
||||||
|
// Optionnel : rediriger quand même si tu veux forcer
|
||||||
|
// window.location.href = 'index.php';
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user