<?php
$language = !empty($_GET["intgrtn_language"]) ? $_GET["intgrtn_language"] : null;
$country = !empty($_GET["country"]) ? $_GET["country"] : null;

$availableLanguages = array("en", "pl", "es");
$availableCountries = array("EN", "PL", "ES");
if ($country && !$language) {
	if (in_array($country, $availableCountries)) {
		header('Location: ' . strtolower($country) . '/index.php?' . $_SERVER['QUERY_STRING']);
	} else if (!empty($_SERVER['QUERY_STRING'])) {
		header('Location: en/index.php?' . $_SERVER['QUERY_STRING']);
	} else {
		header('Location: en/index.php');
	}
} else if ($language) {
	if (in_array($_GET["intgrtn_language"], $availableLanguages)) {
		header('Location: ' . $language . '/index.php?' . $_SERVER['QUERY_STRING']);
	} else if (!empty($_SERVER['QUERY_STRING'])) {
		header('Location: en/index.php?' . $_SERVER['QUERY_STRING']);
	} else {
		header('Location: en/index.php');
	}
} else if (!empty($_SERVER['QUERY_STRING'])) {
	header('Location: en/index.php?' . $_SERVER['QUERY_STRING']);
} else {
	header('Location: en/index.php');
}
