Adds platforms switcher in menu

main
Yasen Pramatarov 2024-09-24 09:39:30 +03:00
parent ff2a96119e
commit 6cc1efff15
2 changed files with 32 additions and 2 deletions

View File

@ -17,4 +17,32 @@ function getUTCOffset($timezone) {
}
// switch platforms
function switchPlatform($platform_id) {
// get the current URL and parse it
$scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$current_url = "$scheme://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url_components = parse_url($current_url);
// parse query parameters if they exist
parse_str($url_components['query'] ?? '', $query_params);
// check if the 'platform' parameter is set
if (isset($query_params['platform'])) {
// change the platform to the new platform_id
$query_params['platform'] = $platform_id;
// rebuild the query and the URL
$new_query_string = http_build_query($query_params);
$new_url = $scheme . '://' . $url_components['host'] . $url_components['path'] . '?' . $new_query_string;
// return the new URL with the new platform_id
return $new_url;
// there is no 'platform', we redirect to front page of the new platform_id
} else {
return $current_url;
}
}
?>

View File

@ -12,9 +12,11 @@
<?php if ( isset($_SESSION['username']) ) { ?>
<?php foreach ($platformsAll as $platform) { ?>
<?php foreach ($platformsAll as $platform) {
$platform_switch_url = switchPlatform($platform['id'])
?>
<li style="margin-right: 3px;">
<a style="background-color: #111;" href="?platform=<?= htmlspecialchars($platform['id']) ?>&page=dashboard">
<a style="background-color: #111;" href="<?= htmlspecialchars($platform_switch_url) ?>">
<?= htmlspecialchars($platform['name']) ?>
</a>
</li>