scc24php/.hta_404.php

76 lines
2.8 KiB
PHP

<?php
require('.hta_config/env.php');
require('.hta_header.php');
$headerContent = file_get_contents('./.hta_header.php');
$requestUri = $_SERVER['REQUEST_URI'];
$urlParts = explode('/', $requestUri);
if ($urlParts[1] === 'notice') {
$slug = $urlParts[2];
} elseif($urlParts[1] === 'departments'){
$slug = $urlParts[2];
} else{
$slug = $urlParts[1];
}
$querySlug = explode('.', $slug)[0];
$fileName = $slug;
// function saveHtmlFile($fileName, $headerContent, $pageContent){
// $footerContent = file_get_contents('./.hta_footer.php');
// $totalPageContent = $headerContent . $pageContent . $footerContent;
// $filePath = __DIR__ . '/' . $fileName;
// if (file_put_contents($filePath, $totalPageContent)) {
// echo "<p class='text-success'>Page saved successfully at $filePath.</p>";
// } else {
// echo "<p class='text-danger'>Failed to save the page.</p>";
// }
// }
try {
$conn = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM `scc24` WHERE `slug` = :querySlug");
$stmt->bindParam(':querySlug', $querySlug, PDO::PARAM_STR);
$stmt->execute();
$content = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (isset($content[0]['content']) && $content[0]['content']) {
$pageContent = '
<div class="container mx-auto" style="display: flex; flex-direction: column; justify-content: center; align-items: center;">
<div class="" style="padding-top:20px; padding-bottom:15px; font-size:25px;">
';
if ($content[0]['type'] !== 'faculty') {
$pageContent .= '<p style="text-align: center;">' . htmlspecialchars($content[0]['title']) . '</p>';
}
$pageContent .= '
</div>
<div class="">' . $content[0]['content'] . '</div>
</div>';
// Call the function to save the HTML file
// saveHtmlFile($fileName, $headerContent, $pageContent);
} else {
$pageContent = '
<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 100px 0; ">
<p style="text-align: center; font-size: 30px; font-weight: bold;">Page not found (404).</p>
<a href="/">Back to home</a>
</div>';
}
} catch (PDOException $e) {
$pageContent = "<p class='text-danger'>Error: " . $e->getMessage() . "</p>";
}
// Render page content here
echo $pageContent;
$footerContent = file_get_contents('./.hta_footer.php');
// Function to save HTML file
?>