This commit is contained in:
Flatlogic Bot 2025-09-24 14:03:58 +00:00
parent 6915e64858
commit 3cef421e69
2 changed files with 65 additions and 7 deletions

View File

@ -19,15 +19,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_course'])) {
$tournament_date = null; $tournament_date = null;
} }
if ($isValid) {
$num_holes_to_validate = ($hole_count == 9) ? 9 : 18;
for ($i = 1; $i <= 18; $i++) { for ($i = 1; $i <= 18; $i++) {
$par_value = filter_input(INPUT_POST, 'par_hole_' . $i, FILTER_VALIDATE_INT); $par_value = filter_input(INPUT_POST, 'par_hole_' . $i, FILTER_VALIDATE_INT);
if ($i <= $num_holes_to_validate) {
if ($par_value === false || $par_value < 1 || $par_value > 7) { if ($par_value === false || $par_value < 1 || $par_value > 7) {
$error = "Invalid par value for hole " . $i . ". Please enter a number between 1 and 7."; $error = "Invalid par value for hole " . $i . ". Please enter a number between 1 and 7.";
$isValid = false; $isValid = false;
break; break;
} }
} else {
// For 9-hole courses, holes 10-18 should be 0.
if ($par_value !== 0) {
$par_value = 0;
}
}
$pars[] = $par_value; $pars[] = $par_value;
} }
}
if ($isValid) { if ($isValid) {
try { try {
@ -208,5 +219,37 @@ try {
</footer> </footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
const holeCountSelect = document.getElementById('hole_count');
function toggleParHoles() {
const selectedHoles = parseInt(holeCountSelect.value, 10);
for (let i = 1; i <= 18; i++) {
const holeInput = document.getElementById('par_hole_' + i);
const holeInputDiv = holeInput.parentElement;
if (i > 9) {
if (selectedHoles === 9) {
holeInputDiv.style.display = 'none';
holeInput.value = 0;
holeInput.required = false;
} else {
holeInputDiv.style.display = '';
if (holeInput.value == 0) { // Only reset if it was 0
holeInput.value = 4; // reset to default
}
holeInput.required = true;
}
}
}
}
holeCountSelect.addEventListener('change', toggleParHoles);
// Initial check on page load
toggleParHoles();
});
</script>
</body> </body>
</html> </html>

View File

@ -65,6 +65,21 @@ try {
"); ");
echo "Table 'scores' created successfully or already exists.<br>"; echo "Table 'scores' created successfully or already exists.<br>";
// Add hole_count to courses if it doesn't exist
$stmt = $pdo->query("SHOW COLUMNS FROM courses LIKE 'hole_count'");
if ($stmt->rowCount() == 0) {
$pdo->exec("ALTER TABLE courses ADD COLUMN hole_count INT NOT NULL DEFAULT 18");
echo "Column 'hole_count' added to 'courses' table.<br>";
}
// Add tournament_date to courses if it doesn't exist
$stmt = $pdo->query("SHOW COLUMNS FROM courses LIKE 'tournament_date'");
if ($stmt->rowCount() == 0) {
$pdo->exec("ALTER TABLE courses ADD COLUMN tournament_date DATE");
echo "Column 'tournament_date' added to 'courses' table.<br>";
}
} catch (PDOException $e) { } catch (PDOException $e) {
die("DB ERROR: " . $e->getMessage()); die("DB ERROR: " . $e->getMessage());
} }