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

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

     返回值：无

 作者：      
      
修改注释：      
NO.1      
姓名：            
时间：      
修改说明：      
*********************************************************/  
require("../../inc/header.inc");
$helpId = "2.1.2.4"; 
$DEBUG = 0;
$sysInfoTable = 'OMC_PUB.sysInfo';
?>
<script LANGUAGE="JavaScript">           
function openSet(oType,tNum){
	var x,y;
	x = document.body.scrollLeft;
	y = document.body.scrollTop;

	URL="./tgEdit.php?oType="+oType+"&tNum="+tNum+"&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();
}


function delFirm(i)
{
	var delValue,x,y;
	x = document.body.scrollLeft;
	y = document.body.scrollTop;

	if(confirm('Do you want to delete the selected?')!=true){
		window.location.href='<?php echo $PHP_SELF;?>'+"?scroll_x="+x+"&scroll_y="+y;
	}else{
		window.location.href='<?php echo $PHP_SELF;?>?delete=1&delValue='+i+"&scroll_x="+x+"&scroll_y="+y;
	}
}

</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 = 20;

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

$nGetComm = 0;
$nSetComm = 3;

$nInteger = 2;
$nOctStr = 4;

$nProcFail = 0;
$nWaitProc = 1;
$nInProc   = 2;	
$nOutProc  = 3;

//Attributes of TG
$oidTg = "2.1.4"; 
$pTg = explode(".",$oidTg);
$i = 0;
$wTg = '';
while(isset($pTg[$i])) {
	$lNum = $i+1;
	if($DEBUG) echo "<br>pTg[$i]=$pTg[$i]";
	$wTg = $wTg." AND level_$lNum = $pTg[$i] ";
	$i++;
}


/************get default value**************/
$defSql = " SELECT initValue FROM paramConf WHERE keyId > 0 ".$wTg;
$defRes = @mysqli_query($pubConn,$defSql);
$defRow = @mysqli_fetch_array($defRes);
$defaultValue = $defRow[initValue];
//echo "<br>defaultValue=$defaultValue";

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

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

	$incomingCallTypeArr=array(
			array('num' => '0',  'remark' => 'Normal', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'In', 'color' => '#0000FF')
	);

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

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

if($DEFAULT_SYS == 'MSC'){
	$tgTypeArr=array(
			array('num' => '0',  'remark' => 'PSTN',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'HPLMN',		'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'VPLMN',		'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'SUB',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => 'IP',			'color' => '#0000FF'),
			array('num' => '5',  'remark' => 'Intercept',	'color' => '#0000FF'),
			array('num' => '6',  'remark' => 'Interconnection',	'color' => '#0000FF')
	);
}else{
	$tgTypeArr=array(
			array('num' => '0',  'remark' => 'PSTN',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'HPLMN',		'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'VPLMN',		'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'SUB',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => 'IP',			'color' => '#0000FF'),
			//array('num' => '5',  'remark' => 'GP',			'color' => '#0000FF'),
			array('num' => '5',  'remark' => 'Intercept',	'color' => '#0000FF'),			
			array('num' => '6',  'remark' => 'Interconnection',	'color' => '#0000FF')
	);
}
	$atFlagArr=array(
			array('num' => '0',  'remark' => 'N', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'Y', 'color' => '#0000FF')
	);

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

	$netTypeArr=array(
			array('num' => '0',  'remark' => 'Inter',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'Inter-S',	'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'NAT',			'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'NI-S',		'color' => '#0000FF'),
			array('num' => '4',  'remark' => '--',					'color' => '#0000FF')
	);

	$cirTypeArr=array(
			array('num' => '0',  'remark' => 'Clockwise',		'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'Anti-C',	'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'Odd',				'color' => '#0000FF'),
			array('num' => '3',  'remark' => 'Even',			'color' => '#0000FF'),
			array('num' => '4',  'remark' => '--',				'color' => '#0000FF')
	);

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

