diff --git a/admin.php b/admin.php index 19571c1..68cc25d 100644 --- a/admin.php +++ b/admin.php @@ -143,15 +143,16 @@ if (isset($_GET['delete_settlement_type'])) { 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 = ?, type = ?, description = ? WHERE id = ?"); - $stmt->execute([$name, $type, $description, $id]); + $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, type, description) VALUES (?, ?, ?)"); - $stmt->execute([$name, $type, $description]); + $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; @@ -168,6 +169,7 @@ if (isset($_GET['delete_modifier'])) { 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']; $image_url = null; if ($id > 0) { @@ -184,11 +186,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' } } if ($id > 0) { - $stmt = $db->prepare("UPDATE factions SET name = ?, image_url = ?, fa_icon = ? WHERE id = ?"); - $stmt->execute([$name, $image_url, $fa_icon, $id]); + $stmt = $db->prepare("UPDATE factions SET name = ?, slug = ?, image_url = ?, fa_icon = ? WHERE id = ?"); + $stmt->execute([$name, $slug, $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]); + $stmt = $db->prepare("INSERT INTO factions (name, slug, image_url, fa_icon) VALUES (?, ?, ?, ?)"); + $stmt->execute([$name, $slug, $image_url, $fa_icon]); } header("Location: admin.php?tab=factions&success=1"); exit; @@ -201,6 +203,107 @@ if (isset($_GET['delete_faction'])) { 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']; + + $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 = ? WHERE id = ?"); + $stmt->execute([$name, $slug, $icon, $description, $image_url, $id]); + } else { + $stmt = $db->prepare("INSERT INTO game_resources (name, slug, icon, description, image_url) VALUES (?, ?, ?, ?, ?)"); + $stmt->execute([$name, $slug, $icon, $description, $image_url]); + } + + 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; +} + // --- DATA FETCHING --- $users_list = []; $objects_list = []; @@ -208,12 +311,13 @@ $statuses_list = []; $settlement_types_list = []; $modifiers_list = []; $factions_list = []; +$resources_list = []; +$lootboxes_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(); - // For each object, get its modifiers 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']]); @@ -228,6 +332,20 @@ if ($tab === 'users') { $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(); +} elseif ($tab === 'resources') { + $resources_list = $db->query("SELECT * FROM game_resources ORDER BY name ASC")->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(); + } } ?> @@ -243,7 +361,7 @@ if ($tab === 'users') { 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; } + .container { padding: 40px; max-width: 1400px; margin: 0 auto; } .tabs { display: flex; gap: 5px; margin-bottom: 20px; border-bottom: 2px solid #2d3545; flex-wrap: wrap; } .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; } @@ -269,6 +387,21 @@ if ($tab === 'users') { .modifier-tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: bold; margin-right: 5px; margin-bottom: 5px; } .tag-bonus { background: #a3be8c; color: #000; } .tag-malus { background: #bf616a; color: #fff; } + + .sub-form-row { display: flex; gap: 8px; margin-bottom: 5px; align-items: center; } + .sub-form-row .btn-del-row { flex: 0 0 30px; background: #bf616a; color: #fff; padding: 5px; border-radius: 4px; text-align: center; cursor: pointer; } + + .sub-form-header { display: flex; gap: 8px; margin-bottom: 5px; font-size: 10px; color: #8c92a3; text-transform: uppercase; font-weight: bold; } + .sub-form-header .btn-del-row-placeholder { flex: 0 0 30px; } + + /* Custom toggle switch */ + .toggle-container { display: flex; align-items: center; gap: 5px; font-size: 9px; color: #8c92a3; flex: 0 0 100px; } + .switch { position: relative; display: inline-block; width: 40px; height: 20px; flex-shrink: 0; } + .switch input { opacity: 0; width: 0; height: 0; } + .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #334155; transition: .4s; border-radius: 20px; } + .slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; } + input:checked + .slider { background-color: #a3be8c; } + input:checked + .slider:before { transform: translateX(20px); }
@@ -297,6 +430,8 @@ if ($tab === 'users') { Statuts / États Types d'Établissements Factions + Ressources + Lootboxes @@ -384,7 +519,7 @@ if ($tab === 'users') {| Visuel | Nom | Slug | Bonus/Malus | Actions | |||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Visuel | Nom | Bonus/Malus | Slug | Actions | |||||||||||||||||||||||||||||||||||||||||||
| - | |
prepare("SELECT m.name, m.type FROM modifiers m JOIN celestial_object_type_modifiers cotm ON m.id = cotm.modifier_id WHERE cotm.celestial_object_type_id = ?"); @@ -408,6 +542,7 @@ if ($tab === 'users') { | + |
Suppr
@@ -429,6 +564,10 @@ if ($tab === 'users') {
+
+
+
+
|