diff --git a/admin.php b/admin.php
index 57b2cd9..03f9c45 100644
--- a/admin.php
+++ b/admin.php
@@ -1,119 +1,396 @@
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']
-];
?>
-
- Console MJ
+ Console Admin - Nexus
-
-
- $res): ?>
-
-
+
-
-
-
Retour au Secteur
-
Console de Commandement MJ
-
-
-
-
Planètes Libérées
-
/
-
-
-
-
-
-
+
+
+
Opération effectuée avec succès.
+
+
+
+
+
Gestion des Rôles
-
- | Planète |
- Type |
- Statut |
- Contrôle Sol |
- Action |
-
+ | Utilisateur | Email | Rôle Actuel | Nouveau Rôle |
-
+
- |
- |
- |
- % |
- Localiser |
+ |
+ |
+
+
+
+
+ |
+
+
+ |
-
-
+
+
+
Objets Célestes
+
+
+
+ | Icône | Nom | Slug | Actions |
+
+
+
+ |
+ |
+ |
+
+
+ Suppr
+ |
+
+
+
+
+
+
+
Statuts / États
+
+
+
+ | Couleur | Nom | Slug | Actions |
+
+
+
+ |
+ |
+ |
+
+
+ Suppr
+ |
+
+
+
+
+
+
+
Villes / Avant-postes
+
+
+
+ | Nom | Slug | Description | Actions |
+
+
+
+ |
+ |
+ |
+
+
+ Suppr
+ |
+
+
+
+
+
+
+
+
-
+