<?php
require("../sub_inc/commfunc.php");
$DEBUG = 0;
$url = "$PHP_SELF?backurl=$backurl";
if($DEBUG) echo "<br>正在调试中！！";
?>
<script LANGUAGE="JavaScript">       
function delFirm(flag,No1,No2)
{
	var delValue,x,y;
	confirmStr = 'Do you want to delete the selected?';
	
	if(confirm(confirmStr) != true)
		window.location.href='<?php echo $url;?>';
	else
	{
		if(flag == 'e1')
			window.location.href='<?php echo $url;?>&&delflag='+flag+'&delValue1='+No1+'&delValue2='+No2;
		else if(flag == 'tg')
			window.location.href='<?php echo $url;?>&&delflag='+flag+'&delValue='+No1;
	}
}
function slctTG(item,flag,No1)
{
	if(confirm('Do you want to set this TG?') != true)
		window.location.href='<?php echo $url;?>';
	else
	{
		if(item.checked == true)
			setValue = 'FD';
		else
			setValue = 'FF';
		window.location.href='<?php echo $url;?>&&delflag='+flag+'&delValue='+No1+'&setValue='+setValue;
	}
}
</script>
<body topmargin="0" leftmargin="12">

<?php

$helpID = "1.1.1";

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

$nGetComm = 0;
$nSetComm = 3;
	
$maxNum = 120;

$msc_paramTable = 'OBJ_322.param_99';
$msc_parConfTable = 'OBJ_322.paramConf';
$e1_oid = array('2.1.4','2.4.1','2.4.2','2.4.3','2.4.4');
$mtp3_sqltable = 'OBJ_222.param_99';
$mtp3_oid = '2.9.0';
$linkset_oid = '2.4.1';
$link_oid = '2.5.1';
$route_oid = '2.6.4';
$sg_oid = '2.9.0';
$pubdb = 'OMC_PUB';

$sysinfo = 'OMC_PUB.sysInfo';
$sysTypeNo = '322';


//get system ip
{
	for($i=0; $i < 2; $i++)
	{
		$getsql = "SELECT ip FROM $sysinfo where sysTypeNo = $sysTypeNo and sysNo = '$i'";
		if($DEBUG) echo "getsql = $getsql<br>";
		$ip_init = @mysqli_query($pubConn,$getsql);
		$ip_init = mysqli_fetch_array($ip_init);
		$ip_init = $ip_init[0];
		$ip_array = explode('.',$ip_init);
		
		for($j = 0;$j < sizeof($ip_array);$j++)
		{
			$ip = $ip_array[$j];
			$mss_ip[$i] .= omc_keep_length(dechex($ip),'0','2');
		}	
	}
	$mss_ip[0] = omc_keep_length($mss_ip[0],'0','8');
	$mss_ip[1] = omc_keep_length($mss_ip[1],'0','8');
	if($DEBUG)
	{
		echo "<br>mss0_ip = $mss_ip[0]<br>";	
		echo "mss1_ip = $mss_ip[1]<br>";	
	}
}
				
