<?php
    ini_set
('display_errors'1);
    
ini_set('display_startup_errors'1);
    
error_reporting(E_ALL);

    require_once 
'Functions/db_credentials.php';
    require_once 
'Functions/db_connection.php';

    
// Check if $dbc is set
    
if (!isset($dbc) || !$dbc) {
        die(
"Database connection failed.");
    }
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="Styles/styles.css">
    <title>Task 2 - Custom CMS</title>
</head>

<body>
    <?php include "Pages/nav.php"?>

    <?php
        $page 
"welcome"// default page

        
if (isset($_GET['page'])) {
            
$page $_GET['page'];
        }

        
$filePath "Pages/" $page ".php";

        if (
$page === "cms") {
            include_once 
"cms.php"// cms.php is not in pages folder and has to be checked seperately
        
} elseif (file_exists($filePath)) {
            include_once 
$filePath
        } else {
            include_once 
"Pages/page_not_found.php";
        }

        
// Close the database connection only if it's valid
        
if (isset($dbc) && $dbc instanceof mysqli) {
            
mysqli_close($dbc);
        }
    
?>
</body>
</html>