<?php
$HTTP_HOST = $_SERVER["HTTP_HOST"];
list( $topdom,$domain,$subdom,$ssubdom,$sssubdom ) = array_reverse(explode(".", $HTTP_HOST));
#
#### Get User Agent (browser) ###########
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$agent = '';
if(preg_match('/MSIE/i',$u_agent)) { $agent = "ie"; }
elseif(preg_match('/Firefox/i',$u_agent)) { $agent = "firefox"; }
elseif(preg_match('/Safari/i',$u_agent)) { $agent = "safari"; }
elseif(preg_match('/Chrome/i',$u_agent)) { $agent = "chrome"; }
elseif(preg_match('/Flock/i',$u_agent)) { $agent = "flock"; }
elseif(preg_match('/Opera/i',$u_agent)) { $agent = "opera"; }
elseif(preg_match('/Lynx/i',$u_agent)) { $agent = "lynx"; }
else { $agent = "other"; }
#
if (($agent != "other") || ($agent == "") || !isset($agent))  { header ("Location: http://$HTTP_HOST/"); exit; }
if ($subdom != "sitemap") {
	header('Content-type: text/xml');
} else {
	if ($_SERVER['REQUEST_URI'] == "/sitemap.xml") {
		header ("Location: http://$HTTP_HOST/");
		exit;
	}
}
$domainarray = array("www","intro","energy","management","control","services","contact","projects","tools","bacnet","psychrometry","reliable","clients","jobs","work","solutions","synergy","systems","commissioning","monitoring","conservation","hvac","hamiltonsmith");
if ($subdom == "sitemap") {
	print "<TABLE STYLE='width: 100%;' border=0 cellspacing=0 cellpadding=0>";
	while (list($num, $sub) = each($domainarray)) {
		++$num;
		$sub = trim($sub);
		print "\t<TR>\n";
		print "\t<TD STYLE='border-bottom: 1px solid #ffffff; height: 32px; vertical-align: bottom;'><A STYLE='text-decoration: none;' HREF='http://$sub.$domain.$topdom'>http://$sub.$domain.$topdom</A></TD>\n";
		print "\t<TD STYLE='border-bottom: 1px solid #ffffff; height: 32px; vertical-align: bottom;' align='right'>".date('c')."</TD>\n";
		print "\t</TR>\n";
	}
	print "</TABLE>";
} else {
	print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
	print "<?xml-stylesheet type=\"text/css\" href=\"xml.css\"?>\n";
	print "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd\">\n";
	while (list($num, $sub) = each($domainarray)) {
		++$num;
		$sub = trim($sub);
		print "\t<url>\n";
		print "\t<loc>http://$HTTP_HOST/?url=$sub.$domain.$topdom</loc>\n";
		print "\t<lastmod>".date('c')."</lastmod>\n";
		print "\t<changefreq>weekly</changefreq>\n";
		print "\t<priority>0.8</priority>\n";
		print "\t</url>\n";
	}

	$filename = "cgi-bin/domainlist.txt";
	$filestring = file_get_contents($filename);
	$filearray = explode("\n", $filestring);
	while (list($var, $val) = each($filearray)) {
		++$var;
		$val = trim($val);
		print "\t<url>\n";
		print "\t<loc>http://$HTTP_HOST/?url=$subdom.$val</loc>\n";
		print "\t<lastmod>".date('c')."</lastmod>\n";
		print "\t<changefreq>weekly</changefreq>\n";
		print "\t<priority>0.8</priority>\n";
		print "\t</url>\n";
	}
	print "</urlset>";
}
?>

