2024-01-20 16:04:27 +01:00
|
|
|
<?php
|
|
|
|
session_start();
|
|
|
|
require_once 'config.php';
|
|
|
|
|
|
|
|
// Check if user is logged in
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
2024-01-20 18:23:08 +01:00
|
|
|
include 'login.php';
|
2024-01-20 16:04:27 +01:00
|
|
|
} else {
|
|
|
|
// Fetch user details
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
$query = "SELECT * FROM users WHERE id = $user_id";
|
|
|
|
$result = mysqli_query($mysqli, $query);
|
|
|
|
$user = mysqli_fetch_assoc($result);
|
|
|
|
|
2024-01-20 18:55:42 +01:00
|
|
|
|
|
|
|
$page = basename($_SERVER['QUERY_STRING']);
|
|
|
|
$nav = file_get_contents("$template_dir/navigation.html");
|
|
|
|
|
2024-01-20 19:04:39 +01:00
|
|
|
$paths_to_check = array();
|
|
|
|
|
|
|
|
$paths_to_check[] = "pages/global";
|
|
|
|
|
|
|
|
if ($user['isAdmin'] == 1) {
|
|
|
|
$paths_to_check[] = "pages/admin";
|
|
|
|
}
|
|
|
|
|
|
|
|
$paths_to_check[] = "pages/user";
|
|
|
|
|
2024-01-20 18:55:42 +01:00
|
|
|
if(empty($page)){
|
2024-01-20 19:04:39 +01:00
|
|
|
$page = 'index';
|
2024-01-20 18:55:42 +01:00
|
|
|
}
|
|
|
|
|
2024-01-20 19:04:39 +01:00
|
|
|
$page_file = "$template_dir/404.html";
|
2024-01-20 18:55:42 +01:00
|
|
|
|
2024-01-20 19:04:39 +01:00
|
|
|
foreach($paths_to_check as $page_dir){
|
|
|
|
$page_file_tmp = "$page_dir/$page.html";
|
|
|
|
if(file_exists($page_file_tmp)){
|
|
|
|
$page_file = $page_file_tmp;
|
|
|
|
break;
|
|
|
|
}
|
2024-01-20 18:00:30 +01:00
|
|
|
}
|
2024-01-20 18:55:42 +01:00
|
|
|
ob_start();
|
|
|
|
include $page_file;
|
|
|
|
$page_data = ob_get_clean();
|
|
|
|
|
|
|
|
$page_data = str_replace("__NAV_TEMPLATE__", $nav, $page_data);
|
|
|
|
|
|
|
|
echo $page_data;
|
|
|
|
|
|
|
|
|
2024-01-20 16:04:27 +01:00
|
|
|
}
|
|
|
|
?>
|