<?php
require("../../inc/lib.inc");
require("./function.inc");

$global_id=0;
function AssignID($sysTypeNo,$sysNo)
{
	global $global_id;
	
	$id="{$sysTypeNo}_{$sysNo}_{$global_id}";
	$global_id++;
	return $id;
}
?>

<?php
$config=parse_ini_file("config.ini",true);
$config_count=sizeof($config);

$config_index=-1;
for($index=0;$index<$config_count;$index++)
{
	if($config[$index][SysTypeNo] == $sysTypeNo)
	{
		$config_index=$index;
		break;
	}
}

if($config_index == -1)
{
	exit();
}

$plat=GetPlatInfo($config[$config_index],$sysNo);
$module=GetSingleModuleInfo($sysTypeNo,$sysNo);

$total_response="";

//Application Status
$id=AssignID($sysTypeNo,$sysNo);
$message="{$id},{$module[AppStatus][Display]},{$module[AppStatus][Value]},{$module[AppStatus][Color]};";
$total_response.=$message;

//Refresh Time
$id=AssignID($sysTypeNo,$sysNo);
$message="{$id},{$module[RefreshTime][Display]},{$module[RefreshTime][Value]},{$module[RefreshTime][Color]};";
$total_response.=$message;

//Start Time
$id=AssignID($sysTypeNo,$sysNo);
$message="{$id},{$plat[StartTime][Display]},{$plat[StartTime][Value]},{$plat[StartTime][Color]};";
$total_response.=$message;


switch($sysTypeNo)
{
case 0:
	//Dual Server Status
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[DualServerStatus][Value]},{$module[DualServerStatus][Color]};";
	$total_response.=$message;
	
	//IOSyncInfo
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[IOSyncInfo][Value]},{$module[IOSyncInfo][Color]};";
	$total_response.=$message;
	
	//Last Master Log File Num
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SQLSyncInfo][Value]},{$module[SQLSyncInfo][Color]};";
	$total_response.=$message;
	
	
	//Process Status
	for($i=0;$i<$module[TotalProcessNum];$i++)
	{
		if($i < $module[CurrentProcessNum])
		{
			$id=AssignID($sysTypeNo,$sysNo);
			$message="{$id},layerShow,no,no;";
			$total_response.=$message;
			
			$id=AssignID($sysTypeNo,$sysNo);
			$message="{$id},block,{$module[Process][$i][Value]},{$module[Process][$i][Color]};";
			$total_response.=$message;
		}
		else
		{
			$id=AssignID($sysTypeNo,$sysNo);
			$message="{$id},layerHide,no,no;";
			$total_response.=$message;
			
			$id=AssignID($sysTypeNo,$sysNo);
			$message="{$id},block,{$module[Process][$i][Value]},{$module[Process][$i][Color]};";
			//$total_response.=$message;
		}
	}
	
	break;
case 320:
	//Dual Server Status
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[DualServerStatus][Value]},{$module[DualServerStatus][Color]};";
	$total_response.=$message;
	
	//E1 License
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[E1License][Value]},{$module[E1License][Color]};";
	$total_response.=$message;
	
	//E1 Used
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[E1Used][Value]},{$module[E1Used][Color]};";
	$total_response.=$message;
	
	//Serial Number
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SerialNumber][Value]},{$module[SerialNumber][Color]};";
	$total_response.=$message;
	
	//VLR Refresh Time
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[VLR][RefreshTime][Value]},{$module[VLR][RefreshTime][Color]};";
	$total_response.=$message;
	
	//VLR AppStatus
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[VLR][AppStatus][Value]},{$module[VLR][AppStatus][Color]};";
	$total_response.=$message;
	
	//VLR Subscriber Number
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[VLR][SubscriberNumber][Value]},{$module[SubscriberNumber][Status][Color]};";
	$total_response.=$message;
	
	//VLR License
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[VLR][License][Value]},{$module[VLR][License][Status][Color]};";
	$total_response.=$message;
	
	break;
