<%
include("language.html")
if _SESSION["logined"] ~= nil then

local domain = _GET["domain"] or _POST["domain"]
%>
<html>
<head>
<title>Domain Graphs</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<%if _COOKIE["admin_lang"] == "schinese" or _COOKIE["admin_lang"] == "tchinese" or _COOKIE["admin_lang"] == "japanese" then%>
body,td,span {font:12px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%else%>
body,td,span {font:12px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%end%>
img {border:0px;}

.listhead
{
		border-top: 1px solid white; border-right: 1px solid #ACA899; border-left: 1px solid white; border-bottom: 3px solid #CBC7B8;
		font: 12px/22px arial; cursor: hand; text-align: center; background-color: #EBEADB; overflow:hidden; height:22px;
}

.listhead2
{
		border-top: 1px solid white; border-right: 1px solid #ACA899; border-left: 1px solid white; border-bottom: 3px solid #FCC247;
		font: 12px/22px arial; cursor: hand; text-align: center; background-color: #FAF9F4; overflow:hidden; height:22px;
}

.listhead3
{
		border-top: 1px solid white; border-right: 1px solid white; border-left: 1px solid white; border-bottom: 3px solid #CBC7B8;
		font: 12px/22px arial; cursor: hand; text-align: center; background-color: #EBEADB; overflow:hidden; height:22px;
}

.listhead4
{
		border-top: 1px solid white; border-right: 1px solid white; border-left: 1px solid white; border-bottom: 3px solid #FCC247;
		font: 12px/22px arial; cursor: hand; text-align: center; background-color: #FAF9F4; overflow:hidden; height:22px;
}

.listtr01
{
		background-color: #FFFFFF;
		padding: 3px;
}

.listtr02
{
		background-color: #3366CC;
		color: #FFF;
		padding: 3px;
}
</style>


<script language="javascript" src="include/common.js"></script>
<!--[if IE]>
<script type="text/javascript" src="include/excanvas.js"></script>
<![endif]-->
<script type="text/javascript" src="include/dygraph.js"></script>
<script language="javascript">
var g1 = null;
var g2 = null;
var g3 = null;
var data1 = "";
var data2 = "";
var data3 = "";
var time1 = "";
var time2 = "";
var time3 = "";
var domain = "<%=domain%>";

var httpObj = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();
var httpObj2 = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();
var httpObj3 = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();

function getDownloadSpeed()
{
	var expdate = new Date(); 
	expdate.setTime(expdate.getTime() + (86400*1000)); 
	setCookie("chart1_time", $("timetype1").value, expdate); 

	httpObj.open("POST","admin_get_chartdata.html");
	httpObj.onreadystatechange = function(){getchart_result(httpObj); };
	httpObj.send("domain="+domain+"&timetype="+$("timetype1").value+"&datatype=0&r="+Math.random());
}

function getUploadSpeed()
{
	var expdate = new Date(); 
	expdate.setTime(expdate.getTime() + (86400*1000)); 
	setCookie("chart2_time", $("timetype2").value, expdate); 

	httpObj2.open("POST","admin_get_chartdata.html");
	httpObj2.onreadystatechange = function(){getchart_result(httpObj2); };
	httpObj2.send("domain="+domain+"&timetype="+$("timetype2").value+"&datatype=1&r="+Math.random());
}

function getSessionNumber()
{
	var expdate = new Date(); 
	expdate.setTime(expdate.getTime() + (86400*1000)); 
	setCookie("chart3_time", $("timetype3").value, expdate); 

	httpObj3.open("POST","admin_get_chartdata.html");
	httpObj3.onreadystatechange = function(){getchart_result(httpObj3); };
	httpObj3.send("domain="+domain+"&timetype="+$("timetype3").value+"&datatype=2&r="+Math.random());
}

function getchart_result(httpObject)
{
	try
	{
		var arrRoot = httpObject.responseText.split("||");
		var nDataType = arrRoot[0];
		var nTimeType = arrRoot[1];
		var arrNowTime = arrRoot[2].split("-");
		var arrValue = arrRoot[3].split(",");
		var strData = "";
		var d = new Date(parseInt(arrNowTime[0],10),parseInt(arrNowTime[1],10)-1,parseInt(arrNowTime[2],10),
		parseInt(arrNowTime[3],10),parseInt(arrNowTime[4],10),parseInt(arrNowTime[5],10));

		if(nTimeType == 0)
		{
			d.setSeconds(d.getSeconds()-300);
			for(var i=0;i<60;i++)
			{
				d.setSeconds(d.getSeconds() + 5);
				strData += d.getFullYear()+"/"+(d.getMonth()+1)+"/"+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()+","+arrValue[i]+"\n";
			}
		}
		else if(nTimeType == 1)
		{
			d.setHours(d.getHours()-5);
			d.setSeconds(d.getSeconds()-150);
			for(var i=0;i<60;i++)
			{
				d.setSeconds(d.getSeconds() + 300);
				strData += d.getFullYear()+"/"+(d.getMonth()+1)+"/"+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()+","+arrValue[i]+"\n";
			}
		}
		else if(nTimeType == 2)
		{
			d.setDate(d.getDate()-10);
			d.setSeconds(d.getSeconds()-7200);
			for(var i=0;i<60;i++)
			{
				d.setSeconds(d.getSeconds() + 14400);
				strData += d.getFullYear()+"/"+(d.getMonth()+1)+"/"+d.getDate()+" "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds()+","+arrValue[i]+"\n";
			}
		}


		if(nDataType == 0)
		{
			data1 = arrRoot[3];
			time1 = nTimeType;
			g1 = new Dygraph(
			$("graphdiv1"),
			"Date,<%=LANG['str_download_speed']%> (KB/s)\n" + strData,
			{
				colors:['blue'],
				fillGraph:true,
				includeZero:true,
				pixelsPerXLabel:80,
				pixelsPerYLabel:18,
				labelsDiv: $("labels1")
			}
			);
		}
		else if(nDataType == 1)
		{
			data2 = arrRoot[3];
			time2 = nTimeType;
			g2 = new Dygraph(
			$("graphdiv2"),
			"Date,<%=LANG['str_upload_speed']%> (KB/s)\n" + strData,
			{
				colors:['green'],
				fillGraph:true,
				includeZero:true,
				pixelsPerXLabel:80,
				pixelsPerYLabel:18,
				labelsDiv: $("labels2")
			}
			);
		}
		else if(nDataType == 2)
		{
			data3 = arrRoot[3];
			time3 = nTimeType;
			g3 = new Dygraph(
			$("graphdiv3"),
			"Date,<%=LANG['str_online_sessions']%>\n" + strData,
			{
				colors:['red'],
				fillGraph:true,
				includeZero:true,
				pixelsPerXLabel:80,
				pixelsPerYLabel:18,
				labelsDiv: $("labels3")
			}
			);
		}

	}
	catch(e){}
}

</script>
</head>
<body>

<div id="labels1" style="height:20px;">&nbsp;</div>
<div id="graphdiv1" style="width:680px; height:120px;border:solid 1px #CCC; border-left:solid 4px #CCC;"></div>
<div style="width:690px; height:20px;" align="right">
<b><%=LANG["str_download_speed"]%></b> (KB/s)
<select id="timetype1" onchange="getDownloadSpeed();">
<option value="0" selected><%=LANG["str_last_5min"]%></option>
<option value="1"><%=LANG["str_last_5hour"]%></option>
<option value="2"><%=LANG["str_last_10day"]%></option>
</select>
</div>

<div id="labels2" style="height:20px;">&nbsp;</div>
<div id="graphdiv2" style="width:680px; height:120px;border:solid 1px #CCC; border-left:solid 4px #CCC;"></div>
<div style="width:690px; height:20px;" align="right">
<b><%=LANG["str_upload_speed"]%></b> (KB/s)
<select id="timetype2" onchange="getUploadSpeed();">
<option value="0" selected><%=LANG["str_last_5min"]%></option>
<option value="1"><%=LANG["str_last_5hour"]%></option>
<option value="2"><%=LANG["str_last_10day"]%></option>
</select>
</div>

<div id="labels3" style="height:20px;">&nbsp;</div>
<div id="graphdiv3" style="width:680px; height:120px;border:solid 1px #CCC; border-left:solid 4px #CCC;"></div>
<div style="width:690px; height:20px;" align="right">
<b><%=LANG["str_online_sessions"]%></b>
<select id="timetype3" onchange="getSessionNumber();">
<option value="0" selected><%=LANG["str_last_5min"]%></option>
<option value="1"><%=LANG["str_last_5hour"]%></option>
<option value="2"><%=LANG["str_last_10day"]%></option>
</select>
</div>

<script type="text/javascript">
if(getCookie("chart1_time") >= "1")
{
	$("timetype1").value = getCookie("chart1_time");
}
if(getCookie("chart2_time") >= "1")
{
	$("timetype2").value = getCookie("chart2_time");
}
if(getCookie("chart3_time") >= "1")
{
	$("timetype3").value = getCookie("chart3_time");
}

setInterval("getDownloadSpeed()",4800);
getDownloadSpeed();

setInterval("getUploadSpeed()",4800);
setTimeout("getUploadSpeed()",100);

setInterval("getSessionNumber()",4800);
setTimeout("getSessionNumber()",200);

setTimeout("window.location.reload()",1000*60);
</script>

</body>
</html>

<% 
else
	print("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>")
	print("<script>alert('"..LANG["session_expire"].."');top.location='admin_login.html';</script>")
end 
%>

<noscript><center><H2><%=LANG["error_nojavascript"]%></H2></center></noscript>