diff --git a/assets/script.js b/assets/script.js index 92a2871..a48353d 100644 --- a/assets/script.js +++ b/assets/script.js @@ -20,6 +20,39 @@ function doAccountAction(requestData, successMessage, failureMessage, silent=fal }); } + + +function handlePageResponse(data){ + if(data.Navigation){ + document.getElementById("navbar").innerHTML = data.Navigation; + } + if(data.Page){ + document.getElementById("pagearea").innerHTML = data.Page; + if(data.PageLocation){ + history.pushState({}, "", data.PageLocation); + } + } +} + +function doPageAction(requestData){ + return fetch('/page', { + method: 'POST', + body: requestData, + }) + .then(response => { + if (!response.ok) { + throw new Error(`HTTP error! Status: ${response.status}`); + } + return response.json(); + }) + .then(data => { + handlePageResponse(data); + }) + .catch((error) => { + console.error('Error:', error); + }); +} + function displayList(data, element_id, delete_function=null) { const tableContainer = document.getElementById(element_id); tableContainer.innerHTML = ""; // Clear previous content @@ -86,13 +119,49 @@ function handleResponse(data, SuccessMessage, failureMessage) { }, 3000); } +function navigateTo(site, page){ + const data = new URLSearchParams(); + data.append("action", "getPage"); + data.append("site", site); + data.append("page", page); + doPageAction(data); +} + +function refreshNavbar(){ + const data = new URLSearchParams(); + data.append("action", "getNavigation"); + doPageAction(data); +} + function logout() { const data = new URLSearchParams(); data.append("action", "logout"); doAccountAction(data, "Logout Successful!", "Logout failed.").then(() => { - location.reload(); + refreshNavbar(); + navigateTo("", pageData.defaultPage); // Expected output: "Success!" }); } +function initAjax() { + let links = document.querySelectorAll('.navsite_item, .navpage_item'); + +// Add click event listener to each link + links.forEach(function (link) { + link.addEventListener('click', function (e) { + e.preventDefault(); + + // Get page and site information + let site = this.dataset.site; + let page = this.dataset.page; + + if (site && page) { + navigateTo(site, page); + } + + // You can use this information to update the URL or perform other actions + }); + }); +} +document.addEventListener('DOMContentLoaded', initAjax); diff --git a/assets/style.css b/assets/style.css index 7f638f3..949feda 100644 --- a/assets/style.css +++ b/assets/style.css @@ -1,4 +1,5 @@ @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800&display=swap'); +@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap'); :root { --primary-bg: rgb(27, 21, 41); @@ -239,4 +240,18 @@ table.list-table > tbody, table.list-table > tbody > th, table.list-table > tbod text-align: center; } -/* */ \ No newline at end of file +/* */ + +#loginForm input { + border-radius: 50px; + background: none; + border: 2px solid var(--primary); + width: 175px; +} + +#register_Form input { + border-radius: 50px; + background: none; + border: 2px solid var(--primary); + width: 175px; +} \ No newline at end of file diff --git a/endpoints/global/page.php b/endpoints/global/page.php new file mode 100644 index 0000000..f59be43 --- /dev/null +++ b/endpoints/global/page.php @@ -0,0 +1,13 @@ + getNavigationEndpoint(), + "getPage" => getPageEndpoint($endpoint_data["page"], $endpoint_data["site"]), + default => ["Status" => "Fail", "message" => "Invalid action"], + }; +} \ No newline at end of file diff --git a/index.php b/index.php index da8f996..bed7315 100644 --- a/index.php +++ b/index.php @@ -16,7 +16,7 @@ $canRender = initRouter(); if ($canRender) { /** @noinspection PhpArrayIsAlwaysEmptyInspection */ /** @noinspection PhpArrayIsAlwaysEmptyInspection */ - session_set_cookie_params(0, '/', "." . $routerRequest["domain"] . "." . $routerRequest["tld"], true, true); +; session_set_cookie_params(0, '/', "." . $routerRequest["domain"] . "." . $routerRequest["tld"], true, true); session_start(); if (!isLoggedIn()) { diff --git a/lib/account.php b/lib/account.php index 91ce90e..15d7a7c 100644 --- a/lib/account.php +++ b/lib/account.php @@ -174,7 +174,7 @@ function doRegister($firstname, $lastname, $email, $password, $activation_token) $privilege_level = $routerConfig["logged_in_default_permission_level"]; /** @noinspection SpellCheckingInspection */ - $stmt->bind_param("ssssiss", $firstname, $lastname, $email, $passwordHash, $privilege_level, $activation_token, $activation_token); + $stmt->bind_param("ssssis", $firstname, $lastname, $email, $passwordHash, $privilege_level, $activation_token); $stmt->execute(); diff --git a/lib/dynamic_style.php b/lib/dynamic_style.php new file mode 100644 index 0000000..5fcd604 --- /dev/null +++ b/lib/dynamic_style.php @@ -0,0 +1,14 @@ +"; + $color = dechex($_SESSION["favorite_color"]); + $dynamic_style .= "--root{ --favorite-color: #$color;"; + $dynamic_style .= ""; + } + return $dynamic_style; + +} \ No newline at end of file diff --git a/lib/navigation.php b/lib/navigation.php index d6f9f20..4f1609d 100644 --- a/lib/navigation.php +++ b/lib/navigation.php @@ -83,15 +83,21 @@ function generateNavigation(): string } if($page_required_permission <= $_SESSION["privilege_level"]) { - $navpages .= "