if($_SERVER['REQUEST_METHOD'] == "POST")
{
	//update E1 port
	{
		$failFlag = 0;
		if($DEBUG) 
		{
			echo "e1_num = $e1_num<br>";
			echo "avail_cic = $avail_cic<br>";
		}
		
		for($i=0; $i < $e1_num; $i++)
		{
			$org_253 = ${'e1_253_org_'.$i};
			$org_254 = ${'e1_254_org_'.$i};
			
			$new_253 = ${'e1_253_'.$i};
			$new_254 = ${'e1_254_'.$i};
			
			$e1_cic_org = ${'e1_cic_'.$i};
	
			if($DEBUG)
			{
				echo "<br>org_253 = $org_253<br>";
				echo "org_254 = $org_254<br>";
				echo "new_253 = $new_253<br>";
				echo "new_254 = $new_254<br>";
				echo "e1_cic_org = $e1_cic_org<br>";
			}
			
			if($new_253 == '' || $new_254 == '')
			{
				echo "<script LANGUAGE=\"JavaScript\">";
				echo "alert('Parameter can\'t be blank!');";
				echo " </script>";
				$failFlag = 1;
				continue;	
			}
			
			//if($org_253 == $new_253 && $org_254 == $new_254)
				//continue;
			
			$flag_253 = 0;
			$flag_254 = 0;
			$flag_126 = 0;
			$flag_127 = 0;
			if($org_253 != $new_253)
			{
				$objWhereStr = getLevelWhere($e1_oid[4]);
				$getsql = "SELECT initValue FROM $msc_paramTable where $objWhereStr and instanceNo = '$new_253'";
				if($DEBUG) echo "getsql = $getsql<br>";
				$init_253 = @mysqli_query($pubConn,$getsql);
				$init_253 = mysqli_fetch_array($init_253);
				$init_253 = $init_253[0];
				$flag_253 = getBitValue($init_253,'0.0-0.0');
				
				$objWhereStr = getLevelWhere($link_oid);
				$getsql = "SELECT initValue FROM $mtp3_sqltable where $objWhereStr and instanceNo = '$new_253'";
				if($DEBUG) echo "getsql = $getsql<br>";
				$link_init = @mysqli_query($pubConn,$getsql);
				$link_init = mysqli_fetch_array($link_init);
				$link_init = $link_init[0];
				$flag_126 = getBitValue($link_init,'06.5-06.5');
			}
			
			if($org_254 != $new_254)
			{
				$objWhereStr = getLevelWhere($e1_oid[4]);
				$getsql = "SELECT initValue FROM $msc_paramTable where $objWhereStr and instanceNo = '$new_254'";
				if($DEBUG) echo "getsql = $getsql<br>";
				$init_254 = @mysqli_query($pubConn,$getsql);
				$init_254 = mysqli_fetch_array($init_254);
				$init_254 = $init_254[0];			
				$flag_254 = getBitValue($init_254,'0.0-0.0');
				
				$objWhereStr = getLevelWhere($link_oid);
				$getsql = "SELECT initValue FROM $mtp3_sqltable where $objWhereStr and instanceNo = '$new_254'";
				if($DEBUG) echo "getsql = $getsql<br>";
				$link_init = @mysqli_query($pubConn,$getsql);
				$link_init = mysqli_fetch_array($link_init);
				$link_init = $link_init[0];
				$flag_127 = getBitValue($link_init,'06.5-06.5');
			}
			
			if($flag_253 == 1 || $flag_254 == 1 || $flag_126 == 1 || $flag_127 == 1)
			{
				if($flag_253 == 1 || $falg_126 == 1) $alert_no = $new_253;
				else $alert_no = $new_254;
				
				echo "<script LANGUAGE=\"JavaScript\">";
				echo "alert('E1 port $alert_no is now in use!');";
				echo " </script>";	
				$failFlag = 1;
				continue;
			}
			//update
			if($e1_cic_org == (hexdec('FF')+1)/32)
				$cic_init = $avail_cic;
			else
				$cic_init = $e1_cic_org;
			if($cic_init >= 8)
			{
				echo "<script LANGUAGE=\"JavaScript\">";
				echo "alert('The parameter table is full, unable to add new!');";
				echo " </script>";	
				$failFlag = 1;
				continue;	
			}
			
			$slc_no = $cic_init;
			$slc_no = omc_keep_length(dechex($slc_no),'0','2');
			$cic_init = $cic_init * 32;
			$cic_init = omc_keep_length(dechex($cic_init),'0','2');
			
			if($mss_ip[0] != '' and $mss_ip[1] != '')
			{								 				
				$link_init_arr = array('7E00AC12620101000000000000000000000007','7F00AC12630101000000000000000000000007');
				$link_init_arr[0] = setBitValue($link_init_arr[0],'02.0-05.7',$mss_ip[0]);
				$link_init_arr[0] = setBitValue($link_init_arr[0],'15.0-18.7',$mss_ip[1]);
				$link_init_arr[1] = setBitValue($link_init_arr[1],'02.0-05.7',$mss_ip[1]);
				$link_init_arr[1] = setBitValue($link_init_arr[1],'15.0-18.7',$mss_ip[0]);
			}

			for($k=253; $k < 255; $k++)
			{
				$org = ${'org_'.$k};
				$new = ${'new_'.$k};
				if($org != $new && $org != '')
				{
					$objWhereStr = getLevelWhere($e1_oid[1]);//e1 interface
						$setsql = "update $msc_paramTable set initValue = '00' where $objWhereStr and instanceNo = '$org'";
						mysqli_query($pubConn,$setsql);
						echo mysqli_error($pubConn);
						if($DEBUG) echo "$setsql<br>";
				
					$objWhereStr = getLevelWhere($e1_oid[2]);//assign tg to e1
						$setsql = "update $msc_paramTable set initValue = 'EE' where $objWhereStr and instanceNo = '$org'";
						mysqli_query($pubConn,$setsql);
						echo mysqli_error($pubConn);
						if($DEBUG) echo "$setsql<br>";
					
					$objWhereStr = getLevelWhere($e1_oid[3]);//cic
						$setsql = "update $msc_paramTable set initValue = '00' where $objWhereStr and instanceNo = '$org'";
						mysqli_query($pubConn,$setsql);
						echo mysqli_error($pubConn);
						if($DEBUG) echo "$setsql<br>";
					
					$objWhereStr = getLevelWhere($e1_oid[4]);//e1 flag
						$setsql = "update $msc_paramTable set initValue = '00' where $objWhereStr and instanceNo = '$org'";
						mysqli_query($pubConn,$setsql);
						echo mysqli_error($pubConn);
						if($DEBUG) echo "$setsql<br>";
						
					$objWhereStr = getLevelWhere($link_oid);
						$setsql = "update $mtp3_sqltable set initValue = '8000FFFFFFFF000000000000000000FFFFFFFF' 
							where $objWhereStr and instanceNo = '$org'";
						mysqli_query($pubConn,$setsql);
						echo mysqli_error($pubConn);
						if($DEBUG) echo "$setsql<br>";
				}
				
				$objWhereStr = getLevelWhere($e1_oid[1]);//'01 = ISUP'
					$setsql = "update $msc_paramTable set initValue = '01' where $objWhereStr and instanceNo = '$new'";
					mysqli_query($pubConn,$setsql);
					echo mysqli_error($pubConn);
					if($DEBUG) echo "$setsql<br>";
				
				$tg_init = dechex($k);
				$objWhereStr = getLevelWhere($e1_oid[2]);
					$setsql = "update $msc_paramTable set initValue = '$tg_init' where $objWhereStr and instanceNo = '$new'";
					mysqli_query($pubConn,$setsql);
					echo mysqli_error($pubConn);
					if($DEBUG) echo "$setsql<br>";
				
				$objWhereStr = getLevelWhere($e1_oid[3]);
					$setsql = "update $msc_paramTable set initValue = '$cic_init' where $objWhereStr and instanceNo = '$new'";
					mysqli_query($pubConn,$setsql);
					echo mysqli_error($pubConn);
					if($DEBUG) echo "$setsql<br>";
				
				$objWhereStr = getLevelWhere($e1_oid[4]);
					$setsql = "update $msc_paramTable set initValue = '03' where $objWhereStr and instanceNo = '$new'";
					mysqli_query($pubConn,$setsql);
					echo mysqli_error($pubConn);
					if($DEBUG) echo "$setsql<br>";
				
				$index = $k - 253;
				$e1_link_init = setBitValue($link_init_arr[$index],'01.0-01.7',$slc_no);
				$e1_link_init = setBitValue($e1_link_init,'08.0-08.7',$slc_no);
				$e1_link_init = strtoupper($e1_link_init);
				$objWhereStr = getLevelWhere($link_oid);
					$setsql = "update $mtp3_sqltable set initValue = '$e1_link_init' where $objWhereStr and instanceNo = '$new'";
					mysqli_query($pubConn,$setsql);
					echo mysqli_error($pubConn);
					if($DEBUG) echo "$setsql<br>";
				
				//open k8e1 enable
				open8ke1Enable($new,1);
			}
		}
	}
	//update Loopback trunk group
	{
		$spcTree_array = array(
		array('International',		'14-bit',	'spc_int_14',	 '2.3.1'),
		array('International spare','14-bit',	'spc_int_sp_14', '2.3.2'),
		array('National',			'14-bit',	'spc_nat_14',	 '2.3.3'),
		array('National spare',		'14-bit',	'spc_nat_sp_14', '2.3.4'),
		array('International',		'24-bit',	'spc_int_24',	 '2.3.5'),
		array('International spare','24-bit',	'spc_int_sp_24', '2.3.6'),
		array('National',			'24-bit',	'spc_nat_24',	 '2.3.7'),
		array('National spare',		'24-bit',	'spc_nat_sp_24', '2.3.8')
		);
		
		$querysql = "select initValue from $mtp3_sqltable where level_1 = '2' and level_2 = '2'  and level_3 = '0'";
		$result = mysqli_query($pubConn,$querysql);
		$indicator = mysqli_fetch_array($result);
		echo mysqli_error($pubConn);
		if($DEBUG)echo "<br>indicator = {$indicator[0]}<br>";
		
		for($i = 0; $i < 4; $i++)
		{
			$flag = getBitValue($indicator[0],"0.$i");
			if ($flag == 0)
				$spc_index[$i] = $i;
			else
				$spc_index[$i] = $i+4;
		}
		
		for($i = 0; $i < 4; $i ++)
		{
			$level_array = explode('.',$spcTree_array[$spc_index[$i]][3]);
			
			for($j = 0;$j < sizeof($level_array);$j ++)
			{
				$level_no = $j + 1;
				${level_.$level_no} = $level_array[$j];
			}
			$getsql = "select initValue from $mtp3_sqltable 
			where level_1 = '$level_1' and level_2 = '$level_2' and level_3 = '$level_3' ";
			$result = mysqli_query($pubConn,$getsql);
			$row[$i] = mysqli_fetch_array($result);
			$row[$i] = $row[$i][0];
			if($DEBUG)echo "getsql = $getsql<br>";
			if($DEBUG)echo "spc_$i=$row[$i]<br>";
		}
		
//		$dpc1 = dechex(hexdec($row[3]) + 1);//14bit NS
//		$dpc2 = dechex(hexdec($row[3]) + 2);
		$dpc1 = dechex(253);//arwean modified 2006-8-21 15:43
		$dpc2 = dechex(254);
		
		$initValue_126 = '0000000F00000000000000000000000000000000';
		$initValue_127 = '0000000F00000000000000000000000000000000';
		
		$dpc1 = omc_keep_length($dpc1,'0','6');
		$dpc2 = omc_keep_length($dpc2,'0','6');
		
		$initValue_126 = strtoupper(setBitValue($initValue_126,'0.0-2.7',$dpc1));
		$initValue_127 = strtoupper(setBitValue($initValue_127,'0.0-2.7',$dpc2));
		
		$objWhereStr = getLevelWhere($linkset_oid);//2.4.1
		$setsql = "update $mtp3_sqltable set initValue = '$initValue_126' where $objWhereStr and instanceNo = '126'";
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql<br>";
		
		$setsql = "update $mtp3_sqltable set initValue = '$initValue_127' where $objWhereStr and instanceNo = '127'";
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql<br>";
		
		$initValue_254 = '0000007E80';
		$initValue_255 = '0000007F80';
		
		$initValue_254 = setBitValue($initValue_254,'0.0-2.7',$dpc1);
		$initValue_255 = setBitValue($initValue_255,'0.0-2.7',$dpc2);
		
		$objWhereStr = getLevelWhere($route_oid);//2.6.4
		$setsql = "update $mtp3_sqltable set initValue = '$initValue_254' where $objWhereStr and instanceNo = '254'";
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql<br>";
		
		$setsql = "update $mtp3_sqltable set initValue = '$initValue_255' where $objWhereStr and instanceNo = '255'";
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql<br>";
		
		//====old								
		//$initValue_253 = '000000FD730304FE0000EE0000000000';
		//$initValue_254 = '000000FE330341FF0000EE0000000000';
		//====new
		$initValue_253 = '000000FD450304FE00006E0000000000';
		                  
		$initValue_254 = '000000FE450341FD00006E0000000000';	
		                 							
		$dpc1 = omc_keep_length($dpc1,'0','8');
		$dpc2 = omc_keep_length($dpc2,'0','8');
		$initValue_253 = strtoupper(setBitValue($initValue_253,'0.0-3.7',$dpc1));
		$initValue_254 = strtoupper(setBitValue($initValue_254,'0.0-3.7',$dpc2));
		
		$objWhereStr = getLevelWhere($e1_oid[0]);
		$setsql = "update $msc_paramTable set initValue = '$initValue_253' where $objWhereStr and instanceNo = '253'";
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql<br>";
		
		$setsql = "update $msc_paramTable set initValue = '$initValue_254' where $objWhereStr and instanceNo = '254'";
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql<br>";
		
		$initValue_252 = '01010000000000';
		$initValue_253 = '01000000000000';
		
		$initValue_252 = setBitValue($initValue_252,'03.0-06.7',$mss_ip[1]);
		$initValue_253 = setBitValue($initValue_253,'03.0-06.7',$mss_ip[0]);
		
		$objWhereStr = getLevelWhere($sg_oid);
		$setsql = "update $mtp3_sqltable set initValue = '$initValue_252' where $objWhereStr and instanceNo = '252'";
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql<br>";
		
		$setsql = "update $mtp3_sqltable set initValue = '$initValue_253' where $objWhereStr and instanceNo = '253'";
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql<br>";
	}
	//update serverd tg
	for($i=0; $i< $tg_no; $i++)
	{
		$checkboxName=${"servedTg_$i"};
		$inst = ${"servedTgIns_$i"};
		$objWhereStr = getLevelWhere($e1_oid[0]);
		$getsql = "SELECT initValue FROM $msc_paramTable where $objWhereStr and instanceNo = '$inst'";
		if($DEBUG) echo "getsql = $getsql<br>";
		$tg_init = @mysqli_query($pubConn,$getsql);
		$tg_init = mysqli_fetch_array($tg_init);
		$tg_init = $tg_init[0];
		
		if(isset($checkboxName))
		{
			$setValue='FD';
			$tg_init = setBitValue($tg_init,'4.6-4.6','1');
		}
		
		else
		{
			$setValue='FF';
			$tg_init = setBitValue($tg_init,'4.6-4.6','0');
		}
		
		$tg_init = setBitValue($tg_init,'7.0-7.7',$setValue);
				
		$objWhereStr = getLevelWhere($e1_oid[0]);
		$setsql = "update $msc_paramTable set initValue = '$tg_init' where $objWhereStr and instanceNo = '$inst'";
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
	}//end update servered tg.
	if(!$DEBUG && $failFlag)
	{
		echo "<script LANGUAGE=\"JavaScript\">";
		echo "\n window.location.href=\"$url\";";
		echo "\n </script>";
	}
	else if(!$DEBUG && isset($Set))
	{
		echo "<script LANGUAGE=\"JavaScript\">";
		echo "\n window.location.href=\"$backurl\";";
		echo "\n </script>";
	}	
}

