<?php
// Language codes:
// en-US : English American
// en-GB : English British
// de    : German
// fr    : French
// it    : Italian
// sk    : Slovak
// pl    : Polish

function detectLanguage() {
  $acceptLanguage = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  $languages = explode(',', $acceptLanguage);
  $firstLanguage = $languages[0];
  return trim($firstLanguage);
}

$browserLanguage = detectLanguage();

$isAdmin = (\S::get_session('user')['admin'] == 1) ? true : false;
// echo $browserLanguage;
if($browserLanguage !== 'pl' && $browserLanguage !== 'pl-PL'){
  if(!$isAdmin){
    switch ($browserLanguage) {
      // case 'en-US':
      //   header('Location: https://eng.vidok.com/'); exit;
      //   break;
      // case 'en-GB':
      //   header('Location: https://gb.vidok.com/'); exit;
      //   break;
      case 'de':
        header('Location: https://de.vidok.com/'); exit;
        break;
      case 'de-DE':
        header('Location: https://de.vidok.com/'); exit;
        break;
      case 'fr':
        header('Location: https://fr.vidok.com/'); exit;
        break;
      case 'fr-FR':
        header('Location: https://fr.vidok.com/'); exit;
        break;
      case 'it':
        header('Location: https://it.vidok.com/'); exit;
        break;
      case 'it-IT':
        header('Location: https://it.vidok.com/'); exit;
        break;
      case 'sk':
        header('Location: https://sk.vidok.com/'); exit;
        break;
      case 'sk-SK':
        header('Location: https://sk.vidok.com/'); exit;
        break;
      case 'pl':
        header('Location: https://vidok.com/'); exit;
        break;
      case 'pl-PL':
        header('Location: https://vidok.com/'); exit;
        break;
      default:
        break;
    };
  };
};
?>