39029-vm/builds.php
2026-03-06 17:54:56 +00:00

127 lines
4.6 KiB
PHP

<?php
require_once __DIR__ . '/includes/app.php';
ensure_tables();
$pageTitle = 'Builds';
$active = 'builds';
$pdo = db();
$filters = [
'search' => trim($_GET['search'] ?? ''),
'game' => trim($_GET['game'] ?? ''),
'class' => trim($_GET['class'] ?? ''),
'patch' => trim($_GET['patch'] ?? ''),
];
$sql = "SELECT id, title, game, class_name, patch, summary, author, created_at FROM builds WHERE 1=1";
$params = [];
if ($filters['search']) {
$sql .= " AND (title LIKE :search OR summary LIKE :search)";
$params[':search'] = '%' . $filters['search'] . '%';
}
if ($filters['game']) {
$sql .= " AND game = :game";
$params[':game'] = $filters['game'];
}
if ($filters['class']) {
$sql .= " AND class_name = :class";
$params[':class'] = $filters['class'];
}
if ($filters['patch']) {
$sql .= " AND patch = :patch";
$params[':patch'] = $filters['patch'];
}
$sql .= " ORDER BY created_at DESC";
$stmt = $pdo->prepare($sql);
$stmt->execute($params);
$builds = $stmt->fetchAll();
$games = $pdo->query("SELECT DISTINCT game FROM builds ORDER BY game")->fetchAll(PDO::FETCH_COLUMN);
$classes = $pdo->query("SELECT DISTINCT class_name FROM builds ORDER BY class_name")->fetchAll(PDO::FETCH_COLUMN);
$patches = $pdo->query("SELECT DISTINCT patch FROM builds WHERE patch IS NOT NULL AND patch != '' ORDER BY patch")->fetchAll(PDO::FETCH_COLUMN);
include __DIR__ . '/includes/header.php';
?>
<div class="d-flex flex-wrap justify-content-between align-items-center mb-4 gap-2">
<div>
<h1 class="h3 mb-1">Build Library</h1>
<p class="muted mb-0">Filter by game, class, and patch for fast comparisons.</p>
</div>
<a class="btn btn-primary" href="create_build.php">Publish build</a>
</div>
<form class="app-card mb-4" method="get">
<div class="row g-3 align-items-end">
<div class="col-lg-4">
<label class="form-label">Search builds</label>
<input class="form-control" type="text" name="search" placeholder="Title or summary" value="<?= h($filters['search']) ?>">
</div>
<div class="col-sm-6 col-lg-2">
<label class="form-label">Game</label>
<select class="form-select" name="game">
<option value="">All</option>
<?php foreach ($games as $game): ?>
<option value="<?= h($game) ?>" <?= $filters['game'] === $game ? 'selected' : '' ?>><?= h($game) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-sm-6 col-lg-2">
<label class="form-label">Class</label>
<select class="form-select" name="class">
<option value="">All</option>
<?php foreach ($classes as $class): ?>
<option value="<?= h($class) ?>" <?= $filters['class'] === $class ? 'selected' : '' ?>><?= h($class) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-sm-6 col-lg-2">
<label class="form-label">Patch</label>
<select class="form-select" name="patch">
<option value="">All</option>
<?php foreach ($patches as $patch): ?>
<option value="<?= h($patch) ?>" <?= $filters['patch'] === $patch ? 'selected' : '' ?>><?= h($patch) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-sm-6 col-lg-2 d-grid">
<button class="btn btn-outline-light" type="submit">Apply</button>
</div>
</div>
</form>
<div class="row g-3">
<?php if (!$builds): ?>
<div class="col-12">
<div class="app-card">
<h2 class="h5">No matches yet</h2>
<p class="muted">Try broadening filters or publish a new build to seed the library.</p>
<a class="btn btn-outline-light" href="create_build.php">Publish build</a>
</div>
</div>
<?php else: ?>
<?php foreach ($builds as $build): ?>
<div class="col-md-6 col-lg-4">
<div class="app-card h-100">
<div class="d-flex justify-content-between align-items-start mb-2">
<span class="badge badge-soft"><?= h($build['game']) ?></span>
<?php if (!empty($build['patch'])): ?>
<span class="badge badge-soft">Patch <?= h($build['patch']) ?></span>
<?php endif; ?>
</div>
<h2 class="h5"><?= h($build['title']) ?></h2>
<p class="muted mb-3"><?= h($build['summary'] ?: 'Build summary pending.') ?></p>
<div class="d-flex justify-content-between align-items-center">
<span class="muted"><?= h($build['class_name']) ?> · <?= h($build['author']) ?></span>
<a class="btn btn-sm btn-outline-light" href="build.php?id=<?= h((string)$build['id']) ?>">View</a>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>