if(isset($delflag))
{
	if($delflag == 'e1')
	{
		for($i=1;$i < 3; $i++)
		{
			$instanceNo = ${'delValue'.$i};
			delete_e1($instanceNo);
			//disable 8ke1.
			open8ke1Enable($instanceNo,0);
		}
	}
	else if($delflag == 'tg')
	{
		$objWhereStr = getLevelWhere($e1_oid[0]);
		$getsql = "SELECT initValue FROM $msc_paramTable where $objWhereStr and instanceNo = '$delValue'";
		if($DEBUG) echo "getsql = $getsql<br>";
		$tg_init = @mysqli_query($pubConn,$getsql);
		$tg_init = mysqli_fetch_array($tg_init);
		$tg_init = $tg_init[0];
		if($setValue=='FF')
			$tg_init = setBitValue($tg_init,'4.6-4.6','0');
		else
			$tg_init = setBitValue($tg_init,'4.6-4.6','1');
			
		$tg_init = setBitValue($tg_init,'7.0-7.7',$setValue);
				
		$objWhereStr = getLevelWhere($e1_oid[0]);
		$setsql = "update $msc_paramTable set initValue = '$tg_init' where $objWhereStr and instanceNo = '$delValue'";
		mysqli_query($pubConn,$setsql);
		echo mysqli_error($pubConn);
		if($DEBUG) echo "$setsql<br>";	
	}
	if(!$DEBUG)
	{
		echo "<script LANGUAGE=\"JavaScript\">";
		echo "\n window.location.href=\"$url\";";
		echo "\n </script>";
	}	

}

