prepare("INSERT INTO fuel_types (name) VALUES (?)"); $stmt->execute([$name]); $_SESSION['notification'] = ['text' => 'Fuel type added successfully!', 'type' => 'success']; } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error adding fuel type: ' . $e->getMessage(), 'type' => 'danger']; } } else { $_SESSION['notification'] = ['text' => 'Fuel type name is required.', 'type' => 'warning']; } } // Edit Fuel Type elseif (isset($_POST['edit_fuel_type'])) { $id = $_POST['fuel_type_id']; $name = trim($_POST['name']); if (!empty($name) && !empty($id)) { try { $stmt = $db->prepare("UPDATE fuel_types SET name = ? WHERE id = ?"); $stmt->execute([$name, $id]); $_SESSION['notification'] = ['text' => 'Fuel type updated successfully!', 'type' => 'success']; } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error updating fuel type: ' . $e->getMessage(), 'type' => 'danger']; } } else { $_SESSION['notification'] = ['text' => 'Fuel type name and ID are required.', 'type' => 'warning']; } } header("Location: fuel_types.php"); exit; } // Delete Fuel Type if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['id'])) { try { $db = db(); $stmt = $db->prepare("SELECT COUNT(*) FROM tanks WHERE fuel_type_id = ?"); $stmt->execute([$_GET['id']]); if ($stmt->fetchColumn() > 0) { $_SESSION['notification'] = ['text' => 'Cannot delete. This fuel type is in use by one or more tanks.', 'type' => 'warning']; } else { $stmt = $db->prepare("DELETE FROM fuel_types WHERE id = ?"); $stmt->execute([$_GET['id']]); $_SESSION['notification'] = ['text' => 'Fuel type deleted successfully!', 'type' => 'success']; } } catch (PDOException $e) { $_SESSION['notification'] = ['text' => 'Error deleting fuel type: ' . $e->getMessage(), 'type' => 'danger']; } header("Location: fuel_types.php"); exit; } if (isset($_SESSION['notification'])) { $notification = $_SESSION['notification']; unset($_SESSION['notification']); } $fuel_types = db()->query("SELECT * FROM fuel_types ORDER BY name ASC")->fetchAll(PDO::FETCH_ASSOC); $page_title = "Fuel Type Management"; ?>
| ID | Name | Actions |
|---|---|---|
| = htmlspecialchars($type['id']) ?> | = htmlspecialchars($type['name']) ?> |