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

session_name('CINE_Le_Paris');
session_start();

// For debugging, 
// echo "<pre>Session Data: ";
// var_dump($_SESSION);
// echo "</pre>";
// echo "<pre>GET Data: ";
// var_dump($_GET);
// echo "</pre>";


// --- Bootstrap ---
require __DIR__ '/config/db_credentials.php';
require 
__DIR__ '/config/db.php';

// --- Page Resolution ---

$allowedPages = [
    
'home''profile''login''calendar''volunteer''plans'
    
'dashboard''logout''movies''moviedetail''extras''films'
    
'persons''assignments''active-plans''planresponse'
    
'supervisedplages'
];

$defaultPage 'home';
$pageKey $defaultPage;

if (
    !empty(
$_GET['page']) &&
    
is_string($_GET['page']) && // Ensure it's a string
    
preg_match('/^[a-zA-Z0-9_]+$/'$_GET['page']) &&
    
in_array($_GET['page'], $allowedPagestrue)
) {
    
$pageKey $_GET['page'];
}


$pageMap = [
    
'home'              => 'pages/home.php',
    
'profile'           => 'pages/profile.php',
    
'login'             => 'pages/login.php',
    
'calendar'          => 'admin/calendar.php',
    
'volunteer'         => 'pages/volunteer.php',
    
'plans'             => 'admin/plans.php',
    
'dashboard'         => 'admin/dashboard.php',
    
'logout'            => 'actions/logout.php',
    
'movies'            => 'pages/movies.php',
    
'moviedetail'       => 'pages/moviedetail.php',
    
'extras'            => 'admin/extras.php',
    
'films'             => 'admin/films.php',
    
'persons'           => 'admin/persons.php',
    
'assignments'       => 'admin/assignments.php',
    
'activeplans'       => 'pages/activeplans.php'
    
'planresponse'      => 'admin/planresponse.php',
    
'supervisedplages' => 'admin/supervisedplages.php'
];

$pageFile __DIR__ "/" . ($pageMap[$pageKey] ?? 'pages/404.php');



if (!
file_exists($pageFile)) {
    
$pageFile __DIR__ '/pages/404.php';
}

?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <meta name="author" content="Noah Rippinger">
  <title>CinĂ© Le Paris - <?php echo ucfirst(htmlspecialchars($pageKey)); ?></title>
  <link rel="icon" href="favicon.ico" type="image/x-icon">
</head>
<body>
  <?php
    
// Only show navbar if not on the dashboard page or other admin pages where it might be redundant
    
$adminPagesForNavbarExclusion = ['dashboard',];
    if (!
in_array($pageKey$adminPagesForNavbarExclusion)) {
        
// Check if the navbar file exists before including
        
$navbarFile __DIR__ '/includes/navbar.php';
        if (
file_exists($navbarFile)) {
            include 
$navbarFile;
        } else {
            echo 
"<!-- Navbar file not found -->";
        }
    }
  
?>
  <?php
    
// Check if the page file to be included exists
    
if (file_exists($pageFile)) {
        include 
$pageFile;
    } else {
        echo 
"<p>Error: Page file not found at " htmlspecialchars($pageFile) . "</p>";
    }
  
?>
</body>
</html>