prepare("INSERT INTO nozzles (name, pump_id, tank_id) VALUES (?, ?, ?)"); $stmt->execute([$name, $pump_id, $tank_id]); $_SESSION['notification'] = ['text' => 'Nozzle added successfully!', 'type' => 'success']; } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error adding nozzle: ' . $e->getMessage(), 'type' => 'danger']; } } else { $_SESSION['notification'] = ['text' => 'All fields are required.', 'type' => 'warning']; } } // Edit Nozzle elseif (isset($_POST['edit_nozzle'])) { $id = $_POST['nozzle_id']; $name = trim($_POST['name']); $pump_id = $_POST['pump_id']; $tank_id = $_POST['tank_id']; if (!empty($name) && !empty($pump_id) && !empty($tank_id) && !empty($id)) { try { $stmt = $db->prepare("UPDATE nozzles SET name = ?, pump_id = ?, tank_id = ? WHERE id = ?"); $stmt->execute([$name, $pump_id, $tank_id, $id]); $_SESSION['notification'] = ['text' => 'Nozzle updated successfully!', 'type' => 'success']; } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error updating nozzle: ' . $e->getMessage(), 'type' => 'danger']; } } else { $_SESSION['notification'] = ['text' => 'All fields and ID are required.', 'type' => 'warning']; } } header("Location: nozzles.php"); exit; } // Soft Delete Nozzle if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) { try { $db = db(); $stmt = $db->prepare("UPDATE nozzles SET deleted_at = NOW() WHERE id = ?"); $stmt->execute([$_GET['id']]); $_SESSION['notification'] = ['text' => 'Nozzle deleted successfully!', 'type' => 'success']; } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error deleting nozzle: ' . $e->getMessage(), 'type' => 'danger']; } header("Location: nozzles.php"); exit; } if (isset($_SESSION['notification'])) { $notification = $_SESSION['notification']; unset($_SESSION['notification']); } $db = db(); $nozzles = $db->query("SELECT n.*, p.name as pump_name, t.name as tank_name FROM nozzles n JOIN pumps p ON n.pump_id = p.id JOIN tanks t ON n.tank_id = t.id WHERE n.deleted_at IS NULL ORDER BY n.created_at DESC")->fetchAll(PDO::FETCH_ASSOC); $pumps = $db->query("SELECT * FROM pumps WHERE deleted_at IS NULL")->fetchAll(PDO::FETCH_ASSOC); $tanks = $db->query("SELECT * FROM tanks")->fetchAll(PDO::FETCH_ASSOC); $page_title = "Nozzle Management"; ?> <?= htmlspecialchars($page_title) ?> - Petrol Pump Management

Name Pump Tank Created At Actions