<?php
/*********************************************************      
 程序说明：         
    功能说明：E1参数配置

    调用关系：调用: header.inc     
              被调用:   
 
    变量说明：

     返回值：无

 作者：   
      
修改注释：      
NO.1      
Name: Lilong
Date:12:22:07 PM Tuesday, February 24, 2004
Description: Display Status of device which received heartbeat.
*********************************************************/  
require("../../inc/header.inc");
$helpId = "2.1.2.1"; 
$DEBUG = 0;
$sysInfoTable = 'OMC_PUB.sysInfo';
?>
<script LANGUAGE="JavaScript">           
function openSet(sNum,pNum){
	var x,y;
	x = document.body.scrollLeft;
	y = document.body.scrollTop;

	URL="./e1Edit.php?sNum="+sNum+"&pNum="+pNum+"&scroll_x="+x+"&scroll_y="+y;
	var msgWindow = open(URL, 'newWin', 'toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,width=400,height=420');
	msgWindow.focus();
}
</script>
<?php
$sysTypeNo_0 = "111";
if($thisOmcType==10){
	$sysTypeNo_1 = "251";
}else{
	$sysTypeNo_1 = "322";
}

$db_0 = "OBJ_".$sysTypeNo_0;
$db_1 = "OBJ_".$sysTypeNo_1;

$tb_0 = "param_0";
$tb_1 = "param_1";
$tb_2 = "param_99";

$maxNum = 30;

$nPubFlag = 99;
$nSubSysParam		= 0;
$nGlobalSubSysParam = 1;
$nGlobalSysParam	= 2;

$nGetComm = 0;
$nSetComm = 3;

$nInteger = 2;
$nOctStr = 4;

$nProcFail = 0;//failure
$nWaitProc = 1;//wait
$nInProc   = 2;
$nOutProc  = 3;

//E1 flag
$oidFlag = "2.1"; 
$pE1 = explode(".",$oidFlag);
$i = 0;
$wFlag = '';
while(isset($pE1[$i]))
{
	$lNum = $i+1;
	if($DEBUG) echo "<br>pE1[$i]=$pE1[$i]";
	$wFlag = $wFlag." AND level_$lNum = $pE1[$i] ";
	$i++;
}


//2.6 CRC4 flag
$oidCrc = "2.6"; 
$pE1 = explode(".",$oidCrc);
$i = 0;
$wCrc = '';
while(isset($pE1[$i])) {
	$lNum = $i+1;
	if($DEBUG)echo "<br>pE1[$i]=$pE1[$i]";
	$wCrc = $wCrc." AND level_$lNum = $pE1[$i] ";
	$i++;
}

//2.2 E1 MTP2 alarm flag
$oidDlink = "2.2"; 
$pE1 = explode(".",$oidDlink);
$i = 0;
$wDlink = '';
while(isset($pE1[$i]))
{
	$lNum = $i+1;
	if($DEBUG)echo "<br>pE1[$i]=$pE1[$i]";
	$wDlink = $wDlink." AND level_$lNum = $pE1[$i] ";
	$i++;
}

//2.4.1 2.4.2 2.4.3 MSC
$uwMsc = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND (level_3 = '1' OR level_3 = '2' OR level_3 = '3') ";


$wMsc = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND (level_3 = '1' OR level_3 = '2' OR level_3 = '3') ORDER BY level_3 ";

$wMsc_1 = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND level_3 = '1' AND instanceNo  = '$pNum' ";

$wMsc_2 = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND level_3 = '2' AND instanceNo  = '$pNum' ";

$wMsc_3 = " WHERE subSysNo = '99' AND level_1 = '2' AND level_2 = '4'  AND level_3 = '3' AND instanceNo  = '$pNum' ";

$eFlagArr=array(
		array('num' => '0',  'remark' => 'N', 'color' => '#FF0000'),
		array('num' => '1',  'remark' => 'Y', 'color' => '#0000FF'),
		array('num' => '2',  'remark' => 'T', 'color' => '#0000FF')

);

$eCrcArr=array(
		array('num' => '0',  'remark' => 'Off', 'color' => '#FF0000'),
		array('num' => '1',  'remark' => 'On', 'color' => '#0000FF')
);

$eDlinkArr=array(
		array('num' => '0',  'remark' => 'N', 'color' => '#FF0000'),
		array('num' => '1',  'remark' => 'Y', 'color' => '#0000FF')
);

$mPtArr=array(
		array('num' => '0',  'remark' => 'TUP', 'color' => '#FF0000'),
		array('num' => '1',  'remark' => 'ISUP', 'color' => '#0000FF'),
		array('num' => '2',  'remark' => 'AIF', 'color' => '#0000FF'),
		array('num' => '3',  'remark' => 'ISDN NT', 'color' => '#0000FF'),
		array('num' => '4',  'remark' => 'ISDN LT', 'color' => '#0000FF'),
		array('num' => '5',  'remark' => 'CIC CNF', 'color' => '#0000FF'),
		array('num' => '6',  'remark' => 'CIC INT', 'color' => '#0000FF')
);
//****************************************************************
//函数
//	ChComm($sysId)
//函数说明:检查命令处理结果
//	
//变量说明: 
//	无
//	
//                                                             
//返回值：$paramType
//$nSubSysParam			= 0;
//$nGlobalSubSysParam	= 1;
//$nGlobalSysParam		= 2;	
//作者：
//      
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------

