Alpha V0.2

This commit is contained in:
Flatlogic Bot 2026-02-22 03:02:18 +00:00
parent bf569922e9
commit 430868a6e8
4 changed files with 902 additions and 357 deletions

441
admin.php
View File

@ -1,119 +1,396 @@
<?php
require_once 'db/config.php';
session_start();
$db = db();
// MJ Actions
if (isset($_POST['reset_world'])) {
$db->exec("UPDATE cities SET current_red_percentage = 100, is_liberated = 0");
$db->exec("UPDATE planets SET terrestrial_control = 0, status = 'hostile'");
header("Location: admin.php?success=reset");
// Auth Check: Must be logged in and be admin
if (!isset($_SESSION['user_id'])) {
header("Location: auth.php?page=login");
exit;
}
$total_planets = $db->query("SELECT COUNT(*) FROM planets")->fetchColumn();
$liberated_planets = $db->query("SELECT COUNT(*) FROM planets WHERE status = 'stable'")->fetchColumn();
$total_cities = $db->query("SELECT COUNT(*) FROM cities")->fetchColumn();
$liberated_cities = $db->query("SELECT COUNT(*) FROM cities WHERE is_liberated = 1")->fetchColumn();
$user_id = $_SESSION['user_id'];
$user_stmt = $db->prepare("SELECT role FROM users WHERE id = ?");
$user_stmt->execute([$user_id]);
$current_user = $user_stmt->fetch();
$planets_stats = $db->query("SELECT * FROM planets ORDER BY terrestrial_control DESC")->fetchAll();
if (!$current_user || $current_user['role'] !== 'admin') {
die("Accès refusé. Cette console est réservée aux Administrateurs.");
}
$tab = isset($_GET['tab']) ? $_GET['tab'] : 'users';
// --- HANDLERS ---
// Handle User Role Update
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'update_user_role') {
$target_user_id = (int)$_POST['target_user_id'];
$new_role = $_POST['new_role'];
if (in_array($new_role, ['user', 'gm', 'admin'])) {
$stmt = $db->prepare("UPDATE users SET role = ? WHERE id = ?");
$stmt->execute([$new_role, $target_user_id]);
}
header("Location: admin.php?tab=users&success=1");
exit;
}
// Handle Celestial Object Type CRUD
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_object_type') {
$id = (int)$_POST['id'];
$name = $_POST['name'];
$slug = $_POST['slug'];
$icon = $_POST['icon'];
$description = $_POST['description'];
if ($id > 0) {
$stmt = $db->prepare("UPDATE celestial_object_types SET name = ?, slug = ?, icon = ?, description = ? WHERE id = ?");
$stmt->execute([$name, $slug, $icon, $description, $id]);
} else {
$stmt = $db->prepare("INSERT INTO celestial_object_types (name, slug, icon, description) VALUES (?, ?, ?, ?)");
$stmt->execute([$name, $slug, $icon, $description]);
}
header("Location: admin.php?tab=objects&success=1");
exit;
}
if (isset($_GET['delete_object'])) {
$id = (int)$_GET['delete_object'];
$db->prepare("DELETE FROM celestial_object_types WHERE id = ?")->execute([$id]);
header("Location: admin.php?tab=objects&success=1");
exit;
}
// Handle Status CRUD
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_status') {
$id = (int)$_POST['id'];
$name = $_POST['name'];
$slug = $_POST['slug'];
$color = $_POST['color'];
$description = $_POST['description'];
if ($id > 0) {
$stmt = $db->prepare("UPDATE celestial_object_statuses SET name = ?, slug = ?, color = ?, description = ? WHERE id = ?");
$stmt->execute([$name, $slug, $color, $description, $id]);
} else {
$stmt = $db->prepare("INSERT INTO celestial_object_statuses (name, slug, color, description) VALUES (?, ?, ?, ?)");
$stmt->execute([$name, $slug, $color, $description]);
}
header("Location: admin.php?tab=statuses&success=1");
exit;
}
if (isset($_GET['delete_status'])) {
$id = (int)$_GET['delete_status'];
$db->prepare("DELETE FROM celestial_object_statuses WHERE id = ?")->execute([$id]);
header("Location: admin.php?tab=statuses&success=1");
exit;
}
// Handle Settlement Type CRUD
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_settlement') {
$id = (int)$_POST['id'];
$name = $_POST['name'];
$slug = $_POST['slug'];
$description = $_POST['description'];
if ($id > 0) {
$stmt = $db->prepare("UPDATE settlement_types SET name = ?, slug = ?, description = ? WHERE id = ?");
$stmt->execute([$name, $slug, $description, $id]);
} else {
$stmt = $db->prepare("INSERT INTO settlement_types (name, slug, description) VALUES (?, ?, ?)");
$stmt->execute([$name, $slug, $description]);
}
header("Location: admin.php?tab=settlements&success=1");
exit;
}
if (isset($_GET['delete_settlement'])) {
$id = (int)$_GET['delete_settlement'];
$db->prepare("DELETE FROM settlement_types WHERE id = ?")->execute([$id]);
header("Location: admin.php?tab=settlements&success=1");
exit;
}
// --- DATA FETCHING ---
$users_list = [];
$objects_list = [];
$statuses_list = [];
$settlements_list = [];
if ($tab === 'users') {
$users_list = $db->query("SELECT id, username, email, role FROM users ORDER BY username ASC")->fetchAll();
} elseif ($tab === 'objects') {
$objects_list = $db->query("SELECT * FROM celestial_object_types ORDER BY name ASC")->fetchAll();
} elseif ($tab === 'statuses') {
$statuses_list = $db->query("SELECT * FROM celestial_object_statuses ORDER BY name ASC")->fetchAll();
} elseif ($tab === 'settlements') {
$settlements_list = $db->query("SELECT * FROM settlement_types ORDER BY name ASC")->fetchAll();
}
// Mock Resources
$resources = [
'Metal' => ['val' => '136 053', 'max' => '1 210 000', 'prod' => '+1 980', 'icon' => 'fa-cube'],
'Crystal' => ['val' => '127 322', 'max' => '1 010 000', 'prod' => '+1 703', 'icon' => 'fa-gem'],
'Deuterium' => ['val' => '32 277', 'max' => '50 000', 'prod' => '+28', 'icon' => 'fa-flask'],
'Energy' => ['val' => '2 100', 'max' => '2 100', 'prod' => '', 'icon' => 'fa-bolt'],
'Dark Matter' => ['val' => '4 930', 'max' => '', 'prod' => '', 'icon' => 'fa-atom']
];
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Console MJ</title>
<title>Console Admin - Nexus</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<link href="assets/css/custom.css?v=<?php echo time(); ?>" rel="stylesheet">
<style>
body { background: #000; color: #fff; font-family: Arial, sans-serif; }
header#top-bar { height: auto; padding: 10px; background: rgba(10, 15, 30, 0.9); border-bottom: 2px solid #2d3545; display: flex; justify-content: center; align-items: center; }
.resource-container { display: flex; gap: 10px; flex-wrap: wrap; }
.resource-box { background: #0a0a0a; border: 1px solid #3b4252; padding: 5px 15px; text-align: left; min-width: 140px; position: relative; }
.resource-box i { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); opacity: 0.3; font-size: 20px; }
.resource-name { font-size: 10px; color: #8c92a3; text-transform: uppercase; }
.resource-value { font-size: 13px; font-weight: bold; color: #fff; }
body { background: #000; color: #fff; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; }
header { background: #1a202c; padding: 10px 20px; border-bottom: 2px solid #2d3545; display: flex; justify-content: space-between; align-items: center; }
.nav-links a { color: #88c0d0; text-decoration: none; margin-right: 20px; font-weight: bold; font-size: 14px; }
.nav-links a:hover { color: #fff; }
.container { padding: 40px; max-width: 1200px; margin: 0 auto; }
.tabs { display: flex; gap: 5px; margin-bottom: 20px; border-bottom: 2px solid #2d3545; }
.tab-link { padding: 10px 20px; text-decoration: none; color: #8c92a3; background: #0a0f1d; border: 1px solid #2d3545; border-bottom: none; font-weight: bold; font-size: 14px; }
.tab-link.active { background: #1a202c; color: #88c0d0; border-bottom: 2px solid #88c0d0; }
#main-content { padding: 40px; display: flex; flex-direction: column; align-items: center; }
.view-frame { background: rgba(20, 30, 50, 0.8); border: 1px solid #4c566a; padding: 30px; max-width: 1000px; width: 100%; }
table { width: 100%; border-collapse: collapse; background: #0a0f1d; margin-top: 20px; }
th, td { border: 1px solid #2d3545; padding: 12px; text-align: left; }
th { background: #1a202c; color: #88c0d0; font-size: 13px; text-transform: uppercase; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { border: 1px solid #2d3545; padding: 10px; text-align: left; font-size: 12px; }
th { background: #1e293b; color: #8c92a3; text-transform: uppercase; font-size: 10px; }
.stat-card { background: #0a0a0a; border: 1px solid #2d3545; padding: 15px; margin-bottom: 20px; }
.form-card { background: #1e293b; padding: 20px; border: 1px solid #334155; margin-bottom: 30px; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 12px; color: #8c92a3; margin-bottom: 5px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; background: #0f172a; border: 1px solid #334155; color: #fff; padding: 8px; box-sizing: border-box; }
.btn-danger { background: #bf616a; border: none; color: white; padding: 10px 20px; cursor: pointer; font-weight: bold; text-transform: uppercase; }
.btn-danger:hover { background: #d08770; }
.back-link { display: inline-block; margin-bottom: 20px; color: #88c0d0; text-decoration: none; font-weight: bold; }
.back-link:hover { text-decoration: underline; }
.btn { border: none; padding: 8px 15px; cursor: pointer; font-weight: bold; border-radius: 4px; font-size: 12px; }
.btn-add { background: #a3be8c; color: #000; }
.btn-edit { background: #ebcb8b; color: #000; }
.btn-del { background: #bf616a; color: #fff; text-decoration: none; }
.btn-ok { background: #88c0d0; color: #000; }
.success-msg { background: #a3be8c; color: #000; padding: 10px; margin-bottom: 20px; border-radius: 4px; font-weight: bold; }
</style>
</head>
<body>
<header id="top-bar">
<div class="resource-container">
<?php foreach($resources as $name => $res): ?>
<div class="resource-box">
<div class="resource-name"><?php echo $name; ?></div>
<div class="resource-value"><?php echo $res['val']; ?></div>
<i class="fa-solid <?php echo $res['icon']; ?>"></i>
</div>
<?php endforeach; ?>
<header>
<div style="display: flex; align-items: center; gap: 20px;">
<h2 style="margin: 0; color: #bf616a;"><i class="fa-solid fa-shield-halved"></i> CONSOLE ADMIN</h2>
<nav class="nav-links">
<a href="index.php"><i class="fa-solid fa-eye"></i> Vue Joueur</a>
<a href="gm_console.php" target="_blank"><i class="fa-solid fa-headset"></i> Console MJ</a>
</nav>
</div>
<div>
<span style="font-weight: bold; color: #88c0d0;"><?php echo htmlspecialchars($_SESSION['username']); ?></span>
</div>
</header>
<main id="main-content">
<div class="view-frame">
<a href="index.php" class="back-link"><i class="fa-solid fa-arrow-left"></i> Retour au Secteur</a>
<h2 class="text-accent" style="margin-top: 0; color: #88c0d0;">Console de Commandement MJ</h2>
<div style="display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px;">
<div class="stat-card">
<div class="text-muted small">Planètes Libérées</div>
<div class="text-success" style="font-size: 20px; font-weight: bold; color: #a3be8c;"><?php echo $liberated_planets; ?> / <?php echo $total_planets; ?></div>
</div>
<div class="stat-card">
<div class="text-muted small">Villes Libérées</div>
<div class="text-success" style="font-size: 20px; font-weight: bold; color: #a3be8c;"><?php echo $liberated_cities; ?> / <?php echo $total_cities; ?></div>
</div>
<div class="stat-card">
<form method="POST" onsubmit="return confirm('Wipe total ?');">
<button type="submit" name="reset_world" class="btn-danger">RÉINITIALISER L'UNIVERS</button>
</form>
</div>
</div>
<div class="container">
<?php if (isset($_GET['success'])): ?>
<div class="success-msg"><i class="fa-solid fa-check-circle"></i> Opération effectuée avec succès.</div>
<?php endif; ?>
<div class="tabs">
<a href="?tab=users" class="tab-link <?php echo $tab === 'users' ? 'active' : ''; ?>"><i class="fa-solid fa-users"></i> Utilisateurs</a>
<a href="?tab=objects" class="tab-link <?php echo $tab === 'objects' ? 'active' : ''; ?>"><i class="fa-solid fa-earth-europe"></i> Objets Célestes</a>
<a href="?tab=statuses" class="tab-link <?php echo $tab === 'statuses' ? 'active' : ''; ?>"><i class="fa-solid fa-signal"></i> Statuts / États</a>
<a href="?tab=settlements" class="tab-link <?php echo $tab === 'settlements' ? 'active' : ''; ?>"><i class="fa-solid fa-city"></i> Villes / Avant-postes</a>
</div>
<?php if ($tab === 'users'): ?>
<h3 style="color: #88c0d0;">Gestion des Rôles</h3>
<table>
<thead>
<tr>
<th>Planète</th>
<th>Type</th>
<th>Statut</th>
<th>Contrôle Sol</th>
<th>Action</th>
</tr>
<tr><th>Utilisateur</th><th>Email</th><th>Rôle Actuel</th><th>Nouveau Rôle</th></tr>
</thead>
<tbody>
<?php foreach ($planets_stats as $p): ?>
<?php foreach ($users_list as $u): ?>
<tr>
<td><?php echo $p['name']; ?></td>
<td><?php echo strtoupper($p['type'] ?? 'PLANET'); ?></td>
<td style="color: <?php echo ($p['status'] == 'stable' ? '#a3be8c' : '#bf616a'); ?>"><?php echo strtoupper($p['status']); ?></td>
<td><?php echo $p['terrestrial_control']; ?>%</td>
<td><a href="index.php?galaxy_id=<?php echo $p['galaxy_id'] ?? 1; ?>&sector_id=<?php echo $p['sector_id']; ?>" style="color: #88c0d0; text-decoration: none;">Localiser</a></td>
<td><strong><?php echo htmlspecialchars($u['username']); ?></strong></td>
<td><?php echo htmlspecialchars($u['email']); ?></td>
<td>
<span style="background: <?php echo $u['role'] === 'admin' ? '#bf616a' : ($u['role'] === 'gm' ? '#ebcb8b' : '#4c566a'); ?>; padding: 2px 8px; border-radius: 10px; font-size: 11px; color: #000; font-weight: bold;">
<?php echo strtoupper($u['role']); ?>
</span>
</td>
<td>
<form method="POST" style="display: flex; gap: 10px;">
<input type="hidden" name="action" value="update_user_role">
<input type="hidden" name="target_user_id" value="<?php echo $u['id']; ?>">
<select name="new_role">
<option value="user" <?php echo $u['role'] === 'user' ? 'selected' : ''; ?>>Utilisateur</option>
<option value="gm" <?php echo $u['role'] === 'gm' ? 'selected' : ''; ?>>Maître du Jeu (MJ)</option>
<option value="admin" <?php echo $u['role'] === 'admin' ? 'selected' : ''; ?>>Administrateur</option>
</select>
<button type="submit" class="btn btn-ok">Modifier</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</main>
<?php elseif ($tab === 'objects'): ?>
<h3 style="color: #88c0d0;">Objets Célestes</h3>
<div class="form-card">
<h4>Ajouter / Modifier un Objet</h4>
<form method="POST" id="objectForm">
<input type="hidden" name="action" value="upsert_object_type">
<input type="hidden" name="id" id="obj_id" value="0">
<div style="display: flex; gap: 20px;">
<div class="form-group" style="flex: 1;">
<label>Nom (Affichage)</label>
<input type="text" name="name" id="obj_name" required placeholder="Ex: Planète">
</div>
<div class="form-group" style="flex: 1;">
<label>Slug (Identifiant technique)</label>
<input type="text" name="slug" id="obj_slug" required placeholder="Ex: planet">
</div>
<div class="form-group" style="flex: 1;">
<label>Icône (FontAwesome)</label>
<input type="text" name="icon" id="obj_icon" required placeholder="Ex: fa-earth-europe">
</div>
</div>
<div class="form-group">
<label>Description</label>
<textarea name="description" id="obj_desc" rows="2"></textarea>
</div>
<button type="submit" class="btn btn-add">ENREGISTRER L'OBJET</button>
<button type="button" class="btn" style="background: #4c566a; color: #fff;" onclick="resetObjectForm()">ANNULER</button>
</form>
</div>
<table>
<thead><tr><th>Icône</th><th>Nom</th><th>Slug</th><th>Actions</th></tr></thead>
<tbody>
<?php foreach ($objects_list as $o): ?>
<tr>
<td><i class="fa-solid <?php echo htmlspecialchars($o['icon']); ?> fa-lg"></i></td>
<td><strong><?php echo htmlspecialchars($o['name']); ?></strong></td>
<td><code><?php echo htmlspecialchars($o['slug']); ?></code></td>
<td>
<button class="btn btn-edit" onclick='editObject(<?php echo json_encode($o); ?>)'>Editer</button>
<a href="?tab=objects&delete_object=<?php echo $o['id']; ?>" class="btn btn-del" onclick="return confirm('Supprimer cet objet ?')">Suppr</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php elseif ($tab === 'statuses'): ?>
<h3 style="color: #88c0d0;">Statuts / États</h3>
<div class="form-card">
<h4>Ajouter / Modifier un Statut</h4>
<form method="POST" id="statusForm">
<input type="hidden" name="action" value="upsert_status">
<input type="hidden" name="id" id="st_id" value="0">
<div style="display: flex; gap: 20px;">
<div class="form-group" style="flex: 1;">
<label>Nom du Statut</label>
<input type="text" name="name" id="st_name" required>
</div>
<div class="form-group" style="flex: 1;">
<label>Slug</label>
<input type="text" name="slug" id="st_slug" required>
</div>
<div class="form-group" style="flex: 1;">
<label>Couleur (Hex ou CSS)</label>
<input type="text" name="color" id="st_color" required placeholder="Ex: #ef4444">
</div>
</div>
<div class="form-group">
<label>Description</label>
<textarea name="description" id="st_desc" rows="2"></textarea>
</div>
<button type="submit" class="btn btn-add">ENREGISTRER LE STATUT</button>
<button type="button" class="btn" style="background: #4c566a; color: #fff;" onclick="resetStatusForm()">ANNULER</button>
</form>
</div>
<table>
<thead><tr><th>Couleur</th><th>Nom</th><th>Slug</th><th>Actions</th></tr></thead>
<tbody>
<?php foreach ($statuses_list as $s): ?>
<tr>
<td><div style="width: 20px; height: 20px; background: <?php echo $s['color']; ?>; border: 1px solid #fff;"></div></td>
<td><strong><?php echo htmlspecialchars($s['name']); ?></strong></td>
<td><code><?php echo htmlspecialchars($s['slug']); ?></code></td>
<td>
<button class="btn btn-edit" onclick='editStatus(<?php echo json_encode($s); ?>)'>Editer</button>
<a href="?tab=statuses&delete_status=<?php echo $s['id']; ?>" class="btn btn-del" onclick="return confirm('Supprimer ce statut ?')">Suppr</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php elseif ($tab === 'settlements'): ?>
<h3 style="color: #88c0d0;">Villes / Avant-postes</h3>
<div class="form-card">
<h4>Ajouter / Modifier un Type d'Établissement</h4>
<form method="POST" id="settlementForm">
<input type="hidden" name="action" value="upsert_settlement">
<input type="hidden" name="id" id="set_id" value="0">
<div style="display: flex; gap: 20px;">
<div class="form-group" style="flex: 1;">
<label>Nom</label>
<input type="text" name="name" id="set_name" required>
</div>
<div class="form-group" style="flex: 1;">
<label>Slug</label>
<input type="text" name="slug" id="set_slug" required>
</div>
</div>
<div class="form-group">
<label>Description</label>
<textarea name="description" id="set_desc" rows="2"></textarea>
</div>
<button type="submit" class="btn btn-add">ENREGISTRER</button>
<button type="button" class="btn" style="background: #4c566a; color: #fff;" onclick="resetSettlementForm()">ANNULER</button>
</form>
</div>
<table>
<thead><tr><th>Nom</th><th>Slug</th><th>Description</th><th>Actions</th></tr></thead>
<tbody>
<?php foreach ($settlements_list as $st): ?>
<tr>
<td><strong><?php echo htmlspecialchars($st['name']); ?></strong></td>
<td><code><?php echo htmlspecialchars($st['slug']); ?></code></td>
<td><small><?php echo htmlspecialchars($st['description']); ?></small></td>
<td>
<button class="btn btn-edit" onclick='editSettlement(<?php echo json_encode($st); ?>)'>Editer</button>
<a href="?tab=settlements&delete_settlement=<?php echo $st['id']; ?>" class="btn btn-del" onclick="return confirm('Supprimer ce type ?')">Suppr</a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<script>
function editObject(data) {
document.getElementById('obj_id').value = data.id;
document.getElementById('obj_name').value = data.name;
document.getElementById('obj_slug').value = data.slug;
document.getElementById('obj_icon').value = data.icon;
document.getElementById('obj_desc').value = data.description;
window.scrollTo(0,0);
}
function resetObjectForm() { document.getElementById('objectForm').reset(); document.getElementById('obj_id').value = 0; }
function editStatus(data) {
document.getElementById('st_id').value = data.id;
document.getElementById('st_name').value = data.name;
document.getElementById('st_slug').value = data.slug;
document.getElementById('st_color').value = data.color;
document.getElementById('st_desc').value = data.description;
window.scrollTo(0,0);
}
function resetStatusForm() { document.getElementById('statusForm').reset(); document.getElementById('st_id').value = 0; }
function editSettlement(data) {
document.getElementById('set_id').value = data.id;
document.getElementById('set_name').value = data.name;
document.getElementById('set_slug').value = data.slug;
document.getElementById('set_desc').value = data.description;
window.scrollTo(0,0);
}
function resetSettlementForm() { document.getElementById('settlementForm').reset(); document.getElementById('set_id').value = 0; }
</script>
</body>
</html>
</html>

View File

@ -0,0 +1,88 @@
<?php
require_once 'db/config.php';
$db = db();
try {
// 1. Create celestial_object_types table
$db->exec("CREATE TABLE IF NOT EXISTS celestial_object_types (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
slug VARCHAR(50) NOT NULL UNIQUE,
icon VARCHAR(50) NOT NULL,
description TEXT
)");
// 2. Create celestial_object_statuses table
$db->exec("CREATE TABLE IF NOT EXISTS celestial_object_statuses (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
slug VARCHAR(50) NOT NULL UNIQUE,
color VARCHAR(20) NOT NULL,
description TEXT
)");
// 3. Create settlement_types table
$db->exec("CREATE TABLE IF NOT EXISTS settlement_types (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
slug VARCHAR(50) NOT NULL UNIQUE,
description TEXT
)");
// 4. Seed initial data
$object_types = [
['Planète', 'planet', 'fa-earth-europe', 'Une planète habitable ou non.'],
['Champ d\'astéroïdes', 'asteroid', 'fa-mountain', 'Riche en minerais.'],
['Trou noir', 'black_hole', 'fa-circle-dot', 'Phénomène gravitationnel extrême.'],
['Pulsar', 'pulsar', 'fa-bolt', 'Étoile à neutrons hautement magnétisée.'],
['Étoile', 'star', 'fa-sun', 'Étoile centrale d\'un système.'],
['Comète', 'comet', 'fa-comet', 'Petit corps céleste de glace et de poussière.'],
['Vaisseau abandonné', 'wreckage', 'fa-ship', 'Épave dérivant dans l\'espace.'],
['Champ de bataille', 'battlefield', 'fa-burst', 'Vestiges d\'un affrontement spatial.'],
['Vortex', 'vortex', 'fa-whirlpool', 'Anomalie spatio-temporelle.'],
];
$stmt = $db->prepare("INSERT IGNORE INTO celestial_object_types (name, slug, icon, description) VALUES (?, ?, ?, ?)");
foreach ($object_types as $ot) {
$stmt->execute($ot);
}
$statuses = [
['Inhabité / Vide', 'empty', 'rgba(255,255,255,0.05)', 'Aucune présence détectée.'],
['Hostile', 'hostile', '#ef4444', 'Zone contrôlée par des ennemis.'],
['Stable / Allié', 'stable', '#a3be8c', 'Zone sûre et amicale.'],
['Contrôlé', 'controlled', '#5e81ac', 'Zone sous contrôle total.'],
['Contesté', 'contested', '#ebcb8b', 'Zone de conflit actif.'],
['Ressources', 'resource', '#f59e0b', 'Zone riche en ressources exploitables.'],
['PNA', 'pna', '#d08770', 'Pacte de Non-Agression en vigueur.'],
['Vortex', 'vortex', '#8b5cf6', 'Zone instable.'],
['Inhabité (Neutre)', 'inhabited', '#eceff4', 'Présence neutre ou civile.'],
];
$stmt = $db->prepare("INSERT IGNORE INTO celestial_object_statuses (name, slug, color, description) VALUES (?, ?, ?, ?)");
foreach ($statuses as $s) {
$stmt->execute($s);
}
$settlement_types = [
['Avant-poste', 'avant-poste', 'Petite base avancée.'],
['Petite ville', 'petite', 'Établissement mineur.'],
['Moyenne ville', 'moyenne', 'Établissement standard.'],
['Grande ville', 'grande', 'Métropole importante.'],
['Mégacité', 'mégacité', 'Centre urbain colossal.'],
];
$stmt = $db->prepare("INSERT IGNORE INTO settlement_types (name, slug, description) VALUES (?, ?, ?)");
foreach ($settlement_types as $st) {
$stmt->execute($st);
}
// 5. Update planets and cities tables to use IDs (optional but better for integrity)
// For now, let's just make sure the tables exist and can be managed.
// We will update the code to use these tables for the select options.
echo "Migration completed successfully.";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}

372
gm_console.php Normal file
View File

@ -0,0 +1,372 @@
<?php
require_once 'db/config.php';
session_start();
$db = db();
// Auth Check: Must be logged in and be admin or gm
if (!isset($_SESSION['user_id'])) {
header("Location: auth.php?page=login");
exit;
}
$user_id = $_SESSION['user_id'];
$user_stmt = $db->prepare("SELECT role FROM users WHERE id = ?");
$user_stmt->execute([$user_id]);
$current_user = $user_stmt->fetch();
if (!$current_user || ($current_user['role'] !== 'admin' && $current_user['role'] !== 'gm')) {
die("Accès refusé. Vous devez être un Maître du Jeu (MJ) pour accéder à cette console.");
}
$is_admin = ($current_user['role'] === 'admin');
// Fetch Dynamic Types and Statuses
$object_types_db = $db->query("SELECT * FROM celestial_object_types ORDER BY id ASC")->fetchAll(PDO::FETCH_ASSOC);
$statuses_db = $db->query("SELECT * FROM celestial_object_statuses ORDER BY id ASC")->fetchAll(PDO::FETCH_ASSOC);
$settlement_types_db = $db->query("SELECT * FROM settlement_types ORDER BY id ASC")->fetchAll(PDO::FETCH_ASSOC);
$object_types_map = []; foreach($object_types_db as $ot) $object_types_map[$ot['slug']] = $ot;
$statuses_map = []; foreach($statuses_db as $s) $statuses_map[$s['slug']] = $s;
// Handle Planet/Slot Update
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'update_slot') {
$slot_id = (int)$_POST['slot_id'];
$galaxy_id = (int)$_POST['galaxy_id'];
$sector_id = (int)$_POST['sector_id'];
$slot_num = (int)$_POST['slot_num'];
$name = $_POST['name'];
$type = $_POST['type'];
$status = $_POST['status'];
$orbital = (int)$_POST['orbital_control'];
$terrestrial = (int)$_POST['terrestrial_control'];
if ($type === 'empty') {
if ($slot_id > 0) {
$db->prepare("DELETE FROM planets WHERE id = ?")->execute([$slot_id]);
}
} else {
if ($slot_id > 0) {
$stmt = $db->prepare("UPDATE planets SET name = ?, type = ?, status = ?, orbital_control = ?, terrestrial_control = ? WHERE id = ?");
$stmt->execute([$name, $type, $status, $orbital, $terrestrial, $slot_id]);
$planet_id = $slot_id;
} else {
$stmt = $db->prepare("INSERT INTO planets (galaxy_id, sector_id, slot, name, type, status, orbital_control, terrestrial_control) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->execute([$galaxy_id, $sector_id, $slot_num, $name, $type, $status, $orbital, $terrestrial]);
$planet_id = $db->lastInsertId();
}
// Handle Settlement (City)
if (!empty($_POST['city_name'])) {
$c_name = $_POST['city_name'];
$c_type = $_POST['city_type'];
// Simple check if city exists for this planet
$stmt = $db->prepare("SELECT id FROM cities WHERE planet_id = ?");
$stmt->execute([$planet_id]);
$city = $stmt->fetch();
if ($city) {
$db->prepare("UPDATE cities SET name = ?, type = ? WHERE id = ?")->execute([$c_name, $c_type, $city['id']]);
} else {
$db->prepare("INSERT INTO cities (planet_id, name, type) VALUES (?, ?, ?)")->execute([$planet_id, $c_name, $c_type]);
}
}
}
header("Location: gm_console.php?view=sector&galaxy_id=$galaxy_id&sector_id=$sector_id&success=1");
exit;
}
// Handle Sector Update
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'update_sector') {
$sector_id = (int)$_POST['sector_id'];
$galaxy_id = (int)$_POST['galaxy_id'];
$s_name = $_POST['sector_name'];
$s_status = $_POST['sector_status'];
$stmt = $db->prepare("SELECT id FROM sectors WHERE id = ?");
$stmt->execute([$sector_id]);
if ($stmt->fetch()) {
$db->prepare("UPDATE sectors SET name = ?, status = ? WHERE id = ?")->execute([$s_name, $s_status, $sector_id]);
} else {
$db->prepare("INSERT INTO sectors (id, name, status, galaxy_id) VALUES (?, ?, ?, ?)")->execute([$sector_id, $s_name, $s_status, $galaxy_id]);
}
header("Location: gm_console.php?view=sector&galaxy_id=$galaxy_id&sector_id=$sector_id&success=1");
exit;
}
$view = isset($_GET['view']) ? $_GET['view'] : 'galaxy';
$galaxy_id = isset($_GET['galaxy_id']) ? (int)$_GET['galaxy_id'] : 1;
$sector_id = isset($_GET['sector_id']) ? (int)$_GET['sector_id'] : 1;
$grid_size = 36;
if ($view === 'sector') {
// Fetch planets AND their cities
$stmt = $db->prepare("SELECT p.*, c.name as city_name, c.type as city_type FROM planets p LEFT JOIN cities c ON p.id = c.planet_id WHERE p.galaxy_id = ? AND p.sector_id = ? AND p.slot BETWEEN 1 AND ?");
$stmt->execute([$galaxy_id, $sector_id, $grid_size]);
$objects_raw = $stmt->fetchAll();
$grid = array_fill(1, $grid_size, null);
foreach ($objects_raw as $obj) {
$grid[$obj['slot']] = $obj;
}
$stmt = $db->prepare("SELECT * FROM sectors WHERE id = ?");
$stmt->execute([$sector_id]);
$sector_info = $stmt->fetch();
} elseif ($view === 'galaxy') {
$stmt = $db->prepare("SELECT sector_id, slot, status, type FROM planets WHERE galaxy_id = ? ORDER BY sector_id, slot ASC");
$stmt->execute([$galaxy_id]);
$all_planets = $stmt->fetchAll();
$sector_data = [];
foreach ($all_planets as $p) {
$sector_data[$p['sector_id']][$p['slot']] = ['status' => $p['status'], 'type' => $p['type']];
}
$stmt = $db->prepare("SELECT id, status FROM sectors WHERE galaxy_id = ?");
$stmt->execute([$galaxy_id]);
$global_sector_statuses = $stmt->fetchAll(PDO::FETCH_KEY_PAIR);
}
function getStatusColor($status, $type, $statuses_map, $object_types_map) {
if (isset($statuses_map[$status])) return $statuses_map[$status]['color'];
return 'rgba(255,255,255,0.05)';
}
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Console MJ - Nexus</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<link href="assets/css/custom.css?v=<?php echo time(); ?>" rel="stylesheet">
<style>
body { background: #000; color: #fff; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; }
header { background: #1a202c; padding: 10px 20px; border-bottom: 2px solid #2d3545; display: flex; justify-content: space-between; align-items: center; }
.nav-links a { color: #88c0d0; text-decoration: none; margin-right: 20px; font-weight: bold; font-size: 14px; }
.nav-links a:hover { color: #fff; }
.container { padding: 20px; display: flex; flex-direction: column; align-items: center; }
.galaxy-map { background: rgba(0,0,0,0.9); border: 2px solid #2d3545; display: grid; grid-template-columns: repeat(6, 120px); grid-template-rows: repeat(6, 100px); gap: 1px; }
.slot { background: #050505; border: 1px solid #1a1a1a; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; cursor: pointer; transition: all 0.2s; }
.slot:hover { background: #1a2a4a; border-color: #88c0d0; transform: scale(1.05); z-index: 10; }
.slot-id { position: absolute; top: 2px; left: 5px; font-size: 9px; color: #444; }
.object-icon { font-size: 24px; margin-bottom: 5px; }
.object-name { font-size: 10px; font-weight: bold; color: #3b82f6; text-align: center; max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sector-grid { display: grid; grid-template-columns: repeat(6, 160px); grid-template-rows: repeat(6, 130px); gap: 10px; }
.sector-card { background: rgba(10,15,30,0.9); border: 1px solid #3b4252; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; text-decoration: none; color: #fff; padding: 10px; position: relative; transition: all 0.2s; }
.sector-card:hover { border-color: #88c0d0; background: #1a2a4a; }
.mini-map { display: grid; grid-template-columns: repeat(6, 8px); gap: 2px; background: #000; padding: 5px; border: 1px solid #4c566a; }
.mini-dot { width: 8px; height: 8px; background: rgba(255,255,255,0.05); }
.sector-status-label { position: absolute; top: 5px; right: 5px; font-size: 8px; padding: 2px 5px; border-radius: 3px; background: rgba(0,0,0,0.5); }
#editModal, #sectorModal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.8); z-index: 1000; justify-content: center; align-items: center; }
.modal-content { background: #1e293b; padding: 30px; border: 2px solid #88c0d0; width: 450px; box-shadow: 0 0 50px rgba(136, 192, 208, 0.2); max-height: 90vh; overflow-y: auto; }
.modal-content h3 { margin-top: 0; color: #88c0d0; }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-size: 12px; color: #8c92a3; margin-bottom: 5px; }
.form-group input, .form-group select { width: 100%; background: #0f172a; border: 1px solid #334155; color: #fff; padding: 10px; box-sizing: border-box; }
.btn-save { background: #a3be8c; color: #000; border: none; padding: 10px 20px; font-weight: bold; cursor: pointer; width: 100%; font-size: 16px; margin-top: 10px; }
.btn-cancel { background: #bf616a; color: #fff; border: none; padding: 10px 20px; font-weight: bold; cursor: pointer; width: 100%; margin-top: 10px; }
</style>
</head>
<body>
<header>
<div style="display: flex; align-items: center; gap: 20px;">
<h2 style="margin: 0; color: #ebcb8b;"><i class="fa-solid fa-headset"></i> CONSOLE MJ</h2>
<nav class="nav-links">
<a href="?view=galaxy"><i class="fa-solid fa-braille"></i> Galaxie</a>
<?php if ($is_admin): ?>
<a href="admin.php" target="_blank"><i class="fa-solid fa-shield-halved"></i> Console Admin</a>
<?php endif; ?>
<a href="index.php"><i class="fa-solid fa-eye"></i> Vue Joueur</a>
</nav>
</div>
<div>
<span style="color: #8c92a3; font-size: 12px;">Maître du Jeu: </span>
<span style="font-weight: bold; color: #88c0d0;"><?php echo htmlspecialchars($_SESSION['username']); ?></span>
</div>
</header>
<div class="container">
<?php if ($view === 'galaxy'): ?>
<h3 style="color: #88c0d0;">Sélecteur de Secteur</h3>
<div class="sector-grid">
<?php for($s=1; $s<=$grid_size; $s++):
$sStatus = $global_sector_statuses[$s] ?? 'unexplored';
?>
<a href="?view=sector&galaxy_id=<?php echo $galaxy_id; ?>&sector_id=<?php echo $s; ?>" class="sector-card">
<span class="sector-status-label" style="background: <?php echo ($sStatus == 'stable' ? '#a3be8c' : ($sStatus == 'hostile' ? '#bf616a' : ($sStatus == 'war' ? '#ef4444' : '#4c566a'))); ?>; color: #000; font-weight: bold;"><?php echo strtoupper($sStatus); ?></span>
<div class="mini-map">
<?php for($p=1; $p<=$grid_size; $p++):
$dotColor = 'rgba(255,255,255,0.05)';
if (isset($sector_data[$s][$p])) { $dotColor = getStatusColor($sector_data[$s][$p]['status'], $sector_data[$s][$p]['type'], $statuses_map, $object_types_map); }
?>
<div class="mini-dot" style="background-color: <?php echo $dotColor; ?>;"></div>
<?php endfor; ?>
</div>
<div style="font-size: 14px; font-weight: bold; margin-top: 5px;">SECTEUR <?php echo $s; ?></div>
</a>
<?php endfor; ?>
</div>
<?php elseif ($view === 'sector'): ?>
<div style="display: flex; justify-content: space-between; width: 100%; max-width: 720px; align-items: center; margin-bottom: 20px;">
<div style="display: flex; align-items: center; gap: 15px;">
<a href="?view=galaxy" style="color: #88c0d0; text-decoration: none;"><i class="fa-solid fa-arrow-left"></i> Retour</a>
<h3 style="color: #88c0d0; margin: 0;">Secteur <?php echo $sector_id; ?>: <?php echo htmlspecialchars($sector_info['name'] ?? "Secteur $sector_id"); ?></h3>
</div>
<button onclick="editSector()" style="background: #5e81ac; border: none; color: #fff; padding: 8px 15px; cursor: pointer; font-size: 12px; font-weight: bold; border-radius: 4px;"><i class="fa-solid fa-pen-to-square"></i> MODIFIER SECTEUR</button>
</div>
<div class="galaxy-map">
<?php for($i=1; $i<=$grid_size; $i++): ?>
<div class="slot" onclick='editSlot(<?php echo $i; ?>, <?php echo json_encode($grid[$i] ?? null); ?>)'>
<span class="slot-id"><?php echo $i; ?></span>
<?php if (isset($grid[$i])): $obj = $grid[$i]; ?>
<div class="object-icon">
<?php
$icon = $object_types_map[$obj['type']]['icon'] ?? 'fa-circle';
$color = getStatusColor($obj['status'], $obj['type'], $statuses_map, $object_types_map);
?>
<i class="fa-solid <?php echo $icon; ?>" style="color: <?php echo $color; ?>;"></i>
</div>
<span class="object-name"><?php echo htmlspecialchars($obj['name']); ?></span>
<?php else: ?>
<div style="opacity: 0.1;"><i class="fa-solid fa-plus"></i></div>
<?php endif; ?>
</div>
<?php endfor; ?>
</div>
<?php endif; ?>
</div>
<!-- Edit Slot Modal -->
<div id="editModal">
<div class="modal-content">
<h3 id="modalTitle">Éditer Case</h3>
<form method="POST">
<input type="hidden" name="action" value="update_slot">
<input type="hidden" name="slot_id" id="form_slot_id">
<input type="hidden" name="slot_num" id="form_slot_num">
<input type="hidden" name="galaxy_id" value="<?php echo $galaxy_id; ?>">
<input type="hidden" name="sector_id" value="<?php echo $sector_id; ?>">
<div class="form-group">
<label>Nom de l'objet / Planète</label>
<input type="text" name="name" id="form_name" placeholder="Ex: Terra Nova..." required>
</div>
<div class="form-group">
<label>Type d'objet céleste</label>
<select name="type" id="form_type">
<option value="empty">VIDE (Supprimer)</option>
<?php foreach($object_types_db as $ot): ?>
<option value="<?php echo $ot['slug']; ?>"><?php echo $ot['name']; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label>Statut / État</label>
<select name="status" id="form_status">
<?php foreach($statuses_db as $st): ?>
<option value="<?php echo $st['slug']; ?>"><?php echo $st['name']; ?></option>
<?php endforeach; ?>
</select>
</div>
<div style="background: rgba(0,0,0,0.2); padding: 15px; border: 1px dashed #4c566a; margin-bottom: 15px;">
<label style="font-size: 11px; color: #88c0d0; font-weight: bold; display: block; margin-bottom: 10px;">GESTION VILLE / AVANT-POSTE</label>
<div class="form-group">
<label>Nom de l'établissement</label>
<input type="text" name="city_name" id="form_city_name" placeholder="Laisser vide si aucun">
</div>
<div class="form-group">
<label>Taille / Type</label>
<select name="city_type" id="form_city_type">
<?php foreach($settlement_types_db as $set): ?>
<option value="<?php echo $set['slug']; ?>"><?php echo $set['name']; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div style="display: flex; gap: 10px;">
<div class="form-group" style="flex: 1;">
<label>Contrôle Orbital (%)</label>
<input type="number" name="orbital_control" id="form_orbital" min="0" max="100" value="0">
</div>
<div class="form-group" style="flex: 1;">
<label>Contrôle Sol (%)</label>
<input type="number" name="terrestrial_control" id="form_terrestrial" min="0" max="100" value="0">
</div>
</div>
<button type="submit" class="btn-save">ENREGISTRER LES MODIFICATIONS</button>
<button type="button" class="btn-cancel" onclick="closeModal()">ANNULER</button>
</form>
</div>
</div>
<!-- Edit Sector Modal -->
<div id="sectorModal">
<div class="modal-content">
<h3>Paramètres du Secteur</h3>
<form method="POST">
<input type="hidden" name="action" value="update_sector">
<input type="hidden" name="sector_id" value="<?php echo $sector_id; ?>">
<input type="hidden" name="galaxy_id" value="<?php echo $galaxy_id; ?>">
<div class="form-group">
<label>Nom du Secteur</label>
<input type="text" name="sector_name" value="<?php echo htmlspecialchars($sector_info['name'] ?? "Secteur $sector_id"); ?>">
</div>
<div class="form-group">
<label>Statut Global du Secteur</label>
<select name="sector_status">
<option value="unexplored" <?php echo ($sector_info['status'] ?? '') == 'unexplored' ? 'selected' : ''; ?>>Inexploré</option>
<option value="stable" <?php echo ($sector_info['status'] ?? '') == 'stable' ? 'selected' : ''; ?>>Stable / Pacifique</option>
<option value="hostile" <?php echo ($sector_info['status'] ?? '') == 'hostile' ? 'selected' : ''; ?>>Hostile / Contesté</option>
<option value="war" <?php echo ($sector_info['status'] ?? '') == 'war' ? 'selected' : ''; ?>>Zone de Guerre Mondiale</option>
</select>
</div>
<button type="submit" class="btn-save">METTRE À JOUR LE SECTEUR</button>
<button type="button" class="btn-cancel" onclick="closeSectorModal()">ANNULER</button>
</form>
</div>
</div>
<script>
function editSlot(num, data) {
document.getElementById('modalTitle').innerText = 'Modifier la case n°' + num;
document.getElementById('form_slot_num').value = num;
if (data) {
document.getElementById('form_slot_id').value = data.id;
document.getElementById('form_name').value = data.name;
document.getElementById('form_type').value = data.type;
document.getElementById('form_status').value = data.status;
document.getElementById('form_orbital').value = data.orbital_control;
document.getElementById('form_terrestrial').value = data.terrestrial_control;
document.getElementById('form_city_name').value = data.city_name || '';
document.getElementById('form_city_type').value = data.city_type || 'avant-poste';
} else {
document.getElementById('form_slot_id').value = 0;
document.getElementById('form_name').value = 'Objet ' + num;
document.getElementById('form_type').value = 'planet';
document.getElementById('form_status').value = 'empty';
document.getElementById('form_orbital').value = 0;
document.getElementById('form_terrestrial').value = 0;
document.getElementById('form_city_name').value = '';
document.getElementById('form_city_type').value = 'avant-poste';
}
document.getElementById('editModal').style.display = 'flex';
}
function closeModal() { document.getElementById('editModal').style.display = 'none'; }
function editSector() { document.getElementById('sectorModal').style.display = 'flex'; }
function closeSectorModal() { document.getElementById('sectorModal').style.display = 'none'; }
window.onclick = function(event) {
if (event.target == document.getElementById('editModal')) closeModal();
if (event.target == document.getElementById('sectorModal')) closeSectorModal();
}
</script>
</body>
</html>

358
index.php
View File

@ -3,16 +3,29 @@ require_once 'db/config.php';
session_start();
$db = db();
$user_role = 'user';
if (isset($_SESSION['user_id'])) {
$stmt = $db->prepare("SELECT role FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$u_data = $stmt->fetch();
$user_role = $u_data['role'] ?? 'user';
}
$view = isset($_GET['view']) ? $_GET['view'] : 'sector';
$galaxy_id = isset($_GET['galaxy_id']) ? (int)$_GET['galaxy_id'] : 1;
$sector_id = isset($_GET['sector_id']) ? (int)$_GET['sector_id'] : 1;
// Fetch Dynamic Types and Statuses
$object_types_db = $db->query("SELECT * FROM celestial_object_types")->fetchAll(PDO::FETCH_ASSOC);
$statuses_db = $db->query("SELECT * FROM celestial_object_statuses")->fetchAll(PDO::FETCH_ASSOC);
$object_types_map = []; foreach($object_types_db as $ot) $object_types_map[$ot['slug']] = $ot;
$statuses_map = []; foreach($statuses_db as $s) $statuses_map[$s['slug']] = $s;
// Grid size: 6x6 = 36 slots per sector
$grid_size = 36;
$grid_cols = 6;
$grid_rows = 6;
// Mock Resources (Following the screenshot's style)
// Mock Resources
$resources = [
'Metal' => ['val' => '136 053', 'max' => '1 210 000', 'prod' => '+1 980', 'icon' => 'fa-cube'],
'Crystal' => ['val' => '127 322', 'max' => '1 010 000', 'prod' => '+1 703', 'icon' => 'fa-gem'],
@ -22,50 +35,33 @@ $resources = [
];
if ($view === 'sector') {
// Fetch Objects for the current sector (6x6 grid = 36 slots)
$stmt = $db->prepare("SELECT * FROM planets WHERE galaxy_id = ? AND sector_id = ? AND slot BETWEEN 1 AND ?");
$stmt = $db->prepare("SELECT p.*, c.name as city_name, c.type as city_type FROM planets p LEFT JOIN cities c ON p.id = c.planet_id WHERE p.galaxy_id = ? AND p.sector_id = ? AND p.slot BETWEEN 1 AND ?");
$stmt->execute([$galaxy_id, $sector_id, $grid_size]);
$objects_raw = $stmt->fetchAll();
$grid = array_fill(1, $grid_size, null);
foreach ($objects_raw as $obj) {
if ($obj['slot'] >= 1 && $obj['slot'] <= $grid_size) {
$grid[$obj['slot']] = $obj;
}
}
$page_title = "Secteur $sector_id [G$galaxy_id]";
foreach ($objects_raw as $obj) { $grid[$obj['slot']] = $obj; }
$stmt = $db->prepare("SELECT name FROM sectors WHERE id = ?");
$stmt->execute([$sector_id]);
$sector_info = $stmt->fetch();
$sector_display_name = $sector_info['name'] ?? "Secteur $sector_id";
$page_title = "$sector_display_name [G$galaxy_id]";
} else {
// Galaxy View: Fetch all planets in this galaxy to build mini-maps
$stmt = $db->prepare("SELECT sector_id, slot, status, type FROM planets WHERE galaxy_id = ? ORDER BY sector_id, slot ASC");
$stmt->execute([$galaxy_id]);
$all_planets = $stmt->fetchAll();
$sector_data = [];
$active_sectors = [];
foreach ($all_planets as $p) {
$sector_data[$p['sector_id']][$p['slot']] = [
'status' => $p['status'],
'type' => $p['type']
];
if (!in_array($p['sector_id'], $active_sectors)) {
$active_sectors[] = (int)$p['sector_id'];
}
$sector_data[$p['sector_id']][$p['slot']] = ['status' => $p['status'], 'type' => $p['type']];
if (!in_array($p['sector_id'], $active_sectors)) { $active_sectors[] = (int)$p['sector_id']; }
}
$page_title = "Galaxie $galaxy_id";
}
function getStatusColor($status, $type = 'planet') {
if ($status == 'hostile') return '#ef4444'; // Rouge
if ($status == 'controlled' || $status == 'contested') return '#5e81ac'; // Bleu cassé
if ($status == 'allied' || $status == 'stable') return '#a3be8c'; // Vert cassé
if ($status == 'resource' || $type == 'asteroid') return '#f59e0b'; // Ressources / Orange
if ($status == 'pna') return '#d08770'; // PNA
if ($status == 'vortex' || $type == 'black_hole') return '#8b5cf6'; // Vortex / Violet
if ($status == 'empty' || $type == 'empty') return 'rgba(255,255,255,0.05)';
if ($status == 'inhabited') return '#eceff4'; // Planète inhabitée (Blanc cassé)
return 'rgba(255,255,255,0.05)'; // Fallback to empty
function getStatusColor($status, $statuses_map) {
return $statuses_map[$status]['color'] ?? 'rgba(255,255,255,0.05)';
}
?>
<!DOCTYPE html>
<html lang="fr">
@ -76,215 +72,51 @@ function getStatusColor($status, $type = 'planet') {
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<link href="assets/css/custom.css?v=<?php echo time(); ?>" rel="stylesheet">
<style>
body {
background: #000;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
color: #fff;
background-image: radial-gradient(circle at 50% 50%, #1a2a4a 0%, #000 70%);
background-attachment: fixed;
}
#main-wrapper {
display: flex;
flex-direction: column;
min-height: 100vh;
background: rgba(0, 0, 0, 0.4);
}
header#top-bar {
height: auto;
padding: 10px;
background: rgba(10, 15, 30, 0.95);
border-bottom: 2px solid #2d3545;
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
}
.resource-container {
display: flex;
gap: 10px;
flex-wrap: wrap;
justify-content: center;
}
.user-auth-bar {
width: 100%;
display: flex;
justify-content: flex-end;
padding: 0 20px;
box-sizing: border-box;
font-size: 12px;
margin-bottom: 5px;
}
body { background: #000; margin: 0; padding: 0; font-family: Arial, sans-serif; color: #fff; background-image: radial-gradient(circle at 50% 50%, #1a2a4a 0%, #000 70%); background-attachment: fixed; }
#main-wrapper { display: flex; flex-direction: column; min-height: 100vh; background: rgba(0, 0, 0, 0.4); }
header#top-bar { padding: 10px; background: rgba(10, 15, 30, 0.95); border-bottom: 2px solid #2d3545; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.resource-container { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.user-auth-bar { width: 100%; display: flex; justify-content: flex-end; padding: 0 20px; box-sizing: border-box; font-size: 12px; margin-bottom: 5px; }
.user-auth-bar a { color: #88c0d0; text-decoration: none; margin-left: 15px; display: flex; align-items: center; gap: 5px; }
.user-auth-bar a:hover { text-decoration: underline; color: #fff; }
.user-auth-bar .username { color: #ebcb8b; font-weight: bold; }
.resource-box {
background: #0a0a0a;
border: 1px solid #3b4252;
padding: 5px 15px;
text-align: left;
min-width: 140px;
position: relative;
}
.resource-box { background: #0a0a0a; border: 1px solid #3b4252; padding: 5px 15px; text-align: left; min-width: 140px; position: relative; }
.resource-box i { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); opacity: 0.3; font-size: 20px; }
.resource-name { font-size: 10px; color: #8c92a3; text-transform: uppercase; }
.resource-value { font-size: 13px; font-weight: bold; color: #fff; }
.resource-prod { font-size: 10px; color: #22c55e; }
#game-container {
flex-grow: 1;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
}
.nav-panel {
background: rgba(20, 30, 50, 0.95);
border: 1px solid #4c566a;
padding: 15px;
width: 200px;
margin-bottom: 20px;
box-shadow: 0 0 15px rgba(0,0,0,0.5);
}
#game-container { flex-grow: 1; padding: 20px; display: flex; flex-direction: column; align-items: center; }
.nav-panel { background: rgba(20, 30, 50, 0.95); border: 1px solid #4c566a; padding: 15px; width: 200px; margin-bottom: 20px; box-shadow: 0 0 15px rgba(0,0,0,0.5); }
.nav-panel h3 { margin: 0 0 10px 0; font-size: 14px; text-transform: uppercase; color: #88c0d0; border-bottom: 1px solid #4c566a; padding-bottom: 5px; }
.nav-panel div { margin-bottom: 8px; font-size: 12px; }
.nav-panel label { display: inline-block; width: 60px; color: #8c92a3; }
.nav-panel input { width: 60px; background: #000; border: 1px solid #4c566a; color: #fff; padding: 2px 5px; text-align: center; }
.nav-panel button { width: 100%; background: #4c566a; border: none; color: #fff; padding: 5px; margin-top: 10px; cursor: pointer; text-transform: uppercase; font-weight: bold; }
.nav-panel button:hover { background: #5e81ac; }
/* Main Sector Map (6x6 Grid) */
.galaxy-map {
background: rgba(0, 0, 0, 0.9);
border: 2px solid #2d3545;
padding: 1px;
display: grid;
grid-template-columns: repeat(6, 120px);
grid-template-rows: repeat(6, 100px);
gap: 1px;
position: relative;
}
/* Galaxy View (Grid of Sectors - 6x6) */
.sector-grid {
display: grid;
grid-template-columns: repeat(6, 160px);
grid-template-rows: repeat(6, 130px);
gap: 10px;
}
.sector-card {
background: rgba(10, 15, 30, 0.9);
border: 1px solid #3b4252;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.2s;
text-decoration: none;
color: #fff;
padding: 10px;
position: relative;
}
.sector-card:hover {
border-color: #88c0d0;
background: rgba(20, 30, 50, 0.95);
transform: translateY(-2px);
box-shadow: 0 0 15px rgba(136, 192, 208, 0.2);
}
.galaxy-map { background: rgba(0, 0, 0, 0.9); border: 2px solid #2d3545; padding: 1px; display: grid; grid-template-columns: repeat(6, 120px); grid-template-rows: repeat(6, 100px); gap: 1px; position: relative; }
.sector-grid { display: grid; grid-template-columns: repeat(6, 160px); grid-template-rows: repeat(6, 130px); gap: 10px; }
.sector-card { background: rgba(10, 15, 30, 0.9); border: 1px solid #3b4252; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; transition: all 0.2s; text-decoration: none; color: #fff; padding: 10px; position: relative; }
.sector-card:hover { border-color: #88c0d0; background: rgba(20, 30, 50, 0.95); transform: translateY(-2px); box-shadow: 0 0 15px rgba(136, 192, 208, 0.2); }
.sector-card.empty { opacity: 0.7; }
/* Mini-map Grid (6x6) */
.mini-map {
display: grid;
grid-template-columns: repeat(6, 8px);
grid-template-rows: repeat(6, 8px);
gap: 2px;
margin-bottom: 12px;
background: rgba(0,0,0,0.7);
padding: 5px;
border: 1px solid #4c566a;
}
.mini-dot {
width: 8px;
height: 8px;
background: rgba(255,255,255,0.05);
border-radius: 1px;
}
.slot {
background: #050505;
border: 1px solid #1a1a1a;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
cursor: pointer;
transition: all 0.2s;
}
.slot:hover {
background: #111;
border-color: #3b82f6;
z-index: 10;
}
.slot-id {
position: absolute;
top: 2px;
left: 5px;
font-size: 9px;
color: #444;
}
.object-icon {
font-size: 24px;
margin-bottom: 5px;
}
.object-name { font-size: 10px; font-weight: bold; color: #3b82f6; }
.mini-map { display: grid; grid-template-columns: repeat(6, 8px); gap: 2px; margin-bottom: 12px; background: rgba(0,0,0,0.7); padding: 5px; border: 1px solid #4c566a; }
.mini-dot { width: 8px; height: 8px; background: rgba(255,255,255,0.05); }
.slot { background: #050505; border: 1px solid #1a1a1a; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; cursor: pointer; transition: all 0.2s; }
.slot:hover { background: #111; border-color: #3b82f6; z-index: 10; }
.slot-id { position: absolute; top: 2px; left: 5px; font-size: 9px; color: #444; }
.object-icon { font-size: 24px; margin-bottom: 5px; }
.object-name { font-size: 10px; font-weight: bold; color: #3b82f6; text-align: center; }
.object-status { font-size: 9px; color: #8c92a3; }
.legend {
margin-top: 20px;
background: rgba(10, 15, 30, 0.95);
border: 1px solid #2d3545;
padding: 10px 20px;
display: flex;
gap: 15px;
font-size: 10px;
flex-wrap: wrap;
max-width: 1000px;
justify-content: center;
}
.city-label { font-size: 8px; color: #ebcb8b; margin-top: 2px; }
.legend { margin-top: 20px; background: rgba(10, 15, 30, 0.95); border: 1px solid #2d3545; padding: 10px 20px; display: flex; gap: 15px; font-size: 10px; flex-wrap: wrap; max-width: 1000px; justify-content: center; }
.legend-item { display: flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 1px; border: 1px solid rgba(255,255,255,0.2); }
.breadcrumb {
margin-bottom: 20px;
font-size: 14px;
color: #88c0d0;
}
.dot { width: 8px; height: 8px; border-radius: 1px; }
.breadcrumb { margin-bottom: 20px; font-size: 14px; color: #88c0d0; }
.breadcrumb a { color: #fff; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.admin-link { position: fixed; bottom: 10px; right: 10px; background: #bf616a; color: #fff; padding: 5px 10px; text-decoration: none; font-size: 10px; font-weight: bold; }
.admin-footer { position: fixed; bottom: 0; left: 0; width: 100%; background: rgba(0,0,0,0.8); padding: 5px 20px; display: flex; justify-content: flex-end; gap: 15px; border-top: 1px solid #2d3545; }
.admin-footer a { color: #fff; text-decoration: none; font-size: 11px; font-weight: bold; padding: 5px 10px; border-radius: 3px; }
.btn-mj { background: #ebcb8b; color: #000 !important; }
.btn-adm { background: #bf616a; }
</style>
</head>
<body>
@ -315,36 +147,21 @@ function getStatusColor($status, $type = 'planet') {
<main id="game-container">
<div class="breadcrumb">
<a href="?view=galaxy&galaxy_id=<?php echo $galaxy_id; ?>">Galaxie <?php echo $galaxy_id; ?></a>
<?php if($view === 'sector'): ?>
&nbsp;>&nbsp; Secteur <?php echo $sector_id; ?>
<?php endif; ?>
<?php if($view === 'sector'): ?> &nbsp;>&nbsp; <?php echo htmlspecialchars($sector_display_name); ?> <?php endif; ?>
</div>
<div style="display: flex; gap: 40px; align-items: flex-start; width: 100%; max-width: 1100px; justify-content: center;">
<!-- Navigation -->
<div class="nav-panel">
<h3>Univers</h3>
<form method="GET">
<input type="hidden" name="view" value="<?php echo $view; ?>">
<div>
<label>Galaxie</label>
<input type="number" name="galaxy_id" value="<?php echo $galaxy_id; ?>" min="1">
</div>
<?php if($view === 'sector'): ?>
<div>
<label>Secteur</label>
<input type="number" name="sector_id" value="<?php echo $sector_id; ?>" min="1">
</div>
<?php endif; ?>
<form method="GET"><input type="hidden" name="view" value="<?php echo $view; ?>">
<div><label>Galaxie</label><input type="number" name="galaxy_id" value="<?php echo $galaxy_id; ?>" min="1"></div>
<?php if($view === 'sector'): ?><div><label>Secteur</label><input type="number" name="sector_id" value="<?php echo $sector_id; ?>" min="1"></div><?php endif; ?>
<button type="submit">Localiser</button>
</form>
<?php if($view === 'sector'): ?>
<button onclick="location.href='?view=galaxy&galaxy_id=<?php echo $galaxy_id; ?>'" style="background: #3b4252; margin-top: 5px;">Vue Galaxie</button>
<?php endif; ?>
<?php if($view === 'sector'): ?><button onclick="location.href='?view=galaxy&galaxy_id=<?php echo $galaxy_id; ?>'" style="background: #3b4252; margin-top: 5px;">Vue Galaxie</button><?php endif; ?>
</div>
<?php if($view === 'sector'): ?>
<!-- Sector Map (6x6 Grid) -->
<div class="galaxy-map">
<?php for($i=1; $i<=$grid_size; $i++): ?>
<div class="slot">
@ -352,16 +169,16 @@ function getStatusColor($status, $type = 'planet') {
<?php if (isset($grid[$i])): $obj = $grid[$i]; ?>
<div class="object-icon">
<?php
$icon = 'fa-earth-europe';
$color = getStatusColor($obj['status'], $obj['type']);
if ($obj['type'] == 'asteroid') { $icon = 'fa-mountain'; }
if ($obj['type'] == 'black_hole') { $icon = 'fa-circle-dot'; }
if ($obj['type'] == 'star') { $icon = 'fa-sun'; }
$icon = $object_types_map[$obj['type']]['icon'] ?? 'fa-earth-europe';
$color = getStatusColor($obj['status'], $statuses_map);
?>
<i class="fa-solid <?php echo $icon; ?>" style="color: <?php echo $color; ?>;"></i>
</div>
<span class="object-name"><?php echo $obj['name']; ?></span>
<span class="object-status"><?php echo ucfirst($obj['status']); ?></span>
<span class="object-name"><?php echo htmlspecialchars($obj['name']); ?></span>
<span class="object-status"><?php echo $statuses_map[$obj['status']]['name'] ?? ucfirst($obj['status']); ?></span>
<?php if (!empty($obj['city_name'])): ?>
<span class="city-label"><i class="fa-solid fa-city"></i> <?php echo htmlspecialchars($obj['city_name']); ?></span>
<?php endif; ?>
<?php else: ?>
<div style="opacity: 0.05;"><i class="fa-solid fa-circle fa-sm"></i></div>
<?php endif; ?>
@ -369,51 +186,42 @@ function getStatusColor($status, $type = 'planet') {
<?php endfor; ?>
</div>
<?php else: ?>
<!-- Galaxy View (Grid of Sectors - 6x6) -->
<div class="sector-grid">
<?php for($s=1; $s<=$grid_size; $s++):
$isActive = in_array($s, $active_sectors);
?>
<?php for($s=1; $s<=$grid_size; $s++): $isActive = in_array($s, $active_sectors); ?>
<a href="?view=sector&galaxy_id=<?php echo $galaxy_id; ?>&sector_id=<?php echo $s; ?>" class="sector-card <?php echo $isActive ? '' : 'empty'; ?>">
<!-- Mini Map Preview (6x6 Grid) -->
<div class="mini-map">
<?php for($p=1; $p<=$grid_size; $p++):
$dotColor = 'rgba(255,255,255,0.05)';
if (isset($sector_data[$s][$p])) {
$dotColor = getStatusColor($sector_data[$s][$p]['status'], $sector_data[$s][$p]['type']);
}
if (isset($sector_data[$s][$p])) { $dotColor = getStatusColor($sector_data[$s][$p]['status'], $statuses_map); }
?>
<div class="mini-dot" style="background-color: <?php echo $dotColor; ?>;"></div>
<?php endfor; ?>
</div>
<div style="font-size: 10px; color: #88c0d0;">SECTEUR</div>
<div style="font-size: 20px; font-weight: bold;"><?php echo $s; ?></div>
<?php if($isActive): ?>
<div style="font-size: 8px; color: #a3be8c; margin-top: 5px;"><i class="fa-solid fa-check"></i> Actif</div>
<?php else: ?>
<div style="font-size: 8px; color: #4c566a; margin-top: 5px;">Inexploré</div>
<?php endif; ?>
<?php if($isActive): ?><div style="font-size: 8px; color: #a3be8c; margin-top: 5px;"><i class="fa-solid fa-check"></i> Actif</div>
<?php else: ?><div style="font-size: 8px; color: #4c566a; margin-top: 5px;">Inexploré</div><?php endif; ?>
</a>
<?php endfor; ?>
</div>
<?php endif; ?>
</div>
<!-- Legend -->
<div class="legend">
<div class="legend-item"><span class="dot" style="background: rgba(255,255,255,0.05);"></span> Système vide</div>
<div class="legend-item"><span class="dot" style="background: #eceff4;"></span> Planète inhabitée</div>
<div class="legend-item"><span class="dot" style="background: #ef4444;"></span> Planète hostile</div>
<div class="legend-item"><span class="dot" style="background: #f59e0b;"></span> Ressources</div>
<div class="legend-item"><span class="dot" style="background: #d08770;"></span> Planète en PNA</div>
<div class="legend-item"><span class="dot" style="background: #a3be8c;"></span> Planète alliée / stable</div>
<div class="legend-item"><span class="dot" style="background: #5e81ac;"></span> Planète contrôlée</div>
<div class="legend-item"><span class="dot" style="background: #8b5cf6;"></span> Vortex</div>
<?php foreach($statuses_db as $s): ?>
<div class="legend-item"><span class="dot" style="background: <?php echo $s['color']; ?>;"></span> <?php echo $s['name']; ?></div>
<?php endforeach; ?>
</div>
</main>
</div>
<a href="admin.php" class="admin-link">Console MJ</a>
<?php if ($user_role === 'admin' || $user_role === 'gm'): ?>
<div class="admin-footer">
<a href="gm_console.php" target="_blank" class="btn-mj"><i class="fa-solid fa-headset"></i> CONSOLE MG</a>
<?php if ($user_role === 'admin'): ?>
<a href="admin.php" target="_blank" class="btn-adm"><i class="fa-solid fa-shield-halved"></i> CONSOLE ADMIN</a>
<?php endif; ?>
</div>
<?php endif; ?>
</body>
</html>
</html>