Alpha V2.3
This commit is contained in:
parent
0c69342648
commit
e00d27784d
271
admin.php
271
admin.php
@ -1,4 +1,36 @@
|
||||
<?php
|
||||
|
||||
function get_user_grade($pdo, $user_id) {
|
||||
$stmt = $pdo->prepare("SELECT role FROM users WHERE id = ?");
|
||||
$stmt->execute([$user_id]);
|
||||
$user = $stmt->fetch();
|
||||
if (!$user) return null;
|
||||
|
||||
$role = $user['role'];
|
||||
$level = 0;
|
||||
try {
|
||||
$stmt_lvl = $pdo->prepare("SELECT level FROM users WHERE id = ?");
|
||||
$stmt_lvl->execute([$user_id]);
|
||||
$level = (int)$stmt_lvl->fetchColumn();
|
||||
} catch (Exception $e) {
|
||||
// level column might not exist
|
||||
}
|
||||
|
||||
if ($role === 'admin') {
|
||||
$stmt = $pdo->prepare("SELECT * FROM grades WHERE user_type = 'admin' LIMIT 1");
|
||||
$stmt->execute();
|
||||
return $stmt->fetch();
|
||||
} elseif ($role === 'gm') {
|
||||
$stmt = $pdo->prepare("SELECT * FROM grades WHERE user_type = 'GM' LIMIT 1");
|
||||
$stmt->execute();
|
||||
return $stmt->fetch();
|
||||
} else {
|
||||
$stmt = $pdo->prepare("SELECT * FROM grades WHERE user_type = 'utilisateur' AND ? BETWEEN min_level AND max_level LIMIT 1");
|
||||
$stmt->execute([$level]);
|
||||
return $stmt->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
require_once 'db/config.php';
|
||||
session_start();
|
||||
$db = db();
|
||||
@ -377,6 +409,44 @@ if (isset($_GET['delete_resource'])) {
|
||||
}
|
||||
|
||||
// Handle Lootbox CRUD
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_grade') {
|
||||
$id = (int)$_POST['id'];
|
||||
$name = trim($_POST['name']);
|
||||
$slug = trim($_POST['slug']);
|
||||
$user_type = $_POST['user_type'];
|
||||
$min_level = ($user_type === 'utilisateur') ? (int)$_POST['min_level'] : null;
|
||||
$max_level = ($user_type === 'utilisateur') ? (int)$_POST['max_level'] : null;
|
||||
|
||||
if ($user_type === 'utilisateur' && $min_level > $max_level) {
|
||||
header('Location: ?tab=ranks&error=invalid_range');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 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 > ?)");
|
||||
$check->execute([$id, $min_level, $max_level]);
|
||||
if ($check->fetch()) {
|
||||
header('Location: ?tab=ranks&error=overlap_levels');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
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]);
|
||||
} 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]);
|
||||
}
|
||||
header('Location: ?tab=ranks&success=1');
|
||||
exit;
|
||||
} catch (PDOException $e) {
|
||||
header('Location: ?tab=ranks&error=db');
|
||||
exit;
|
||||
}
|
||||
}
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'upsert_lootbox') {
|
||||
$id = (int)$_POST['id'];
|
||||
$name = $_POST['name'];
|
||||
@ -450,6 +520,13 @@ if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["action"]) && $_POST["
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isset($_GET['delete_grade'])) {
|
||||
$id = (int)$_GET['delete_grade'];
|
||||
$stmt = db()->prepare("DELETE FROM grades WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
header('Location: ?tab=ranks&success=deleted');
|
||||
exit;
|
||||
}
|
||||
if (isset($_GET["delete_project_log"])) {
|
||||
$id = (int)$_GET["delete_project_log"];
|
||||
$db->prepare("DELETE FROM project_logs WHERE id = ?")->execute([$id]);
|
||||
@ -458,6 +535,7 @@ if (isset($_GET["delete_project_log"])) {
|
||||
}
|
||||
|
||||
// --- DATA FETCHING ---
|
||||
|
||||
$users_list = [];
|
||||
$objects_list = [];
|
||||
$statuses_list = [];
|
||||
@ -470,6 +548,7 @@ $resources_list = [];
|
||||
$lootboxes_list = [];
|
||||
$project_logs_list = [];
|
||||
$levels_list = [];
|
||||
$ranks_list = [];
|
||||
|
||||
if ($tab === 'users') {
|
||||
$users_list = $db->query("SELECT id, username, email, role FROM users ORDER BY username ASC")->fetchAll();
|
||||
@ -507,6 +586,8 @@ if ($tab === 'users') {
|
||||
$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 === 'ranks') {
|
||||
$ranks_list = $db->query("SELECT * FROM grades ORDER BY user_type DESC, min_level 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();
|
||||
@ -748,10 +829,98 @@ if ($tab === 'users') {
|
||||
</table>
|
||||
<?php elseif ($tab === 'ranks'): ?>
|
||||
<h3 style="color: #88c0d0;">Gestion des Grades</h3>
|
||||
|
||||
<?php if (isset($_GET['error']) && $_GET['error'] === 'overlap_levels'): ?>
|
||||
<div style="background: #bf616a; color: #fff; padding: 10px; border-radius: 4px; margin-bottom: 15px;">
|
||||
Erreur : Les intervalles de niveaux pour les grades utilisateurs ne doivent pas se chevaucher.
|
||||
</div>
|
||||
<?php elseif (isset($_GET['error']) && $_GET['error'] === 'invalid_range'): ?>
|
||||
<div style="background: #bf616a; color: #fff; padding: 10px; border-radius: 4px; margin-bottom: 15px;">
|
||||
Erreur : Le niveau maximum doit être supérieur ou égal au niveau minimum.
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="form-card">
|
||||
<p><i class="fa-solid fa-info-circle"></i> À configurer</p>
|
||||
<h4>Ajouter / Modifier un Grade</h4>
|
||||
<form method="POST" id="rankForm">
|
||||
<input type="hidden" name="action" value="upsert_grade">
|
||||
<input type="hidden" name="id" id="rank_id" value="0">
|
||||
<div style="display: flex; gap: 20px; margin-bottom: 15px;">
|
||||
<div class="form-group" style="flex: 2;">
|
||||
<label>Nom du Grade</label>
|
||||
<input type="text" name="name" id="rank_name" required placeholder="Ex: Pionnier">
|
||||
</div>
|
||||
<div class="form-group" style="flex: 2;">
|
||||
<label>Slug (Identifiant technique unique)</label>
|
||||
<input type="text" name="slug" id="rank_slug" required placeholder="Ex: pionnier">
|
||||
</div>
|
||||
<div class="form-group" style="flex: 1;">
|
||||
<label>Type d'utilisateur</label>
|
||||
<select name="user_type" id="rank_type" required onchange="updateRankFields()">
|
||||
<option value="utilisateur">Utilisateur</option>
|
||||
<option value="GM">GM</option>
|
||||
<option value="admin">Admin</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div style="display: flex; gap: 20px;">
|
||||
<div class="form-group" style="flex: 1;">
|
||||
<label>Niveau Minimum</label>
|
||||
<input type="number" name="min_level" id="rank_min" min="0" placeholder="Ex: 1">
|
||||
</div>
|
||||
<div class="form-group" style="flex: 1;">
|
||||
<label>Niveau Maximum</label>
|
||||
<input type="number" name="max_level" id="rank_max" min="0" placeholder="Ex: 10">
|
||||
</div>
|
||||
</div>
|
||||
<div style="margin-top: 15px;">
|
||||
<button type="submit" class="btn btn-add">ENREGISTRER LE GRADE</button>
|
||||
<button type="button" class="btn" style="background: #4c566a; color: #fff;" onclick="resetRankForm()">ANNULER</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nom</th>
|
||||
<th>Slug</th>
|
||||
<th>Type</th>
|
||||
<th>Intervalle Niveau</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($ranks_list)): ?>
|
||||
<tr><td colspan="5" style="text-align: center;">Aucun grade configuré.</td></tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($ranks_list as $r): ?>
|
||||
<tr>
|
||||
<td><strong><?php echo htmlspecialchars($r['name']); ?></strong></td>
|
||||
<td><code><?php echo htmlspecialchars($r['slug']); ?></code></td>
|
||||
<td>
|
||||
<span class="badge <?php echo $r['user_type'] === 'admin' ? 'tag-malus' : ($r['user_type'] === 'GM' ? 'tag-bonus' : ''); ?>"
|
||||
style="background: <?php echo $r['user_type'] === 'admin' ? '#bf616a' : ($r['user_type'] === 'GM' ? '#ebcb8b' : '#88c0d0'); ?>; color: #2e3440; padding: 2px 8px; border-radius: 10px; font-size: 10px; text-transform: uppercase; font-weight: bold;">
|
||||
<?php echo htmlspecialchars($r['user_type']); ?>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($r['user_type'] === 'utilisateur'): ?>
|
||||
<?php echo $r['min_level']; ?> - <?php echo $r['max_level']; ?>
|
||||
<?php else: ?>
|
||||
<span style="color: #4c566a;">N/A</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<button class="btn btn-edit" onclick='editRank(<?php echo json_encode($r, JSON_HEX_APOS); ?>)'>Editer</button>
|
||||
<a href="?tab=ranks&delete_grade=<?php echo $r['id']; ?>" class="btn btn-del" onclick="return confirm('Supprimer ce grade ?')">Suppr</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php elseif ($tab === 'badges'): ?>
|
||||
<h3 style="color: #88c0d0;">Titres & Badges</h3>
|
||||
<div class="form-card">
|
||||
@ -1522,7 +1691,55 @@ if ($tab === 'users') {
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<?php elseif ($tab === 'lootboxes'): ?>
|
||||
<h3 style="color: #88c0d0;">Système de Lootboxes</h3>
|
||||
@ -1942,6 +2159,54 @@ function editStatus(data) {
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user