34352-vm/edit_score.php
Flatlogic Bot 0f8fd03d51 1.3
2025-09-24 21:22:36 +00:00

60 lines
2.2 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
session_start();
// TODO: Add role-based authentication check here.
// For example, check if $_SESSION['user_role'] is 'admin' or 'coach'.
// if (!isset($_SESSION['user_role']) || !in_array($_SESSION['user_role'], ['admin', 'coach'])) {
// die('Access denied. You do not have permission to edit scores.');
// }
$score_id = $_GET['score_id'] ?? null;
if (!$score_id) {
die('Score ID is required.');
}
$pdoc = db();
$stmt = $pdoc->prepare('SELECT s.*, p.name as player_name, c.name as course_name, c.hole_count FROM scores s JOIN players p ON s.player_id = p.id JOIN courses c ON s.course_id = c.id WHERE s.id = ?');
$stmt->execute([$score_id]);
$score = $stmt->fetch();
if (!$score) {
die('Score not found.');
}
$pars = [];
$stmt = $pdoc->prepare('SELECT * FROM courses WHERE id = ?');
$stmt->execute([$score['course_id']]);
$course = $stmt->fetch();
for ($i = 1; $i <= 18; $i++) {
$pars[$i] = $course['par_hole_' . $i];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edit Score</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container mt-5">
<h1>Edit Score for <?= htmlspecialchars($score['player_name']) ?> on <?= htmlspecialchars($score['course_name']) ?></h1>
<form action="submit_score.php" method="post">
<input type="hidden" name="score_id" value="<?= $score_id ?>">
<input type="hidden" name="action" value="update">
<div class="row">
<?php for ($i = 1; $i <= $score['hole_count']; $i++): ?>
<div class="col-md-4 mb-3">
<label for="hole_<?= $i ?>" class="form-label">Hole <?= $i ?> (Par <?= $pars[$i] ?>)</label>
<input type="number" class="form-control" id="hole_<?= $i ?>" name="scores[<?= $i ?>]" value="<?= htmlspecialchars($score['hole_' . $i . '_score']) ?>" min="1" required>
</div>
<?php endfor; ?>
</div>
<button type="submit" class="btn btn-primary">Update Score</button>
</form>
</div>
</body>
</html>