85 lines
1.8 KiB
PHP
85 lines
1.8 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<?php include_once "../../base/meta.php" ?>
|
|
|
|
<title>Guest Book DB</title>
|
|
|
|
<script src="./js/formValidation.js"></script>
|
|
<script src="./js/textarea.js"></script>
|
|
|
|
<link href="./css/styles.css" rel="stylesheet" />
|
|
</head>
|
|
|
|
<body>
|
|
<?php
|
|
// HTML
|
|
include_once "../../base/icons.php";
|
|
// PHP
|
|
include_once "../../base/settings.php";
|
|
include_once "../../base/headers.php";
|
|
Headers::html();
|
|
include_once "../../base/database.php";
|
|
|
|
include_once "./queries.php";
|
|
|
|
session_name("PHP_SESSION_guestBook");
|
|
session_start();
|
|
$errors = $_SESSION["error"] ?? [];
|
|
$_SESSION["error"] = [];
|
|
|
|
if (isset($_GET["p"]) && !is_numeric($_GET["p"])) {
|
|
Headers::redirect(".");
|
|
return;
|
|
}
|
|
$page = isset($_GET["p"]) ? intval($_GET["p"]) : 0;
|
|
|
|
$db = DB::openConnection();
|
|
|
|
|
|
|
|
$stmt = $db->prepare($countQuery);
|
|
$stmt->execute();
|
|
$maxPage = intdiv($stmt->fetch(PDO::FETCH_COLUMN), 9);
|
|
if ($page > $maxPage) {
|
|
Headers::redirect("./?p=$maxPage");
|
|
return;
|
|
}
|
|
|
|
$stmt = $db->prepare($dataQuery . $page * 9);
|
|
$stmt->execute();
|
|
$data = $stmt->fetchAll();
|
|
|
|
DB::closeConnection($db);
|
|
?>
|
|
|
|
<div class="container-fluid p-0">
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="#">Guest Book</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="row m-0">
|
|
<div class="col">
|
|
<?php foreach ($errors as $error) {
|
|
include "./components/error.php";
|
|
} ?>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row row-cols-1 row-cols-lg-3 g-3 m-0 mb-3">
|
|
<?php foreach ($data as $comment) {
|
|
include "./components/comment.php";
|
|
} ?>
|
|
</div>
|
|
|
|
<?php include "./components/pagination.php" ?>
|
|
|
|
<hr />
|
|
<?php include "./components/newComment.php" ?>
|
|
</div>
|
|
</body>
|
|
|
|
</html>
|