//HLR
case 330:
//AUC
case 340:
//PPS
case 360:
case 395:
//EIR
case 380:
//MNP
case 370:
	//License
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[License][Value]},{$module[License][Color]};";
	$total_response.=$message;
	
	//User
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[User][Value]},{$module[User][Color]};";
	$total_response.=$message;
	
	//Serial Number
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SerialNumber][Value]},{$module[SerialNumber][Color]};";
	$total_response.=$message;
	break;
//AAS
case 311:
	//Serial Number
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SerialNumber][Value]},{$module[SerialNumber][Color]};";
	$total_response.=$message;
	break;
//SMEG
case 355:
	//License
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[License][Value]},{$module[License][Color]};";
	$total_response.=$message;
	
	//User
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[User][Value]},{$module[User][Color]};";
	$total_response.=$message;
	
	//SMPP TX Status
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SMPPTXStatus][Value]},{$module[SMPPTXStatus][Color]};";
	$total_response.=$message;
	
	//SMPP RX Status
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SMPPRXStatus][Value]},{$module[SMPPRXStatus][Color]};";
	$total_response.=$message;
	
	//SMTP TX Status
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SMTPTXStatus][Value]},{$module[SMTPTXStatus][Color]};";
	$total_response.=$message;
	
	//SMTP RX Status
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SMTPRXStatus][Value]},{$module[SMTPRXStatus][Color]};";
	$total_response.=$message;
	
	//Serial Number
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SerialNumber][Value]},{$module[SerialNumber][Color]};";
	$total_response.=$message;
	break;
//OPPS
case 375:
	//License
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[License][Value]},{$module[License][Color]};";
	$total_response.=$message;
	
	//User
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[User][Value]},{$module[User][Color]};";
	$total_response.=$message;
	
	//OPR Status
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[OPRStatus][Value]},{$module[OPRStatus][Color]};";
	$total_response.=$message;
	
	//IMDX Status
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[IMDXStatus][Value]},{$module[IMDXStatus][Color]};";
	$total_response.=$message;
	
	//Serial Number
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SerialNumber][Value]},{$module[SerialNumber][Color]};";
	$total_response.=$message;
	break;
//iRLS
case 379:
//iPALIM
case 378:
//MHC
case 386:
	//Serial Number
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SerialNumber][Value]},{$module[SerialNumber][Color]};";
	$total_response.=$message;
	break;
//VSS
case 390:
	//Total Mailbox
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[TotalMailbox][Value]},{$module[TotalMailbox][Color]};";
	$total_response.=$message;
	
	//Registered Mailbox
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[RegisteredMailbox][Value]},{$module[RegisteredMailbox][Color]};";
	$total_response.=$message;
	
	//Active Mailbox
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[ActiveMailbox][Value]},{$module[ActiveMailbox][Color]};";
	$total_response.=$message;
	
	//Total Voicemail
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[TotalVoicemail][Value]},{$module[TotalVoicemail][Color]};";
	$total_response.=$message;
	
	//Total Seconds of Voicemail
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[TotalSecondVoicemail][Value]},{$module[TotalSecondVoicemail][Color]};";
	$total_response.=$message;
	
	//Average Seconds of Voicemail
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[AverageSecondVoicemail][Value]},{$module[AverageSecondVoicemail][Color]};";
	$total_response.=$message;
	
	//SMPP State
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SMPPState][Value]},{$module[SMPPState][Color]};";
	$total_response.=$message;
	break;
//TMG
case 391:
//AMRMG
case 392:
//GbC
case 393:
	//MaxE1Number
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[MaxE1Number][Value]},{$module[MaxE1Number][Color]};";
	$total_response.=$message;
	
	//OnlineUser
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[OnlineUser][Value]},{$module[OnlineUser][Color]};";
	$total_response.=$message;
	
	//Serial Number
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SerialNumber][Value]},{$module[SerialNumber][Color]};";
	$total_response.=$message;
	break;