function ChComm($sysId,$chkType=1)
{     
	global $omc_db;
	global $remark,$nProcFail,$nWaitProc,$nInProc,$nOutProc;

	$commTable = "parameterComm";
	$DEBUG = 0;

	$sysIdArr = explode('_',$sysId);
	$sysTypeNo	= $sysIdArr[0];
	$sysNo		= $sysIdArr[1];
	$subSysNo	= $sysIdArr[2];
	
	if($chkType==0)
		$selComm = " SELECT commState,remark FROM $commTable WHERE sysTypeNo = '$sysTypeNo' ";
	else
		$selComm = " SELECT commState,remark FROM $commTable WHERE sysTypeNo = '$sysTypeNo' AND sysNo = '$sysNo' ";
	
	if($DEBUG)echo "<br>selComm=$selComm";
	$selRes  = @mysqli_query($pubConn,$selComm);
	$selRow  = @mysqli_fetch_array($selRes);
	echo mysqli_error($pubConn);
	$outProcCount=0;
	do
	{
		$temCommState = $selRow[commState];
		if(isset($selRow[remark])){
			$remark = $selRow[remark];
			if($DEBUG)echo "<br>remark=$remark";
		}
		if($DEBUG)echo "<br>temCommState=$temCommState";
		if($temCommState == $nWaitProc){
			return($nWaitProc);
		}elseif($temCommState == $nInProc){
			return($nInProc);
		}elseif($temCommState == $nOutProc){
			$commState = $nOutProc;
			$outProcCount++;
		}else{
			$commState = $nProcFail;
		}
	}while($selRow  = @mysqli_fetch_array($selRes));
	if($outProcCount > 0){
		return($nOutProc);
	}else{
		return($nProcFail);
	}
}

//****************************************************************
//函数
//	从Buffer_2拷贝到$buffer_1
//函数说明:
//	
//变量说明: 
//	无
//	
//                                                             
//返回值：$paramType
//	
//作者：
//      
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
//parameter(dst,src,*,*)
function copyBuffer($buffer_1,$buffer_2,$wDef,$type='1')
{     
	global $sysTypeNo_0,$sysTypeNo_1,$db_0,$db_1,$tb_0,$tb_1,$tb_2,$wFlag,$wCrc,$wDlink,$uwMsc;
	$DEBUG = 0;
	$addWer = "	AND (LENGTH($buffer_2) > 0) AND $buffer_2 != 'Null' AND $buffer_2 NOT LIKE 'Error%' ";

	//E1 flag
	for($i=0;$i<2;$i++)
	{
		$temTb = ${tb_.$i};
		$uFlagSql = " UPDATE $temTb set $buffer_1=$buffer_2 WHERE subSysNo >= 0 ".$wFlag.$addWer; 
		if($DEBUG) echo "<br>uFlagSql=$uFlagSql";
		$uFlagRes = @mysqli_query($pubConn,$uFlagSql);
		if(!$uFlagRes)
			$noSuccess=1;
	}


	//2.6 CRC4 flag
	for($i=0;$i<2;$i++)
	{
		$temTb = ${tb_.$i};
		$uCrcSql = " UPDATE $temTb set $buffer_1=$buffer_2 WHERE subSysNo >= 0 ".$wCrc.$addWer; 
		if($DEBUG)echo "<br>uCrcSql=$uCrcSql";
		$uCrcRes = @mysqli_query($pubConn,$uCrcSql);
		echo mysqli_error($pubConn);
		if(!$uFlagRes)
			$noSuccess=1;
	}

	//2.2 E1 MTP2 alarm flag
	for($i=0;$i<2;$i++)
	{
		$temTb = ${tb_.$i};
		$uDlinkSql = " UPDATE $temTb set $buffer_1=$buffer_2 WHERE subSysNo >= 0 ".$wDlink.$addWer; 
		if($DEBUG)echo "<br>uDlinkSql=$uDlinkSql";
		$uDlinkRes = @mysqli_query($pubConn,$uDlinkSql);
		echo mysqli_error($pubConn);
		if(!$uFlagRes)
			$noSuccess=1;
	}


	//2.4.1 2.4.2 2.4.3 MSC
	$uMscSql = " UPDATE $tb_2 set $buffer_1=$buffer_2 ".$uwMsc.$addWer;
	if($DEBUG) echo " <br>uMscSql=$uMscSql ";
	$uMscRes = @mysqli_query($pubConn,$uMscSql);
	$uMscRow = @mysqli_fetch_array($uMscRes);
	echo mysqli_error($pubConn);
	if(!$uFlagRes)
		$noSuccess=1;

	if($noSuccess)
		return 0;
	else
		return 1;
}

