diff --git a/admin.php b/admin.php
index ffe8fe7..22fa861 100644
--- a/admin.php
+++ b/admin.php
@@ -22,295 +22,1635 @@ $tab = isset($_GET['tab']) ? $_GET['tab'] : 'users';
// --- HANDLERS ---
-// Status Profiles
-if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["action"] === "upsert_status_profile") {
- $id = (int)$_POST["id"]; $name = $_POST["name"]; $slug = $_POST["slug"]; $enabled = isset($_POST["enabled"]) ? 1 : 0; $priority = (int)$_POST["priority"]; $scope_object_type = $_POST["scope_object_type"] === "" ? null : $_POST["scope_object_type"];
- $rules = []; if (isset($_POST['rule_status_id']) && is_array($_POST['rule_status_id'])) { foreach ($_POST['rule_status_id'] as $idx => $sid) { $rules[] = ['status_id' => (int)$sid, 'condition_type' => $_POST['rule_condition_type'][$idx], 'min_value' => $_POST['rule_min_value'][$idx] !== "" ? (float)$_POST['rule_min_value'][$idx] : null, 'max_value' => $_POST['rule_max_value'][$idx] !== "" ? (float)$_POST['rule_max_value'][$idx] : null]; } }
- $config = json_encode(['rules' => $rules]);
- if ($id > 0) { $stmt = $db->prepare("UPDATE celestial_object_status_profiles SET name = ?, slug = ?, enabled = ?, priority = ?, scope_object_type = ?, config = ? WHERE id = ?"); $stmt->execute([$name, $slug, $enabled, $priority, $scope_object_type, $config, $id]); }
- else { $stmt = $db->prepare("INSERT INTO celestial_object_status_profiles (name, slug, enabled, priority, scope_object_type, config) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([$name, $slug, $enabled, $priority, $scope_object_type, $config]); }
- header("Location: admin.php?tab=status_profiles&success=1"); exit;
-}
-if (isset($_GET["delete_status_profile"])) { $db->prepare("DELETE FROM celestial_object_status_profiles WHERE id = ?")->execute([(int)$_GET["delete_status_profile"]]); header("Location: admin.php?tab=status_profiles&success=1"); exit; }
-
-// User Roles
+// 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;
+ $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;
}
-// Celestial Object Types
+// 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']; $status_profile_id = !empty($_POST['status_profile_id']) ? (int)$_POST['status_profile_id'] : null; $modifier_ids = isset($_POST['modifiers']) ? $_POST['modifiers'] : [];
- $image_url = null; if ($id > 0) { $stmt_img = $db->prepare("SELECT image_url FROM celestial_object_types WHERE id = ?"); $stmt_img->execute([$id]); $image_url = $stmt_img->fetchColumn(); }
- if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION); $filename = $slug . "_" . time() . "." . $ext; $target = "assets/images/celestial/" . $filename; if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) $image_url = $target; }
- $orbital_enabled = isset($_POST["orbital_control_enabled"]) ? 1 : 0; $terrestrial_enabled = isset($_POST["terrestrial_control_enabled"]) ? 1 : 0;
- if ($id > 0) { $stmt = $db->prepare("UPDATE celestial_object_types SET name = ?, slug = ?, icon = ?, description = ?, image_url = ?, orbital_control_enabled = ?, terrestrial_control_enabled = ?, status_profile_id = ? WHERE id = ?"); $stmt->execute([$name, $slug, $icon, $description, $image_url, $orbital_enabled, $terrestrial_enabled, $status_profile_id, $id]); }
- else { $stmt = $db->prepare("INSERT INTO celestial_object_types (name, slug, icon, description, image_url, orbital_control_enabled, terrestrial_control_enabled, status_profile_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$name, $slug, $icon, $description, $image_url, $orbital_enabled, $terrestrial_enabled, $status_profile_id]); $id = $db->lastInsertId(); }
+ $id = (int)$_POST['id'];
+ $name = $_POST['name'];
+ $slug = $_POST['slug'];
+ $icon = $_POST['icon'];
+ $description = $_POST['description'];
+ $status_profile_id = !empty($_POST['status_profile_id']) ? (int)$_POST['status_profile_id'] : null;
+ $modifier_ids = isset($_POST['modifiers']) ? $_POST['modifiers'] : [];
+
+ $image_url = null;
+ if ($id > 0) {
+ $stmt_img = $db->prepare("SELECT image_url FROM celestial_object_types WHERE id = ?");
+ $stmt_img->execute([$id]);
+ $image_url = $stmt_img->fetchColumn();
+ }
+
+ if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
+ $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
+ $filename = $slug . "_" . time() . "." . $ext;
+ $target = "assets/images/celestial/" . $filename;
+ if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
+ $image_url = $target;
+ }
+ }
+
+ $orbital_enabled = isset($_POST["orbital_control_enabled"]) ? 1 : 0;
+ $terrestrial_enabled = isset($_POST["terrestrial_control_enabled"]) ? 1 : 0;
+
+ if ($id > 0) {
+ $stmt = $db->prepare("UPDATE celestial_object_types SET name = ?, slug = ?, icon = ?, description = ?, image_url = ?, orbital_control_enabled = ?, terrestrial_control_enabled = ?, status_profile_id = ? WHERE id = ?");
+ $stmt->execute([$name, $slug, $icon, $description, $image_url, $orbital_enabled, $terrestrial_enabled, $status_profile_id, $id]);
+ } else {
+ $stmt = $db->prepare("INSERT INTO celestial_object_types (name, slug, icon, description, image_url, orbital_control_enabled, terrestrial_control_enabled, status_profile_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
+ $stmt->execute([$name, $slug, $icon, $description, $image_url, $orbital_enabled, $terrestrial_enabled, $status_profile_id]);
+ $id = $db->lastInsertId();
+ }
+
+ // Sync modifiers
$db->prepare("DELETE FROM celestial_object_type_modifiers WHERE celestial_object_type_id = ?")->execute([$id]);
- if (!empty($modifier_ids)) { $ins = $db->prepare("INSERT INTO celestial_object_type_modifiers (celestial_object_type_id, modifier_id) VALUES (?, ?)"); foreach ($modifier_ids as $mid) $ins->execute([$id, (int)$mid]); }
- header("Location: admin.php?tab=objects&success=1"); exit;
-}
-if (isset($_GET['delete_object'])) { $db->prepare("DELETE FROM celestial_object_types WHERE id = ?")->execute([(int)$_GET['delete_object']]); header("Location: admin.php?tab=objects&success=1"); exit; }
+ if (!empty($modifier_ids)) {
+ $ins = $db->prepare("INSERT INTO celestial_object_type_modifiers (celestial_object_type_id, modifier_id) VALUES (?, ?)");
+ foreach ($modifier_ids as $mid) {
+ $ins->execute([$id, (int)$mid]);
+ }
+ }
-// Statuses
+ 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 (isset($_POST["is_blinking"]) && $_POST["is_blinking"] === "on") { if (strpos($color, ";blink") === false) $color .= ";blink"; } else { $color = str_replace(";blink", "", $color); }
- 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'])) { $db->prepare("DELETE FROM celestial_object_statuses WHERE id = ?")->execute([(int)$_GET['delete_status']]); header("Location: admin.php?tab=statuses&success=1"); exit; }
+ $id = (int)$_POST["id"];
+ $name = $_POST["name"];
+ $slug = $_POST["slug"];
+ $color = $_POST["color"];
+ $description = $_POST["description"];
+
+ // Gérer le clignotement
+ if (isset($_POST["is_blinking"]) && $_POST["is_blinking"] === "on") {
+ if (strpos($color, ";blink") === false) {
+ $color .= ";blink";
+ }
+ } else {
+ $color = str_replace(";blink", "", $color);
+ }
-// Factions
-if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_faction') {
- $id = (int)$_POST['id']; $name = $_POST['name']; $slug = $_POST['slug']; $fa_icon = $_POST['fa_icon']; $color = $_POST['color']; $is_playable = isset($_POST['is_playable']) ? 1 : 0;
- $image_url = null; if ($id > 0) { $stmt_img = $db->prepare("SELECT image_url FROM factions WHERE id = ?"); $stmt_img->execute([$id]); $image_url = $stmt_img->fetchColumn(); }
- if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION); $filename = $slug . "_" . time() . "." . $ext; $target = "assets/images/factions/" . $filename; if (!is_dir("assets/images/factions")) mkdir("assets/images/factions", 0777, true); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) $image_url = $target; }
- if ($id > 0) { $stmt = $db->prepare("UPDATE factions SET name = ?, slug = ?, fa_icon = ?, color = ?, image_url = ?, is_playable = ? WHERE id = ?"); $stmt->execute([$name, $slug, $fa_icon, $color, $image_url, $is_playable, $id]); }
- else { $stmt = $db->prepare("INSERT INTO factions (name, slug, fa_icon, color, image_url, is_playable) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([$name, $slug, $fa_icon, $color, $image_url, $is_playable]); }
- header("Location: admin.php?tab=factions&success=1"); exit;
+ 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_faction'])) { $db->prepare("DELETE FROM factions WHERE id = ?")->execute([(int)$_GET['delete_faction']]); header("Location: admin.php?tab=factions&success=1"); exit; }
-// Resources
-if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_resource') {
- $id = (int)$_POST['id']; $name = $_POST['name']; $slug = $_POST['slug']; $icon = $_POST['icon']; $description = $_POST['description']; $show_in_header = isset($_POST["show_in_header"]) ? 1 : 0;
- $image_url = null; if ($id > 0) { $stmt_img = $db->prepare("SELECT image_url FROM game_resources WHERE id = ?"); $stmt_img->execute([$id]); $image_url = $stmt_img->fetchColumn(); }
- if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) { $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION); $filename = $slug . "_" . time() . "." . $ext; $target = "assets/images/resources/" . $filename; if (!is_dir("assets/images/resources")) mkdir("assets/images/resources", 0777, true); if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) $image_url = $target; }
- if ($id > 0) { $stmt = $db->prepare("UPDATE game_resources SET name = ?, slug = ?, icon = ?, description = ?, show_in_header = ?, image_url = ? WHERE id = ?"); $stmt->execute([$name, $slug, $icon, $description, $show_in_header, $image_url, $id]); }
- else { $stmt = $db->prepare("INSERT INTO game_resources (name, slug, icon, description, show_in_header, image_url) VALUES (?, ?, ?, ?, ?, ?)"); $stmt->execute([$name, $slug, $icon, $description, $show_in_header, $image_url]); }
- header("Location: admin.php?tab=resources&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;
}
-if (isset($_GET['delete_resource'])) { $db->prepare("DELETE FROM game_resources WHERE id = ?")->execute([(int)$_GET['delete_resource']]); header("Location: admin.php?tab=resources&success=1"); exit; }
-// Modifiers
-if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_modifier') {
- $id = (int)$_POST['id']; $name = $_POST['name']; $type = $_POST['type']; $slug = $_POST['slug']; $description = $_POST['description']; $icon = $_POST['icon'];
- if ($id > 0) { $stmt = $db->prepare("UPDATE modifiers SET name = ?, type = ?, slug = ?, description = ?, icon = ? WHERE id = ?"); $stmt->execute([$name, $type, $slug, $description, $icon, $id]); }
- else { $stmt = $db->prepare("INSERT INTO modifiers (name, type, slug, description, icon) VALUES (?, ?, ?, ?, ?)"); $stmt->execute([$name, $type, $slug, $description, $icon]); }
- header("Location: admin.php?tab=modifiers&success=1"); exit;
+// Handle Status Profile CRUD
+if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["action"] === "upsert_status_profile") {
+ $id = (int)$_POST["id"];
+ $name = $_POST["name"];
+ $slug = $_POST["slug"];
+
+ if ($id > 0) {
+ $stmt = $db->prepare("UPDATE celestial_object_status_profiles SET name = ?, slug = ? WHERE id = ?");
+ $stmt->execute([$name, $slug, $id]);
+ } else {
+ $stmt = $db->prepare("INSERT INTO celestial_object_status_profiles (name, slug) VALUES (?, ?)");
+ $stmt->execute([$name, $slug]);
+ }
+ header("Location: admin.php?tab=statuses&success=1");
+ exit;
}
-if (isset($_GET['delete_modifier'])) { $db->prepare("DELETE FROM modifiers WHERE id = ?")->execute([(int)$_GET['delete_modifier']]); header("Location: admin.php?tab=modifiers&success=1"); exit; }
-// Settlement Types
+if (isset($_GET["delete_status_profile"])) {
+ $id = (int)$_GET["delete_status_profile"];
+ // Check if it is used
+ $count = $db->query("SELECT COUNT(*) FROM celestial_object_status_rules WHERE profile_id = $id")->fetchColumn();
+ $count2 = $db->query("SELECT COUNT(*) FROM celestial_object_types WHERE status_profile_id = $id")->fetchColumn();
+ if ($count == 0 && $count2 == 0) {
+ $db->prepare("DELETE FROM celestial_object_status_profiles WHERE id = ?")->execute([$id]);
+ header("Location: admin.php?tab=statuses&success=1");
+ } else {
+ header("Location: admin.php?tab=statuses&error=profile_in_use");
+ }
+ exit;
+}
+
+// Handle Status Rule CRUD
+if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_status_rule') {
+ $id = (int)$_POST['id'];
+ $name = $_POST['name'];
+ $status_id = (int)$_POST['status_id'];
+ $profile_id = (int)$_POST['profile_id'];
+ $priority = (int)$_POST['priority'];
+
+ $orbital_count_op = $_POST['orbital_count_op'] ?: null;
+ $orbital_count_val = $_POST['orbital_count_val'] !== '' ? (int)$_POST['orbital_count_val'] : null;
+ $terrestrial_count_op = $_POST['terrestrial_count_op'] ?: null;
+ $terrestrial_count_val = $_POST['terrestrial_count_val'] !== '' ? (int)$_POST['terrestrial_count_val'] : null;
+ $orbital_dominance = $_POST['orbital_dominance'] ?: null;
+ $terrestrial_dominance = $_POST['terrestrial_dominance'] ?: null;
+ $is_empty_case = isset($_POST['is_empty_case']) ? 1 : 0;
+
+ if ($id > 0) {
+ $stmt = $db->prepare("UPDATE celestial_object_status_rules SET name = ?, status_id = ?, profile_id = ?, priority = ?, orbital_count_op = ?, orbital_count_val = ?, terrestrial_count_op = ?, terrestrial_count_val = ?, orbital_dominance = ?, terrestrial_dominance = ?, is_empty_case = ? WHERE id = ?");
+ $stmt->execute([$name, $status_id, $profile_id, $priority, $orbital_count_op, $orbital_count_val, $terrestrial_count_op, $terrestrial_count_val, $orbital_dominance, $terrestrial_dominance, $is_empty_case, $id]);
+ } else {
+ $stmt = $db->prepare("INSERT INTO celestial_object_status_rules (name, status_id, profile_id, priority, orbital_count_op, orbital_count_val, terrestrial_count_op, terrestrial_count_val, orbital_dominance, terrestrial_dominance, is_empty_case) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ $stmt->execute([$name, $status_id, $profile_id, $priority, $orbital_count_op, $orbital_count_val, $terrestrial_count_op, $terrestrial_count_val, $orbital_dominance, $terrestrial_dominance, $is_empty_case]);
+ }
+ header("Location: admin.php?tab=statuses&success=1");
+ exit;
+}
+
+if (isset($_GET['delete_status_rule'])) {
+ $id = (int)$_GET['delete_status_rule'];
+ $db->prepare("DELETE FROM celestial_object_status_rules 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_type') {
- $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=settlement_types&success=1"); exit;
-}
-if (isset($_GET['delete_settlement_type'])) { $db->prepare("DELETE FROM settlement_types WHERE id = ?")->execute([(int)$_GET['delete_settlement_type']]); header("Location: admin.php?tab=settlement_types&success=1"); exit; }
+ $id = (int)$_POST['id'];
+ $name = $_POST['name'];
+ $slug = $_POST['slug'];
+ $description = $_POST['description'];
-// Lootboxes
-if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_lootbox') {
- $id = (int)$_POST['id']; $name = $_POST['name']; $slug = $_POST['slug']; $description = $_POST['description'];
- if ($id > 0) { $db->prepare("UPDATE lootboxes SET name = ?, slug = ?, description = ? WHERE id = ?")->execute([$name, $slug, $description, $id]); }
- else { $db->prepare("INSERT INTO lootboxes (name, slug, description) VALUES (?, ?, ?)")->execute([$name, $slug, $description]); }
- header("Location: admin.php?tab=lootboxes&success=1"); exit;
+ 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=settlement_types&success=1");
+ exit;
+}
+
+if (isset($_GET['delete_settlement_type'])) {
+ $id = (int)$_GET['delete_settlement_type'];
+ $db->prepare("DELETE FROM settlement_types WHERE id = ?")->execute([$id]);
+ header("Location: admin.php?tab=settlement_types&success=1");
+ exit;
+}
+
+// Handle Modifiers CRUD
+if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_modifier') {
+ $id = (int)$_POST['id'];
+ $name = $_POST['name'];
+ $slug = $_POST['slug'];
+ $type = $_POST['type'];
+ $description = $_POST['description'];
+
+ if ($id > 0) {
+ $stmt = $db->prepare("UPDATE modifiers SET name = ?, slug = ?, type = ?, description = ? WHERE id = ?");
+ $stmt->execute([$name, $slug, $type, $description, $id]);
+ } else {
+ $stmt = $db->prepare("INSERT INTO modifiers (name, slug, type, description) VALUES (?, ?, ?, ?)");
+ $stmt->execute([$name, $slug, $type, $description]);
+ }
+ header("Location: admin.php?tab=modifiers&success=1");
+ exit;
+}
+
+if (isset($_GET['delete_modifier'])) {
+ $id = (int)$_GET['delete_modifier'];
+ $db->prepare("DELETE FROM modifiers WHERE id = ?")->execute([$id]);
+ header("Location: admin.php?tab=modifiers&success=1");
+ exit;
+}
+
+// Handle Faction CRUD
+if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_faction') {
+ $id = (int)$_POST['id'];
+ $name = $_POST['name'];
+ $slug = $_POST['slug'];
+ $fa_icon = $_POST['fa_icon'];
+ $color = $_POST['color'];
+ $image_url = null;
+ $alliance_ids = isset($_POST['alliances']) ? $_POST['alliances'] : [];
+
+ if ($id > 0) {
+ $stmt_img = $db->prepare("SELECT image_url FROM factions WHERE id = ?");
+ $stmt_img->execute([$id]);
+ $image_url = $stmt_img->fetchColumn();
+ }
+ if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
+ $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
+ $filename = "faction_" . time() . "." . $ext;
+ $target = "assets/images/factions/" . $filename;
+ if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
+ $image_url = $target;
+ }
+ }
+ if ($id > 0) {
+ $stmt = $db->prepare("UPDATE factions SET name = ?, slug = ?, image_url = ?, fa_icon = ?, color = ? WHERE id = ?");
+ $stmt->execute([$name, $slug, $image_url, $fa_icon, $color, $id]);
+ } else {
+ $stmt = $db->prepare("INSERT INTO factions (name, slug, image_url, fa_icon, color) VALUES (?, ?, ?, ?, ?)");
+ $stmt->execute([$name, $slug, $image_url, $fa_icon, $color]);
+ $id = $db->lastInsertId();
+ }
+
+ // Handle Alliances (Reciprocal)
+ $db->prepare("DELETE FROM faction_alliances WHERE faction_id_1 = ? OR faction_id_2 = ?")->execute([$id, $id]);
+ foreach ($alliance_ids as $ally_id) {
+ $f1 = min((int)$id, (int)$ally_id);
+ $f2 = max((int)$id, (int)$ally_id);
+ if ($f1 === $f2) continue;
+ $db->prepare("INSERT IGNORE INTO faction_alliances (faction_id_1, faction_id_2) VALUES (?, ?)")->execute([$f1, $f2]);
+ }
+
+ header("Location: admin.php?tab=factions&success=1");
+ exit;
+}
+
+if (isset($_GET['delete_faction'])) {
+ $id = (int)$_GET['delete_faction'];
+ $db->prepare("DELETE FROM factions WHERE id = ?")->execute([$id]);
+ header("Location: admin.php?tab=factions&success=1");
+ exit;
+}
+
+// Handle Resource CRUD
+if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_resource') {
+ $id = (int)$_POST['id'];
+ $name = $_POST['name'];
+ $slug = $_POST['slug'];
+ $icon = $_POST['icon'];
+ $description = $_POST['description'];
+ $show_in_header = isset($_POST["show_in_header"]) ? 1 : 0;
+
+ $image_url = null;
+ if ($id > 0) {
+ $stmt_img = $db->prepare("SELECT image_url FROM game_resources WHERE id = ?");
+ $stmt_img->execute([$id]);
+ $image_url = $stmt_img->fetchColumn();
+ }
+
+ if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
+ $ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
+ $filename = "res_" . $slug . "_" . time() . "." . $ext;
+ if (!is_dir("assets/images/resources")) {
+ mkdir("assets/images/resources", 0775, true);
+ }
+ $target = "assets/images/resources/" . $filename;
+ if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) {
+ $image_url = $target;
+ }
+ }
+
+ if ($id > 0) {
+ $stmt = $db->prepare("UPDATE game_resources SET name = ?, slug = ?, icon = ?, description = ?, image_url = ?, show_in_header = ? WHERE id = ?");
+ $stmt->execute([$name, $slug, $icon, $description, $image_url, $show_in_header, $id]);
+ } else {
+ $stmt = $db->prepare("INSERT INTO game_resources (name, slug, icon, description, image_url, show_in_header) VALUES (?, ?, ?, ?, ?, ?)");
+ $stmt->execute([$name, $slug, $icon, $description, $image_url, $show_in_header]);
+ }
+
+ header("Location: admin.php?tab=resources&success=1");
+ exit;
+}
+
+if (isset($_GET['delete_resource'])) {
+ $id = (int)$_GET['delete_resource'];
+ $db->prepare("DELETE FROM game_resources WHERE id = ?")->execute([$id]);
+ header("Location: admin.php?tab=resources&success=1");
+ exit;
+}
+
+// Handle Lootbox CRUD
+if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_lootbox') {
+ $id = (int)$_POST['id'];
+ $name = $_POST['name'];
+ $slug = $_POST['slug'];
+ $description = $_POST['description'];
+
+ if ($id > 0) {
+ $stmt = $db->prepare("UPDATE lootboxes SET name = ?, slug = ?, description = ? WHERE id = ?");
+ $stmt->execute([$name, $slug, $description, $id]);
+ } else {
+ $stmt = $db->prepare("INSERT INTO lootboxes (name, slug, description) VALUES (?, ?, ?)");
+ $stmt->execute([$name, $slug, $description]);
+ $id = $db->lastInsertId();
+ }
+
+ // Handle Rolls
+ $db->prepare("DELETE FROM lootbox_rolls WHERE lootbox_id = ?")->execute([$id]);
+ if (isset($_POST['rolls_count']) && is_array($_POST['rolls_count'])) {
+ $ins_roll = $db->prepare("INSERT INTO lootbox_rolls (lootbox_id, roll_count, probability) VALUES (?, ?, ?)");
+ foreach ($_POST['rolls_count'] as $idx => $rc) {
+ $prob = (float)$_POST['rolls_prob'][$idx];
+ if ($prob > 0) {
+ $ins_roll->execute([$id, (int)$rc, $prob]);
+ }
+ }
+ }
+
+ // Handle Items
+ $db->prepare("DELETE FROM lootbox_items WHERE lootbox_id = ?")->execute([$id]);
+ if (isset($_POST['item_slug']) && is_array($_POST['item_slug'])) {
+ $ins_item = $db->prepare("INSERT INTO lootbox_items (lootbox_id, resource_slug, probability, quantity_min, quantity_max, is_guaranteed) VALUES (?, ?, ?, ?, ?, ?)");
+ foreach ($_POST['item_slug'] as $idx => $islug) {
+ $is_guaranteed = isset($_POST['item_is_guaranteed'][$idx]) ? (int)$_POST['item_is_guaranteed'][$idx] : 0;
+ $iprob = $is_guaranteed ? 100.00 : (float)$_POST['item_prob'][$idx];
+
+ if ($is_guaranteed || $iprob > 0) {
+ $qmin = (int)$_POST['item_qmin'][$idx];
+ $qmax = (int)$_POST['item_qmax'][$idx];
+ $ins_item->execute([$id, $islug ?: null, $iprob, $qmin, $qmax, $is_guaranteed]);
+ }
+ }
+ }
+
+ header("Location: admin.php?tab=lootboxes&success=1");
+ exit;
+}
+
+if (isset($_GET['delete_lootbox'])) {
+ $id = (int)$_GET['delete_lootbox'];
+ $db->prepare("DELETE FROM lootboxes WHERE id = ?")->execute([$id]);
+ header("Location: admin.php?tab=lootboxes&success=1");
+ exit;
+}
+
+
+// Handle Project Log CRUD
+if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["action"] === "upsert_project_log") {
+ $id = (int)$_POST["id"];
+ $version = $_POST["version"];
+ $title = $_POST["title"];
+ $content_log = $_POST["content"];
+
+ if ($id > 0) {
+ $stmt = $db->prepare("UPDATE project_logs SET version = ?, title = ?, content = ? WHERE id = ?");
+ $stmt->execute([$version, $title, $content_log, $id]);
+ } else {
+ $stmt = $db->prepare("INSERT INTO project_logs (version, title, content) VALUES (?, ?, ?)");
+ $stmt->execute([$version, $title, $content_log]);
+ }
+ header("Location: admin.php?tab=project_logs&success=1");
+ exit;
+}
+
+if (isset($_GET["delete_project_log"])) {
+ $id = (int)$_GET["delete_project_log"];
+ $db->prepare("DELETE FROM project_logs WHERE id = ?")->execute([$id]);
+ header("Location: admin.php?tab=project_logs&success=1");
+ exit;
}
-if (isset($_GET['delete_lootbox'])) { $db->prepare("DELETE FROM lootboxes WHERE id = ?")->execute([(int)$_GET['delete_lootbox']]); header("Location: admin.php?tab=lootboxes&success=1"); exit; }
// --- DATA FETCHING ---
-$users_list = []; $objects_list = []; $statuses_list = []; $status_profiles_list = []; $modifiers_list = []; $factions_list = []; $resources_list = []; $settlement_types_list = []; $lootboxes_list = []; $project_logs_list = [];
+$users_list = [];
+$objects_list = [];
+$statuses_list = [];
+$status_rules_list = [];
+$status_profiles_list = [];
+$settlement_types_list = [];
+$modifiers_list = [];
+$factions_list = [];
+$resources_list = [];
+$lootboxes_list = [];
+$project_logs_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 o.*, p.name as profile_name FROM celestial_object_types o LEFT JOIN celestial_object_status_profiles p ON o.status_profile_id = p.id ORDER BY o.name ASC")->fetchAll();
- foreach ($objects_list as &$obj) { $stmt = $db->prepare("SELECT modifier_id FROM celestial_object_type_modifiers WHERE celestial_object_type_id = ?"); $stmt->execute([$obj['id']]); $obj['modifier_ids'] = $stmt->fetchAll(PDO::FETCH_COLUMN); } unset($obj);
- $status_profiles_list = $db->query("SELECT id, name FROM celestial_object_status_profiles WHERE enabled = 1 ORDER BY name ASC")->fetchAll();
+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();
+ foreach ($objects_list as &$obj) {
+ $stmt = $db->prepare("SELECT modifier_id FROM celestial_object_type_modifiers WHERE celestial_object_type_id = ?");
+ $stmt->execute([$obj['id']]);
+ $obj['modifier_ids'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
+ }
+ unset($obj);
$modifiers_list = $db->query("SELECT * FROM modifiers ORDER BY type, name ASC")->fetchAll();
-}
-elseif ($tab === 'statuses') { $statuses_list = $db->query("SELECT * FROM celestial_object_statuses ORDER BY name ASC")->fetchAll(); }
-elseif ($tab === 'status_profiles') {
- $status_profiles_list = $db->query("SELECT * FROM celestial_object_status_profiles ORDER BY priority DESC, name ASC")->fetchAll();
- $statuses_list = $db->query("SELECT id, name FROM celestial_object_statuses ORDER BY name ASC")->fetchAll();
- $object_types_list = $db->query("SELECT id, name, slug FROM celestial_object_types ORDER BY name ASC")->fetchAll();
+ $status_profiles_list = $db->query("SELECT * FROM celestial_object_status_profiles ORDER BY name ASC")->fetchAll();
+} elseif ($tab === 'statuses') {
+ $statuses_list = $db->query("SELECT * FROM celestial_object_statuses ORDER BY name ASC")->fetchAll();
+ $status_rules_list = $db->query("SELECT r.*, s.name as status_name, p.name as profile_name FROM celestial_object_status_rules r JOIN celestial_object_statuses s ON r.status_id = s.id LEFT JOIN celestial_object_status_profiles p ON r.profile_id = p.id ORDER BY r.profile_id, r.priority DESC, r.name ASC")->fetchAll();
+ $status_profiles_list = $db->query("SELECT * FROM celestial_object_status_profiles ORDER BY name ASC")->fetchAll();
+ $factions_list = $db->query("SELECT * FROM factions ORDER BY name ASC")->fetchAll();
+} elseif ($tab === 'settlement_types') {
+ $settlement_types_list = $db->query("SELECT * FROM settlement_types ORDER BY name ASC")->fetchAll();
+} elseif ($tab === 'modifiers') {
+ $modifiers_list = $db->query("SELECT * FROM modifiers ORDER BY type, name ASC")->fetchAll();
+} elseif ($tab === 'factions') {
+ $factions_list = $db->query("SELECT * FROM factions ORDER BY name ASC")->fetchAll();
+ foreach ($factions_list as &$f) {
+ $stmt = $db->prepare("SELECT faction_id_1 as ally_id FROM faction_alliances WHERE faction_id_2 = ? UNION SELECT faction_id_2 as ally_id FROM faction_alliances WHERE faction_id_1 = ?");
+ $stmt->execute([$f['id'], $f['id']]);
+ $f['alliance_ids'] = $stmt->fetchAll(PDO::FETCH_COLUMN);
+ }
+ unset($f);
+} elseif ($tab === 'resources') {
+ $resources_list = $db->query("SELECT * FROM game_resources ORDER BY name ASC")->fetchAll();
+} elseif ($tab === 'project_logs') {
+ $project_logs_list = $db->query("SELECT * FROM project_logs ORDER BY created_at DESC")->fetchAll();
+} elseif ($tab === 'lootboxes') {
+ $lootboxes_list = $db->query("SELECT * FROM lootboxes ORDER BY name ASC")->fetchAll();
+ $resources_list = $db->query("SELECT name, slug FROM game_resources ORDER BY name ASC")->fetchAll();
+ foreach ($lootboxes_list as &$lb) {
+ $stmt_r = $db->prepare("SELECT * FROM lootbox_rolls WHERE lootbox_id = ?");
+ $stmt_r->execute([$lb['id']]);
+ $lb['rolls'] = $stmt_r->fetchAll();
+
+ $stmt_i = $db->prepare("SELECT * FROM lootbox_items WHERE lootbox_id = ?");
+ $stmt_i->execute([$lb['id']]);
+ $lb['items'] = $stmt_i->fetchAll();
+ }
+ unset($lb);
}
-elseif ($tab === 'resources') { $resources_list = $db->query("SELECT * FROM game_resources ORDER BY name ASC")->fetchAll(); }
-elseif ($tab === 'factions') { $factions_list = $db->query("SELECT * FROM factions ORDER BY name ASC")->fetchAll(); }
-elseif ($tab === 'modifiers') { $modifiers_list = $db->query("SELECT * FROM modifiers ORDER BY type, name ASC")->fetchAll(); }
-elseif ($tab === 'settlement_types') { $settlement_types_list = $db->query("SELECT * FROM settlement_types ORDER BY name ASC")->fetchAll(); }
-elseif ($tab === 'lootboxes') { $lootboxes_list = $db->query("SELECT * FROM lootboxes ORDER BY name ASC")->fetchAll(); }
-elseif ($tab === 'project_logs') { $project_logs_list = $db->query("SELECT * FROM project_logs ORDER BY created_at DESC")->fetchAll(); }
?>
- Console Admin - Nexus
+
+ Console Admin - Nexus
-
+
+
+
+
Opération effectuée avec succès.
+
+
-
+
Gestion des Rôles
+
+
+ | Utilisateur | Email | Rôle Actuel | Nouveau Rôle |
+
+
+
+
+ |
+ |
+
+
+
+
+ |
+
+
+ |
+
+
+
+
-
-
| Visuel | Nom | Slug | Profil | Actions |
- | | | | X |
+
Objets Célestes
+