The following files exists in this folder. Click to view.
ladder.php142 lines UTF-8 Windows (CRLF) 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
<?php
require "database.php";
require "auth.php";
requireLogin();
$ladderID = $_GET["id"] ?? null;
$playerID = $_SESSION["player_id"];
if (!$ladderID) {
die("No ladder selected");
}
/* Ladder info */
$stmt = $conn->prepare(
"SELECT L.*, P.Username AS OwnerName
FROM Ladder L
JOIN Players P ON L.OwnerPlayerID = P.PlayerID
WHERE L.LadderID = ?"
);
$stmt->execute([$ladderID]);
$ladder = $stmt->fetch();
if (!$ladder) {
die("Ladder not found");
}
$isOwner = ($ladder["OwnerPlayerID"] == $playerID);
/* Players in ladder */
$stmt = $conn->prepare(
"SELECT P.PlayerID, P.Username, LP.CurrentScore
FROM LadderPlayers LP
JOIN Players P ON LP.PlayerID = P.PlayerID
WHERE LP.LadderID = ?
ORDER BY LP.CurrentScore DESC"
);
$stmt->execute([$ladderID]);
$players = $stmt->fetchAll();
/* Recent matches */
$stmt = $conn->prepare(
"SELECT m.PlayedAt,
p1.Username AS P1,
p2.Username AS P2,
w.Username AS Winner
FROM Matches m
JOIN Players p1 ON m.Player1ID = p1.PlayerID
JOIN Players p2 ON m.Player2ID = p2.PlayerID
JOIN Players w ON m.WinnerID = w.PlayerID
WHERE m.LadderID = ?
ORDER BY m.PlayedAt DESC
LIMIT 5"
);
$stmt->execute([$ladderID]);
$matches = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html>
<head>
<title><?= htmlspecialchars($ladder["LadderName"]) ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<!-- Ladder header -->
<h2><?= htmlspecialchars($ladder["LadderName"]) ?></h2>
<p>
Owner: <strong><?= htmlspecialchars($ladder["OwnerName"]) ?></strong><br>
Invite Code:
<span class="badge bg-secondary fs-6">
<?= htmlspecialchars($ladder["InviteCode"]) ?>
</span>
</p>
<!-- buttons -->
<div class="mb-3">
<a href="match_create.php?ladder_id=<?= $ladderID ?>"
class="btn btn-success">
Submit Match
</a>
<a href="match_history.php?ladder_id=<?= $ladderID ?>"
class="btn btn-outline-primary">
Match History
</a>
<a href="dashboard.php" class="btn btn-secondary">
Back
</a>
</div>
<!-- Players table -->
<table class="table table-striped mt-4">
<thead>
<tr>
<th>#</th>
<th>Player</th>
<th>Score</th>
</tr>
</thead>
<tbody>
<?php $i = 1; foreach ($players as $player): ?>
<tr>
<td><?= $i++ ?></td>
<td><?= htmlspecialchars($player["Username"]) ?></td>
<td><?= $player["CurrentScore"] ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<!-- Recent matches -->
<h4 class="mt-5">Recent Matches</h4>
<ul class="list-group">
<?php if (!$matches): ?>
<li class="list-group-item text-muted">
No matches played yet
</li>
<?php endif; ?>
<?php foreach ($matches as $m): ?>
<li class="list-group-item">
<?= htmlspecialchars($m["P1"]) ?>
vs
<?= htmlspecialchars($m["P2"]) ?>
—
Winner:
<strong><?= htmlspecialchars($m["Winner"]) ?></strong>
</li>
<?php endforeach; ?>
</ul>
</div>
</body>
</html>