prepare("UPDATE pf_budget_items SET name=?, amount=?, category=?, type=?, payment_day=?, is_estimate=?, reg_month=?, mapping_keywords=? WHERE id=?"); $stmt->execute([$name, $amount, $category, $type, $payment_day, $is_estimate, $reg_month, $keywords, $id]); } else { // INSERT $stmt = $pdo->prepare("INSERT INTO pf_budget_items (name, amount, category, type, payment_day, is_estimate, reg_month, mapping_keywords) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$name, $amount, $category, $type, $payment_day, $is_estimate, $reg_month, $keywords]); } header('Location: /budget.php?tab=recap'); // Ou ta redirection habituelle exit; } // --- ACTION : COCHER/DÉCOCHER RAPIDE (VIA JS FETCH) --- if ($action === 'toggle-check') { $id = $_POST['id']; $status = $_POST['status']; // 1 ou 0 $sql = "UPDATE pf_budget_items SET is_checked = ? WHERE id = ?"; $stmt = $pdo->prepare($sql); $stmt->execute([$status, $id]); // On renvoie du JSON car c'est un appel JS (pas de redirection) header('Content-Type: application/json'); echo json_encode(['success' => true]); exit; } // --- ACTION : SUPPRIMER --- if ($action === 'delete') { $id = $_POST['id']; $pdo->prepare("DELETE FROM pf_budget_items WHERE id = ?")->execute([$id]); // On peut répondre en JSON pour le JS ou rediriger if (isset($_POST['ajax'])) { header('Content-Type: application/json'); echo json_encode(['success' => true]); } else { header('Location: /budget.php?tab=recap'); } exit; } }