diff --git a/admin.php b/admin.php index 396cb88..bfb4070 100644 --- a/admin.php +++ b/admin.php @@ -408,7 +408,8 @@ if (isset($_GET['delete_resource'])) { exit; } -// Handle Lootbox CRUD + +// Handle Grade CRUD if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_grade') { $id = (int)$_POST['id']; $name = trim($_POST['name']); @@ -422,6 +423,22 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' exit; } + $image_url = null; + if ($id > 0) { + $stmt_img = $db->prepare("SELECT image_url FROM grades 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 = "grade_" . time() . "." . $ext; + if (!is_dir("assets/images/grades")) mkdir("assets/images/grades", 0775, true); + $target = "assets/images/grades/" . $filename; + if (move_uploaded_file($_FILES["image"]["tmp_name"], $target)) { + $image_url = $target; + } + } + // Check for overlap if user_type is 'utilisateur' if ($user_type === 'utilisateur') { $check = db()->prepare("SELECT id FROM grades WHERE user_type = 'utilisateur' AND id != ? AND NOT (max_level < ? OR min_level > ?)"); @@ -434,11 +451,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' try { if ($id > 0) { - $stmt = db()->prepare("UPDATE grades SET name = ?, slug = ?, user_type = ?, min_level = ?, max_level = ? WHERE id = ?"); - $stmt->execute([$name, $slug, $user_type, $min_level, $max_level, $id]); + $stmt = db()->prepare("UPDATE grades SET name = ?, slug = ?, user_type = ?, min_level = ?, max_level = ?, image_url = ? WHERE id = ?"); + $stmt->execute([$name, $slug, $user_type, $min_level, $max_level, $image_url, $id]); } else { - $stmt = db()->prepare("INSERT INTO grades (name, slug, user_type, min_level, max_level) VALUES (?, ?, ?, ?, ?)"); - $stmt->execute([$name, $slug, $user_type, $min_level, $max_level]); + $stmt = db()->prepare("INSERT INTO grades (name, slug, user_type, min_level, max_level, image_url) VALUES (?, ?, ?, ?, ?, ?)"); + $stmt->execute([$name, $slug, $user_type, $min_level, $max_level, $image_url]); } header('Location: ?tab=ranks&success=1'); exit; @@ -447,7 +464,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST[' exit; } } -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_lootbox') { +if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["action"] === "upsert_lootbox") { $id = (int)$_POST['id']; $name = $_POST['name']; $slug = $_POST['slug']; @@ -695,7 +712,7 @@ if ($tab === 'users') {
| Image | Nom | Slug | Type | @@ -892,14 +914,21 @@ if ($tab === 'users') {||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Aucun grade configuré. | |||||||||||||||
| Aucun grade configuré. | |||||||||||||||
|
+
+ |
|
-
@@ -1650,475 +1679,12 @@ if ($tab === 'users') {
document.getElementById('log_id').value = 0;
document.getElementById('logForm').reset();
}
-
- function toggleMS(id) {
- const d = document.getElementById(id);
- d.style.display = d.style.display === 'block' ? 'none' : 'block';
- }
- function updateMSLabel(containerId) {
- const container = document.getElementById(containerId);
- const checkboxes = container.querySelectorAll('input[type="checkbox"]:checked');
- const display = container.querySelector('.ms-display');
- if (checkboxes.length === 0) {
- display.innerText = "Toutes / Peu importe";
- } else {
- const labels = Array.from(checkboxes).map(cb => cb.parentElement.innerText.trim());
- display.innerText = labels.join(', ');
- }
- }
- document.addEventListener('click', function(e) {
- if (!e.target.closest('.ms-container')) {
- document.querySelectorAll('.ms-dropdown').forEach(d => d.style.display = 'none');
- }
- });
-
- function editLevel(data) {
- document.getElementById("level_id").value = data.id;
- document.getElementById("level_name").value = data.name;
- document.getElementById("level_slug").value = data.slug;
- document.getElementById("level_resource_id").value = data.resource_id;
- document.getElementById("level_required_quantity").value = data.required_quantity;
- window.scrollTo(0,0);
- }
- function resetLevelForm() {
- document.getElementById("levelForm").reset();
- document.getElementById("level_id").value = 0;
- const select = document.getElementById("level_resource_id");
- for (let i = 0; i < select.options.length; i++) {
- if (select.options[i].text.toLowerCase().includes("expérience") || select.options[i].text.toLowerCase().includes("experience")) {
- select.selectedIndex = i;
- break;
- }
- }
- }
-
-function updateRankFields() {
- const type = document.getElementById('rank_type').value;
- const min = document.getElementById('rank_min');
- const max = document.getElementById('rank_max');
- if (type === 'utilisateur') {
- min.disabled = false;
- max.disabled = false;
- min.required = true;
- max.required = true;
- min.style.opacity = '1';
- max.style.opacity = '1';
- } else {
- min.disabled = true;
- max.disabled = true;
- min.required = false;
- max.required = false;
- min.style.opacity = '0.5';
- max.style.opacity = '0.5';
- min.value = '';
- max.value = '';
- }
-}
-
-function editRank(rank) {
- document.getElementById('rank_id').value = rank.id;
- document.getElementById('rank_name').value = rank.name;
- document.getElementById('rank_slug').value = rank.slug;
- document.getElementById('rank_type').value = rank.user_type;
- document.getElementById('rank_min').value = rank.min_level || '';
- document.getElementById('rank_max').value = rank.max_level || '';
- updateRankFields();
- window.scrollTo({ top: 0, behavior: 'smooth' });
-}
-
-function resetRankForm() {
- document.getElementById('rankForm').reset();
- document.getElementById('rank_id').value = '0';
- updateRankFields();
-}
-
-// Initial call to set fields on load
-document.addEventListener('DOMContentLoaded', function() {
- if (document.getElementById('rank_type')) {
- updateRankFields();
- }
-});
-
-
-
-
- Système de Lootboxes-
-
-
- Créer / Modifier une Lootbox- -
| |||||||||||||