Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4feeb6dacd |
@ -1,118 +1,8 @@
|
||||
|
||||
/*
|
||||
Custom Styles for Personal Portfolio
|
||||
*/
|
||||
|
||||
:root {
|
||||
--primary-color: #3B82F6;
|
||||
--secondary-color: #10B981;
|
||||
--background-color: #F9FAFB;
|
||||
--surface-color: #FFFFFF;
|
||||
--text-color: #1F2937;
|
||||
--light-text-color: #6B7280;
|
||||
--border-radius: 0.5rem;
|
||||
--shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
|
||||
--shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
background-color: var(--background-color);
|
||||
color: var(--text-color);
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
.navbar {
|
||||
transition: background-color 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
.navbar-scrolled {
|
||||
background-color: var(--surface-color);
|
||||
box-shadow: var(--shadow-md);
|
||||
}
|
||||
|
||||
.hero {
|
||||
.card-header {
|
||||
background-color: #343a40;
|
||||
color: white;
|
||||
padding: 8rem 0;
|
||||
position: relative;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.hero::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-image: linear-gradient(to right, rgba(59, 130, 246, 0.8), rgba(16, 185, 129, 0.8)), url('../images/hero-kittens-45170.jpg');
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
z-index: -1;
|
||||
}
|
||||
|
||||
.hero h1 {
|
||||
font-size: 3.5rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.hero p {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background-color: var(--primary-color);
|
||||
border-color: var(--primary-color);
|
||||
padding: 0.75rem 1.5rem;
|
||||
border-radius: var(--border-radius);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.btn-primary:hover {
|
||||
opacity: 0.9;
|
||||
background-color: var(--primary-color);
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.section {
|
||||
padding: 5rem 0;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
text-align: center;
|
||||
margin-bottom: 3rem;
|
||||
font-size: 2.5rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.portfolio-card {
|
||||
border: none;
|
||||
border-radius: var(--border-radius);
|
||||
box-shadow: var(--shadow-md);
|
||||
overflow: hidden;
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
}
|
||||
|
||||
.portfolio-card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
|
||||
}
|
||||
|
||||
.form-control:focus {
|
||||
box-shadow: 0 0 0 0.25rem rgba(59, 130, 246, 0.25);
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
footer {
|
||||
background-color: var(--surface-color);
|
||||
padding: 2rem 0;
|
||||
border-top: 1px solid #e5e7eb;
|
||||
}
|
||||
|
||||
#contact-alert {
|
||||
position: fixed;
|
||||
top: 1rem;
|
||||
right: 1rem;
|
||||
z-index: 1050;
|
||||
display: none;
|
||||
min-width: 250px;
|
||||
}
|
||||
24
db/migrate.php
Normal file
24
db/migrate.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
// Simple migration script
|
||||
require_once __DIR__ . '/config.php';
|
||||
|
||||
try {
|
||||
$pdo = db();
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$migrationsDir = __DIR__ . '/migrations';
|
||||
$files = glob($migrationsDir . '/*.sql');
|
||||
sort($files);
|
||||
|
||||
foreach ($files as $file) {
|
||||
echo "Running migration: " . basename($file) . "\n";
|
||||
$sql = file_get_contents($file);
|
||||
$pdo->exec($sql);
|
||||
}
|
||||
|
||||
echo "Migrations completed successfully.\n";
|
||||
|
||||
} catch (PDOException $e) {
|
||||
die("Migration failed: " . $e->getMessage());
|
||||
}
|
||||
|
||||
23
db/migrations/001_initial_schema.sql
Normal file
23
db/migrations/001_initial_schema.sql
Normal file
@ -0,0 +1,23 @@
|
||||
CREATE TABLE IF NOT EXISTS `teams` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL UNIQUE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `tournaments` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`start_date` DATETIME DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `matches` (
|
||||
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
||||
`tournament_id` INT NOT NULL,
|
||||
`round` INT NOT NULL,
|
||||
`team1_id` INT,
|
||||
`team2_id` INT,
|
||||
`winner_id` INT,
|
||||
FOREIGN KEY (`tournament_id`) REFERENCES `tournaments`(`id`) ON DELETE CASCADE,
|
||||
FOREIGN KEY (`team1_id`) REFERENCES `teams`(`id`) ON DELETE SET NULL,
|
||||
FOREIGN KEY (`team2_id`) REFERENCES `teams`(`id`) ON DELETE SET NULL,
|
||||
FOREIGN KEY (`winner_id`) REFERENCES `teams`(`id`) ON DELETE SET NULL
|
||||
);
|
||||
6
includes/footer.php
Normal file
6
includes/footer.php
Normal file
@ -0,0 +1,6 @@
|
||||
</div>
|
||||
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
32
includes/header.php
Normal file
32
includes/header.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../db/config.php';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Hearthstone Tournament Manager</title>
|
||||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
||||
<link rel="stylesheet" href="/assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="/">Hearthstone Tournaments</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/teams.php">Teams</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/tournaments.php">Tournaments</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="container mt-4">
|
||||
159
index.php
159
index.php
@ -1,147 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>John Doe - Personal Portfolio</title>
|
||||
<meta name="description" content="A one-page personal site to showcase work and receive contact requests.">
|
||||
<meta name="author" content="John Doe">
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
?>
|
||||
|
||||
<!-- Open Graph / Facebook -->
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:url" content="https://your-domain.com/">
|
||||
<meta property="og:title" content="John Doe - Personal Portfolio">
|
||||
<meta property="og:description" content="Showcasing my work and projects.">
|
||||
<meta property="og:image" content="https://picsum.photos/seed/og-image/1200/630">
|
||||
<div class="jumbotron">
|
||||
<h1 class="display-4">Welcome to the Hearthstone Tournament Manager!</h1>
|
||||
<p class="lead">This is a simple application to manage your Hearthstone tournaments.</p>
|
||||
<hr class="my-4">
|
||||
<p>You can add teams, create tournaments, and manage matches.</p>
|
||||
<a class="btn btn-primary btn-lg" href="/teams.php" role="button">Manage Teams</a>
|
||||
<a class="btn btn-secondary btn-lg" href="/tournaments.php" role="button">Manage Tournaments</a>
|
||||
</div>
|
||||
|
||||
<!-- Twitter -->
|
||||
<meta property="twitter:card" content="summary_large_image">
|
||||
<meta property="twitter:url" content="https://your-domain.com/">
|
||||
<meta property="twitter:title" content="John Doe - Personal Portfolio">
|
||||
<meta property="twitter:description" content="Showcasing my work and projects.">
|
||||
<meta property="twitter:image" content="https://picsum.photos/seed/og-image/1200/630">
|
||||
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap" rel="stylesheet">
|
||||
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="navbar navbar-expand-lg navbar-dark fixed-top">
|
||||
<div class="container">
|
||||
<a class="navbar-brand fw-bold" href="#">MyPortfolio</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav ms-auto">
|
||||
<li class="nav-item"><a class="nav-link" href="#home">Home</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#about">About</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#portfolio">Portfolio</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#contact">Contact</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<header id="home" class="hero">
|
||||
<div class="container">
|
||||
<h1 class="display-4">Welcome to My Digital Space</h1>
|
||||
<p class="lead">I build modern, responsive, and beautiful web applications.</p>
|
||||
<a href="#portfolio" class="btn btn-primary btn-lg mt-3">View My Work</a>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section id="about" class="section">
|
||||
<div class="container">
|
||||
<h2 class="section-title">About Me</h2>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-8 text-center">
|
||||
<p class="lead">I am a passionate web developer with a love for clean code and user-centric design. With a background in computer science and several years of experience, I specialize in creating dynamic and engaging websites. When I'm not coding, I enjoy hiking and photography.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="portfolio" class="section bg-light">
|
||||
<div class="container">
|
||||
<h2 class="section-title">Portfolio</h2>
|
||||
<div class="row g-4">
|
||||
<div class="col-md-6 col-lg-4">
|
||||
<div class="card portfolio-card">
|
||||
<img src="assets/images/kitten-7778873.jpg" class="card-img-top" alt="A computer screen with code on it.">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Project One</h5>
|
||||
<p class="card-text">A brief description of the project, its purpose, and the technologies used. This is a placeholder.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 col-lg-4">
|
||||
<div class="card portfolio-card">
|
||||
<img src="assets/images/kitten-7778872.jpg" class="card-img-top" alt="A person's hands typing on a laptop.">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Project Two</h5>
|
||||
<p class="card-text">A brief description of the project, its purpose, and the technologies used. This is a placeholder.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 col-lg-4">
|
||||
<div class="card portfolio-card">
|
||||
<img src="assets/images/kitten-4450241.jpg" class="card-img-top" alt="Code on a screen with a blurry background.">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Project Three</h5>
|
||||
<p class="card-text">A brief description of the project, its purpose, and the technologies used. This is a placeholder.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section id="contact" class="section">
|
||||
<div class="container">
|
||||
<h2 class="section-title">Get In Touch</h2>
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-lg-6">
|
||||
<form id="contactForm" novalidate>
|
||||
<div class="mb-3">
|
||||
<label for="name" class="form-label">Name</label>
|
||||
<input type="text" class="form-control" id="name" name="name" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email" class="form-label">Email</label>
|
||||
<input type="email" class="form-control" id="email" name="email" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="message" class="form-label">Message</label>
|
||||
<textarea class="form-control" id="message" name="message" rows="5" required></textarea>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
<button type="submit" class="btn btn-primary">Send Message</button>
|
||||
</div>
|
||||
</form>
|
||||
<div class="mt-3 text-center">
|
||||
<small class="text-muted">For testing purposes, emails may be sent to a default address. Please configure your own SMTP settings in the <code>.env</code> file for production use.</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer class="text-center">
|
||||
<div class="container">
|
||||
<p class="mb-0">© <?php echo date("Y"); ?> John Doe. All Rights Reserved.</p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<!-- Alert Toast -->
|
||||
<div id="contact-alert" class="alert" role="alert"></div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/footer.php';
|
||||
?>
|
||||
|
||||
69
teams.php
Normal file
69
teams.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
$message = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_team'])) {
|
||||
$teamName = trim($_POST['team_name']);
|
||||
if (!empty($teamName)) {
|
||||
try {
|
||||
$stmt = db()->prepare("INSERT INTO teams (name) VALUES (?)");
|
||||
$stmt->execute([$teamName]);
|
||||
$message = '<div class="alert alert-success">Team added successfully!</div>';
|
||||
} catch (PDOException $e) {
|
||||
if ($e->errorInfo[1] == 1062) { // Duplicate entry
|
||||
$message = '<div class="alert alert-danger">Error: A team with this name already exists.</div>';
|
||||
} else {
|
||||
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch all teams
|
||||
$teamsStmt = db()->query("SELECT * FROM teams ORDER BY name");
|
||||
$teams = $teamsStmt->fetchAll();
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Add New Team</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php echo $message; ?>
|
||||
<form method="POST" action="teams.php">
|
||||
<div class="form-group">
|
||||
<label for="team_name">Team Name</label>
|
||||
<input type="text" class="form-control" id="team_name" name="team_name" required>
|
||||
</div>
|
||||
<button type="submit" name="add_team" class="btn btn-primary">Add Team</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Existing Teams</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-group">
|
||||
<?php if (count($teams) > 0): ?>
|
||||
<?php foreach ($teams as $team): ?>
|
||||
<li class="list-group-item"><?php echo htmlspecialchars($team['name']); ?></li>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<li class="list-group-item">No teams found.</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/footer.php';
|
||||
?>
|
||||
187
tournament_view.php
Normal file
187
tournament_view.php
Normal file
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
||||
header("Location: /tournaments.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$tournamentId = $_GET['id'];
|
||||
|
||||
// Fetch tournament details
|
||||
$stmt = db()->prepare("SELECT * FROM tournaments WHERE id = ?");
|
||||
$stmt->execute([$tournamentId]);
|
||||
$tournament = $stmt->fetch();
|
||||
|
||||
if (!$tournament) {
|
||||
header("Location: /tournaments.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$message = '';
|
||||
|
||||
// Generate bracket
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['generate_bracket'])) {
|
||||
// Check if matches already exist
|
||||
$stmt = db()->prepare("SELECT COUNT(*) FROM matches WHERE tournament_id = ?");
|
||||
$stmt->execute([$tournamentId]);
|
||||
if ($stmt->fetchColumn() == 0) {
|
||||
$teamsStmt = db()->query("SELECT * FROM teams");
|
||||
$teams = $teamsStmt->fetchAll();
|
||||
shuffle($teams);
|
||||
|
||||
$round = 1;
|
||||
$numTeams = count($teams);
|
||||
|
||||
for ($i = 0; $i < $numTeams; $i += 2) {
|
||||
$team1_id = $teams[$i]['id'];
|
||||
$team2_id = isset($teams[$i+1]) ? $teams[$i+1]['id'] : null;
|
||||
|
||||
$stmt = db()->prepare("INSERT INTO matches (tournament_id, round, team1_id, team2_id) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$tournamentId, $round, $team1_id, $team2_id]);
|
||||
|
||||
if ($team2_id === null) { // Bye week
|
||||
$matchId = db()->lastInsertId();
|
||||
$stmt = db()->prepare("UPDATE matches SET winner_id = ? WHERE id = ?");
|
||||
$stmt->execute([$team1_id, $matchId]);
|
||||
}
|
||||
}
|
||||
$message = '<div class="alert alert-success">Bracket generated successfully!</div>';
|
||||
} else {
|
||||
$message = '<div class="alert alert-warning">Bracket has already been generated.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
// Update winner
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_winner'])) {
|
||||
$matchId = $_POST['match_id'];
|
||||
$winnerId = $_POST['winner_id'];
|
||||
|
||||
$stmt = db()->prepare("UPDATE matches SET winner_id = ? WHERE id = ?");
|
||||
$stmt->execute([$winnerId, $matchId]);
|
||||
$message = '<div class="alert alert-success">Winner updated!</div>';
|
||||
}
|
||||
|
||||
// Generate next round
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['next_round'])) {
|
||||
$stmt = db()->prepare("SELECT MAX(round) FROM matches WHERE tournament_id = ?");
|
||||
$stmt->execute([$tournamentId]);
|
||||
$currentRound = $stmt->fetchColumn();
|
||||
|
||||
$stmt = db()->prepare("SELECT winner_id FROM matches WHERE tournament_id = ? AND round = ? AND winner_id IS NOT NULL");
|
||||
$stmt->execute([$tournamentId, $currentRound]);
|
||||
$winners = $stmt->fetchAll(PDO::FETCH_COLUMN);
|
||||
|
||||
if (count($winners) > 1) {
|
||||
$nextRound = $currentRound + 1;
|
||||
for ($i = 0; $i < count($winners); $i += 2) {
|
||||
$team1_id = $winners[$i];
|
||||
$team2_id = isset($winners[$i+1]) ? $winners[$i+1] : null;
|
||||
|
||||
$stmt = db()->prepare("INSERT INTO matches (tournament_id, round, team1_id, team2_id) VALUES (?, ?, ?, ?)");
|
||||
$stmt->execute([$tournamentId, $nextRound, $team1_id, $team2_id]);
|
||||
|
||||
if ($team2_id === null) { // Bye week
|
||||
$matchId = db()->lastInsertId();
|
||||
$stmt = db()->prepare("UPDATE matches SET winner_id = ? WHERE id = ?");
|
||||
$stmt->execute([$team1_id, $matchId]);
|
||||
}
|
||||
}
|
||||
$message = '<div class="alert alert-success">Next round generated!</div>';
|
||||
} else {
|
||||
$message = '<div class="alert alert-info">Tournament finished!</div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Fetch matches
|
||||
$matchesStmt = db()->prepare("
|
||||
SELECT m.id, m.round, t1.name as team1_name, t2.name as team2_name, m.team1_id, m.team2_id, w.name as winner_name
|
||||
FROM matches m
|
||||
LEFT JOIN teams t1 ON m.team1_id = t1.id
|
||||
LEFT JOIN teams t2 ON m.team2_id = t2.id
|
||||
LEFT JOIN teams w ON m.winner_id = w.id
|
||||
WHERE m.tournament_id = ?
|
||||
ORDER BY m.round, m.id
|
||||
");
|
||||
$matchesStmt->execute([$tournamentId]);
|
||||
$matches = $matchesStmt->fetchAll();
|
||||
|
||||
$rounds = [];
|
||||
foreach ($matches as $match) {
|
||||
$rounds[$match['round']][] = $match;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<h2><?php echo htmlspecialchars($tournament['name']); ?></h2>
|
||||
|
||||
<?php echo $message; ?>
|
||||
|
||||
<?php if (count($matches) == 0): ?>
|
||||
<form method="POST" class="mb-4">
|
||||
<button type="submit" name="generate_bracket" class="btn btn-primary">Generate Bracket</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
<?php
|
||||
$stmt = db()->prepare("SELECT MAX(round) FROM matches WHERE tournament_id = ?");
|
||||
$stmt->execute([$tournamentId]);
|
||||
$currentRound = $stmt->fetchColumn();
|
||||
|
||||
$stmt = db()->prepare("SELECT COUNT(*) FROM matches WHERE tournament_id = ? AND round = ? AND winner_id IS NULL");
|
||||
$stmt->execute([$tournamentId, $currentRound]);
|
||||
$unfinishedMatches = $stmt->fetchColumn();
|
||||
|
||||
if ($unfinishedMatches == 0) {
|
||||
$stmt = db()->prepare("SELECT COUNT(DISTINCT winner_id) FROM matches WHERE tournament_id = ? AND round = ?");
|
||||
$stmt->execute([$tournamentId, $currentRound]);
|
||||
$distinctWinners = $stmt->fetchColumn();
|
||||
if ($distinctWinners > 1) {
|
||||
echo '<form method="POST" class="mb-4"><button type="submit" name="next_round" class="btn btn-success">Generate Next Round</button></form>';
|
||||
} else {
|
||||
echo '<div class="alert alert-success"><strong>Winner:</strong> ' . $rounds[$currentRound][0]['winner_name'] . '</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<div class="row">
|
||||
<?php foreach ($rounds as $round => $round_matches): ?>
|
||||
<div class="col-md-4">
|
||||
<div class="card mb-4">
|
||||
<div class="card-header">
|
||||
<h3>Round <?php echo $round; ?></h3>
|
||||
</div>
|
||||
<ul class="list-group list-group-flush">
|
||||
<?php foreach ($round_matches as $match): ?>
|
||||
<li class="list-group-item">
|
||||
<form method="POST">
|
||||
<input type="hidden" name="match_id" value="<?php echo $match['id']; ?>">
|
||||
<strong><?php echo htmlspecialchars($match['team1_name']); ?></strong> vs <strong><?php echo htmlspecialchars($match['team2_name'] ?? 'BYE'); ?></strong>
|
||||
<hr>
|
||||
<?php if ($match['winner_name']): ?>
|
||||
<p>Winner: <strong><?php echo htmlspecialchars($match['winner_name']); ?></strong></p>
|
||||
<?php elseif ($match['team2_name']): ?>
|
||||
<div class="form-group">
|
||||
<label>Set Winner:</label>
|
||||
<select name="winner_id" class="form-control">
|
||||
<option value="<?php echo $match['team1_id']; ?>"><?php echo htmlspecialchars($match['team1_name']); ?></option>
|
||||
<option value="<?php echo $match['team2_id']; ?>"><?php echo htmlspecialchars($match['team2_name']); ?></option>
|
||||
</select>
|
||||
</div>
|
||||
<button type="submit" name="update_winner" class="btn btn-sm btn-primary">Save</button>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/footer.php';
|
||||
?>
|
||||
69
tournaments.php
Normal file
69
tournaments.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/header.php';
|
||||
|
||||
$message = '';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_tournament'])) {
|
||||
$tournamentName = trim($_POST['tournament_name']);
|
||||
if (!empty($tournamentName)) {
|
||||
try {
|
||||
$stmt = db()->prepare("INSERT INTO tournaments (name) VALUES (?)");
|
||||
$stmt->execute([$tournamentName]);
|
||||
$message = '<div class="alert alert-success">Tournament created successfully!</div>';
|
||||
} catch (PDOException $e) {
|
||||
$message = '<div class="alert alert-danger">Error: ' . $e->getMessage() . '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch all tournaments
|
||||
$tournamentsStmt = db()->query("SELECT * FROM tournaments ORDER BY start_date DESC");
|
||||
$tournaments = $tournamentsStmt->fetchAll();
|
||||
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Create New Tournament</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php echo $message; ?>
|
||||
<form method="POST" action="tournaments.php">
|
||||
<div class="form-group">
|
||||
<label for="tournament_name">Tournament Name</label>
|
||||
<input type="text" class="form-control" id="tournament_name" name="tournament_name" required>
|
||||
</div>
|
||||
<button type="submit" name="add_tournament" class="btn btn-primary">Create Tournament</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h2>Existing Tournaments</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="list-group">
|
||||
<?php if (count($tournaments) > 0): ?>
|
||||
<?php foreach ($tournaments as $tournament): ?>
|
||||
<li class="list-group-item">
|
||||
<a href="/tournament_view.php?id=<?php echo $tournament['id']; ?>">
|
||||
<?php echo htmlspecialchars($tournament['name']); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
<?php else: ?>
|
||||
<li class="list-group-item">No tournaments found.</li>
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
require_once __DIR__ . '/includes/footer.php';
|
||||
?>
|
||||
Loading…
x
Reference in New Issue
Block a user