//****************************************************************
//函数
//	get 或 set
//函数说明:
//	
//变量说明: 
//	无
//                                                             
//返回值：$commType
//	
//作者：
//      
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------
function eSetGet($commType) {     
	global $sysTypeNo_0,$sysTypeNo_1,$db_0,$db_1,$tb_0,$tb_1,$tb_2,$wFlag,$wCrc,$wDlink,$uwMsc,$nProcFail,$nWaitProc,$nInProc,$nOutProc;
	global $maxNum,$remark,$nGetComm,$nSetComm;
	$DEBUG = 0;

	$sysInfoTable = 'OMC_PUB.sysInfo';
	/**************check single plane or dual plane*******************/
	$tmpSql = " SELECT sysNo,subSysNo,updateTime
				FROM $sysInfoTable
				WHERE sysTypeNo='$sysTypeNo_0' AND updateTime > '0'
				ORDER BY sysNo,subSysNo
			";
	//echo "<br>tmpSql=$tmpSql";
	$tmpRes = @mysqli_query($pubConn,$tmpSql);
	$tmpRow = @mysqli_fetch_array($tmpRes);
	echo mysqli_error($pubConn);
	do
	{
		$tmpSysNo = $tmpRow[sysNo];
		$tmpSubSysNo = $tmpRow[subSysNo];
		$tmpIsUpdate[$tmpSysNo][$tmpSubSysNo] = $tmpRow[updateTime] > 0 ? 1:0;
	}while($tmpRow = @mysqli_fetch_array($tmpRes));
	
	$tmpIsUpdate[0][0]="1";


	if($commType == $nGetComm)
		$showType = "Get ";
	else
		$showType = "Set ";
	//E1 flag
	for($j=0;$j<2;$j++) {
		if($sTimeOut)
			break;

		for($k=0;$k<16;$k++){
			if($tmpIsUpdate[$j][$k])
				break;
		}

		if($k==16)
			continue;

		$sysId = "111_".$j."_99";
		//echo "<br>sysId=$sysId";
		//$commType = $nSetComm;
		$objIdStr = "2.1.*";
		$flag = sysCommSend($sysId,$commType,$objIdStr);
		//echo "<br>flag=$flag";

		$i = 0;
		while(1)
		{
			if($i == 0)
				echo "<br>$showType E1 Flag(plane$j)";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				$sTimeOut = 1;
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	

			$sysId = "111_$j";
			$chRes=ChComm($sysId);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				$pNext1 = 1;
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}
	}

	//2.4.3 CIC of E1
	if($pNext1)
	{
		$sysId = $sysTypeNo_1."_99";
		//$commType = $nSetComm;
		$objIdStr = "2.4.3.*";
		$cic = sysCommSend($sysId,$commType,$objIdStr);
		//echo "<br>cic=$cic";

		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>$showType E1 CIC";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	

			$sysId = $sysTypeNo_1;
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				$pNext2 = 1;
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}
	
	}//end of $pNext1


	//2.4.2 Assign TG to E1
	if($pNext2)
	{
		$sysId = $sysTypeNo_1."_99";
		//$commType = $nSetComm;
		$objIdStr = "2.4.2.*";
		$tg = sysCommSend($sysId,$commType,$objIdStr);
		//echo "<br>tg=$tg";

		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>$showType TG";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	

			$sysId = $sysTypeNo_1;
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				$pNext3 = 1;
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}
	}


	//2.4.1 E1 interface
	if($pNext3)
	{
		$sysId = $sysTypeNo_1."_99";
		//$commType = $nSetComm;
		$objIdStr = "2.4.1.*";
		$port = sysCommSend($sysId,$commType,$objIdStr);
		//echo "<br>port=$port";

		$i = 0;
		while(1)
		{
			//echo "<br>i=$i";
			if($i == 0)
				echo "<br>$showType E1 interface";
			if($i > $maxNum){
				echo "<br><font size=\"2\" color=\"#FF0000\"> Timeout</font>";
				break;
			}
			echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
			flush();	

			$sysId = $sysTypeNo_1;
			$chkType = "0";
			$chRes=ChComm($sysId,$chkType);
			//echo "<br>chRes=$chRes";
			if($chRes == $nOutProc || $chRes == $nProcFail){
				$pNext4 = 1;
				if($chRes == $nProcFail)
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				elseif($remark == 'response timeout')
					echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
				else
					echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
				break;
			}
	
			sleep(1);
			$i++;
		}
	
	}

	//2.6 CRC4 flag
	if($pNext4)
	{

		for($j=0;$j<2;$j++)
		{
			if($sTimeOut)
				break;

			for($k=0;$k<16;$k++){
				if($tmpIsUpdate[$j][$k])
					break;
			}

			if($k==16)
				continue;

			$sysId = "111_".$j."_99";
			//$commType = $nSetComm;
			$objIdStr = "2.6.*";
			$crc4 = sysCommSend($sysId,$commType,$objIdStr);
			//echo "<br>crc4=$crc4";	

			$i = 0;
			while(1)
			{
				//echo "<br>i=$i";
				if($i == 0)
					echo "<br>$showType E1 crc4(plane$j)";
				if($i > $maxNum){
					echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
					$sTimeOut = 1;
					break;
				}
				echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
				flush();	

				$sysId = "111_$j";
				$chRes=ChComm($sysId);
				//echo "<br>chRes=$chRes";
				if($chRes == $nOutProc || $chRes == $nProcFail){
					$pNext5 = 1;
					if($chRes == $nProcFail)
						echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
					elseif($remark == 'response timeout')
						echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
					else
						echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
					break;
				}
	
				sleep(1);
				$i++;
			}
	
		}

	}


	//2.2 E1 MTP2 alarm flag
	if($pNext5)
	{
		for($j=0;$j<2;$j++)
		{

			if($sTimeOut)
				break;
			
			//check single plane or dual plane
			for($k=0;$k<16;$k++){
				if($tmpIsUpdate[$j][$k])
					break;
			}

			if($k==16)
				continue;


			$sysId = "111_".$j."_99";
			//$commType = $nSetComm;
			$objIdStr = "2.2.*";
			$dlink = sysCommSend($sysId,$commType,$objIdStr);
			//echo "<br>dlink=$dlink";

			$i = 0;
			while(1)
			{
				//echo "<br>i=$i";
				if($i==0)
					echo "<br>$showType E1 dlink(plane$j)";
				if($i > $maxNum){
					echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
					$sTimeOut = 1;
					break;
				}
				echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
				flush();	

				$sysId = "111_$j";
				$chRes=ChComm($sysId);
				//echo "<br>chRes=$chRes";
				if($chRes == $nOutProc || $chRes == $nProcFail){
					$pNext5 = 1;
					if($chRes == $nProcFail)
						echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
					elseif($remark == 'response timeout')
						echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
					else
						echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
					break;
				}
	
				sleep(1);
				$i++;
			}
		}
	}

	return 1;
}//end of function

