diff --git a/_delete_person.php b/_delete_person.php index 2b824f5..fd29201 100644 --- a/_delete_person.php +++ b/_delete_person.php @@ -2,15 +2,50 @@ require_once 'db/config.php'; session_start(); +header('Content-Type: application/json'); + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + if (isset($_POST['person_id'])) { + $id = $_POST['person_id']; + + try { + $pdo = db(); + $stmt = $pdo->prepare("DELETE FROM people WHERE id = ?"); + $stmt->execute([$id]); + + if ($stmt->rowCount() > 0) { + echo json_encode(['success' => true, 'message' => 'Osoba usunięta pomyślnie.']); + } else { + http_response_code(404); + echo json_encode(['success' => false, 'error' => 'Nie znaleziono osoby.']); + } + } catch (PDOException $e) { + http_response_code(500); + // Log the real error to a secure log file + error_log("Database error on person delete: " . $e->getMessage()); + // Send a generic error message to the client + echo json_encode(['success' => false, 'error' => 'Błąd serwera podczas usuwania osoby.']); + } + exit; + } + http_response_code(400); + echo json_encode(['success' => false, 'error' => 'Brak ID osoby.']); + exit; +} + +// Keep GET for backwards compatibility or simple cases, but it redirects. if (isset($_GET['id'])) { $id = $_GET['id']; - + $pdo = db(); $stmt = $pdo->prepare("DELETE FROM people WHERE id = ?"); $stmt->execute([$id]); - + $_SESSION['success_message'] = 'Osoba usunięta pomyślnie.'; header('Location: persons.php'); exit; } + +http_response_code(405); +echo json_encode(['success' => false, 'error' => 'Nieprawidłowa metoda żądania.']); ?> \ No newline at end of file diff --git a/index.php b/index.php index c4db48c..2daba49 100644 --- a/index.php +++ b/index.php @@ -227,11 +227,11 @@ $status_colors = [
- +
- +
@@ -274,7 +274,7 @@ $status_colors = [
- +
@@ -355,11 +355,11 @@ $status_colors = [
- +
- +
@@ -403,7 +403,7 @@ $status_colors = [
- +
@@ -512,7 +512,7 @@ document.addEventListener('DOMContentLoaded', function () { var modalBody = instanceModal.querySelector('.modal-body'); // Load content via AJAX - fetch(`_get_instance_details.php?personId=${personId}&processId=${processId}`) + fetch(`_get_instance_details.php?person_id=${personId}&process_id=${processId}`) .then(response => response.text()) .then(html => { modalBody.innerHTML = html; @@ -565,10 +565,10 @@ document.addEventListener('DOMContentLoaded', function () { .then(response => response.json()) .then(data => { document.getElementById('editPersonId').value = data.person.id; - document.getElementById('editFirstName').value = data.person.firstName; - document.getElementById('editLastName').value = data.person.lastName; + document.getElementById('editFirstName').value = data.person.first_name; + document.getElementById('editLastName').value = data.person.last_name; document.getElementById('editEmail').value = data.person.email; - document.getElementById('editCompanyName').value = data.person.companyName; + document.getElementById('editCompanyName').value = data.person.company_name; document.getElementById('editPhone').value = data.person.phone; document.getElementById('editRole').value = data.person.role; document.getElementById('editBniGroup').value = data.person.bni_group_id || '';