diff --git a/public/userarea/quotations.php b/public/userarea/quotations.php new file mode 100644 index 0000000..ff8fff4 --- /dev/null +++ b/public/userarea/quotations.php @@ -0,0 +1,381 @@ +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 = ''; + + $stmt = $pdo->prepare("INSERT INTO quotations (description, customer, iduser) VALUES (?, ?, ?)"); + $stmt->execute([$description, $customer, $user_id]); + $newId = $pdo->lastInsertId(); + + // Log creazione + error_log("Creata nuova quotation ID: $newId"); + + // Reindirizza alla modifica della nuova quotation + header("Location: quotations.php?edit_id=" . $newId . "&status=success&message=" . urlencode("Quotation creata con successo")); + 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'] ?? ''; + + $stmt = $pdo->prepare("UPDATE quotations SET description = ?, customer = ? WHERE id = ? AND iduser = ?"); + $stmt->execute([$description, $customer, $id, $user_id]); + + // Log modifica + error_log("Modificata quotation ID: $id"); + + // Reindirizza alla lista delle quotations + header("Location: quotations.php?status=success&message=" . urlencode("Quotation modificata con successo")); + exit; +} + +// Gestione cancellazione quotation +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'delete' && isset($_POST['id'])) { + $id = intval($_POST['id']); + + $stmt = $pdo->prepare("DELETE FROM quotations WHERE id = ? AND iduser = ?"); + $stmt->execute([$id, $user_id]); + + // Log cancellazione + error_log("Cancellata quotation ID: $id"); + + header("Location: quotations.php?status=success&message=" . urlencode("Quotation cancellata con successo")); + exit; +} + +// Recupera tutte le quotations per l'utente +$stmt = $pdo->prepare("SELECT * FROM quotations WHERE iduser = ? ORDER BY creation_date DESC"); +$stmt->execute([$user_id]); +$quotations = $stmt->fetchAll(PDO::FETCH_ASSOC); + +// Verifica se è richiesta la modifica di una quotation +$editQuotation = null; +if (isset($_GET['edit_id'])) { + $editId = intval($_GET['edit_id']); + $stmt = $pdo->prepare("SELECT * FROM quotations WHERE id = ? AND iduser = ?"); + $stmt->execute([$editId, $user_id]); + $editQuotation = $stmt->fetch(PDO::FETCH_ASSOC); +} +?> + + + + + + + + + + + + + Gestione Quotations - <?= htmlspecialchars($titlewebsite, ENT_QUOTES, 'UTF-8'); ?> + + + +
+ + +
+
+
+
+
+
+
Gestione Quotations
+
+
+
+
+ + +
Modifica Quotation ID:
+
+ + +
+ + +
+
+ + +
+ + Torna alla Lista +
+
+
Azioni
+ + +
+ + +
+ +
+
Quotations Esistenti
+ + + + + + + + + + + + + + + + + + + + + +
IDData CreazioneDescrizioneClienteAzioni
+ + + + + + + + + +
+ +
+
+
+
+ + + + +
+ + +
+ + + + + + + + + + + \ No newline at end of file