//==========================================================
//输出并显示数据
//==========================================================
echo "<form method=\"POST\" name=\"Set\" action=\"$url\">";
echo "<input type=\"hidden\" name=\"sg_ins_no\" value=\"$sg_unuesd\">";

echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "$strConfiguration > <a href=\"../overview/overview.php\">Network</a> > <a href=\"$backurl\">MSC</a> > <a href=\"#\">Loopback</a>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
//showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";

echo "<table width=\"100%\">";
echo "<tr><td width=70%>&nbsp";
//echo "<b>MSS  interconnection:&nbsp;&nbsp;</b>";
echo "<td width=\"20%\">";
echo "<input type=\"submit\" value=$strSave class=\"button\" name=\"Set\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";	
echo "&nbsp;&nbsp;&nbsp;&nbsp;";
echo "<input type=\"reset\" value=$strUndo  class=\"button\" name=\"Reset\" style=\"left: 1; top: 2; width: 60; height: 25; position: relative\">";
echo "</td>";
echo "<td width=\"10%\" align=\"right\"><a href=\"$backurl\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">$strBack</a>";
echo "</td></tr>";
echo "</table>";
?>
<table  width=100%   border="1"  cellpadding="1" cellspacing="0"  bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF"> 
<?php

//output E1 port
{
	$objWhereStr = getLevelWhere($link_oid);//2.5.1 Link attributes
	$getsql = "SELECT initValue FROM $mtp3_sqltable where $objWhereStr";
	if($DEBUG) echo "getsql = $getsql<br>";
	$e1_link_result = @mysqli_query($pubConn,$getsql);
		
	$objWhereStr = getLevelWhere($e1_oid[2]);//2.4.2 asign tg to e1
	$defSql = "select initValue from $msc_parConfTable where $objWhereStr";
	$defRes = @mysqli_query($pubConn,$defSql);
	$defRow = @mysqli_fetch_array($defRes);
	$defValue = $defRow[0];
	
	$getsql="SELECT initValue,instanceNo FROM $msc_paramTable
					WHERE $objWhereStr AND initValue != '$defValue'	";					
	if($DEBUG) echo "getsql = $getsql<br>";
	$result = @mysqli_query($pubConn,$getsql);
	$e1_253_num = 0;
	$e1_254_num = 0;
	$e1_e1_num = 0;
	while($e1_tg = mysqli_fetch_array($result))
	{
		$insNo = $e1_tg[instanceNo];	
		$e1_tg = hexdec($e1_tg[0]);
		
		$objWhereStr = getLevelWhere($e1_oid[3]);//2.4.3 cic of e1
		$getsql = "SELECT initValue FROM $msc_paramTable where $objWhereStr and instanceNo = '$insNo'";
		if($DEBUG) echo "getsql = $getsql<br>";
		$e1_cic = mysqli_query($pubConn,$getsql);
		$e1_cic = mysqli_fetch_array($e1_cic);
		$e1_cic = hexdec($e1_cic[0]);
		
		if($e1_tg == 253)
		{
			$e1_253[$e1_253_num] = $insNo;	
			$e1_253_cic[$e1_253_num] = $e1_cic;
			$e1_253_num++;
			
		}
		else if ($e1_tg == 254)
		{
			$e1_254[$e1_254_num] = $insNo;
			$e1_254_cic[$e1_254_num] = $e1_cic;	
			$e1_254_num++;
		}		
	}
	
	if(isset($e1_new))
	{
		$e1_254[$e1_254_num] = '';
		$e1_254_cic[$e1_254_num] = hexdec('FF')+1;	
		$e1_254_num++;
		
		$e1_253[$e1_253_num] = '';	
		$e1_253_cic[$e1_253_num] = hexdec('FF')+1;
		$e1_253_num++;
	}
	
	$total_num = ($e1_253_num >= $e1_254_num) ? $e1_253_num : $e1_254_num;
	
	if($DEBUG) echo "e1_253_num = $e1_253_num<br>";
	if($DEBUG) echo "e1_254_num = $e1_254_num<br>";
	if($DEBUG) echo "total_num = $total_num<br>";
	
	if($total_num == 0)
		$e1_nrow = 2;
	else
		$e1_nrow = $total_num + 1;
	echo "<tr>";
	echo "<td width = 20% bgcolor=\"#E6E6E6\" rowspan=\"$e1_nrow\"><table width=100%><tr>";
	echo "<td><b>E1 port</b></td>";
	echo "<td align=right><input type=\"submit\" name=\"e1_new\" value=\"+\" style=\"font-size:18;font-weight:bold\"
		onmouseover=\"this.className='style8'\" onmouseout=\"this.className='style7'\" class=\"style7\"></td>";
	echo "</tr>";
	echo "</table></td>"; 
	echo "<td bgcolor=\"#E6E6E6\"><table width=100%><tr>";
	echo "<td width=30%><b>MSS0(0-127)</b></td>";
	echo "<td width=30%><b>MSS1(128-255)</b></td>";
	echo "<td align=right><b>Delete</b></td>";
	echo "</tr>";
	echo "</table></td>";
	echo "</tr>";
	
	if($total_num == 0)
	{
		echo "<tr>";
		echo "<td><table width=100%><tr>";
		echo "<td width=30%><b>--</b></td>";
		echo "<td><b>--</b></td>";
		echo "</tr>";
		echo "</table></td>";
		echo "</tr>";
	}
	
	
	//used for exception handle
	//用于处理tg 253和tg 254对应的e1 link数目不一致的情况
	{
		
		$e1_253_cic[$total_num] = hexdec('FF')+2;
		$e1_254_cic[$total_num] = hexdec('FF')+2;
		//$e1_253[$total_num] = -1;
		//$e1_254[$total_num] = -1;
	}
	for($i=0; $i < $total_num; $i++)
	{
		$e1_253_min = 0;
		$e1_254_min = 0;	
		for($j=0; $j < $total_num; $j++)
		{
			if($DEBUG) echo "<br>e1_253_cic[$j]=$e1_253_cic[$j]<br>";
			if($DEBUG) echo "e1_254_cic[$j]=$e1_254_cic[$j]<br>";
			if(!isset($e1_253_cic[$j])) $e1_253_cic[$j] = hexdec('FF')+2;//used for exception handle
			if($e1_253_cic[$j] < $e1_253_cic[$e1_253_min]) 
			{
				$e1_253_min = $j;	
			}
			if(!isset($e1_254_cic[$j])) $e1_254_cic[$j] = hexdec('FF')+2;//used for exception handle
			if($e1_254_cic[$j] < $e1_254_cic[$e1_254_min]) 
			{
				$e1_254_min = $j;	
			}
		}
		//used for exception handle
		if($e1_253_cic[$e1_253_min] != $e1_254_cic[$e1_254_min])
		{
			if($e1_253_cic[$e1_253_min] > $e1_254_cic[$e1_254_min])
			{
				$e1_253_min = $total_num;
				$cur_cic = $e1_254_cic[$e1_254_min] / 32;
			}
			else
			{
				$e1_254_min = $total_num;
				$cur_cic = $e1_253_cic[$e1_253_min] / 32;
			}
		}
		else
			$cur_cic = $e1_254_cic[$e1_254_min] / 32;
			
		if($DEBUG) echo "<br>e1_253_cic[$e1_253_min] = $e1_253_cic[$e1_253_min]<br>";
		if($DEBUG) echo "e1_254_cic[$e1_254_min] = $e1_254_cic[$e1_254_min]<br>";
		if($DEBUG) echo "cur_cic = $cur_cic<br>";
		
		//if($e1_254_cic[$e1_254_min] != $e1_253_cic[$e1_253_min])
			//continue;
		
		echo "<tr>";
		echo "<td><table width=100%><tr>";
		if(isset($e1_new) && $i==$e1_253_num-1)
		{
			$objDb = "OBJ_322";
			$paramTable = "param_99";
			$objIdStr='2.4.2';
			$objWhereStr =getLevelWhere($objIdStr);	
			{//e1_253
				echo "<td width=30%>";
				$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable
								WHERE $objWhereStr AND initValue = 'EE' and instanceNo<'128'
								"; 		
			//	$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable WHERE $objWhereStr "; 				
				$result=mysqli_query($pubConn,$getInstanceSql);
				
				//echo "<br>$getInstanceSql";
				echo "<select name=\"e1_253_$i\" size=\"1\" style=width:\"$nShowsize\">";
				while($row=mysqli_fetch_array($result))
				{	
					$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable
									WHERE instanceNo='$row[instanceNo]' and level_1 = '2' and level_2 = '5' and level_3 = '1'
									";
					$result_1=mysqli_query($pubConn,$getInstanceSql);
					$LinkRow=mysqli_fetch_array($result_1);
					$tempFlag = getBitValue($LinkRow[initValue],'06.5-06.5');					
					if($tempFlag==0)//E1 link disbale
					{
						$tempnum = $row[instanceNo]/8;
						$cardno = Floor($tempnum);
						$cardE1no = $row[instanceNo] - $cardno*8;
						$cscNo = Floor($cardno/16);
						$subCardNo = $cardno%16;
						$cardname = "CSC$cscNo"."&nbsp;"."Card-$subCardNo-$cardE1no";
						
						echo "<option value=$row[instanceNo]>$cardname</option>";
					}				
				}
				echo"</select>";
				echo "</td>";
			}
			{//e1_254
				echo "<td>";
				$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable
								WHERE $objWhereStr AND initValue = 'EE' and instanceNo>'127'
								"; 		
			//	$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable WHERE $objWhereStr "; 				
				$result=mysqli_query($pubConn,$getInstanceSql);
				
				//echo "<br>$getInstanceSql";
				echo "<select name=\"e1_254_$i\" size=\"1\" style=width:\"$nShowsize\">";
				while($row=mysqli_fetch_array($result))
				{	
					$getInstanceSql="SELECT initValue,instanceNo FROM $paramTable
									WHERE instanceNo='$row[instanceNo]' and level_1 = '2' and level_2 = '5' and level_3 = '1'
									";
					$result_1=mysqli_query($pubConn,$getInstanceSql);
					$LinkRow=mysqli_fetch_array($result_1);
					$tempFlag = getBitValue($LinkRow[initValue],'06.5-06.5');					
					if($tempFlag==0)//E1 link disbale
					{
						$tempnum = $row[instanceNo]/8;
						$cardno = Floor($tempnum);
						$cardE1no = $row[instanceNo] - $cardno*8;
						$cscNo = Floor($cardno/16);
						$subCardNo = $cardno%16;
						$cardname = "CSC$cscNo"."&nbsp;"."Card-$subCardNo-$cardE1no";
						
						echo "<option value=$row[instanceNo]>$cardname</option>";
					}				
				}
				echo"</select>";
				echo "</td>";
			}
		}
		else
		{
			echo "<td width=30%><input type=\"text\" size = \"4\" maxlength=3 value=\"$e1_253[$e1_253_min]\" class=\"text\" 
				name=\"e1_253_$i\" onchange = checkInput(this,10,127)></td>";
			echo "<td ><input type=\"text\" size = \"4\" maxlength=3 value=\"$e1_254[$e1_254_min]\" class=\"text\" 
				name=\"e1_254_$i\" onchange = checkInput(this,10,255,128)></td>";
		}
		if(!isset($e1_new) || ($i != $e1_253_num-1))
		{
			if(!isset($e1_253[$e1_253_min])) $e1_253[$e1_253_min] = -1;//used for exception handle
			if(!isset($e1_254[$e1_254_min])) $e1_254[$e1_254_min] = -1;//used for exception handle
			
			echo "<td align=right><input type=\"checkbox\" name=\"pre_del_$i\" value=\"\" 
				onClick=\"javascript:delFirm('e1',$e1_253[$e1_253_min],$e1_254[$e1_254_min])\"></td>";
		}
		echo "</tr>";
		echo "</table></td>";
		echo "</tr>";		
		
		if($cur_cic != $i && !isset($unused_cic))
		{
			$unused_cic = $i;
			echo "<input type=\"hidden\" name=\"avail_cic\" value=\"$unused_cic\">";
		}
		echo "<input type=\"hidden\" name=\"e1_cic_$i\" value=\"$cur_cic\">";
		echo "<input type=\"hidden\" name=\"e1_253_org_$i\" value=\"$e1_253[$e1_253_min]\">";
		echo "<input type=\"hidden\" name=\"e1_254_org_$i\" value=\"$e1_254[$e1_254_min]\">";			
		
		$e1_253_cic[$e1_253_min] = hexdec('FF')+2;
		$e1_254_cic[$e1_254_min] = hexdec('FF')+2;	
	}
	if(!isset($unused_cic))
	{
		$unused_cic = $cur_cic + 1;
		echo "<input type=\"hidden\" name=\"avail_cic\" value=\"$unused_cic\">";	
	}
	echo "<input type=\"hidden\" name=\"e1_num\" value=\"$total_num\">";
}
//output Trunk group
{
	echo "<tr>";
	echo "<td bgcolor=\"#E6E6E6\"><b>Loopback trunk group</b></td>";
	echo "<td><table width=100%><tr>";
	echo "<td width=30%>253</td>";
	echo "<td>254</td>";
	echo "</tr>";
	echo "</table></td>";
	echo "</tr>";
}
//output Served trunk group
{
	{//get linkset name.
		$levelWhere = getLevelWhere('2.4.1');
		$sqlTab = "OBJ_222.param_99";
		$selSql = "select initValue from $sqlTab where $levelWhere";
		if($DEBUG) echo "<br>Line ". __LINE__ . ": $selSql";
		$result	=mysqli_query($pubConn,$selSql);
		$i=0;
		while($rows=mysqli_fetch_array($result))
		{
			$enable=getBitValue($rows[initValue],'3.2-3.2');
			if($enable)
			{
				$linksetArr[$i][dpc]=hexdec(getBitValue($rows[initValue],'0.0-2.7'));
				$linksetArr[$i][name] = getBitValue($rows[initValue],'7.0-16.7');
				$i++;
			}
		}
	}//end get linkset name.
	$objWhereStr = getLevelWhere($e1_oid[0]);
	$defSql = "select initValue from $msc_parConfTable where $objWhereStr";
	$defRes = @mysqli_query($pubConn,$defSql);
	$defRow = mysqli_fetch_array($defRes);
	$getsql = "SELECT initValue,instanceNo FROM $msc_paramTable where $objWhereStr and initValue!='{$defRow[initValue]}'";
	if($DEBUG)
	 echo "getsql = $getsql<br>";
	
	
	
	
	$result = @mysqli_query($pubConn,$getsql);
	echo "<tr>";
	echo "<td width = 20% bgcolor=\"#E6E6E6\"><b>Served trunk group</b></td>";
	echo "<td width=\"80%\"><table width=\"100%\">";
	$i=0;
	while($tgRows = mysqli_fetch_array($result))
	{
		if($tgRows[instanceNo]==253 || $tgRows[instanceNo]== 254||$tgRows[instanceNo]==250||$tgRows[instanceNo]==251||$tgRows[instanceNo]==252||$tgRows[instanceNo]==255)
			continue;
		$tg_row = $tgRows[0];
		$enable_flag = getBitValue($tg_row,'4.0-4.0');
		if($enable_flag==1)
		{
			$alter_TG = hexdec(getBitValue($tg_row,'7.0-7.7'));
			$alterTgFlag = getBitValue($tg_row,'4.6-4.6');
			$DPC = hexdec(getBitValue($tg_row,'0.0-3.7'));
			for($j=0; $j< sizeof($linksetArr); $j++)
			{
				if($DPC == $linksetArr[$j][dpc])
				{
					$linksetName = trim(toAscii($linksetArr[$j][name]));
						break;
				}
			}
			if(!isset($linksetName) || ord($linksetName)==0)
				$linksetName = 'TG_'.$tgRows[instanceNo];
			if($linksetName==='CNF Center')
				continue;
			if($i%5==0)
				echo "<tr>";
			echo "<td>";
			if($alterTgFlag == 1 && $alter_TG == 253)
				$checkedStr = 'checked';
			else
				$checkedStr = '';
			echo "<span title=\"TG {$tgRows[instanceNo]}\"><input type=\"checkbox\" name=\"servedTg_$i\" vlue=\"\" $checkedStr>$linksetName</span>";//onClick=\"javascript:slctTG(this,'tg',$tgRows[instanceNo])\"
			echo "<input type=\"hidden\" name=\"servedTgIns_$i\" value=\"{$tgRows[instanceNo]}\">";
			echo "</td>";
			unset($linksetName);
			$i++;
		}
	}
	echo "</table></td>";
	echo "</tr>";
	echo "<input type=\"hidden\" name=\"tg_no\" value=\"$i\">";
}

echo "<input type=\"hidden\" name=\"backurl\" value=\"$backurl\"";
echo "</form>";
?>
<table>
