<?php
class State_Statistic {
	function display($args) {

		require_once "./includes/isgwtelnet.php";
		include('./includes/header.php');
		
		$isgw = new isgwtelnet();	
		$result=$isgw->isgw_login();
		if ($result==false) {
			$ret.="<font size='3' color='red'>".STATE_ISWG_ERROR_DIS."</font>"; 
			return $ret;
		}
		$channelresult=$isgw->isgw_portstatistic();
		
		//LISTING CALL OPERATIONS
		$rows="";
		$rows=explode("\n",$channelresult);
		
		
		
		$ret.= "<br><br>";
		$ret.= "<table class='contenttoc' id='table'>";
		$ret.= "<th colspan=6>".PORTS_STAT_TABLE_HEADER_DIS."</th>";	
		$ret.= "<tr><td><b>".PORTS_STAT_PORT_DIS."</b></td>";
		$ret.= "<td><b>".PORTS_STAT_DIRECTION_DIS."</b></td><td><b>".PORTS_STAT_CALLS_DIS."</b></td>
				<td><b>".PORTS_STAT_CONNECTED_DIS."</b></td><td><b>".PORTS_STAT_CONNECTED_TIME_DIS."</b></td>
				<td><b>".PORTS_STAT_LESS_10_SEC_DIS."</b></td></tr>";

		
		$i=0;
		foreach ($rows as $value){
			//echo $value ."<br>";			
				if (strstr($value,"SESSION STATISTICS")){
					continue;
				}
				if (strstr($value, "-----")) {
					continue;
				}
				if (strstr($value, "CALLS TOTAL")) {
					continue;
				}
			
				//get PORT and Type
				$tmp=explode("=>", $value);
				$tmp2=explode(":", $tmp[0]);
				$port=substr($tmp2[0], 6, 1);
				$tmp3=explode(" ", $tmp2[1]);
			 	$type=$tmp3[2];
			 	
			 	if (!$port) {
			 		continue;
			 	}
			 	
			 	$arr[$i]["port"]=$port;
			 	$arr[$i]["type"]=$type;
			 	
			   	 //get totall calls
			   	$tmp2=explode("(", $tmp[1]);
			 	$arr[$i]["$type"]["calls"]=$tmp2[0];
				$tmp3=explode(" ", $tmp2[1]);
			 	$arr[$i]["$type"]["connected"]=$tmp3[0];
				
				//ctime
			 	$tmp2=explode(" ", $tmp[2]);
			 	$tmp3=explode(")", $tmp2[4]);
			 	$arr[$i]["$type"]["ctime"]=$tmp3[0];
			 
				//less t 10
				$tmp2=explode("(", $tmp[3]);	
				$tmp3=explode(" ", $tmp2[1]);
			 	$arr[$i]["$type"]["lt10"]=$tmp3[0];
				$i++;
			}


                        $i=0;				
                        if ($arr) {
                            foreach ($arr as $value) {
                                $ret.="<tr>";
                                $ret.="<td>".$value["port"]."</td>";
                                $ret.="<td>".$value["type"]."</td>";
                                $ret.="<td>".$value[$value["type"]]["calls"]."</td>";
                                $ret.="<td>".$value[$value["type"]]["connected"]."</td>";
                                $ret.="<td>".$value[$value["type"]]["ctime"]."</td>";
                                $ret.="<td>".$value[$value["type"]]["lt10"]."</td>";
                                $ret.="</tr>";			
                                $i++;
                            }	
                        }
		$ret.="</table>";	
		return $ret;

	}
}

?>
