372 lines
21 KiB
PHP
372 lines
21 KiB
PHP
<?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§or_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§or_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; ?>§or_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>
|