34760-vm/index.php
Flatlogic Bot d47e350516 v1
2025-10-07 16:17:37 +00:00

75 lines
2.9 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
// Pagination
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$records_per_page = 10;
$offset = ($page - 1) * $records_per_page;
// Get total number of surveys
$total_stmt = db()->query("SELECT COUNT(*) FROM surveys");
$total_records = $total_stmt->fetchColumn();
$total_pages = ceil($total_records / $records_per_page);
// Fetch surveys for the current page
$surveys_stmt = db()->prepare("SELECT * FROM surveys ORDER BY created_at DESC LIMIT :limit OFFSET :offset");
$surveys_stmt->bindValue(':limit', $records_per_page, PDO::PARAM_INT);
$surveys_stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
$surveys_stmt->execute();
$surveys = $surveys_stmt->fetchAll();
$pageTitle = "Available Surveys";
$description = "Choose a survey to provide your feedback.";
require_once 'templates/header.php';
?>
<main>
<section class="hero">
<div class="container">
<h1>Available Surveys</h1>
<p>Please choose one of the surveys below to provide your feedback.</p>
</div>
</section>
<section class="survey-section">
<div class="container">
<div class="list-group">
<?php if (empty($surveys)): ?>
<p class="list-group-item">No surveys available at the moment.</p>
<?php else: ?>
<?php foreach ($surveys as $survey): ?>
<a href="survey.php?id=<?= $survey['id'] ?>" class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1"><?= htmlspecialchars($survey['title']) ?></h5>
<small><?= date('M j, Y', strtotime($survey['created_at'])) ?></small>
</div>
<p class="mb-1"><?= htmlspecialchars($survey['description']) ?></p>
</a>
<?php endforeach; ?>
<?php endif; ?>
</div>
<!-- Pagination Links -->
<nav aria-label="Page navigation">
<ul class="pagination justify-content-center mt-4">
<?php if ($page > 1): ?>
<li class="page-item"><a class="page-link" href="?page=<?= $page - 1 ?>">Previous</a></li>
<?php endif; ?>
<?php for ($i = 1; $i <= $total_pages; $i++): ?>
<li class="page-item <?= ($i == $page) ? 'active' : '' ?>"><a class="page-link" href="?page=<?= $i ?>"><?= $i ?></a></li>
<?php endfor; ?>
<?php if ($page < $total_pages): ?>
<li class="page-item"><a class="page-link" href="?page=<?= $page + 1 ?>">Next</a></li>
<?php endif; ?>
</ul>
</nav>
</div>
</section>
</main>
<?php
require_once 'templates/footer.php';
?>