if($saveSys){
	/****************copy initValue to editValue******************/
	$buffer_1 = "editValue";
	$buffer_2 = "initValue";
	$edCin=copyBuffer($buffer_1,$buffer_2,$wDef);
	if($DEBUG) echo "<br>edCin=$edCin";

	//Get the value to "readValue" buffer. 
	eSetGet($nGetComm);//get value
	/****************copy readValue to undoValue******************/
	$buffer_1 = "undoValue";
	$buffer_2 = "readValue";
	$edCin=copyBuffer($buffer_1,$buffer_2,$wDef);
	if($DEBUG) echo "<br>edCin=$edCin";

	//set editValue to system.
	eSetGet($nSetComm);
	$e1SetFlag = 1;
	session_register("e1SetFlag");

	//if get fail ( undoValue = NULL ) , unregister set flag.
	//8ke1 plat 0
	$where_0	= " level_1=2 AND (level_2=1 OR level_2=2 OR level_2=6) ";
	$selSql_0	= "SELECT distinct undoValue FROM $tb_0 WHERE $where_0 ORDER BY undoValue";
	if($DEBUG) 	echo "selSql_0=$selSql_0,db=$db_0<br>";
	$selRes_0	= @mysqli_query($pubConn,$selSql_0);
	$selRow_0 = mysqli_fetch_array($selRes_0);
	//8ke1 plat 1
	$where_1	= " level_1=2 AND (level_2=1 OR level_2=2 OR level_2=6) ";
	$selSql_1	= "SELECT distinct undoValue FROM $tb_1 WHERE $where_1 ORDER BY undoValue";
	if($DEBUG) echo "selSql_1=$selSql_1,db=$db_0<br>";
	$selRes_1	= @mysqli_query($pubConn,$selSql_1);
	$selRow_1 = mysqli_fetch_array($selRes_1);
	//msc
	$where_2	= " level_1=2 AND level_2=4 AND (level_3=1 OR level_3=2 OR level_3=3) ";
	$selSql_2	= "SELECT distinct undoValue FROM $tb_2 WHERE $where_2 ORDER BY undoValue";
	if($DEBUG) echo "selSql_2=$selSql_2,db=$db_1<br>";
	$selRes_2	= @mysqli_query($pubConn,$selSql_2);
	$selRow_2 = mysqli_fetch_array($selRes_2);

	if ( ('' == $selRow_0[0]) | ('' == $selRow_1[0]) | ('' == $selRow_2[0])) {
		session_unregister("e1SetFlag");
	}

	sleep(1);
	echo "<script language=\"javascript\">";
	//echo "window.location.href='$PHP_SELF';";
	echo "</script>";
}//end of set sys
elseif($readSys) {	
	eSetGet($nGetComm);//get value

	/****************copy readValue to initValue******************/
	$buffer_1 = "initValue";
	$buffer_2 = "readValue";
	$inCre=copyBuffer($buffer_1,$buffer_2,$wDef);
	if($DEBUG) echo "<br>inCre=$inCr";

	sleep(1);
	echo "<script language=\"javascript\">";
	//echo "window.location.href='$PHP_SELF';";
	echo "</script>";
}//end of $readSys
elseif($undoSet){
	/****************copy readValue to editValue******************/
	$buffer_1 = "editValue";
	$buffer_2 = "undoValue";
	$edCin=copyBuffer($buffer_1,$buffer_2,$wDef);
	if($DEBUG) echo "<br>edCin=$edCin";
	
	if ( 1 == eSetGet($nSetComm) ) {
		$buffer_1 = "initValue";
		$buffer_2 = "undoValue";
		$edCin=copyBuffer($buffer_1,$buffer_2,$wDef);
		if($DEBUG) echo "<br>edCin=$edCin";
	}
	session_unregister("e1SetFlag");

	sleep(1);
	echo "<script language=\"javascript\">";
	//echo "window.location.href='$PHP_SELF';";
	echo "</script>";
}
elseif($saveDisk){
	/****************copy initValue to editValue******************/
	$buffer_1 = "editValue";
	$buffer_2 = "initValue";
	$inCed=copyBuffer($buffer_1,$buffer_2,$wDef);
	if($DEBUG) echo "<br>$inCed=$$inCed";

	if($inCed)
		echo "<br><font color=\"#0000FF\">Save success.</font>";
	else
		echo "<br><font color=\"#FF0000\">Save Failure.</font>";

	flush();
	sleep(1);
	echo "<script language=\"javascript\">";
	echo "window.location.href='$PHP_SELF';";
	echo "</script>";
}//end of $saveDisk
elseif($readDisk){
	/****************copy editValue to initValue******************/
	$buffer_1 = "initValue";
	$buffer_2 = "editValue";
	$edCin=copyBuffer($buffer_1,$buffer_2,$wDef);
	if($DEBUG) echo "<br>edCin=$edCin";

	if($edCin)
		echo "<br><font color=\"#0000FF\">Read success.</font>";
	else
		echo "<br><font color=\"#FF0000\">Read failure.</font>";
	
	flush();
	sleep(1);
	echo "<script language=\"javascript\">";
	//echo "window.location.href='$PHP_SELF';";
	echo "</script>";

}//end of $comSys
elseif($comDisk){
	/****************copy editValue to initValue******************/
	$buffer_1 = "initValue";
	$buffer_2 = "editValue";
	$edCin=copyBuffer($buffer_1,$buffer_2,$wDef);
	if($DEBUG) echo "<br>edCin=$edCin";
}//end of $comDisk
elseif($comSys){
	/****************copy editValue to initValue******************/
	$buffer_1 = "initValue";
	$buffer_2 = "readValue";
	$reCin=copyBuffer($buffer_1,$buffer_2,$wDef);
	if($DEBUG) echo "<br>reCin=$reCin";
}
elseif($saveComm){
	session_unregister("e1SetFlag");
	$temTb = ${tb_."2"};
	$updSql = " UPDATE $temTb set initValue = 'B5' WHERE subSysNo = '99' AND level_1 = '3' AND level_2 = '2' ";
	//echo "<br>updSql=$updSql";
	$updRes = @mysqli_query($pubConn,$updSql);
	//echo "<br>updRes=$updRes";
	
	if($sTimeOut)
		break;

	$sysId = $sysTypeNo_1."_99";
	//echo "sysId=$sysId";
	$commType = $nSetComm;
	$objIdStr = "3.2.*";
	$flag = sysCommSend($sysId,$commType,$objIdStr);
	//echo "<br>flag=$flag";

	$i = 0;
	while(1)
	{
		if($i == 0)
			echo "<br>Save parameter to system";
		if($i > $maxNum){
			echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
			$sTimeOut = 1;
			break;
		}
		echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
		flush();	

		$sysId = $sysTypeNo_1;
		$chkType = "0";
		$chRes=ChComm($sysId,$chkType);
		//echo "<br>chRes=$chRes";
		if($chRes == $nOutProc || $chRes == $nProcFail){
			$pNext1 = 1;
			if($chRes == $nProcFail)
				echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
			elseif($remark == 'response timeout')
				echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
			else
				echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
			break;
		}
	
		sleep(1);
		$i++;
	}
}
elseif($resetComm)
{
	$temTb = ${tb_."2"};
	$updSql = " UPDATE $temTb set initValue = '5A' WHERE subSysNo = '99' AND level_1 = '3' AND level_2 = '2' ";
	//echo "<br>updSql=$updSql";
	$updRes = @mysqli_query($pubConn,$updSql);
	//echo "<br>updRes=$updRes";
	
	if($sTimeOut)
		break;

	$sysId = $sysTypeNo_1."_99";
	$commType = $nSetComm;
	$objIdStr = "3.2.*";
	$flag = sysCommSend($sysId,$commType,$objIdStr);
	//echo "<br>flag=$flag";

	$i = 0;
	while(1)
	{
		if($i == 0)
			echo "<br>Reset system";
		if($i > $maxNum){
			echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
			$sTimeOut = 1;
			break;
		}
		echo "<img border=\"0\" src=\"../../images/arrow.gif\" width=\"10\" height=\"10\">";
		flush();	

		$sysId = $sysTypeNo_1;
		$chkType = "0";
		$chRes=ChComm($sysId,$chkType);
		//echo "<br>chRes=$chRes";
		if($chRes == $nOutProc || $chRes == $nProcFail){
			$pNext1 = 1;
			if($chRes == $nProcFail)
				echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
			elseif($remark == 'response timeout')
				echo "<br><font size=\"2\" color=\"#FF0000\">$remark</font><br>";
			else
				echo "<br><font size=\"2\" color=\"#0000FF\">$remark</font><br>";
			break;
		}
	
		sleep(1);
		$i++;
	}
}
if($readSys || $saveSys || $saveComm || $undoSet||$resetComm){
	echo "<br>";
	echo "<p align=\"left\"><a href=\"$PHP_SELF?setFlag=$setFlag\" target=\"contents\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
	exit();
}

