diff --git a/admin.php b/admin.php index e7ea284..19571c1 100644 --- a/admin.php +++ b/admin.php @@ -42,13 +42,29 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' $icon = $_POST['icon']; $description = $_POST['description']; $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; + } + } if ($id > 0) { - $stmt = $db->prepare("UPDATE celestial_object_types SET name = ?, slug = ?, icon = ?, description = ? WHERE id = ?"); - $stmt->execute([$name, $slug, $icon, $description, $id]); + $stmt = $db->prepare("UPDATE celestial_object_types SET name = ?, slug = ?, icon = ?, description = ?, image_url = ? WHERE id = ?"); + $stmt->execute([$name, $slug, $icon, $description, $image_url, $id]); } else { - $stmt = $db->prepare("INSERT INTO celestial_object_types (name, slug, icon, description) VALUES (?, ?, ?, ?)"); - $stmt->execute([$name, $slug, $icon, $description]); + $stmt = $db->prepare("INSERT INTO celestial_object_types (name, slug, icon, description, image_url) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$name, $slug, $icon, $description, $image_url]); $id = $db->lastInsertId(); } @@ -148,12 +164,50 @@ if (isset($_GET['delete_modifier'])) { exit; } +// Handle Faction CRUD +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_faction') { + $id = (int)$_POST['id']; + $name = $_POST['name']; + $fa_icon = $_POST['fa_icon']; + $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 = "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 = ?, image_url = ?, fa_icon = ? WHERE id = ?"); + $stmt->execute([$name, $image_url, $fa_icon, $id]); + } else { + $stmt = $db->prepare("INSERT INTO factions (name, image_url, fa_icon) VALUES (?, ?, ?)"); + $stmt->execute([$name, $image_url, $fa_icon]); + } + 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; +} + // --- DATA FETCHING --- $users_list = []; $objects_list = []; $statuses_list = []; $settlement_types_list = []; $modifiers_list = []; +$factions_list = []; if ($tab === 'users') { $users_list = $db->query("SELECT id, username, email, role FROM users ORDER BY username ASC")->fetchAll(); @@ -172,6 +226,8 @@ if ($tab === 'users') { $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(); } ?> @@ -240,6 +296,7 @@ if ($tab === 'users') { Bonus & Malus Statuts / États Types d'Établissements + Factions @@ -279,7 +336,7 @@ if ($tab === 'users') {

Objets Célestes

Ajouter / Modifier un Objet

