From a1f5af75bd4393395dba4346abaa194676e76494 Mon Sep 17 00:00:00 2001 From: AkisYTB3 Date: Sat, 20 Jan 2024 18:55:42 +0100 Subject: [PATCH] =?UTF-8?q?co=20j=C3=A1=20v=C3=ADm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bruno Rybársky --- config.php | 2 ++ index.php | 30 +++++++++++++++++++++++++----- pages/index_admin.html | 10 ++++++++++ pages/register.html | 8 +++++++- templates/navigation.html | 0 5 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 templates/navigation.html diff --git a/config.php b/config.php index 0b410c0..e2e6cf7 100644 --- a/config.php +++ b/config.php @@ -1,3 +1,5 @@ diff --git a/index.php b/index.php index ef003bf..4c171fb 100644 --- a/index.php +++ b/index.php @@ -12,11 +12,31 @@ if (!isset($_SESSION['user_id'])) { $result = mysqli_query($mysqli, $query); $user = mysqli_fetch_assoc($result); - // Include the appropriate HTML based on user's status - if ($user['isAdmin'] == 1) { - include 'pages/index_admin.html'; // Custom HTML for Admin - } else { - include 'pages/index_user.html'; // Custom HTML for regular user + + $page = basename($_SERVER['QUERY_STRING']); + $nav = file_get_contents("$template_dir/navigation.html"); + + if(empty($page)){ + if ($user['isAdmin'] == 1) { + $page = 'index_admin'; // Custom HTML for Admin + } else { + $page = 'index_user'; // Custom HTML for regular user + } } + + $page_file = "$page_dir/$page.html"; + + if (!file_exists($page_file)) { + $page_file = "$template_dir/404.html"; + } + ob_start(); + include $page_file; + $page_data = ob_get_clean(); + + $page_data = str_replace("__NAV_TEMPLATE__", $nav, $page_data); + + echo $page_data; + + } ?> diff --git a/pages/index_admin.html b/pages/index_admin.html index 2fc4d68..3fefa35 100644 --- a/pages/index_admin.html +++ b/pages/index_admin.html @@ -7,6 +7,16 @@ +

Welcome

+ Register + +

Register

@@ -17,4 +22,5 @@ Already have an account?
- + + \ No newline at end of file diff --git a/templates/navigation.html b/templates/navigation.html new file mode 100644 index 0000000..e69de29