/**************select used E1 card*******************/
$getSql = " SELECT sysNo,subSysNo,baseStat,updateTime
			FROM $sysInfoTable
			WHERE sysTypeNo='$sysTypeNo_0' AND updateTime > '0'
			ORDER BY sysNo,subSysNo
		  ";
//echo "<br>getSql=$getSql";
$getRes = @mysqli_query($pubConn,$getSql);
$getRow = @mysqli_fetch_array($getRes);
echo mysqli_error($pubConn);
do
{
	$sysNo = $getRow[sysNo];
	$subSysNo = $getRow[subSysNo];
	$isUpdate[$sysNo][$subSysNo] = $getRow[updateTime] > 0 ? 1:0;
}while($getRow = @mysqli_fetch_array($getRes));

$isUpdate[0][0]="1";

/************select value to see************/
//E1 flag
for($i=0;$i<2;$i++)
{
	$temTb = ${tb_.$i};
	$flagSql = " SELECT instanceNo,initValue,editValue,readValue FROM $temTb WHERE subSysNo >= 0 ".$wFlag." ORDER BY instanceNo "; 
	if($DEBUG) echo "<br>flagSql=$flagSql";
	$flagRes = @mysqli_query($pubConn,$flagSql);
	$flagRow = @mysqli_fetch_array($flagRes);
	echo mysqli_error($pubConn);
	do
	{
		$instanceNo = $flagRow[instanceNo];
		$initValue = HexDec($flagRow[initValue]);
		$initValue = DecBin($initValue);
		$initValue = omc_keep_length($initValue,0,8);
		if($DEBUG) echo "<br>initValue=$initValue";
		for($j=0;$j<8;$j++)
		{
			$fNum = $instanceNo*8+7-$j;
			$flagArr[$i][$fNum] = substr($initValue,$j,1);
			if($DEBUG) echo "<br>flagArr[$i][$fNum]={$flagArr[$i][$fNum]}";
		}
	}while($flagRow = @mysqli_fetch_array($flagRes));
}

