#!/bin/sh
#This script is created by ssparser automatically. The parser first created by MaoShouyan
printf "Content-type: text/html;charset=gb2312
Cache-Control: no-cache

"
echo -n ""; 
CGI_browsertitle="·-${CGI_name}"
. ../common/common.sh

echo -n "
<script type=\"text/javascript\" src=\"/img/jq.js\"></script>
<script type=\"text/javascript\" src=\"/img/common.js\"></script>
<script type=\"text/javascript\" src=\"/img/highcharts.js\"></script>
<script language=\"javascript\">
function numberformat(num)
{
        if (num >= 1000 * 1000 * 1000)
                return ((num / (1000 * 1000 * 1000))).toFixed(2) + 'Gbps';
        else
        if (num >= 1000 * 1000)
                return ((num / (1000 * 1000))).toFixed(2) + 'Mbps';
        else
        if (num >= 1000)
                return ((num / 1000)).toFixed(2) + 'Kbps';
        else
                return num + 'bps';
}
Highcharts.setOptions({ global: { useUTC: false } });
function creategraph(render, datatype, titletext) {
	var options = ({
		chart: {
			type: 'spline',
			renderTo:render
		},
		title: {
			
                        style: {
                        	font: 'bold 12px Arial'
			},
			enabled: false,
			text:titletext,
			x: -20
		},
		xAxis: {
			type: 'datetime',
			tickPixelInterval: 50,
 			labels: {
                                style: {
                                        font: 'normal 9px Arial',
                                        fontSize:'10px'
                                }
                        }
		},
		yAxis: {
			min: 0,
			tickPixelInterval:30,
			title: {
				text: \"bps\"
			},
 			labels: {
                                style: {
                                        font: 'normal 9px Arial'
                                }
                        },
			plotLines: [{
				value: 0,
				width: 1,
				color: \"#808080\"
			}]
		},
		plotOptions:{
				area:{stacking:false,lineWidth:1,marker:{enabled:false}},
				spline:{
					marker:{
						radius:0,
						lineWidth:1
					},
					lineWidth:1
				}
		},
		tooltip: {
			formatter:function(){
					var dd = new Date(this.x);
					var str = \"ʱ䣺\"+dd.getDate()+'/'+dd.getHours()+':'+dd.getMinutes();
					return str+'<br>'+this.series.name+' '+ numberformat(this.y);
				}
		},
		legend: {
			enabled:false,
			layout: \"vertical\",
			align: \"right\",
			verticalAlign: \"middle\",
			borderWidth: 0
		},
		credits:{enabled: false},
		series: [{name:titletext, color:'#9CC6F0', data: []}]
	});
	
	$.ajax({
		url: 'ajax_ifpxy_rtgraph?datatype='+datatype+'&name=${CGI_name}',
		type:'post',
		dataType:'json',
		success:function(json){
			
			if (datatype == \"in\")
				options.series[0].data = json.inbps;
			else 
				options.series[0].data = json.outbps;
			var chart = new Highcharts.Chart(options);
		}
	});
}
creategraph('mygraph_in', 'in', '${CGI_name}');
creategraph('mygraph_out', 'out', '${CGI_name}');
setInterval(function() {
creategraph('mygraph_in', 'in', '${CGI_name}');
creategraph('mygraph_out', 'out', '${CGI_name}');
}, 10000);
</script>
<body>
";
if [ "${CGI_type}" = "proxy" -o "${CGI_type}" = "pppoe" ]; then
	MOD_TAB_LIST="#/cgi-bin/Monitor/ifpxy_rtgraph?type=${CGI_type}&name=${CGI_name} TopӦ#/cgi-bin/Monitor/proxy_apprate?link=${CGI_name}"
	cgi_print_mod_header  ""  700
fi

echo -n "
<br>
<div id=\"mygraph_in\" style=\"width:700px;height:310px;\"></div>
<div id=\"mygraph_out\" style=\"width:700px;height:310px;\"></div>
</body>
</html>
";