Alpha V2.5.17
This commit is contained in:
parent
21605b9c4e
commit
f4b8494fd3
266
guilde.php
266
guilde.php
@ -136,7 +136,40 @@ if (isset($_GET['join']) && !$in_guild) {
|
||||
}
|
||||
}
|
||||
|
||||
// ACCEPT/REFUSE MEMBER (Validation)
|
||||
// CREATE GUILD
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'create_guild' && !$in_guild) {
|
||||
$name = trim($_POST['name']);
|
||||
$tag = strtoupper(trim($_POST['tag']));
|
||||
$description = trim($_POST['description']);
|
||||
if (strlen($name) < 3) $error = "Nom trop court.";
|
||||
elseif (strlen($tag) < 2) $error = "Tag trop court.";
|
||||
else {
|
||||
$reqs = $db->query("SELECT resource_id, amount FROM guild_creation_requirements WHERE amount > 0")->fetchAll(PDO::FETCH_ASSOC);
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
$can_afford = true;
|
||||
foreach ($reqs as $req) {
|
||||
$stmt = $db->prepare("SELECT amount FROM user_resources WHERE user_id = ? AND resource_id = ?");
|
||||
$stmt->execute([$user_id, $req['resource_id']]);
|
||||
if (($stmt->fetchColumn() ?: 0) < $req['amount']) { $can_afford = false; break; }
|
||||
}
|
||||
if (!$can_afford) { $error = "Ressources insuffisantes."; $db->rollBack(); }
|
||||
else {
|
||||
foreach ($reqs as $req) $db->prepare("UPDATE user_resources SET amount = amount - ? WHERE user_id = ? AND resource_id = ?")->execute([$req['amount'], $user_id, $req['resource_id']]);
|
||||
$db->prepare("INSERT INTO guilds (name, tag, description, recruitment_status) VALUES (?, ?, ?, 'ouvert')")->execute([$name, $tag, $description]);
|
||||
$guild_id = $db->lastInsertId();
|
||||
$db->prepare("INSERT INTO guild_members (guild_id, user_id, role) VALUES (?, ?, 'superviseur')")->execute([$guild_id, $user_id]);
|
||||
$db->prepare("UPDATE users SET guild_id = ? WHERE id = ?")->execute([$guild_id, $user_id]);
|
||||
$_SESSION['guild_id'] = $guild_id;
|
||||
$db->commit();
|
||||
header("Location: guilde.php");
|
||||
exit;
|
||||
}
|
||||
} catch (Exception $e) { $db->rollBack(); $error = "Erreur : " . $e->getMessage(); }
|
||||
}
|
||||
}
|
||||
|
||||
// ACCEPT/REFUSE MEMBER
|
||||
if (isset($_GET['validate']) && $in_guild && ($user_guild_info['role'] === 'superviseur' || $user_guild_info['role'] === 'officier')) {
|
||||
$target_id = (int)$_GET['validate'];
|
||||
$action = $_GET['action_type'] ?? '';
|
||||
@ -224,39 +257,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['
|
||||
}
|
||||
}
|
||||
|
||||
// CREATE GUILD
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'create_guild' && !$in_guild) {
|
||||
$name = trim($_POST['name']);
|
||||
$tag = strtoupper(trim($_POST['tag']));
|
||||
$description = trim($_POST['description']);
|
||||
if (strlen($name) < 3) $error = "Nom trop court.";
|
||||
elseif (strlen($tag) < 2) $error = "Tag trop court.";
|
||||
else {
|
||||
$reqs = $db->query("SELECT resource_id, amount FROM guild_creation_requirements WHERE amount > 0")->fetchAll(PDO::FETCH_ASSOC);
|
||||
$db->beginTransaction();
|
||||
try {
|
||||
$can_afford = true;
|
||||
foreach ($reqs as $req) {
|
||||
$stmt = $db->prepare("SELECT amount FROM user_resources WHERE user_id = ? AND resource_id = ?");
|
||||
$stmt->execute([$user_id, $req['resource_id']]);
|
||||
if (($stmt->fetchColumn() ?: 0) < $req['amount']) { $can_afford = false; break; }
|
||||
}
|
||||
if (!$can_afford) { $error = "Ressources insuffisantes."; $db->rollBack(); }
|
||||
else {
|
||||
foreach ($reqs as $req) $db->prepare("UPDATE user_resources SET amount = amount - ? WHERE user_id = ? AND resource_id = ?")->execute([$req['amount'], $user_id, $req['resource_id']]);
|
||||
$db->prepare("INSERT INTO guilds (name, tag, description, recruitment_status) VALUES (?, ?, ?, 'ouvert')")->execute([$name, $tag, $description]);
|
||||
$guild_id = $db->lastInsertId();
|
||||
$db->prepare("INSERT INTO guild_members (guild_id, user_id, role) VALUES (?, ?, 'superviseur')")->execute([$guild_id, $user_id]);
|
||||
$db->prepare("UPDATE users SET guild_id = ? WHERE id = ?")->execute([$guild_id, $user_id]);
|
||||
$_SESSION['guild_id'] = $guild_id;
|
||||
$db->commit();
|
||||
header("Location: guilde.php");
|
||||
exit;
|
||||
}
|
||||
} catch (Exception $e) { $db->rollBack(); $error = "Erreur : " . $e->getMessage(); }
|
||||
}
|
||||
}
|
||||
|
||||
// --- DATA FETCHING ---
|
||||
|
||||
if ($in_guild) {
|
||||
@ -349,7 +349,7 @@ if ($in_guild) {
|
||||
|
||||
/* GUILD SPECIFIC STYLES */
|
||||
.guild-content { max-width: 1000px; width: 100%; margin-top: 20px; }
|
||||
.guild-card { background: rgba(10, 15, 30, 0.95); border: 1px solid #2d3545; padding: 25px; border-radius: 8px; box-shadow: 0 0 30px rgba(0,0,0,0.5); }
|
||||
.guild-card { background: rgba(10, 15, 30, 0.95); border: 1px solid #2d3545; padding: 25px; border-radius: 8px; box-shadow: 0 0 30px rgba(0,0,0,0.5); margin-bottom: 30px; }
|
||||
h1, h2, h3 { color: #88c0d0; text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid #2d3545; padding-bottom: 10px; }
|
||||
.form-group { margin-bottom: 15px; }
|
||||
.form-group label { display: block; color: #8c92a3; font-size: 13px; margin-bottom: 5px; }
|
||||
@ -422,7 +422,7 @@ if ($in_guild) {
|
||||
<div style="display: flex; align-items: center; gap: 20px;">
|
||||
<a href="index.php" style="text-decoration:none; color:#8c92a3; font-size:11px; font-weight:bold;"><i class="fa-solid fa-arrow-left"></i> Retour au Nexus</a>
|
||||
<?php if (isset($_SESSION["user_id"])): ?>
|
||||
<a href="guilde.php" style="text-decoration:none; color:#88c0d0; font-size:11px; font-weight:bold;"><i class="fa-solid fa-building-shield"></i> <?php echo empty($_SESSION["guild_id"]) ? "Création de guilde" : "Voir ma guilde"; ?></a>
|
||||
<a href="guilde.php" style="text-decoration:none; color:#88c0d0; font-size:11px; font-weight:bold;"><i class="fa-solid fa-building-shield"></i> <?php echo empty($_SESSION["guild_id"]) ? "Gestion de guilde" : "Voir ma guilde"; ?></a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div class="user-auth-bar">
|
||||
@ -459,97 +459,115 @@ if ($in_guild) {
|
||||
<?php if ($message): ?><div class="success-msg"><?php echo $message; ?></div><?php endif; ?>
|
||||
<?php if ($error): ?><div class="error-msg"><?php echo $error; ?></div><?php endif; ?>
|
||||
|
||||
<div class="guild-card">
|
||||
<?php if (!$in_guild): ?>
|
||||
<div style="display: flex; gap: 40px; flex-wrap: wrap;">
|
||||
<!-- Liste des guildes -->
|
||||
<div style="flex: 2; min-width: 300px;">
|
||||
<h2><i class="fa-solid fa-list"></i> Guildes Actives</h2>
|
||||
<table class="guild-table" style="table-layout: fixed; width: 100%; border-collapse: collapse;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 45%; color: #88c0d0; text-transform: uppercase; font-size: 11px; padding: 15px; border-bottom: 1px solid #1e293b; background: rgba(30, 41, 59, 0.5);">Guilde</th>
|
||||
<th style="width: 15%; color: #88c0d0; text-transform: uppercase; font-size: 11px; padding: 15px; border-bottom: 1px solid #1e293b; background: rgba(30, 41, 59, 0.5);">Membres</th>
|
||||
<th style="width: 20%; color: #88c0d0; text-transform: uppercase; font-size: 11px; padding: 15px; border-bottom: 1px solid #1e293b; background: rgba(30, 41, 59, 0.5);">Recrutement</th>
|
||||
<th style="width: 20%; color: #88c0d0; text-transform: uppercase; font-size: 11px; padding: 15px; border-bottom: 1px solid #1e293b; background: rgba(30, 41, 59, 0.5);">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($all_guilds)): ?>
|
||||
<tr><td colspan="4" style="text-align:center; color:#8c92a3; padding: 20px;">Aucune guilde pour le moment.</td></tr>
|
||||
<?php endif; ?>
|
||||
<?php foreach ($all_guilds as $g): ?>
|
||||
<tr>
|
||||
<td style="padding: 15px; border-bottom: 1px solid #1e293b; overflow: hidden;">
|
||||
<strong style="color:#ebcb8b;">[<?php echo htmlspecialchars($g['tag']); ?>]</strong>
|
||||
<strong style="color:#fff;"><?php echo htmlspecialchars($g['name']); ?></strong><br>
|
||||
<small style="color:#8c92a3; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
|
||||
<?php
|
||||
$desc = htmlspecialchars($g['description']);
|
||||
echo (strlen($desc) > 80) ? substr($desc, 0, 80) . "..." : $desc;
|
||||
?>
|
||||
</small>
|
||||
</td>
|
||||
<td style="padding: 15px; border-bottom: 1px solid #1e293b;">
|
||||
<span style="color:#fff; font-weight:bold; display: block;"><?php echo (int)($g['member_count'] ?? 0); ?> / <?php echo (int)$member_limit; ?></span>
|
||||
</td>
|
||||
<td style="padding: 15px; border-bottom: 1px solid #1e293b;">
|
||||
<?php if ($g['recruitment_status'] === 'ouvert'): ?>
|
||||
<span style="color:#a3be8c; font-weight:bold; text-transform: uppercase;">OUVERT</span>
|
||||
<?php elseif ($g['recruitment_status'] === 'validation'): ?>
|
||||
<span style="color:#ebcb8b; font-weight:bold; text-transform: uppercase;">DEMANDE</span>
|
||||
<?php else: ?>
|
||||
<span style="color:#bf616a; font-weight:bold; text-transform: uppercase;">FERMÉ</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td style="padding: 15px; border-bottom: 1px solid #1e293b;">
|
||||
<?php if ($g['recruitment_status'] === 'ouvert' && (int)($g['member_count'] ?? 0) < $member_limit): ?>
|
||||
<a href="?join=<?php echo $g['id']; ?>" class="btn btn-join" style="width:100%; text-align:center; display: block; box-sizing: border-box;">REJOINDRE</a>
|
||||
<?php elseif ($g['recruitment_status'] === 'validation' && (int)($g['member_count'] ?? 0) < $member_limit): ?>
|
||||
<a href="?join=<?php echo $g['id']; ?>" class="btn btn-primary" style="width:100%; text-align:center; display: block; box-sizing: border-box;">POSTULER</a>
|
||||
<?php else: ?>
|
||||
<button class="btn" disabled style="background:#4c566a; color:#8c92a3; width:100%; cursor:not-allowed; display: block; box-sizing: border-box; text-align: center;">
|
||||
<?php echo ((int)($g['member_count'] ?? 0) >= $member_limit) ? 'PLEIN' : 'FERMÉ'; ?>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php if (!$in_guild): ?>
|
||||
<!-- CADRE 1 : FONDER UNE GUILDE -->
|
||||
<div class="guild-card">
|
||||
<h2><i class="fa-solid fa-plus-circle"></i> Fonder une guilde</h2>
|
||||
|
||||
<div style="margin-top: 20px;">
|
||||
<p style="font-size: 13px; color: #8c92a3; margin-bottom: 10px;">Coût requis :</p>
|
||||
<div style="margin-bottom: 25px;">
|
||||
<?php if (empty($display_reqs)): ?><p style="color:#a3be8c; font-weight:bold;">GRATUIT</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($display_reqs as $req):
|
||||
$user_has = $user_resource_amounts[$req['id']] ?? 0;
|
||||
$is_insufficient = $user_has < $req['amount'];
|
||||
?>
|
||||
<div class="req-item <?php echo $is_insufficient ? 'insufficient' : ''; ?>" title="Vous avez: <?php echo number_format($user_has); ?>">
|
||||
<?php if ($req['image_url']): ?><img src="<?php echo htmlspecialchars($req['image_url']); ?>">
|
||||
<?php else: ?><i class="fa-solid <?php echo htmlspecialchars($req['icon'] ?: 'fa-gem'); ?>"></i><?php endif; ?>
|
||||
<strong><?php echo number_format($req['amount']); ?></strong>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- Création -->
|
||||
<div style="flex: 1; min-width: 280px; background: rgba(30, 41, 59, 0.3); padding: 20px; border: 1px solid #2d3545; border-radius: 8px;">
|
||||
<h3>Fonder une Guilde</h3>
|
||||
<div style="margin-bottom: 20px;">
|
||||
<p style="font-size: 13px; color: #8c92a3;">Coût requis :</p>
|
||||
<?php if (empty($display_reqs)): ?><p style="color:#a3be8c;">Gratuit</p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($display_reqs as $req):
|
||||
$user_has = $user_resource_amounts[$req['id']] ?? 0;
|
||||
$is_insufficient = $user_has < $req['amount'];
|
||||
?>
|
||||
<div class="req-item <?php echo $is_insufficient ? 'insufficient' : ''; ?>" title="Vous avez: <?php echo number_format($user_has); ?>">
|
||||
<?php if ($req['image_url']): ?><img src="<?php echo htmlspecialchars($req['image_url']); ?>">
|
||||
<?php else: ?><i class="fa-solid <?php echo htmlspecialchars($req['icon'] ?: 'fa-gem'); ?>"></i><?php endif; ?>
|
||||
<strong><?php echo number_format($req['amount']); ?></strong>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="action" value="create_guild">
|
||||
|
||||
<div style="display: flex; gap: 20px; margin-bottom: 15px;">
|
||||
<div class="form-group" style="flex: 1;">
|
||||
<label>Tag de la guilde (2-5 car.)</label>
|
||||
<input type="text" name="tag" required maxlength="5" placeholder="Ex: [BHFR]">
|
||||
</div>
|
||||
<div class="form-group" style="flex: 3;">
|
||||
<label>Nom de la guilde</label>
|
||||
<input type="text" name="name" required placeholder="Nom de votre organisation">
|
||||
</div>
|
||||
</div>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="action" value="create_guild">
|
||||
<div class="form-group"><label>Nom</label><input type="text" name="name" required placeholder="Nom de votre organisation"></div>
|
||||
<div class="form-group"><label>Tag (2-5 car.)</label><input type="text" name="tag" required maxlength="5" placeholder="TAG"></div>
|
||||
<div class="form-group"><label>Description</label><textarea name="description" rows="3" placeholder="Objectifs de la guilde..."></textarea></div>
|
||||
<button type="submit" class="btn btn-primary" style="width:100%;" <?php echo !$can_afford_creation ? 'disabled' : ''; ?>>
|
||||
<?php echo $can_afford_creation ? 'Fonder la guilde' : 'Ressources insuffisantes'; ?>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Description des objectifs</label>
|
||||
<textarea name="description" rows="3" placeholder="Quels sont les buts de votre guilde ?"></textarea>
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 20px;">
|
||||
<button type="submit" class="btn btn-primary" style="width:100%; padding: 15px; font-size: 14px;" <?php echo !$can_afford_creation ? 'disabled' : ''; ?>>
|
||||
<?php echo $can_afford_creation ? '<i class="fa-solid fa-hammer"></i> ÉTABLIR LA GUILDE' : '<i class="fa-solid fa-lock"></i> RESSOURCES INSUFFISANTES'; ?>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
</div>
|
||||
|
||||
<!-- CADRE 2 : GUILDES ACTIVES -->
|
||||
<div class="guild-card">
|
||||
<h2><i class="fa-solid fa-list"></i> Guildes Actives</h2>
|
||||
<table class="guild-table" style="table-layout: fixed; width: 100%; border-collapse: collapse;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 45%;">Guilde</th>
|
||||
<th style="width: 15%;">Membres</th>
|
||||
<th style="width: 20%;">Recrutement</th>
|
||||
<th style="width: 20%;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if (empty($all_guilds)): ?>
|
||||
<tr><td colspan="4" style="text-align:center; color:#8c92a3; padding: 20px;">Aucune guilde pour le moment.</td></tr>
|
||||
<?php endif; ?>
|
||||
<?php foreach ($all_guilds as $g): ?>
|
||||
<tr>
|
||||
<td style="padding: 15px; border-bottom: 1px solid #1e293b; overflow: hidden;">
|
||||
<strong style="color:#ebcb8b;">[<?php echo htmlspecialchars($g['tag']); ?>]</strong>
|
||||
<strong style="color:#fff;"><?php echo htmlspecialchars($g['name']); ?></strong><br>
|
||||
<small style="color:#8c92a3; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
|
||||
<?php
|
||||
$desc = htmlspecialchars($g['description']);
|
||||
echo (strlen($desc) > 80) ? substr($desc, 0, 80) . "..." : $desc;
|
||||
?>
|
||||
</small>
|
||||
</td>
|
||||
<td style="padding: 15px; border-bottom: 1px solid #1e293b;">
|
||||
<span style="color:#fff; font-weight:bold; display: block;"><?php echo (int)($g['member_count'] ?? 0); ?> / <?php echo (int)$member_limit; ?></span>
|
||||
</td>
|
||||
<td style="padding: 15px; border-bottom: 1px solid #1e293b;">
|
||||
<?php if ($g['recruitment_status'] === 'ouvert'): ?>
|
||||
<span style="color:#a3be8c; font-weight:bold; text-transform: uppercase;">OUVERT</span>
|
||||
<?php elseif ($g['recruitment_status'] === 'validation'): ?>
|
||||
<span style="color:#ebcb8b; font-weight:bold; text-transform: uppercase;">DEMANDE</span>
|
||||
<?php else: ?>
|
||||
<span style="color:#bf616a; font-weight:bold; text-transform: uppercase;">FERMÉ</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td style="padding: 15px; border-bottom: 1px solid #1e293b;">
|
||||
<?php if ($g['recruitment_status'] === 'ouvert' && (int)($g['member_count'] ?? 0) < $member_limit): ?>
|
||||
<a href="?join=<?php echo $g['id']; ?>" class="btn btn-join" style="width:100%; text-align:center; display: block; box-sizing: border-box;">REJOINDRE</a>
|
||||
<?php elseif ($g['recruitment_status'] === 'validation' && (int)($g['member_count'] ?? 0) < $member_limit): ?>
|
||||
<a href="?join=<?php echo $g['id']; ?>" class="btn btn-primary" style="width:100%; text-align:center; display: block; box-sizing: border-box;">POSTULER</a>
|
||||
<?php else: ?>
|
||||
<button class="btn" disabled style="background:#4c566a; color:#8c92a3; width:100%; cursor:not-allowed; display: block; box-sizing: border-box; text-align: center;">
|
||||
<?php echo ((int)($g['member_count'] ?? 0) >= $member_limit) ? 'PLEIN' : 'FERMÉ'; ?>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="guild-card">
|
||||
<div style="display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #88c0d0; padding-bottom: 15px; margin-bottom: 20px;">
|
||||
<div>
|
||||
<span style="color: #ebcb8b; font-weight: bold; font-size: 24px;">[<?php echo htmlspecialchars($user_guild_info['guild_tag']); ?>]</span>
|
||||
@ -643,8 +661,8 @@ if ($in_guild) {
|
||||
<a href="?action=leave" class="btn btn-danger" onclick="return confirm('Quitter la guilde ?')">Quitter la guilde</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user