//2.6 CRC4 flag
for($i=0;$i<2;$i++)
{
	$temTb = ${tb_.$i};
	$crcSql = " SELECT instanceNo,initValue,editValue,readValue FROM $temTb WHERE subSysNo >= 0 ".$wCrc." ORDER BY instanceNo "; 
	if($DEBUG)echo "<br>crcSql=$crcSql";
	$crcRes = @mysqli_query($pubConn,$crcSql);
	$crcRow = @mysqli_fetch_array($crcRes);
	if($DEBUG)echo mysqli_error($pubConn);
	do
	{
		$instanceNo = $crcRow[instanceNo];
		$initValue = HexDec($crcRow[initValue]);
		$initValue = DecBin($initValue);
		$initValue = omc_keep_length($initValue,0,8);
		if($DEBUG)echo "<br>initValue=$initValue";
		for($j=0;$j<8;$j++)
		{
			$fNum = $instanceNo*8+7-$j;
			$crcArr[$i][$fNum] = substr($initValue,$j,1);
			if($DEBUG)echo "<br>crcArr[$i][$fNum]={$crcArr[$i][$fNum]}";
		}
	}while($crcRow = @mysqli_fetch_array($crcRes));
}

//2.2 E1 MTP2 alarm flag
for($i=0;$i<2;$i++)
{
	$temTb = ${tb_.$i};
	$dlinkSql = " SELECT instanceNo,initValue,editValue,readValue FROM $temTb WHERE subSysNo >= 0 ".$wDlink." ORDER BY instanceNo "; 
	if($DEBUG)echo "<br>dlinkSql=$dlinkSql";
	$dlinkRes = @mysqli_query($pubConn,$dlinkSql);
	$dlinkRow = @mysqli_fetch_array($dlinkRes);
	echo mysqli_error($pubConn);
	do{
		$instanceNo = $dlinkRow[instanceNo];
		$initValue = HexDec($dlinkRow[initValue]);
		$initValue = DecBin($initValue);
		$initValue = omc_keep_length($initValue,0,8);
		if($DEBUG)echo "<br>initValue=$initValue";
		for($j=0;$j<8;$j++)
		{
			$fNum = $instanceNo*8+7-$j;
			$dlinkArr[$i][$fNum] = substr($initValue,$j,1);
			if($DEBUG)echo "<br>dlinkArr[$i][$fNum]={$dlinkArr[$i][$fNum]}";
		}
	}while($dlinkRow = @mysqli_fetch_array($dlinkRes));
}


