diff --git a/admin.php b/admin.php index 8a114a6..0809218 100644 --- a/admin.php +++ b/admin.php @@ -632,6 +632,69 @@ if (isset($_GET["delete_project_log"])) { exit; } +// Handle Unit CRUD +if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["action"] === "upsert_unit") { + $id = (int)$_POST["id"]; + $name = $_POST["name"]; + $slug = $_POST["slug"]; + $faction_id = !empty($_POST["faction_id"]) ? (int)$_POST["faction_id"] : null; + $can_be_destroyed = isset($_POST["can_be_destroyed"]) ? 1 : 0; + $can_be_captured = isset($_POST["can_be_captured"]) ? 1 : 0; + $points_per_hit = (int)$_POST["points_per_hit"]; + $bonus_destruction = (int)$_POST["bonus_destruction"]; + $bonus_capture = (int)$_POST["bonus_capture"]; + $grid_data = $_POST["grid_data"]; + + $image_url = null; + if ($id > 0) { + $stmt_img = $db->prepare("SELECT image_url FROM units 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 = "unit_" . $slug . "_" . time() . "." . $ext; + $target = "assets/images/units/" . $filename; + if (!is_dir("assets/images/units/")) mkdir("assets/images/units/", 0775, true); + if (move_uploaded_file($_FILES["image"]["tmp_name"], $target)) { + $image_url = $target; + } + } + + if ($id > 0) { + $stmt = $db->prepare("UPDATE units SET name = ?, slug = ?, faction_id = ?, can_be_destroyed = ?, can_be_captured = ?, points_per_hit = ?, bonus_destruction = ?, bonus_capture = ?, grid_data = ?, image_url = ? WHERE id = ?"); + $stmt->execute([$name, $slug, $faction_id, $can_be_destroyed, $can_be_captured, $points_per_hit, $bonus_destruction, $bonus_capture, $grid_data, $image_url, $id]); + } else { + $stmt = $db->prepare("INSERT INTO units (name, slug, faction_id, can_be_destroyed, can_be_captured, points_per_hit, bonus_destruction, bonus_capture, grid_data, image_url) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([$name, $slug, $faction_id, $can_be_destroyed, $can_be_captured, $points_per_hit, $bonus_destruction, $bonus_capture, $grid_data, $image_url]); + $id = $db->lastInsertId(); + } + + // Handle Rewards + $db->prepare("DELETE FROM unit_rewards WHERE unit_id = ?")->execute([$id]); + if (isset($_POST["reward_action"]) && is_array($_POST["reward_action"])) { + $ins_rw = $db->prepare("INSERT INTO unit_rewards (unit_id, action_type, resource_id, amount) VALUES (?, ?, ?, ?)"); + foreach ($_POST["reward_action"] as $idx => $action) { + $res_id = (int)$_POST["reward_resource_id"][$idx]; + $amount = (int)$_POST["reward_amount"][$idx]; + if ($amount > 0) { + $ins_rw->execute([$id, $action, $res_id, $amount]); + } + } + } + + header("Location: admin.php?tab=units&success=1"); + exit; +} + +if (isset($_GET["delete_unit"])) { + $id = (int)$_GET["delete_unit"]; + $db->prepare("DELETE FROM units WHERE id = ?")->execute([$id]); + header("Location: admin.php?tab=units&success=1"); + exit; +} + // --- DATA FETCHING --- $users_list = []; @@ -645,6 +708,7 @@ $factions_list = []; $resources_list = []; $lootboxes_list = []; $project_logs_list = []; +$units_list = []; $titles_list = []; $badges_list = []; $levels_list = []; @@ -711,6 +775,16 @@ if ($tab === 'users') { $stmt = $db->query("SELECT value FROM guild_restrictions WHERE restriction_key = 'member_limit'"); $guild_member_limit = $stmt->fetchColumn() ?: 50; } +elseif ($tab === "units") { + $units_list = $db->query("SELECT u.*, f.name as faction_name FROM units u LEFT JOIN factions f ON u.faction_id = f.id ORDER BY u.name ASC")->fetchAll(); + foreach ($units_list as &$unit) { + $stmt_rw = $db->prepare("SELECT action_type, resource_id, amount FROM unit_rewards WHERE unit_id = ?"); + $stmt_rw->execute([$unit["id"]]); + $unit["rewards"] = $stmt_rw->fetchAll(); + } + unset($unit); + $factions_list = $db->query("SELECT id, name FROM factions ORDER BY name ASC")->fetchAll(); + $resources_list = $db->query("SELECT id, name FROM game_resources ORDER BY name ASC")->fetchAll(); ?> @@ -762,10 +836,8 @@ if ($tab === 'users') { .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); } + $factions_list = $db->query("SELECT id, name FROM factions ORDER BY name ASC")->fetchAll(); + $resources_list = $db->query("SELECT id, name FROM game_resources ORDER BY name ASC")->fetchAll(); @keyframes blink { 0% { opacity: 1; } @@ -792,6 +864,11 @@ if ($tab === 'users') { .ms-item { padding: 5px 8px; cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 11px; } .ms-item:hover { background: #2d3545; } .ms-item input { width: auto !important; } + .unit-grid-container { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; } + .unit-grid { display: grid; grid-template-columns: repeat(5, 40px); grid-template-rows: repeat(10, 40px); gap: 2px; background: #2d3545; padding: 2px; width: fit-content; } + .unit-cell { width: 40px; height: 40px; background: #0f172a; cursor: pointer; border: 1px solid #334155; } + .unit-cell.active { background: #88c0d0; } + .unit-cell:hover { border-color: #88c0d0; }
@@ -835,6 +912,7 @@ if ($tab === 'users') { Factions Ressources Lootboxes + Unité @@ -870,6 +948,153 @@ if ($tab === 'users') { + +| Image | +Nom / Slug | +Faction | +Propriétés | +Récompenses | +Actions | +
|---|---|---|---|---|---|
| Aucune unité configurée. | |||||
|
+
+
+
+
+
+ |
+
+ +
+ |
+ + + + + | +
+ Pts/Coup: + ● Destructible + ● Capturable + |
+
+ 0): ?>Destr: + pts + 0): ?>Capt: + pts + + + : + + + + |
+ + + Suppr + | +
| Visuel | Nom | Slug | Type | @@ -1861,7 +2087,7 @@ if ($tab === 'users') { -+ | |
@@ -1891,7 +2117,6 @@ if ($tab === 'users') {
- ×
+ `;
+ container.appendChild(row);
+ }
+
+ function resetUnitForm() {
+ document.getElementById('unitForm').reset();
+ document.getElementById('unit_id').value = 0;
+ setUnitGridFromData("");
+ document.getElementById('unitRewardsContainer').innerHTML = 'Action Ressource Quantité |
|---|