feature: Use single file for global navigation, include on other pages

This commit is contained in:
Keith Solomon
2026-02-10 08:29:45 -06:00
parent a49b98f73b
commit f94b4dda95
6 changed files with 53 additions and 57 deletions

View File

@@ -17,15 +17,16 @@ $config = require __DIR__ . '/lib/project-config.php';
$storage = new SpacetradersStorage( $config['db_path'] );
$token = $storage->getAgentToken();
$statusMessage = '';
$errorMessage = '';
$ships = array();
$shipyards = array();
$agent = array();
$statusMessage = '';
$errorMessage = '';
$ships = array();
$shipyards = array();
$agent = array();
$currentSystemSymbol = '';
if (! is_string( $token ) || trim( $token ) === '' ) {
$envToken = getenv( 'SPACETRADERS_TOKEN' );
if (is_string( $envToken ) && trim( $envToken ) !== '' ) {
$token = trim( $envToken );
$storage->setAgentToken( $token );
@@ -146,6 +147,7 @@ try {
$errorMessage = $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
@@ -155,14 +157,11 @@ try {
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="container mx-auto px-4 py-8 bg-stone-800 text-gray-200">
<div class="mb-6 flex gap-4">
<a href="index.php" class="text-blue-400 hover:underline">Agent Info</a>
<a href="mining-fleet.php" class="text-blue-400 hover:underline">Mining Fleet</a>
<a href="config.php" class="text-blue-400 hover:underline">Configuration</a>
</div>
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full">Buy Ships</h1>
<body class="container mx-auto px-4 py-8 bg-stone-800 text-gray-200">
<?php require __DIR__ . '/main-menu.php'; ?>
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full"><a href="buy-ships.php">Spacetraders - Buy Ships</a></h1>
<?php if (isset( $tokenError ) ) : ?>
<div class="mb-6 border border-red-500 p-4 rounded text-red-300">

View File

@@ -35,6 +35,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' ) {
if (! is_string( $token ) || trim( $token ) === '') {
$envToken = getenv( 'SPACETRADERS_TOKEN' );
if (is_string( $envToken ) && trim( $envToken ) !== '' ) {
$token = trim( $envToken );
$storage->setAgentToken( $token );
@@ -56,7 +57,9 @@ $hasToken = is_string( $token ) && trim( $token ) !== '';
</head>
<body class="container mx-auto px-4 py-8 bg-stone-800 text-gray-200">
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full">Spacetraders Configuration</h1>
<?php require __DIR__ . '/main-menu.php'; ?>
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full"><a href="config.php">Spacetraders - Configuration</a></h1>
<div class="mb-6 border border-gray-600 p-4 rounded">
<p class="mb-2 text-sm text-gray-300">
@@ -89,11 +92,5 @@ $hasToken = is_string( $token ) && trim( $token ) !== '';
<button type="submit" name="clear_cache" value="1" class="px-4 py-2 bg-gray-600 rounded hover:bg-gray-500">Clear Cache</button>
</form>
</div>
<div class="flex gap-4">
<a href="index.php" class="text-blue-400 hover:underline">Agent Info</a>
<a href="buy-ships.php" class="text-blue-400 hover:underline">Buy Ships</a>
<a href="mining-fleet.php" class="text-blue-400 hover:underline">Mining Fleet</a>
</div>
</body>
</html>

View File

@@ -237,18 +237,12 @@ try {
</div>
</body>
</html>
<?php exit; ?>
<?php endif; ?>
<?php
exit;
endif;
<div class="mb-6">
<a href="buy-ships.php" class="text-blue-400 hover:underline">Buy Ships</a>
<span class="mx-2">|</span>
<a href="mining-fleet.php" class="text-blue-400 hover:underline">Mining Fleet</a>
<span class="mx-2">|</span>
<a href="config.php" class="text-blue-400 hover:underline">Configuration</a>
</div>
require __DIR__ . '/main-menu.php';
<?php
$msg = '';
$class = '';
@@ -267,7 +261,7 @@ try {
</div>
<?php endif; ?>
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full">Spacetraders Agent and Ships</h1>
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full"><a href="index.php" class="">Spacetraders - Dashboard</a></h1>
<h2 class="text-2xl font-bold mb-2">
Agent: <?php echo htmlspecialchars( ucfirst( strtolower( $agent['symbol'] ) ) ); ?><br>

9
main-menu.php Normal file
View File

@@ -0,0 +1,9 @@
<div class="mb-6">
<a href="index.php" class="text-blue-400 hover:underline">Dashboard</a>
<span class="mx-2">|</span>
<a href="buy-ships.php" class="text-blue-400 hover:underline">Buy Ships</a>
<span class="mx-2">|</span>
<a href="mining-fleet.php" class="text-blue-400 hover:underline">Mining Fleet</a>
<span class="mx-2">|</span>
<a href="config.php" class="text-blue-400 hover:underline">Configuration</a>
</div>

View File

@@ -36,18 +36,19 @@ $config = require __DIR__ . '/lib/project-config.php';
$storage = new SpacetradersStorage( $config['db_path'] );
$token = $storage->getAgentToken();
$statusMessage = '';
$errorMessage = '';
$actionResults = array();
$agent = array();
$ships = array();
$miningShips = array();
$activeContracts = array();
$marketWaypoints = array();
$statusMessage = '';
$errorMessage = '';
$actionResults = array();
$agent = array();
$ships = array();
$miningShips = array();
$activeContracts = array();
$marketWaypoints = array();
$selectedMarketWaypoint = '';
if (! is_string( $token ) || trim( $token ) === '' ) {
$envToken = getenv( 'SPACETRADERS_TOKEN' );
if (is_string( $envToken ) && trim( $envToken ) !== '' ) {
$token = trim( $envToken );
$storage->setAgentToken( $token );
@@ -362,6 +363,7 @@ try {
$errorMessage = $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
@@ -370,14 +372,11 @@ try {
<title>Spacetraders - Mining Fleet</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="container mx-auto px-4 py-8 bg-stone-800 text-gray-200">
<div class="mb-6 flex gap-4">
<a href="index.php" class="text-blue-400 hover:underline">Agent Info</a>
<a href="buy-ships.php" class="text-blue-400 hover:underline">Buy Ships</a>
<a href="config.php" class="text-blue-400 hover:underline">Configuration</a>
</div>
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full">Mining Fleet</h1>
<body class="container mx-auto px-4 py-8 bg-stone-800 text-gray-200">
<?php require __DIR__ . '/main-menu.php'; ?>
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full"><a href="mining-fleet.php">Spacetraders - Mining Fleet</a></h1>
<?php if (isset( $tokenError ) ) : ?>
<div class="mb-6 border border-red-500 p-4 rounded text-red-300">

View File

@@ -18,13 +18,14 @@ $storage = new SpacetradersStorage( $config['db_path'] );
$token = $storage->getAgentToken();
$statusMessage = '';
$errorMessage = '';
$ship = array();
$shipList = array();
$shipSymbol = isset( $_GET['ship'] ) ? trim( (string) $_GET['ship'] ) : '';
$errorMessage = '';
$ship = array();
$shipList = array();
$shipSymbol = isset( $_GET['ship'] ) ? trim( (string) $_GET['ship'] ) : '';
if (! is_string( $token ) || trim( $token ) === '' ) {
$envToken = getenv( 'SPACETRADERS_TOKEN' );
if (is_string( $envToken ) && trim( $envToken ) !== '' ) {
$token = trim( $envToken );
$storage->setAgentToken( $token );
@@ -196,6 +197,7 @@ try {
$errorMessage = $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
@@ -204,15 +206,11 @@ try {
<title>Spacetraders - Ship Details</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="container mx-auto px-4 py-8 bg-stone-800 text-gray-200">
<div class="mb-6 flex gap-4">
<a href="index.php" class="text-blue-400 hover:underline">Agent Info</a>
<a href="mining-fleet.php" class="text-blue-400 hover:underline">Mining Fleet</a>
<a href="buy-ships.php" class="text-blue-400 hover:underline">Buy Ships</a>
<a href="config.php" class="text-blue-400 hover:underline">Configuration</a>
</div>
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full">Ship Details</h1>
<body class="container mx-auto px-4 py-8 bg-stone-800 text-gray-200">
<?php require __DIR__ . '/main-menu.php'; ?>
<h1 class="text-3xl font-bold mb-6 underline decoration-gray-300 w-full"><a href="ship-details.php">Spacetraders - Ship Details</a></h1>
<?php if (isset( $tokenError ) ) : ?>
<div class="mb-6 border border-red-500 p-4 rounded text-red-300">