if($DEFAULT_SYS == 'MSC'){
	$tgLocationArr=array(
			array('num' => '0',  'remark' => 'MSC-0', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'MSC-1', 'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'Both',  'color' => '#FF0000'),
			array('num' => '3',  'remark' => 'Spare', 'color' => '#0000FF')
	);
}else{
	$tgLocationArr=array(
			array('num' => '0',  'remark' => 'SN-0', 'color' => '#FF0000'),
			array('num' => '1',  'remark' => 'SN-1', 'color' => '#0000FF'),
			array('num' => '2',  'remark' => 'Both',  'color' => '#FF0000'),
			array('num' => '3',  'remark' => 'Spare', '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);
	do
	{
		$temCommState = $selRow[commState];
		if($selRow[remark]){
			$remark = $selRow[remark];
			//echo "<br>remark=$remark";
		}
		//echo "<br>temCommState=$temCommState";
		if($temCommState == $nWaitProc)
			return($nWaitProc);
		elseif($temCommState == $nInProc)
			return($nInProc);
		elseif($temCommState == $nOutProc)
			$commState = $nOutProc;
		else
			$commState = 0;
	}while($selRow  = @mysqli_fetch_array($selRes));

	return($commState);
}



//****************************************************************
//函数
//	从Buffer_2拷贝到$buffer_1
//函数说明:
//	
//变量说明: 
//	无
//	
//                                                             
//返回值：$paramType
//
//
//	
//作者
//      
//修改注释：      
//NO.1      
//姓名：            
//时间：      
//修改说明：    
//----------------------------------------------------------

function copyBuffer($buffer_1,$buffer_2,$wDef,$type='1')
{     
	global $sysTypeNo_0,$sysTypeNo_1,$db_0,$db_1,$tb_0,$tb_1,$tb_2,$wTg;
	$DEBUG = 0;
	$addWer = "	AND (LENGTH($buffer_2) > 0) AND $buffer_2 != 'Null' AND $buffer_2 NOT LIKE 'Error%' ";

	//Attributes of TG
	if($type){
		$uTgSql = " UPDATE $tb_2 set $buffer_1=$buffer_2 WHERE subSysNo = '99' ".$wTg.$addWer; 
	}else{
		$uTgSql = " UPDATE $tb_2 set $buffer_1=$buffer_2 WHERE subSysNo = '99' ".$wTg.$wDef.$addWer; 
	}
	if($DEBUG) echo " <br>uTgSql=$uTgSql ";
	$uTgRes = @mysqli_query($pubConn,$uTgSql);

	echo mysqli_error($pubConn);

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

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

	if($commType == $nGetComm)
		$showType = "Get ";
	else
		$showType = "Set ";


	//2.1.4
	$sysId = $sysTypeNo_1."_99";
	$objIdStr = "2.1.4.*";
	$cic = sysCommSend($sysId,$commType,$objIdStr);

	$i = 0;
	while(1)
	{
		//echo "<br>i=$i";
		if($i == 0)
			echo "<br>$showType Attributes of TG&nbsp;&nbsp;";
		if($i > $maxNum){
			echo "<br><font size=\"2\" color=\"#FF0000\">Timeout</font>";
			flush();
			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>";

			flush();
			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);
	$tgSetFlag = 1;
	session_register("tgSetFlag");

	//if get fail ( undoValue = NULL ) , unregister set flag.
	$where	= "WHERE level_1=2 AND level_2=1 AND level_3=4";
	$selSql	= "SELECT distinct undoValue FROM $tb_2 $where ORDER BY undoValue";
	if($DEBUG) echo "selSql(1)=$selSql,db=$db_1<br>";
	$selRes	= @mysqli_query($pubConn,$selSql);
	$selRow = mysqli_fetch_array($selRes);
	if ('' == $selRow[0]) {
		session_unregister("tgSetFlag");
	}

	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("tgSetFlag");

	sleep(1);
	echo "<script language=\"javascript\">";
	//echo "window.location.href='$PHP_SELF';";
	echo "</script>";
}
//end undoSet
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";
	$loadType = 1;
	$edCin=copyBuffer($buffer_1,$buffer_2,$wDef,$loadType);
	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($delete)
{
	$delSql = " UPDATE $tb_2 set initValue = '$defaultValue' WHERE subSysNo = '99' ".$wTg. " AND instanceNo = $delValue ";
	//echo "<br>delSql=$delSql";
	$delRes = @mysqli_query($pubConn,$delSql);
	echo mysqli_error($pubConn);
}
elseif($saveComm) {
	session_unregister("tgSetFlag");
	$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";
	$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\" 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
			FROM $sysInfoTable
			WHERE sysTypeNo='$sysTypeNo_0' AND baseStat > '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];
	$cardArr[$sysNo][subSysNo] = $getRow[baseStat];

}while($getRow = @mysqli_fetch_array($getRes));

/************select value to see************/
//Attributes of TG
$tgSql = " SELECT instanceNo,initValue,initValue,readValue FROM $tb_2 WHERE subSysNo = '99' ".$wTg." ORDER BY instanceNo "; 
if($DEBUG) echo "<br>tgSql=$tgSql";
$tgRes = @mysqli_query($pubConn,$tgSql);
$tgRow = @mysqli_fetch_array($tgRes);
echo mysqli_error($pubConn);
$wDef = " AND (";
$defaultValue_1 = "000000000A0382FF00";
do
{
	$instanceNo = $tgRow[instanceNo];
	$initValue = $tgRow[initValue];

	//echo "<br>$initValue == $defaultValue == $defaultValue_1";
	if($initValue == $defaultValue || $initValue == $defaultValue_1){
		$tgShow[$instanceNo] = 0;
	}else{
		$tgShow[$instanceNo] = 1;
		
		$wDef = $wDef." instanceNo = $instanceNo OR ";
	}
	
	//echo "<br>tgShow[$instanceNo]=$tgShow[$instanceNo]";

	if($DEBUG)echo "<br>initValue=$initValue";
	$dpc = $tgArr[$instanceNo][2] = substr($initValue,2,6);
	if($DEBUG)echo "<br>dpc=$dpc";

	$hex_4 = substr($initValue,8,2);
	if($DEBUG)echo "<br>hex_4=$hex_4";
	$bin_4 = omc_keep_length(DecBin(HexDec($hex_4)),0,8);
	if($DEBUG)echo "<br>bin_4=$bin_4";

	$tgFlag = $tgArr[$instanceNo][0] = substr($bin_4,7,1);
	if($DEBUG)echo "<br>tgFlag=$tgFlag";

	$cdrFlag = $tgArr[$instanceNo][3] = substr($bin_4,6,1);
	if($DEBUG)echo "<br>cdrFlag=$cdrFlag";

	$voFlag = $tgArr[$instanceNo][4] = substr($bin_4,5,1);
	if($DEBUG)echo "<br>voFlag=$voFlag";

	$tgType = $tgArr[$instanceNo][1] = BinDec(substr($bin_4,2,3));
	if($DEBUG)echo "<br>tgType=$tgType";

	$atFlag = $tgArr[$instanceNo][5] = substr($bin_4,1,1);
	if($DEBUG)echo "<br>atFlag=$atFlag";

	$lpFlag = $tgArr[$instanceNo][7] = substr($bin_4,0,1);

	$netType = $tgArr[$instanceNo][8] = HexDec(substr($initValue,10,2));
	if($DEBUG)echo "<br>netType$netType";

	$hex_6 = substr($initValue,12,2);
	if($DEBUG)echo "<br>hex_6=$hex_6";
	$bin_6 = omc_keep_length(DecBin(HexDec($hex_6)),0,8);
	if($DEBUG)echo "<br>bin_6=$bin_6";
	
	$cirType = $tgArr[$instanceNo][9] = BinDec(substr($bin_6,6,2));
	if($DEBUG)echo "<br>cirType=$cirType";
	
	$backFlag = $tgArr[$instanceNo][10] = substr($bin_6,5,1);
	if($DEBUG)echo "<br>backFlag=$backFlag";

	$tgLct = $tgArr[$instanceNo][11] = BinDec(substr($bin_6,0,2));
	if($DEBUG)echo "<br>tgLct=$tgLct";

	$mptyFlag = $tgArr[$instanceNo][12] = BinDec(substr($bin_6,2,1));
	if($DEBUG)echo "<br>mptyFlag=$mptyFlag";

	$tgNum = $tgArr[$instanceNo][6] = HexDec(substr($initValue,14,2));
	if($DEBUG)echo "<br>tgNum=$tgNum";

	$tandemFlag = $tgArr[$instanceNo][13] = HexDec(substr($initValue,16,2));
	if (1 < $tgArr[$instanceNo][13]) {
		$tgArr[$instanceNo][13] = 1;
	}
	if($DEBUG)	echo "<br>tandemFlag={$tgArr[$instanceNo][13]}";

	$incomingCallType = $tgArr[$instanceNo][14] = HexDec(substr($initValue,18,2));
	if (1 < $tgArr[$instanceNo][14]) {
		$tgArr[$instanceNo][14] = 1;
	}
	if($DEBUG)	echo "<br>incomingCallType={$tgArr[$instanceNo][14]}";

}while($tgRow = @mysqli_fetch_array($tgRes));

$wDef = substr($wDef,0,-3);
$wDef = $wDef.")";
if(strlen($wDef) < 10){
	$wDef = 'instanceNo < 0';
}
if($DEBUG)echo "<br>wDef=$wDef";
$tgShow[0] = "1";

$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 "<form method=\"POST\" name=\"confForm\" action=\"$PHP_SELF\">";
?>
<?php
echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "$strConfiguration > $strNetwork > $DEFAULT_SYS > $strTrunkGroup";
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>    
	<?php
		echo "<td width=200 valign=\"middle\"><nobr><b>System:</b>";
		echo "<input type=\"submit\" class=\"button\" value=$strGet name=\"readSys\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		echo "<input type=\"submit\" class=\"button\" value=$strSet name=\"saveSys\" 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("tgSetFlag") ) {
			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\">";
		}
	?>
	</nobr>
	</td>        
	<?php
		echo "<td width=200 valign=\"middle\"><nobr><b>OMC:</b>";	
		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\">";
	?>
	</nobr>
	</td>    
	<td width=200 valign="middle"><nobr><b>New:</b><input type="button" value="<?php echo $strAdd; ?>" onclick="javascript:openSet(1,0);" name="add" style="left: 3; top: 2; width: 60; height: 25; position: relative">
	</nobr>
	</td>    
  </tr>   
-->  
    <tr>    
	<?php
		echo "<td width=200 valign=\"middle\"><nobr><b>System:</b>";
		echo "<input type=\"submit\" class=\"button\" value=$strGet name=\"readSys\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		echo "<input type=\"submit\" class=\"button\" value=$strSet name=\"saveSys\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
		if ( TRUE == session_is_registered("tgSetFlag") ) {
			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\">";
		}
	?>
	</nobr>
	</td>        
	<?php
		echo "<td width=200 valign=\"middle\"><nobr><b>Command:</b>";	
		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\">";
	?>
	</nobr>
	</td>    
	<td width=200 valign="middle"><nobr><b>New:</b><input type="button" value="<?php echo $strAdd; ?>" onclick="javascript:openSet(1,0);" name="add" style="left: 3; top: 2; width: 60; height: 25; position: relative">
	</nobr>
	</td>    
  </tr>   
</table>         
<p></p>
<TABLE  border="1" width="100%" cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF">     
<tr bgcolor="#E6E6E6">
<td width="6%" title="">No.</td>     
<td width="8%" title="TG enable">Flag</td>     
<td width="8%" title="TG category">To</td>     
<td width="8%" title="DPC">DPC</td> 
<td width="8%" title="CDR flag">CDR</td>     
<td width="8%" title="Voice prompt">Voice</td>
<td width="8%" title="Alternative TG flag">ALT flag</td>     
<td width="8%" title="Alternative TG">ALT TG</td>
<td width="8%" title="Incoming loopback">Loopback</td>
<td width="8%" title="Network indicator">NI</td>     
<td width="8%" title="Circuit selection">Circuit</td>     
<td width="8%" title="Collision back off">Back off</td>    
<td width="8%" title="TG location">Location</td>    
<td width="8%" title="Mpty enable">MPTY</td>    
<td width="8%" title="Tandem">Tandem</td>  
<td width="8%" title="Incoming call type">Incoming call type</td>  
<td width="6%" title="">Delete</td>
</tr>
<?php
for($i=0;$i<256;$i++){
	$sNum = floor($i/8);
	$pNum = floor($i%8);

	//if($tgShow[$i]){
	if (1 == $tgArr[$i][0]) {
		if($pNum == 0 && $i > 0)
			echo "<tr bgcolor=\"#E6E6E6\">";
		else
			echo "<tr>";
		echo "<td><a href=javascript:openSet(0,$i)>$i</a></td>";
		echo "<td><nobr>{$tgFlagArr[$tgArr[$i][0]][remark]}</nobr></td>";
		echo "<td><nobr>{$tgTypeArr[$tgArr[$i][1]][remark]}</nobr></td>";
		echo "<td><nobr>{$tgArr[$i][2]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$cdrFlagArr[$tgArr[$i][3]][remark]}</nobr></td>";
		echo "<td><nobr>{$voFlagArr[$tgArr[$i][4]][remark]}</nobr></td>";
		echo "<td><nobr>{$atFlagArr[$tgArr[$i][5]][remark]}</nobr></td>";
		echo "<td><nobr>{$tgArr[$i][6]}&nbsp;</nobr></td>";
		echo "<td><nobr>{$lpFlagArr[$tgArr[$i][7]][remark]}</nobr></td>";
		echo "<td><nobr>{$netTypeArr[$tgArr[$i][8]][remark]}</nobr></td>";
		echo "<td><nobr>{$cirTypeArr[$tgArr[$i][9]][remark]}</nobr></td>";
		echo "<td><nobr>{$backFlagArr[$tgArr[$i][10]][remark]}</nobr></td>";
		echo "<td><nobr>{$tgLocationArr[$tgArr[$i][11]][remark]}</nobr></td>";
		echo "<td><nobr>{$mptyFlagArr[$tgArr[$i][12]][remark]}</nobr></td>";
		echo "<td>{$tandemFlagArr[$tgArr[$i][13]][remark]}</td>";
		echo "<td>{$incomingCallTypeArr[$tgArr[$i][14]][remark]}</td>";
		echo "<td><input type=\"checkbox\" name=\"C$i\" value=\"ON\" onClick=\"javascript:delFirm($i)\" ></td>";
		echo "</tr>";

	}
}
echo "</table>";
echo "<input type=hidden name=\"wDef\" value=\"$wDef\">";
echo "</form>";
?>
</body>
</html>
