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

$availableLanguages = array("gcc", "de", "dk", "es", "fl", "fr", "it", "nl", "no", "pt", "ru", "se");
$availableCountries = array("KW", "OM", "BH", "AE", "SA", "QA", "DE", "DK", "ES", "FL", "FR", "IT", "NL", "NO", "PT", "RU", "SE");
$arabicCountries = array("KW", "OM", "BH", "AE", "SA", "QA");

if ($country && !$language) {
	if (in_array($country, $availableCountries)) {
		if (in_array($country, $arabicCountries)) {
			$country = "GCC";
		}
		header('Location:' . strtolower($country) . '/index.php?' . $_SERVER['QUERY_STRING']);
	} else if (!empty($_SERVER['QUERY_STRING'])) {
		header('Location: lp.php?' . $_SERVER['QUERY_STRING']);
	} else {
		header('Location: lp.php');
	}
} else if ($language) {
	if (in_array($language, $availableLanguages)) {
		header('Location:' . $language . '/index.php?' . $_SERVER['QUERY_STRING']);
	} else if (!empty($_SERVER['QUERY_STRING'])) {
		header('Location: lp.php?' . $_SERVER['QUERY_STRING']);
	} else {
		header('Location: lp.php');
	}
} else if (!empty($_SERVER['QUERY_STRING'])) {
	header('Location: lp.php?' . $_SERVER['QUERY_STRING']);
} else {
	header('Location: lp.php');
}