87 lines
3.3 KiB
PHP
87 lines
3.3 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="row">
|
|
<?php if (empty($surveys)):
|
|
?>
|
|
<div class="col">
|
|
<p>No surveys available at the moment.</p>
|
|
</div>
|
|
<?php else:
|
|
?>
|
|
<?php foreach ($surveys as $survey):
|
|
?>
|
|
<div class="col-md-4 mb-4">
|
|
<div class="card h-100">
|
|
<div class="card-body d-flex flex-column">
|
|
<h5 class="card-title"><?= htmlspecialchars($survey['title']) ?></h5>
|
|
<p class="card-text flex-grow-1"><?= htmlspecialchars($survey['description']) ?></p>
|
|
<a href="survey.php?id=<?= $survey['id'] ?>" class="btn btn-primary mt-auto">Take Survey</a>
|
|
</div>
|
|
<div class="card-footer">
|
|
<small class="text-muted">Created: <?= date('M j, Y', strtotime($survey['created_at'])) ?></small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?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';
|
|
?>
|