-
+
@@ -295,6 +352,10 @@ if ($tab === 'users') {
+
+ + +
@@ -323,11 +384,17 @@ if ($tab === 'users') {
- + - + @@ -392,7 +459,7 @@ if ($tab === 'users') { @@ -439,7 +506,7 @@ if ($tab === 'users') { @@ -482,13 +549,65 @@ if ($tab === 'users') {
IcôneNomSlugBonus/MalusActions
VisuelNomSlugBonus/MalusActions
+ + + + + + @@ -342,7 +409,7 @@ if ($tab === 'users') { - + Suppr
- + Suppr
- + Suppr
- + Suppr
+ + +

Gestion des Factions

+
+

Ajouter / Modifier une Faction

+ + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + +
+ + + + + + + + + + + + +
VisuelNomActions
+ + + + + + + + + + + Suppr + +
@@ -544,6 +663,14 @@ if ($tab === 'users') { window.scrollTo(0,0); } function resetModifierForm() { document.getElementById('modifierForm').reset(); document.getElementById('mod_id').value = 0; } + + function editFaction(data) { + document.getElementById('fac_id').value = data.id; + document.getElementById('fac_name').value = data.name; + document.getElementById('fac_fa_icon').value = data.fa_icon || ''; + window.scrollTo(0,0); + } + function resetFactionForm() { document.getElementById('factionForm').reset(); document.getElementById('fac_id').value = 0; } - + \ No newline at end of file diff --git a/assets/images/celestial/black_hole_1771735023.png b/assets/images/celestial/black_hole_1771735023.png new file mode 100644 index 0000000..9781bd1 Binary files /dev/null and b/assets/images/celestial/black_hole_1771735023.png differ diff --git a/assets/images/celestial/planet_desert_01_1771755173.png b/assets/images/celestial/planet_desert_01_1771755173.png new file mode 100644 index 0000000..05bb417 Binary files /dev/null and b/assets/images/celestial/planet_desert_01_1771755173.png differ diff --git a/assets/images/celestial/planet_volcanic_02_1771733154.png b/assets/images/celestial/planet_volcanic_02_1771733154.png new file mode 100644 index 0000000..212b6b0 Binary files /dev/null and b/assets/images/celestial/planet_volcanic_02_1771733154.png differ diff --git a/assets/images/celestial/planet_volcanic_1771732666.png b/assets/images/celestial/planet_volcanic_1771732666.png new file mode 100644 index 0000000..e744233 Binary files /dev/null and b/assets/images/celestial/planet_volcanic_1771732666.png differ diff --git a/assets/images/celestial/star_1771754685.png b/assets/images/celestial/star_1771754685.png new file mode 100644 index 0000000..253b595 Binary files /dev/null and b/assets/images/celestial/star_1771754685.png differ diff --git a/assets/pasted-20260222-040104-75ec63e6.png b/assets/pasted-20260222-040104-75ec63e6.png new file mode 100644 index 0000000..be0b39b Binary files /dev/null and b/assets/pasted-20260222-040104-75ec63e6.png differ diff --git a/db/add_fa_icon_to_factions.php b/db/add_fa_icon_to_factions.php new file mode 100644 index 0000000..d5249ab --- /dev/null +++ b/db/add_fa_icon_to_factions.php @@ -0,0 +1,16 @@ +query("DESCRIBE factions")->fetchAll(PDO::FETCH_COLUMN); + if (!in_array('fa_icon', $cols)) { + $db->exec("ALTER TABLE factions ADD COLUMN fa_icon VARCHAR(50) NULL AFTER image_url"); + echo "Column 'fa_icon' added to 'factions' table.\n"; + } else { + echo "Column 'fa_icon' already exists in 'factions' table.\n"; + } +} catch (PDOException $e) { + die("Migration failed: " . $e->getMessage()); +} + diff --git a/db/migrate_factions.php b/db/migrate_factions.php new file mode 100644 index 0000000..4c2cf56 --- /dev/null +++ b/db/migrate_factions.php @@ -0,0 +1,35 @@ +exec("CREATE TABLE IF NOT EXISTS factions ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(100) NOT NULL, + image_url VARCHAR(255) NULL, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP + )"); + echo "Table 'factions' created or already exists.\n"; + + // Add faction_id to planets table + $cols = $db->query("DESCRIBE planets")->fetchAll(PDO::FETCH_COLUMN); + if (!in_array('faction_id', $cols)) { + $db->exec("ALTER TABLE planets ADD COLUMN faction_id INT DEFAULT NULL AFTER status"); + echo "Column 'faction_id' added to 'planets' table.\n"; + } else { + echo "Column 'faction_id' already exists in 'planets' table.\n"; + } + + // Check if 'Aucune' faction exists + $stmt = $db->prepare("SELECT COUNT(*) FROM factions WHERE name = 'Aucune'"); + $stmt->execute(); + if ($stmt->fetchColumn() == 0) { + $db->exec("INSERT INTO factions (name) VALUES ('Aucune')"); + echo "Default faction 'Aucune' created.\n"; + } + +} catch (PDOException $e) { + die("Migration failed: " . $e->getMessage()); +} + diff --git a/gm_console.php b/gm_console.php index 001c298..51b90ca 100644 --- a/gm_console.php +++ b/gm_console.php @@ -20,13 +20,15 @@ if (!$current_user || ($current_user['role'] !== 'admin' && $current_user['role' $is_admin = ($current_user['role'] === 'admin'); -// Fetch Dynamic Types, Statuses, and Settlement Types - Sorted Alphabetically +// Fetch Dynamic Types, Statuses, Settlement Types, and Factions $object_types_db = $db->query("SELECT * FROM celestial_object_types ORDER BY name ASC")->fetchAll(PDO::FETCH_ASSOC); $statuses_db = $db->query("SELECT * FROM celestial_object_statuses ORDER BY name ASC")->fetchAll(PDO::FETCH_ASSOC); $settlement_types_db = $db->query("SELECT * FROM settlement_types ORDER BY name ASC")->fetchAll(PDO::FETCH_ASSOC); +$factions_db = $db->query("SELECT * FROM factions ORDER BY name 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; +$factions_map = []; foreach($factions_db as $f) $factions_map[$f['id']] = $f; // Handle Planet/Slot Update if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'update_slot') { @@ -37,6 +39,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' $name = $_POST['name']; $type = $_POST['type']; $status = $_POST['status']; + $faction_id = (int)$_POST['faction_id']; $orbital = (int)$_POST['orbital_control']; $terrestrial = (int)$_POST['terrestrial_control']; @@ -47,12 +50,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' } } 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]); + $stmt = $db->prepare("UPDATE planets SET name = ?, type = ?, status = ?, faction_id = ?, orbital_control = ?, terrestrial_control = ? WHERE id = ?"); + $stmt->execute([$name, $type, $status, $faction_id, $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]); + $stmt = $db->prepare("INSERT INTO planets (galaxy_id, sector_id, slot, name, type, status, faction_id, orbital_control, terrestrial_control) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$galaxy_id, $sector_id, $slot_num, $name, $type, $status, $faction_id, $orbital, $terrestrial]); $planet_id = $db->lastInsertId(); } @@ -72,7 +75,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' $sent_city_ids[] = $c_id; } else { $stmt = $db->prepare("INSERT INTO cities (planet_id, name, settlement_type_id) VALUES (?, ?, ?)"); - $stmt->execute([$planet_id, $c_name, $c_type_id]); + $stmt->execute([$c_name, $c_type_id]); $sent_city_ids[] = $db->lastInsertId(); } } @@ -100,13 +103,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' $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([$s_name, $s_status, $sector_id, $galaxy_id]); - } + $stmt = $db->prepare("INSERT INTO sectors (id, galaxy_id, name, status) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE name = ?, status = ?"); + $stmt->execute([$sector_id, $galaxy_id, $s_name, $s_status, $s_name, $s_status]); + header("Location: gm_console.php?view=sector&galaxy_id=$galaxy_id§or_id=$sector_id&success=1"); exit; } @@ -117,20 +116,18 @@ $sector_id = isset($_GET['sector_id']) ? (int)$_GET['sector_id'] : 1; $grid_size = 36; if ($view === 'sector') { - // Fetch planets $stmt = $db->prepare("SELECT * FROM planets WHERE galaxy_id = ? AND sector_id = ? AND slot BETWEEN 1 AND ?"); $stmt->execute([$galaxy_id, $sector_id, $grid_size]); $objects_raw = $stmt->fetchAll(); $grid = array_fill(1, $grid_size, null); $planet_ids = []; - foreach ($objects_raw as $obj) { - $grid[$obj['slot']] = $obj; + foreach ($objects_raw as $obj) { + $grid[$obj['slot']] = $obj; $planet_ids[] = $obj['id']; $grid[$obj['slot']]['cities'] = []; } - // Fetch ALL cities for these planets if (!empty($planet_ids)) { $placeholders = implode(',', array_fill(0, count($planet_ids), '?')); $stmt = $db->prepare("SELECT * FROM cities WHERE planet_id IN ($placeholders)"); @@ -144,26 +141,24 @@ if ($view === 'sector') { } } } - - $stmt = $db->prepare("SELECT * FROM sectors WHERE id = ?"); + $stmt = $db->prepare("SELECT name FROM sectors WHERE id = ?"); $stmt->execute([$sector_id]); $sector_info = $stmt->fetch(); -} elseif ($view === 'galaxy') { +} else { $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']; } } - $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)'; + if ($type === 'empty') return 'rgba(255,255,255,0.05)'; + return $statuses_map[$status]['color'] ?? 'rgba(255,255,255,0.05)'; } ?> @@ -174,73 +169,130 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {

CONSOLE MJ

-
-
- Maître du Jeu: - -
+
Connecté en tant que MJ: @
-

Sélecteur de Secteur

+

Navigateur de Galaxie

- + -
-
+
Retour

Secteur :

@@ -267,13 +319,31 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
- + +
+ + + + + + + +
+
- + + + + +
@@ -306,19 +376,29 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) {
-
- - +
+
+ + +
+
+ + +
@@ -400,48 +480,47 @@ function getStatusColor($status, $type, $statuses_map, $object_types_map) { const sel = (data && data.settlement_type_id == t.id) ? 'selected' : ''; html += ``; }); - html += `
`; - html += `
`; + html += `
`; div.innerHTML = html; container.appendChild(div); } function editSlot(num, data) { - document.getElementById('modalTitle').innerText = 'Modifier la case n°' + num; document.getElementById('form_slot_num').value = num; - document.getElementById('settlementsContainer').innerHTML = ''; - settlementIndex = 0; - + document.getElementById('form_slot_id').value = data ? data.id : 0; + document.getElementById('modalTitle').innerText = 'Éditer Case #' + 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_faction').value = data.faction_id || 0; document.getElementById('form_orbital').value = data.orbital_control; document.getElementById('form_terrestrial').value = data.terrestrial_control; + // Load settlements + document.getElementById('settlementsContainer').innerHTML = ''; + settlementIndex = 0; if (data.cities && data.cities.length > 0) { data.cities.forEach(c => addSettlementRow(c)); } } 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_name').value = ''; + document.getElementById('form_type').value = 'empty'; + document.getElementById('form_status').value = 'neutral'; + document.getElementById('form_faction').value = document.querySelector('#form_faction option').value; document.getElementById('form_orbital').value = 0; document.getElementById('form_terrestrial').value = 0; + document.getElementById('settlementsContainer').innerHTML = ''; } + 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(); - } - + \ No newline at end of file diff --git a/index.php b/index.php index 1b9cd9b..b71ca87 100644 --- a/index.php +++ b/index.php @@ -15,9 +15,10 @@ $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 +// Fetch Dynamic Types, Statuses and Factions $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); +$factions_db = $db->query("SELECT * FROM factions")->fetchAll(PDO::FETCH_ASSOC); $object_types_map = []; foreach($object_types_db as $ot) { @@ -29,6 +30,7 @@ foreach($object_types_db as $ot) { } $statuses_map = []; foreach($statuses_db as $s) $statuses_map[$s['slug']] = $s; +$factions_map = []; foreach($factions_db as $f) $factions_map[$f['id']] = $f; // Grid size: 6x6 = 36 slots per sector $grid_size = 36; @@ -98,56 +100,148 @@ function getStatusColor($status, $statuses_map) { - - <?php echo $page_title; ?> + Nexus - <?php echo $page_title; ?>