case 394:	
	//Serial Number
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SerialNumber][Value]},{$module[SerialNumber][Color]};";
	$total_response.=$message;
	break;
//SMSC
case 350:
	//License
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[License][Value]},{$module[License][Color]};";
	$total_response.=$message;
	
	//User
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[User][Value]},{$module[User][Color]};";
	$total_response.=$message;
	
	//Serial Number
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SerialNumber][Value]},{$module[SerialNumber][Color]};";
	$total_response.=$message;
	
	//SMPP Link
	for($i=0;$i<4;$i++)
	{
		for($j=0;$j<8;$j++)
		{
			$no=$i*8+$j;
			$id=AssignID($sysTypeNo,$sysNo);
			$message="{$id},block,{$module[SMPPLink][$no][Name][Value]},#000000;";
			$total_response.=$message;
		}
		
		for($j=0;$j<8;$j++)
		{
			$no=$i*8+$j;
			$id=AssignID($sysTypeNo,$sysNo);
			$message="{$id},block,{$module[SMPPLink][$no][Status][Value]},{$module[SMPPLink][$no][Status][Color]};";
			$total_response.=$message;
		}
	}
	break;
//RAID
case 384:
	//License
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[License][Value]},{$module[License][Color]};";
	$total_response.=$message;
	
	//User
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[User][Value]},{$module[User][Color]};";
	$total_response.=$message;
	
	break;
//IUUGW
case 389:
	//SerialNumber
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[SerialNumber][Value]},{$module[SerialNumber][Color]};";
	$total_response.=$message;
	
	//UsedCount
	$id=AssignID($sysTypeNo,$sysNo);
	$message="{$id},block,{$module[UsedCount][Value]},{$module[UsedCount][Color]};";
	$total_response.=$message;
	break;
default:
	break;
}

//Alarm
$sql="select * from sysAlarmLog where sysTypeNo=$sysTypeNo and sysNo=$sysNo and clearBy is null ";
$res=mysqli_query($pubConn,$sql);
$num=mysqli_num_rows($res);
if($num > 0)
{
    // if($sysTypeNo == 362)
    //     $message="<center><font size=2 color=blue>SPGW Alarm List</font></center>";
    // else
        $message="<center><font size=2 color=blue>{$config[$config_index][Module]}_{$sysNo} Alarm List</font></center>";
	$message.="<table width=100% border=1 cellpadding=1 cellspacing=0 bordercolor=#666666 bordercolordark=#FFFFFF bgcolor=\"#ffffff\">";
	$message.="<tr bgcolor=\"#E6E6E6\">";
	$message.="<td>Alarm Level</td>";
	$message.="<td>Events</td>";
	$message.="<td>Alarm Time</td>";
	$message.="</tr>";
	
	for($i=0;$i<$num;$i++)
	{
		$row=mysqli_fetch_array($res);
		$alarmTime=$row[alarmTime];
		$tmpsql="select * from sysAlarmConf where sysTypeNo=$sysTypeNo and compCode='$row[compCode]' and alarmCode='$row[alarmCode]' ";
		$tmpres=@mysqli_query($pubConn,$tmpsql);
		echo mysqli_error($pubConn);
		$tmprow=@mysqli_fetch_array($tmpres);
		$alarmLevel=$tmprow[alarmLevel];
		if(trim($tmprow[alarmDesc_2]) == "")
			$message.="<tr style=\"display:none\">";
		else
			$message.="<tr>";
		$message.="<td>{$alarmLevelDefArr[$alarmLevel][remark]}</td>";
		$message.="<td>{$tmprow[alarmDesc_2]}</td>";
		$message.="<td>$alarmTime</td>";
		$message.="</tr>";
	}
	$message.="</table>";
	
	$total_response.=$message;
}
else
{
	$total_response.="none";
}


echo $total_response;
//echo "hhelo";
?>

