<?php
require_once('php/core.php');
////================================================================
//// API
////================================================================
//if ($_SERVER['HTTP_HOST'] == 'api.stojatek.com') {
//	require_once('php/api/api.php');
//	return 0;
//}
//================================================================
// Data
//================================================================
if (isset($_GET['mime'])) {
	switch($_GET['mime']) {
	case 'css': { fetchCSS(dirname(__FILE__).'/css/'.htmlentities($_GET['css'])); } break;
	case 'js': { fetchJS(dirname(__FILE__).'/js/'.htmlentities($_GET['js'])); } break;
	case 'img': { fetchImage(dirname(__FILE__).'/data/img/'.htmlentities($_GET['img']), htmlentities($_GET['ext'])); } break;
	case 'font': { fetchFont(dirname(__FILE__).'/data/font/'.htmlentities($_GET['font']), htmlentities($_GET['ext'])); } break;
	//case 'audio': { fetchAudio(dirname(__FILE__).'/data/audio/'.htmlentities($_GET['audio']), htmlentities($_GET['ext'])); } break;
	case 'video': { fetchVideo(dirname(__FILE__).'/data/video/'.htmlentities($_GET['video']), htmlentities($_GET['ext'])); } break;
	case 'glsl': { fetchGLSL(dirname(__FILE__).'/data/glsl/'.htmlentities($_GET['glsl']), htmlentities($_GET['ext'])); } break;
	case 'zip': { fetchZIP(dirname(__FILE__).'/data/zip/'.htmlentities($_GET['zip'])); } break;
	case 'json': { fetchJSON(dirname(__FILE__).'/data/json/'.htmlentities($_GET['json'])); } break;
	default: fileNotFound();
	}
	return;
}
//================================================================
// Pages
//================================================================
require_once('php/site.php');
// Setup default header meta tags
SiteHeader::addTag('<meta charset="UTF-8" />');
SiteHeader::addTag('<meta name="viewport" content="width=device-width, initial-scale=1">');
SiteHeader::addTag('<meta name="theme-color" content="#205597" media="(prefers-color-scheme: light)" />');
SiteHeader::addTag('<meta name="theme-color" content="#205597" media="(prefers-color-scheme: dark)" />');
SiteHeader::addTag('<meta name="background_color" content="#205597" media="(prefers-color-scheme: light)" />');
SiteHeader::addTag('<meta name="background_color" content="#205597" media="(prefers-color-scheme: dark)" />');
SiteHeader::addTag('<meta name="description" content="STOJATEK Website" />');
SiteHeader::addTag('<meta name="keywords" content="STOJATEK" />');
SiteHeader::addTag('<link rel="apple-touch-icon" href="stojatek-thumb-512.png" />');
SiteHeader::addTag('<link rel="apple-touch-icon-precomposed" href="stojatek-thumb-512.png" />');
SiteHeader::addTag('<link rel="apple-touch-startup-image" href="stojatek-thumb-512.png" media="orientation: portrait" />');
SiteHeader::addTag('<link rel="apple-touch-startup-image" href="stojatek-thumb-512.png" media="orientation: landscape" />');
SiteHeader::addTag('<link rel="icon" href="favicon.png" />');
SiteHeader::addTag('<link rel="manifest" href="site.webmanifest" crossorigin="anonymous" />');
SiteHeader::addCSS($GLOBALS['mobile'] ? 'site-mobile.css' : 'site-desktop.css');
// Set the default page title
SiteHeader::setTitle('STOJATEK - '.($GLOBALS['mobile'] ? 'mobile' : 'desktop'));
SiteHeader::addClass('dark-theme');
//================================================================
// Pages
//================================================================
if (isset($_GET['url'])) {
	$url = explode('/', filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL));
}
$page = $url[0] ?? null;
if (isset($page)) {
	$page = strtolower($page);
}
// Switch between supported pages
//TODO: Remove IP when ready to publish
if ($_SERVER['REMOTE_ADDR'] === '107.192.130.48') {
	SiteHeader::addJS('core.min.js');
	SiteHeader::addJS('socket.min.js');
	SiteHeader::addJS('api.min.js');
	SiteHeader::addJS('ui.min.js');

	$_SESSION['testing'] = true;
	switch ($page) {
	case 'admin': { include_once('php/pages/admin/admin.php'); } break;
	case 'company': { include_once('php/pages/company.php'); } break;
	case 'home': { include_once('php/pages/home.php'); } break;
	case 'kb': { include_once('php/pages/kb/kb.php'); } break;
	case 'products': { include_once('php/pages/products/products.php'); } break;
	case 'resources': { include_once('php/pages/resources/resources.php'); } break;
	case 'search': { include_once('php/pages/search.php'); } break;
	case 'support': { include_once('php/pages/support/support.php'); } break;
	case 'user': { include_once('php/pages/user/user.php'); } break;
	case 'contractor': { include_once('php/pages/contractor.php'); } break;
	case 'phpinfo': { phpinfo(); die(); }
	default: { include_once('php/pages/construction.php'); } break;
	}
} else {
	switch ($page) {
//	case 'User': { include_once('php/pages/user/user.php'); } break;
	case 'contractor': { include_once('php/pages/contractor.php'); } break;
	default: { include_once('php/pages/construction.php'); } break;
	}
}
