34352-vm/add_score.php
Flatlogic Bot 6424a2c0f6 1.3
2025-09-24 19:44:13 +00:00

153 lines
6.8 KiB
PHP

<?php
require_once 'db/config.php';
$courses = [];
$players = [];
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, name FROM courses ORDER BY name");
$courses = $stmt->fetchAll();
$stmt = $pdo->query("SELECT p.id, p.player_name, t.team_name FROM players p JOIN teams t ON p.team_id = t.id ORDER BY t.team_name, p.player_name");
$players = $stmt->fetchAll();
} catch (PDOException $e) {
// If something goes wrong, we'll have empty arrays.
// For debugging, you might want to log the error:
// error_log($e->getMessage());
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Enter Golf Score</title>
<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=Roboto:wght@400;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-light bg-white shadow-sm">
<div class="container">
<a class="navbar-brand" href="index.php">GolfTracker</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<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 active" href="add_score.php">Enter Score</a>
</li>
</ul>
</div>
</div>
</nav>
<main class="container my-5">
<div class="card p-4">
<h1 class="text-center mb-4">Enter Round Score</h1>
<div class="row mb-3">
<div class="col-md-6">
<label for="playerSelect" class="form-label">Select Player</label>
<select class="form-select" id="playerSelect" required>
<option value="">-- Select a Player --</option>
<?php
$current_team = null;
foreach ($players as $player):
if ($player['team_name'] !== $current_team):
if ($current_team !== null):
echo '</optgroup>';
endif;
$current_team = $player['team_name'];
echo '<optgroup label="' . htmlspecialchars($current_team) . '">';
endif;
?>
<option value="<?php echo $player['id']; ?>"><?php echo htmlspecialchars($player['player_name']); ?></option>
<?php endforeach;
if ($current_team !== null):
echo '</optgroup>';
endif;
?>
</select>
</div>
</div>
<div class="row mb-4">
<div class="col-md-6">
<label for="courseSelect" class="form-label">Select Course</label>
<select class="form-select" id="courseSelect">
<option value="">-- Select a Course --</option>
<?php foreach ($courses as $course): ?>
<option value="<?php echo $course['id']; ?>"><?php echo htmlspecialchars($course['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6 d-flex align-items-end justify-content-center">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="holesToggle">
<label class="form-check-label ms-2" for="holesToggle">Play 18 Holes (9 by default)</label>
</div>
</div>
</div>
<form id="scoreForm">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Hole</th>
<th scope="col">Par</th>
<th scope="col">Score</th>
<th scope="col">Vs Par</th>
<th scope="col">Putts</th>
<th scope="col">Penalties</th>
<th scope="col">Sand Lie</th>
</tr>
</thead>
<tbody id="scoreTable">
<!-- JS will render rows here -->
</tbody>
</table>
</div>
<div class="text-center mt-4">
<button type="submit" class="btn btn-primary btn-lg">Submit Score</button>
</div>
</form>
</div>
</main>
<div class="card totals-card bg-light p-3">
<h4 class="text-center">Round Totals</h4>
<div class="row text-center">
<div class="col"><strong>To Par:</strong> <span id="totalToPar">E</span></div>
<div class="col"><strong>Score:</strong> <span id="totalScore">0</span></div>
<div class="col"><strong>Putts:</strong> <span id="totalPutts">0</span></div>
<div class="col"><strong>Penalties:</strong> <span id="totalPenalties">0</span></div>
<div class="col"><strong>Sand Lies:</strong> <span id="totalSandLies">0</span></div>
</div>
</div>
<div class="position-fixed bottom-0 end-0 p-3" style="z-index: 11">
<div id="successToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header text-white" style="background-color: #0D47A1;">
<strong class="me-auto">Success</strong>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Your score has been submitted successfully! (Client-side demo)
</div>
</div>
</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>