35358-vm/index.php
Flatlogic Bot 3d23e3f6ab v 25-10-30
2025-10-30 15:35:40 +00:00

128 lines
5.6 KiB
PHP

<?php
require_once 'db/config.php';
// Run migrations to ensure the table exists
run_migrations();
$pdo = db();
$shooter_id = 1; // Simulate logged-in shooter
// Handle form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['result_text'])) {
$result_text = trim($_POST['result_text']);
$comments = trim($_POST['comments']);
if (!empty($result_text)) {
$stmt = $pdo->prepare("INSERT INTO results (shooter_id, result_text, comments) VALUES (?, ?, ?)");
$stmt->execute([$shooter_id, $result_text, $comments]);
// Redirect to avoid form resubmission, with a success flag
header("Location: index.php?success=1");
exit;
}
}
// Fetch existing results for the shooter
$stmt = $pdo->prepare("SELECT * FROM results WHERE shooter_id = ? ORDER BY created_at DESC");
$stmt->execute([$shooter_id]);
$results = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>skyderesultater</title>
<meta name="description" content="A simple application for shooters to enter and track their results.">
<meta name="keywords" content="shooting, results, scoring, training, shooter, instructor, skyderesultater, Built with Flatlogic Generator">
<meta property="og:title" content="skyderesultater">
<meta property="og:description" content="A simple application for shooters to enter and track their results.">
<meta property="og:image" content="">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.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="#">
<i class="bi bi-bullseye"></i> skyderesultater
</a>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-8 offset-md-2">
<!-- Add Result Form -->
<div class="card mb-4">
<div class="card-header">
<h5 class="card-title mb-0">Add New Result</h5>
</div>
<div class="card-body">
<form action="index.php" method="POST">
<div class="mb-3">
<label for="result_text" class="form-label">Result / Score</label>
<input type="text" class="form-control" id="result_text" name="result_text" required>
</div>
<div class="mb-3">
<label for="comments" class="form-label">Comments</label>
<textarea class="form-control" id="comments" name="comments" rows="3"></textarea>
</div>
<button type="submit" class="btn btn-success">
<i class="bi bi-check-circle"></i> Save Result
</button>
</form>
</div>
</div>
<!-- Results List -->
<div class="card">
<div class="card-header">
<h5 class="card-title mb-0">Your Past Results</h5>
</div>
<div class="card-body">
<?php if (empty($results)): ?>
<p class="text-center text-muted">You have not entered any results yet.</p>
<?php else: ?>
<ul class="list-group list-group-flush">
<?php foreach ($results as $result): ?>
<li class="list-group-item">
<div class="d-flex w-100 justify-content-between">
<h6 class="mb-1"><?php echo htmlspecialchars($result['result_text']); ?></h6>
<small class="text-muted"><?php echo date("M j, Y, g:i a", strtotime($result['created_at'])); ?></small>
</div>
<p class="mb-1"><?php echo nl2br(htmlspecialchars($result['comments'])); ?></p>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<!-- Success Toast -->
<div class="toast-container">
<div id="successToast" class="toast align-items-center text-white bg-success border-0" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body">
<i class="bi bi-check-circle-fill"></i> Result saved successfully!
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</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>