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'] ); $storage = new SpacetradersStorage( $config['db_path'] );
$token = $storage->getAgentToken(); $token = $storage->getAgentToken();
$statusMessage = ''; $statusMessage = '';
$errorMessage = ''; $errorMessage = '';
$ships = array(); $ships = array();
$shipyards = array(); $shipyards = array();
$agent = array(); $agent = array();
$currentSystemSymbol = ''; $currentSystemSymbol = '';
if (! is_string( $token ) || trim( $token ) === '' ) { if (! is_string( $token ) || trim( $token ) === '' ) {
$envToken = getenv( 'SPACETRADERS_TOKEN' ); $envToken = getenv( 'SPACETRADERS_TOKEN' );
if (is_string( $envToken ) && trim( $envToken ) !== '' ) { if (is_string( $envToken ) && trim( $envToken ) !== '' ) {
$token = trim( $envToken ); $token = trim( $envToken );
$storage->setAgentToken( $token ); $storage->setAgentToken( $token );
@@ -146,6 +147,7 @@ try {
$errorMessage = $e->getMessage(); $errorMessage = $e->getMessage();
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@@ -155,14 +157,11 @@ try {
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
</head> </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 ) ) : ?> <?php if (isset( $tokenError ) ) : ?>
<div class="mb-6 border border-red-500 p-4 rounded text-red-300"> <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 ) === '') { if (! is_string( $token ) || trim( $token ) === '') {
$envToken = getenv( 'SPACETRADERS_TOKEN' ); $envToken = getenv( 'SPACETRADERS_TOKEN' );
if (is_string( $envToken ) && trim( $envToken ) !== '' ) { if (is_string( $envToken ) && trim( $envToken ) !== '' ) {
$token = trim( $envToken ); $token = trim( $envToken );
$storage->setAgentToken( $token ); $storage->setAgentToken( $token );
@@ -56,7 +57,9 @@ $hasToken = is_string( $token ) && trim( $token ) !== '';
</head> </head>
<body class="container mx-auto px-4 py-8 bg-stone-800 text-gray-200"> <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"> <div class="mb-6 border border-gray-600 p-4 rounded">
<p class="mb-2 text-sm text-gray-300"> <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> <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> </form>
</div> </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> </body>
</html> </html>

View File

@@ -237,18 +237,12 @@ try {
</div> </div>
</body> </body>
</html> </html>
<?php exit; ?> <?php
<?php endif; ?> exit;
endif;
<div class="mb-6"> require __DIR__ . '/main-menu.php';
<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>
<?php
$msg = ''; $msg = '';
$class = ''; $class = '';
@@ -267,7 +261,7 @@ try {
</div> </div>
<?php endif; ?> <?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"> <h2 class="text-2xl font-bold mb-2">
Agent: <?php echo htmlspecialchars( ucfirst( strtolower( $agent['symbol'] ) ) ); ?><br> 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'] ); $storage = new SpacetradersStorage( $config['db_path'] );
$token = $storage->getAgentToken(); $token = $storage->getAgentToken();
$statusMessage = ''; $statusMessage = '';
$errorMessage = ''; $errorMessage = '';
$actionResults = array(); $actionResults = array();
$agent = array(); $agent = array();
$ships = array(); $ships = array();
$miningShips = array(); $miningShips = array();
$activeContracts = array(); $activeContracts = array();
$marketWaypoints = array(); $marketWaypoints = array();
$selectedMarketWaypoint = ''; $selectedMarketWaypoint = '';
if (! is_string( $token ) || trim( $token ) === '' ) { if (! is_string( $token ) || trim( $token ) === '' ) {
$envToken = getenv( 'SPACETRADERS_TOKEN' ); $envToken = getenv( 'SPACETRADERS_TOKEN' );
if (is_string( $envToken ) && trim( $envToken ) !== '' ) { if (is_string( $envToken ) && trim( $envToken ) !== '' ) {
$token = trim( $envToken ); $token = trim( $envToken );
$storage->setAgentToken( $token ); $storage->setAgentToken( $token );
@@ -362,6 +363,7 @@ try {
$errorMessage = $e->getMessage(); $errorMessage = $e->getMessage();
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@@ -370,14 +372,11 @@ try {
<title>Spacetraders - Mining Fleet</title> <title>Spacetraders - Mining Fleet</title>
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
</head> </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 ) ) : ?> <?php if (isset( $tokenError ) ) : ?>
<div class="mb-6 border border-red-500 p-4 rounded text-red-300"> <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(); $token = $storage->getAgentToken();
$statusMessage = ''; $statusMessage = '';
$errorMessage = ''; $errorMessage = '';
$ship = array(); $ship = array();
$shipList = array(); $shipList = array();
$shipSymbol = isset( $_GET['ship'] ) ? trim( (string) $_GET['ship'] ) : ''; $shipSymbol = isset( $_GET['ship'] ) ? trim( (string) $_GET['ship'] ) : '';
if (! is_string( $token ) || trim( $token ) === '' ) { if (! is_string( $token ) || trim( $token ) === '' ) {
$envToken = getenv( 'SPACETRADERS_TOKEN' ); $envToken = getenv( 'SPACETRADERS_TOKEN' );
if (is_string( $envToken ) && trim( $envToken ) !== '' ) { if (is_string( $envToken ) && trim( $envToken ) !== '' ) {
$token = trim( $envToken ); $token = trim( $envToken );
$storage->setAgentToken( $token ); $storage->setAgentToken( $token );
@@ -196,6 +197,7 @@ try {
$errorMessage = $e->getMessage(); $errorMessage = $e->getMessage();
} }
?> ?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@@ -204,15 +206,11 @@ try {
<title>Spacetraders - Ship Details</title> <title>Spacetraders - Ship Details</title>
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
</head> </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 ) ) : ?> <?php if (isset( $tokenError ) ) : ?>
<div class="mb-6 border border-red-500 p-4 rounded text-red-300"> <div class="mb-6 border border-red-500 p-4 rounded text-red-300">