//2.4.1 2.4.2 2.4.3 MSC
$mscSql = " SELECT level_3,instanceNo,initValue,editValue,readValue FROM $tb_2 ".$wMsc; 
if($DEBUG) echo "<br>mscSql=$mscSql";
$mscRes = @mysqli_query($pubConn,$mscSql);
$mscRow = @mysqli_fetch_array($mscRes);
echo mysqli_error($pubConn);

do {
	$level_3 = $mscRow[level_3];
	$instanceNo = $mscRow[instanceNo];
	$initValue = HexDec($mscRow[initValue]);
	$mscArr[$level_3][$instanceNo] = $initValue;
	if($DEBUG) echo "<br>mscArr[$level_3][$instanceNo]={$mscArr[$level_3][$instanceNo]}";	
}while($mscRow = @mysqli_fetch_array($mscRes));


if($comSys || $comDisk) {
	for($i=0;$i<128;$i++) {
		if($flagArr[0][$i] != $flagArr[1][$i])
			$flagCol[$i]="#FF0000";
				
		if($mscArr[3][$i] != $mscArr[3][$i+128])
			$mscCol[3][$i]="#FF0000";
		
		if($mscArr[2][$i] != $mscArr[2][$i+128])
			$mscCol[2][$i]="#FF0000";
		
		if($mscArr[1][$i] != $mscArr[1][$i+128])
			$mscCol[1][$i]="#FF0000";

		if($crcArr[0][$i] != $crcArr[1][$i])
			$crcCol[$i]="#FF0000";
		
		if($dlinkArr[0][$i] != $dlinkArr[1][$i])
			$dlinkCol[$i]="#FF0000";
	}
}//end of $comDisk
$scroll_x = isset($scroll_x)?$scroll_x:'0';
$scroll_y = isset($scroll_y)?$scroll_y:'0';
echo "<body onLoad='self.scrollBy($scroll_x,$scroll_y)'>";
echo "<form method=\"POST\" name=\"confForm\" action=\"$PHP_SELF\">";
echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "$strConfiguration > $strNetwork > $DEFAULT_SYS > E1";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "</table>";
?>
<br>&nbsp;
<table border="0" cellpadding="0" cellspacing="0" width="100%">           
<!--
	<tr>           
	<td width=72 valign="middle"><b>System:</b>	</td>            
	<td valign="middle">
	<?php
		echo "<input type=\"submit\" value=$strGet class=\"button\" name=\"readSys\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		echo "<input type=\"submit\" value=$strSet class=\"button\" name=\"saveSys\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		//echo "<input type=\"submit\" value=$strCompare class=\"button\" name=\"comSys\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		echo "<input type=\"submit\" value=$strSave class=\"button\" name=\"saveComm\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		if ( TRUE == session_is_registered("e1SetFlag") ) {
			echo "<input type=\"submit\" value=\"Undo\" class=\"button\" name=\"undoSet\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		}else{
			echo "<input type=\"submit\" value=\"Undo\" DISABLED class=\"button\" name=\"undoSet\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		}
	?>
	</td>      
	<td width=20 valign="middle"> 
      <p align="center"><font color="#000000" size="3"></font></td>           
	<td width=54 valign="middle"><b>OMC:</b></td>           
	<td valign="middle">
	<?php
		echo "<input type=\"submit\" value=$strGet class=\"button\" name=\"readDisk\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		echo "<input type=\"submit\" value=$strSave class=\"button\" name=\"saveDisk\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		//echo "<input type=\"submit\" value=$strCompare class=\"button\" name=\"comDisk\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
	?>
	</td>    
  </tr>          
