getConnection(); // Recupera l'ID dell'utente loggato $user_id = $iduserlogin ?? 1; // Gestione creazione nuova quotation (crea record vuoto su conferma) if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'create') { $description = ''; $customer = ''; try { $stmt = $pdo->prepare("INSERT INTO quotations (description, customer, iduser) VALUES (?, ?, ?)"); $success = $stmt->execute([$description, $customer, $user_id]); if ($success) { $newId = $pdo->lastInsertId(); error_log("Creata nuova quotation ID: $newId"); header("Location: quotations.php?edit_id=" . $newId . "&status=success&message=" . urlencode("Quotation creata con successo")); } else { error_log("Errore: Impossibile creare la quotation, nessun ID generato."); header("Location: quotations.php?status=error&message=" . urlencode("Errore durante la creazione della quotation")); } } catch (PDOException $e) { error_log("Errore PDO durante la creazione della quotation: " . $e->getMessage()); header("Location: quotations.php?status=error&message=" . urlencode("Errore database: " . $e->getMessage())); } exit; } // Gestione modifica quotation if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'update' && isset($_POST['id'])) { $id = intval($_POST['id']); $description = $_POST['description'] ?? ''; $customer = $_POST['customer'] ?? ''; try { $stmt = $pdo->prepare("UPDATE quotations SET description = ?, customer = ? WHERE id = ? AND iduser = ?"); $stmt->execute([$description, $customer, $id, $user_id]); error_log("Modificata quotation ID: $id"); header("Location: quotations.php?status=success&message=" . urlencode("Quotation modificata con successo")); } catch (PDOException $e) { error_log("Errore PDO durante la modifica della quotation: " . $e->getMessage()); header("Location: quotations.php?status=error&message=" . urlencode("Errore database: " . $e->getMessage())); } exit; } // Gestione cancellazione quotation if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete' && isset($_POST['id'])) { $id = intval($_POST['id']); try { $stmt = $pdo->prepare("DELETE FROM quotations WHERE id = ? AND iduser = ?"); $stmt->execute([$id, $user_id]); error_log("Cancellata quotation ID: $id"); header("Location: quotations.php?status=success&message=" . urlencode("Quotation cancellata con successo")); } catch (PDOException $e) { error_log("Errore PDO durante la cancellazione della quotation: " . $e->getMessage()); header("Location: quotations.php?status=error&message=" . urlencode("Errore database: " . $e->getMessage())); } exit; } // Recupera tutte le quotations per l'utente try { $stmt = $pdo->prepare("SELECT * FROM quotations WHERE iduser = ? ORDER BY creation_date DESC"); $stmt->execute([$user_id]); $quotations = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (PDOException $e) { error_log("Errore PDO durante il recupero delle quotations: " . $e->getMessage()); $quotations = []; } // Verifica se è richiesta la modifica di una quotation $editQuotation = null; if (isset($_GET['edit_id'])) { $editId = intval($_GET['edit_id']); try { $stmt = $pdo->prepare("SELECT * FROM quotations WHERE id = ? AND iduser = ?"); $stmt->execute([$editId, $user_id]); $editQuotation = $stmt->fetch(PDO::FETCH_ASSOC); if (!$editQuotation) { error_log("Nessuna quotation trovata per id: $editId"); } } catch (PDOException $e) { error_log("Errore PDO durante il recupero della quotation per modifica: " . $e->getMessage()); $editQuotation = null; } } ?> Gestione Quotations - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?>
Gestione Quotations
Modifica Quotation ID:
Torna alla Lista
Azioni
Quotations Esistenti
$row): ?>
ID Data Creazione Descrizione Cliente Azioni