<?php
require("../../inc/header.inc");
?>
<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('down');" onresize="javascript:adjust_frame('down');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<?php
adjust_head_frame("down");
adjust_title_head_frame("down");
adjust_title_tail_frame("down");

adjust_content_head_frame("down");	
echo "<br>";

	$DEBUG=0;
	
	if(!isset($sel_date))
		$sel_date=0;
	
	if($DEBUG)
		echo "sel_date=$sel_date<br>";
		
	$fieldNameAttr=array("Incoming email attempt",
		                   "Incoming email success",
		                   "Outgoing email attempt",
		                   "Outgoing email success",
		                   "Incoming sms attempt",
		                   "Incoming sms success",
		                   "Outgoing sms attempt",
		                   "Outgoing sms success",
		                   "Total message length",
		                   "Reserved data1",
		                   "Reserved data2");	
		                   
	//get data from database
	$db="CSTA_DB";
	$table_name="smegDetail";
	$temp=date("d",mktime(0,0,0,date("m"),date("d")-$sel_date,date("Y")));
	$table_name=$table_name."_".$temp;
		
	if($DEBUG)echo "table_name:$table_name<br>";	
	
	$from_time=date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-$sel_date,date("Y")));
	$to_time=date("Y-m-d H:i:s",mktime(0,0,0,date("m"),date("d")-$sel_date+1,date("Y")));
	if($DEBUG)echo "from:$from_time--to:$to_time<br>";
		
	$select="select key_sys_id,sum(in_email_att) as in_email_att,sum(in_email_suc) as in_email_suc,sum(out_email_att) as out_email_att,sum(out_email_suc) as out_email_suc,sum(in_sms_att) as in_sms_att,sum(in_sms_suc) as in_sms_suc,sum(out_sms_att) as out_sms_att,sum(out_sms_suc) as out_sms_suc ";
	$from="from $table_name ";
	$where="where csta_datetime >='$from_time' and csta_datetime <'$to_time' ";
	$group="group by key_sys_id ";
	$sql=$select.$from.$where.$group;
	if($DEBUG)echo "$sql<br>";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
		
		
	//init
	$in_email_att_sum=0;
	$in_email_suc_sum=0;
	$out_email_att_sum=0;
	$out_email_suc_sum=0;
	$in_sms_att_sum=0;
	$in_sms_suc_sum=0;
	$out_sms_att_sum=0;
	$out_sms_suca_sum=0;	
					
	if($rows)
	{
		

		do{
				$key_sys_id=$rows[key_sys_id];
				$in_email_att_sum=$rows[in_email_att];
				$in_email_suc_sum=$rows[in_email_suc];
				$out_email_att_sum=$rows[out_email_att];
				$out_email_suc_sum=$rows[out_email_suc];
				$in_sms_att_sum=$rows[in_sms_att];
				$in_sms_suc_sum=$rows[in_sms_suc];
				$out_sms_att_sum=$rows[out_sms_att];
				$out_sms_suca_sum=$rows[out_sms_suc];	
		}while($rows=mysqli_fetch_array($result));	
	}
	
		
	//table title
	echo "<center><b>";
	$sel_date_title=date("Y-m-d",mktime(0,0,0,date("m"),date("d")-$sel_date,date("Y")));
	echo "$strSMSEG Statistic Date: $sel_date_title<br>";
	echo "</b></center>";	
	
	//show the data
	echo "<table border=\"1\" width=\"100%\" bordercolordark=\"#FFFFFF\" bordercolor=\"#808080\" cellspacing=\"0\">";
	echo "<tr>";
		echo "<td bgcolor=\"#E6E6E6\" width=15%><br></td>";
		echo "<td bgcolor=\"#E6E6E6\" width=15%>Type</td>";
		echo "<td bgcolor=\"#E6E6E6\" width=70%>Value</td>";
	echo "</tr>";	
	
	echo "<tr>";
	echo "<td bgcolor=\"#E6E6E6\" rowspan=2>Incoming email</td>";
		echo "<td bgcolor=\"#E6E6E6\">Attempt</td>";
		//Incoming email attempt
		echo "<td>$in_email_att_sum</td></tr>";
		echo "<tr><td bgcolor=\"#E6E6E6\">Success</td>";
		//Incoming email success
		echo "<td>$in_email_suc_sum</td></tr>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td bgcolor=\"#E6E6E6\" rowspan=2>Outgoing email</td>";
		echo "<td bgcolor=\"#E6E6E6\">Attempt</td>";
		//Outgoing email attempt
		echo "<td>$out_email_att_sum</td></tr>";
		echo "<tr><td bgcolor=\"#E6E6E6\">Success</td>";
		//Outgoing email success
		echo "<td>$out_email_suc_sum</td></tr>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td bgcolor=\"#E6E6E6\" rowspan=2>Incoming sms</td>";
		echo "<td bgcolor=\"#E6E6E6\">Attempt</td>";
		//Incoming sms attempt
		echo "<td>$in_sms_att_sum</td></tr>";
		echo "<tr><td bgcolor=\"#E6E6E6\">Success</td>";
		//Incoming sms success
		echo "<td>$in_sms_suc_sum</td></tr>";
	echo "</tr>";
	
	echo "<tr>";
	echo "<td bgcolor=\"#E6E6E6\" rowspan=2>Outgoing sms</td>";
		echo "<td bgcolor=\"#E6E6E6\">Attempt</td>";
		//Outgoing sms attempt
		echo "<td>$out_sms_att_sum</td></tr>";
		echo "<tr><td bgcolor=\"#E6E6E6\">Success</td>";
		//Outgoing sms success
		echo "<td>$out_sms_suca_sum</td></tr>";
		
	echo "<tr><td colspan=2 bgcolor=\"#E6E6E6\">Total message length</td>";
	//Total message length
	echo "<td>0</td></tr>";
	echo "</tr>";
	
	echo "</table>";
	
adjust_content_tail("down");
?>