224 lines
11 KiB
PHP
224 lines
11 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Live Results - Golf Tournament</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">Golf Tournament</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="index.php">Home</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="add_score.php">Add Score</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="admin.php">Admin</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="coach.php">Coach</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link active" href="results.php">Results</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-5">
|
|
<h1 class="text-center mb-4">Tournament Leaderboard</h1>
|
|
|
|
<?php
|
|
require_once 'db/config.php';
|
|
$pdo = db();
|
|
|
|
// Fetch all courses for the dropdown
|
|
$courses_stmt = $pdo->query("SELECT id, name FROM courses ORDER BY name ASC");
|
|
$courses = $courses_stmt->fetchAll();
|
|
|
|
$selected_course_id = isset($_GET['course_id']) ? (int)$_GET['course_id'] : ($courses[0]['id'] ?? 0);
|
|
|
|
?>
|
|
|
|
<div class="row mb-4">
|
|
<div class="col-md-6 mx-auto">
|
|
<form action="results.php" method="GET" class="d-flex">
|
|
<select name="course_id" class="form-select me-2">
|
|
<?php foreach ($courses as $course): ?>
|
|
<option value="<?php echo $course['id']; ?>" <?php echo $selected_course_id == $course['id'] ? 'selected' : ''; ?>>
|
|
<?php echo htmlspecialchars($course['name']); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
<button type="submit" class="btn btn-primary">View</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow-sm">
|
|
<div class="card-body">
|
|
<h2 class="card-title text-center">Individual Standings</h2>
|
|
<?php
|
|
if ($selected_course_id) {
|
|
try {
|
|
// Fetch course details for pars
|
|
$course_stmt = $pdo->prepare("SELECT * FROM courses WHERE id = ?");
|
|
$course_stmt->execute([$selected_course_id]);
|
|
$course_details = $course_stmt->fetch();
|
|
|
|
// Fetch scores for the selected course
|
|
$stmt = $pdo->prepare("
|
|
SELECT s.*, p.name as player_name
|
|
FROM scores s
|
|
JOIN players p ON s.player_id = p.id
|
|
WHERE s.course_id = ?
|
|
ORDER BY s.total_to_par ASC
|
|
");
|
|
$stmt->execute([$selected_course_id]);
|
|
$results = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
$results = [];
|
|
$course_details = null;
|
|
echo "<p class='text-danger text-center'>Database error: " . $e->getMessage() . "</p>";
|
|
}
|
|
} else {
|
|
$results = [];
|
|
$course_details = null;
|
|
}
|
|
?>
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-bordered">
|
|
<thead class="table-dark">
|
|
<tr>
|
|
<th>Rank</th>
|
|
<th>Player</th>
|
|
<?php if ($course_details): ?>
|
|
<?php for ($i = 1; $i <= 18; $i++): ?>
|
|
<th class="text-center">
|
|
<?php echo $i; ?><br>
|
|
<small>(<?php echo $course_details['par_hole_' . $i]; ?>)</small>
|
|
</th>
|
|
<?php endfor; ?>
|
|
<?php endif; ?>
|
|
<th>Total</th>
|
|
<th>To Par</th>
|
|
<th>Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($results)): ?>
|
|
<tr>
|
|
<td colspan="<?php echo $course_details ? 23 : 5; ?>" class="text-center">No results yet for this course.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($results as $index => $row): ?>
|
|
<tr>
|
|
<td><?php echo $index + 1; ?></td>
|
|
<td><a href="player.php?id=<?php echo $row['player_id']; ?>"><?php echo htmlspecialchars($row['player_name']); ?></a></td>
|
|
<?php if ($course_details): ?>
|
|
<?php for ($i = 1; $i <= 18; $i++): ?>
|
|
<td class="text-center">
|
|
<?php
|
|
$score = $row['hole_' . $i . '_score'];
|
|
$par = $course_details['par_hole_' . $i];
|
|
$class = '';
|
|
if ($score !== null) {
|
|
if ($score < $par) $class = 'bg-success text-white'; // Birdie or better
|
|
elseif ($score > $par) $class = 'bg-warning'; // Bogey
|
|
else $class = 'bg-light'; // Par
|
|
}
|
|
echo "<span class='{$class} d-block'>{$score}</span>";
|
|
?>
|
|
</td>
|
|
<?php endfor; ?>
|
|
<?php endif; ?>
|
|
<td><?php echo $row['total_score']; ?></td>
|
|
<td><?php echo ($row['total_to_par'] > 0 ? '+' : '') . $row['total_to_par']; ?></td>
|
|
<td>
|
|
<a href="edit_score.php?score_id=<?php echo $row['id']; ?>" class="btn btn-sm btn-primary">Edit</a>
|
|
<a href="delete_score.php?score_id=<?php echo $row['id']; ?>" class="btn btn-sm btn-danger" onclick="return confirm('Are you sure you want to delete this score?');">Delete</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card shadow-sm mt-4">
|
|
<div class="card-body">
|
|
<h2 class="card-title text-center">Team Standings</h2>
|
|
<?php
|
|
if ($selected_course_id) {
|
|
try {
|
|
$stmt = $pdo->prepare("
|
|
SELECT t.name as team_name, SUM(s.total_score) as total_score
|
|
FROM scores s
|
|
JOIN teams t ON s.team_id = t.id
|
|
WHERE s.course_id = ?
|
|
GROUP BY s.team_id, t.name
|
|
ORDER BY total_score ASC
|
|
");
|
|
$stmt->execute([$selected_course_id]);
|
|
$team_results = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
$team_results = [];
|
|
echo "<p class='text-danger text-center'>Database error: " . $e->getMessage() . "</p>";
|
|
}
|
|
} else {
|
|
$team_results = [];
|
|
}
|
|
?>
|
|
<table class="table table-striped">
|
|
<thead>
|
|
<tr>
|
|
<th>Rank</th>
|
|
<th>Team</th>
|
|
<th>Total Score</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($team_results)): ?>
|
|
<tr>
|
|
<td colspan="3" class="text-center">No team results yet.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($team_results as $index => $row): ?>
|
|
<tr>
|
|
<td><?php echo $index + 1; ?></td>
|
|
<td><?php echo htmlspecialchars($row['team_name']); ?></td>
|
|
<td><?php echo $row['total_score']; ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="bg-light text-center text-lg-start mt-5">
|
|
<div class="text-center p-3" style="background-color: rgba(0, 0, 0, 0.05);">
|
|
© 2025 Golf Tournament
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|