-->
	<tr>           
	<td width=72 valign="middle"><b>System:</b>	</td>            
	<td valign="middle">
	<?php
		echo "<input type=\"submit\" value=$strGet class=\"button\" name=\"readSys\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		echo "<input type=\"submit\" value=$strSet class=\"button\" name=\"saveSys\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		if ( TRUE == session_is_registered("e1SetFlag") ) {
			echo "<input type=\"submit\" value=\"Undo\" class=\"button\" name=\"undoSet\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		}else{
			echo "<input type=\"submit\" value=\"Undo\" DISABLED class=\"button\" name=\"undoSet\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		}
	?>
	</td>      
	<td width=2%></td>
	<td width=54 valign="middle"><b>Command:</b></td>           
	<td valign="middle">
	<?php
		echo "<input type=\"submit\" value=$strSave class=\"button\" name=\"saveComm\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		echo "<input type=\"submit\" value=$strReset class=\"button\" name=\"resetComm\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
	?>
	</td>    
	<td width=300 valign="left"> 
     <p align="center"><font color="#000000" size="3"></font></td>           
  </tr>          
</table>         
<p></p>
<TABLE  border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">     
<tr bgcolor="#E6E6E6">
<td>&nbsp;</td>     
<td colspan="7" align="center">MSC-0</td>     
<td colspan="7" align="center">MSC-1</td>   
<!-- <td>&nbsp;</td> -->     
</tr>
<tr bgcolor="#E6E6E6">
<td width="49" title="">Slot</td>     
<td width="49" title="">Port</td>     
<td width="49" title="E1 enable" >Flag</td>     
<td width="49" title="CIC of E1" >CIC</td> 
<td width="49" title="Assign TG to E1" >TG</td>     
<td width="49" title="E1 interface">Protocol</td>     
<td width="49" title="E1 CRC4 enable" >CRC4</td>
<td width="49" title="E1 MTP2 alarm enable" ><nobr>Alarm</nobr></td>
<td width="49" title="" >Port</td>     
<td width="49" title="E1 enable" >Flag</td>     
<td width="49" title="CIC of E1" >CIC</td> 
<td width="49" title="Assign TG to E1" >TG</td>     
<td width="49" title="E1 interface">Protocol</td>     
<td width="49" title="E1 CRC4 enable" >CRC4</td>
<td width="49" title="E1 MTP2 alarm enable" ><nobr>Alarm</nobr></td>
<!--
<td width="49" >Delete</td>
-->
</tr>
<?php
for($i=0;$i<128;$i++)
{
	$sNum = floor($i/8);
	$pNum = floor($i%8);

	if(!$isUpdate[0][$sNum])
		continue;

	if($pNum == 0 && $i > 0)
		echo "<tr bgcolor=\"#E6E6E6\">";
	else
		echo "<tr>";

	echo "<td>$sNum</font></td>";
	echo "<td><a href=javascript:openSet(0,$i)>$pNum</a></td>";
	echo "<td><font color=\"{$flagCol[$i]}\">{$eFlagArr[$flagArr[0][$i]][remark]}</font></td>";
	if($flagArr[0][$i]){
		echo "<td><font color=\"{$mscCol[3][$i]}\">{$mscArr[3][$i]}</font></td>";
		echo "<td><font color=\"{$mscArr[2][$i]}\">{$mscArr[2][$i]}</font></td>";
		echo "<td><font color=\"{$mscArr[1][$i]}\">{$mPtArr[$mscArr[1][$i]][remark]}&nbsp;</font></td>";
		echo "<td><font color=\"{$crcCol[$i]}\">{$eCrcArr[$crcArr[0][$i]][remark]}</font></td>";
		echo "<td><font color=\"{$dlinkCol[$i]}\">{$eDlinkArr[$dlinkArr[0][$i]][remark]}</font></td>";
	}else{
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td>--</td>";
	}
	echo "<td><a href=javascript:openSet(1,$i)>$pNum</a></td>";
	echo "<td><font color=\"{$flagCol[$i]}\">{$eFlagArr[$flagArr[1][$i]][remark]}</font></td>";
	if($flagArr[1][$i]){
		echo "<td><font color=\"{$mscCol[3][$i]}\">{$mscArr[3][$i+128]}</font></td>";
		echo "<td><font color=\"{$mscCol[2][$i]}\">{$mscArr[2][$i+128]}</font></td>";
		echo "<td><font color=\"{$mscCol[1][$i]}\">{$mPtArr[$mscArr[1][$i+128]][remark]}&nbsp;</font></td>";
		echo "<td><font color=\"{$crcCol[$i]}\">{$eCrcArr[$crcArr[1][$i]][remark]}</font></td>";
		echo "<td><font color=\"{$dlinkCol[$i]}\">{$eDlinkArr[$dlinkArr[1][$i]][remark]}</font></td>";
	}else{
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td>--</td>";
		echo "<td>--</td>";
	}
	//echo "<td><input type=\"checkbox\" name=\"C$i\" value=\"ON\"></td>";
	echo "</tr>";
}
echo "</table>";
echo "<input type=\"hidden\" name=\"wDef\" value=\"$wDef\">";
echo "</form>";
?>
</body>
</html>
