<?php

require("../sub_inc/commfunc.php");
$helpId = "2.1.1"; 
$DEBUG = 0;
if($DEBUG){
	echo"<br><font size=3 color=red>调试中...</font>";
	exit();
}
//******
//$url_temp=$_SERVER["REQUEST_URI"];
//echo "This page URL:$url_temp<br>";


//===================function==========================
function alert($msg)
{
	echo "<script language=\"JavaScript\">\n";
	echo "alert('$msg');\n";
	echo "</script>\n";
}
//=====================================================
//echo "bssIP:$bssIP<br>";
//echo "sysType:$sysType<br>";
//$readValue	 ='readValue';
//$nGetComm	= 0;
//$nSetComm	= 3;
//$maxNum = 30;
//$nProcFail = 0;//failure
//$nWaitProc = 1;//wait
//$nInProc   = 2;
//$nOutProc  = 3;

$pubDb		 = 'OMC_PUB';
$initValue	 ='initValue';

$niArr=array(
	array('id'=>'0','name'=>'International'),
	array('id'=>'1','name'=>'International spare'),
	array('id'=>'2','name'=>'National'),
	array('id'=>'3','name'=>'National spare')
);
$sysTypeArr=array(
	array('id'=>'0','name'=>'MSS'),
	array('id'=>'1','name'=>'BSS'),
	array('id'=>'2','name'=>'Peripheral'),
	array('id'=>'3','name'=>'Switch'),
	array('id'=>'4','name'=>$strGttObjects)
);

$locEleArr=array(
	array('sysTypeName'=>'MSC',	'sysTypeNo'=>'320','sysTypeSSN'=>'8','GT'=>'--','extFlg'=>'0'),
	array('sysTypeName'=>'VLR',	'sysTypeNo'=>'325','sysTypeSSN'=>'7','GT'=>'--','extFlg'=>'0'),
	array('sysTypeName'=>'HLR',	'sysTypeNo'=>'330','sysTypeSSN'=>'6','GT'=>'--','extFlg'=>'0'),
	array('sysTypeName'=>'AUC',	'sysTypeNo'=>'340','sysTypeSSN'=>'10','GT'=>'--','extFlg'=>'0'),
	array('sysTypeName'=>'SMSC','sysTypeNo'=>'350','sysTypeSSN'=>'11','GT'=>'--','extFlg'=>'0'),
	array('sysTypeName'=>'PPS',	'sysTypeNo'=>'360','sysTypeSSN'=>'147','GT'=>'--','extFlg'=>'0'),
	array('sysTypeName'=>'EIR','sysTypeNo'=>'380','sysTypeSSN'=>'9','GT'=>'--','extFlg'=>'0'),
	array('sysTypeName'=>'MNP','sysTypeNo'=>'370','sysTypeSSN'=>'32','GT'=>'--','extFlg'=>'0')
);

$peripheEleArr=array(
	array('sysTypeName'=>'--','sysTypeNo'=>'311'),
	array('sysTypeName'=>'VSS','sysTypeNo'=>'390'),
	array('sysTypeName'=>'','sysTypeNo'=>''),
	//array('sysTypeName'=>'PCR','sysTypeNo'=>'130'),
	array('sysTypeName'=>'CNF','sysTypeNo'=>'160'),
	array('sysTypeName'=>'CNF Center','sysTypeNo'=>'270')
);
$switchEleArr=array(
	array('sysTypeName'=>'SS7','sysTypeNo'=>''),
	array('sysTypeName'=>'ISDN','sysTypeNo'=>'')
);
$appliEleArr=array(
	array('sysTypeName'=>'MSC','sysTypeNo'=>'320'),
	array('sysTypeName'=>'HLR','sysTypeNo'=>'330'),
	array('sysTypeName'=>'VLR','sysTypeNo'=>'325'),
	array('sysTypeName'=>'SMSC','sysTypeNo'=>'350'),
	array('sysTypeName'=>'SGSN','sysTypeNo'=>''),
	array('sysTypeName'=>'-New-','sysTypeNo'=>'')
);

getExistElements($existElementArr);

//print_r($existElementArr);
//if have CNF,then add a CNF-center
if(@array_search('160', $existElementArr)==TRUE)
	$existElementArr[sizeof($existElementArr)] = '270';

if(@array_search('500', $existElementArr)==TRUE)//BSS
	$needBssIp = 1;
?>
<?php

$offsetAppType='00.0-00.7';
$offsetGrpNo = '01.0-01.7';
$offsetBitFlag = '02.0-02.7';//if '1', global title.

$niTypeArr = getNiType();
//echo "niTypeArr";
//print_r($niTypeArr);
?>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{

	echo "<br>Adding Element ... <br>";
	//echo "add:$add<br>";
	if(strlen($add) >0)
	{
		//alert("trunk_no".$trunk_select);
		//alert("linkset_no".$linkset_select);
		if(strlen($elementName)<=0)
		{
			$errorInfo='Please input the element Name';
			alertMsgAndGoLast($errorInfo);
		}
		
		
		
		chkEleName($elementName);
		
		switch($sysType)
		{
			//add mss
			case 0:
			{
				$sysId_arr=array(
						array('oid'=>'2.1',		'sysid'=> '223_99_99',		'selectsysid'=>'-1'), 										
					);
				$SaveArr=array(
						array('oidstr'=>'3.2',	'setvalue'=>'02'	,'sysid'=>'223_99_99'),//sccp	
					);
				{//MSC IP	
				$getSysIdSql = "SELECT sysNo,subSysNo,ip FROM sysInfo
							WHERE sysTypeNo='320' AND sysNo='0'
						";
				if($DEBUG)echo "<br>getSysIdSql:$getSysIdSql";
				$getSysIdResult= mysqli_query($pubConn,$getSysIdSql);
				if($getSysIdRow = @mysqli_fetch_array($getSysIdResult))
				{
					$MSCIP0	=$getSysIdRow[ip];
				}
				else
				{
					$MSCIP0	='255.255.255.255';
				}
				$IP	= explode('.',$MSCIP0);
				$IP0 = omc_keep_length(dechex($IP[0]),"0","2");
				$IP1 = omc_keep_length(dechex($IP[1]),"0","2");
				$IP2 = omc_keep_length(dechex($IP[2]),"0","2");
				$IP3 = omc_keep_length(dechex($IP[3]),"0","2");
				$MSCIP0 = $IP0.$IP1.$IP2.$IP3;					
									
				$getSysIdSql = "SELECT sysNo,subSysNo,ip FROM sysInfo
							WHERE sysTypeNo='320' AND sysNo='1'
						";
				$getSysIdResult= mysqli_query($pubConn,$getSysIdSql);
				if($getSysIdRow=@mysqli_fetch_array($getSysIdResult))
				{
					$MSCIP1	=$getSysIdRow[ip];
				}
				else
				{
					$MSCIP1	='255.255.255.255';
				}	
				$IP	= explode('.',$MSCIP1);
				$IP0 = omc_keep_length(dechex($IP[0]),"0","2");
				$IP1 = omc_keep_length(dechex($IP[1]),"0","2");
				$IP2 = omc_keep_length(dechex($IP[2]),"0","2");
				$IP3 = omc_keep_length(dechex($IP[3]),"0","2");
				$MSCIP1 = $IP0.$IP1.$IP2.$IP3;					
				}//end MSC IP
				//echo "ni:$ni<br>";
				$tmpNi=omc_keep_length($ni,'0',2);
				//echo "tmpNi:$tmpNi<br>";
				$tmpInitValue=$tmpNi.'FFFFFFFFFFFFFFFFFFFF'.$MSCIP0.$MSCIP1;
				$tmpInitValue = strtoupper($tmpInitValue);
				$tmpObjIdStr='2.1';
				$levelWhere = getLevelWhere($tmpObjIdStr);
				if($DEBUG) echo "<BR>levelWhere=$levelWhere";
				$tmpParamTable='OBJ_223.param_99';
				$updateSql="UPDATE $tmpParamTable SET initValue='$tmpInitValue'
							WHERE $levelWhere AND level_3='{$locEleArr[$eleType][sysTypeSSN]}'
							";
				if($DEBUG) 
					echo "<BR>updateSql=$updateSql";
				mysqli_query($pubConn,$updateSql);
				echo mysqli_error($pubConn);
				break;
			}
			//add mss end
			case 1://BSS;
			case 2://Peripheral;
			{
				
				//=================================================================================
				//echo "needBssIp:$needBssIp<hr>";
				if($sysType==1&&$needBssIp==1)
				{
					
					//************check the IP***********************
					if(!strcmp(long2ip(sprintf("%u",ip2long($bssIP))),$bssIP))
						$is_ip_valid=1;
					else
						$is_ip_valid=0;
					if($is_ip_valid==0)	
					{
						alertMsgAndGoLast("IP address format error");
					}
					$result=exec("ping -c 1 ".$bssIP);
					if($result=="1 packets transmitted, 0 packets received, +1 errors, 100% packet loss")
					  alertMsgAndGoLast("object unreachable: The BSS cannot be reached");
					
				}
				
				///==========There has an bug ,add the second CNF do not need DPC 
				if($sysType==2&&$eleType==3)
					$temp="";
				else	
				{
					if(strlen($dpc)<=0)
					{
						$errorInfo='Please input the DPC!';
						alertMsgAndGoLast($errorInfo);
					}
				}
				
				
				
				
				//=================================================================================
				//echo "BSS<br>";
				$sysId_arr=array(
					array('oid'=>'2.4.1',		'sysid'=> '222_99_99',		'selectsysid'=>'-1'),//ls
					array('oid'=>'2.1.4',		'sysid'=> '322_99_99',		'selectsysid'=>'-1'),//tg
					array('oid'=>'2.11',		'sysid'=> '225_99_99',		'selectsysid'=>'-1'),//xapp
				);
				$SaveArr=array(
					array('oidstr'=>'3.2',	'setvalue'=>'B5'	,'sysid'=>'322_99_99'),//MSC
					array('oidstr'=>'3.7',	'setvalue'=>'02'	,'sysid'=>'222_99_99'),//mtp3
					array('oidstr'=>'3.2',	'setvalue'=>'01'	,'sysid'=>'225_99_99'),//xapp	
				);
				//bss
				if($sysType==1)
				{
					//echo "aaa<br>";
					$sysId_arr[]= array('oid'=>'2.2.6',		'sysid'=> '322_99_99',		'selectsysid'=>'-1');//lac
				}
				if($sysType==2)
				{
					$sysId_arr[]= array('oid'=>'2.1.6',		'sysid'=> '322_99_99',		'selectsysid'=>'-1');//announcement									
				}
				//print_r($sysId_arr);
				
				
				if($useSameCnfLinkset!=1)
				{
					//echo "useSameCnfLinkset:$useSameCnfLinkset<br>";
					if(strlen($dpc)<=0)
					{
						$errorInfo='Please input the DPC!';
						alertMsgAndGoLast($errorInfo);
					}
	
					for($i=0;$i<strlen($dpc);$i++)
					{
						if('0'>$dpc[$i]||'9'<$dpc[$i])
						{
							$errorInfo='The DPC is error';
							alertMsgAndGoLast($errorInfo);
						}
					}
					//echo "ni$$ni<br>";
					chkDPC($dpc,$ni);
				}
				
				
				if($sysType==1 && $needBssIp==1)//add BSS sysInfo & OMCR_BSSTABLE
				{
					//echo "bbb<br>";
					$sysInfoTable = "OMC_PUB.sysInfo";
					$tmpSysType = 500;
					$tmpSubSysNo = 0;
					$isRemote = 0;
					//$sysAlias='BSS'.$systemNo;
					//echo "elementName:$elementName<br>";
					$sysAlias=$elementName;
					//=============================================================
					
					/*
					echo isset($ni)."<br>";
					echo isset($systemNo);
					echo "systemNo:$systemNo<br>";
					echo "ni:$ni<br>";
					echo "dpc:$dpc<br>";
					echo "bssIP:$bssIP<br>";
					*/
					$bssid=$systemNo;
					
					sendBssCommand($bssid,$bssIP,$sysAlias);
					//=============================================================
					$addSql = "REPLACE INTO $sysInfoTable (sysTypeNo,sysNo,subSysNo,isRemote,netId,DPC,ip,baseStat,sysAlias,updateTime )
								VALUES('$tmpSysType','$systemNo','$tmpSubSysNo','$isRemote','$ni','$dpc','$bssIP','1','$sysAlias',CURRENT_TIMESTAMP)";

					if($DEBUG) echo "<br>addSql = $addSql";
					$result = mysqli_query($pubConn,$addSql);
					echo mysqli_error($pubConn);

					
				}//end add BSS sysinfo & OMCR_BSSTABLE
				
				

				{//linkset
					$tmpObjIdStr='2.4.1';
					$levelWhere = getLevelWhere($tmpObjIdStr);
					if($DEBUG) echo "<BR>levelWhere=$levelWhere";
					$tmpParamTable='OBJ_222.param_99';
					if($useSameCnfLinkset==1)
					{
						
						$tmpDecValue=hexdec(getBitValue($lsValue,'6.0-6.7'));//total elements in the linkset
						$tmpDecValue++;
						$tmpHexValue=omc_keep_length(dechex($tmpDecValue),'0',2);
						$tmpInitValue=setBitValue($lsValue,'6.0-6.7',$tmpHexValue);
	
						$tmpInitValue = strtoupper($tmpInitValue);
						$tmpInstanceNo=$cnfLS;
					}
					else
					{
						$getSql="SELECT $initValue,instanceNo FROM $tmpParamTable 
								WHERE $levelWhere ";
						if($DEBUG) echo "<BR>getSql=$getSql";
						$result	=mysqli_query($pubConn,$getSql);
						echo mysqli_error($pubConn);
		
						while($rows=mysqli_fetch_array($result))
						{
							if($DEBUG)echo "<BR>initValue=$rows[initValue]";
							$enableFlg=getBitValue($rows[initValue],'3.2-3.2');//enable flag
							if($enableFlg==0)
								break;
						}
						//alert("linkset ".$linkset_select);
						//alert("trunk ".$trunk_select);
						$tmpInstanceNo=$linkset_select;//$rows[instanceNo];
						$lsAssigned=$linkset_select;//$rows[instanceNo];
		
						$tmpInitValue=strtoupper(omc_keep_length(dechex($dpc),'0',6));
						$tmpNi=omc_keep_length(decbin($ni),'0',2);
						//echo "<br>tmpNi=$tmpNi";
						$tmpUnitBinValue='00000'.'1'.$tmpNi;
						$tmpUnitHexValue=omc_keep_length(dechex(bindec($tmpUnitBinValue)),'0',2);
						$tmpInitValue=$tmpInitValue.$tmpUnitHexValue;
						if($DEBUG) 
							echo "<BR>tmpInitValue=$tmpInitValue";
						if($sysType==1)//BSS
						{
							$tmpType='01';
						}
						else if($sysType==2)//Peripheral
						{
							if($eleType==0)//AAS
								$tmpType='02';
							else if($eleType==1)//VSS
								$tmpType='03';
							else if($eleType==2)//PCR
								$tmpType='04';
							else if($eleType==3)//CNF
								$tmpType='05';
							else if($eleType==4)//CNF Center
								$tmpType='06';
						}
						else
							$tmpType='00';
						$tmpInitValue=$tmpInitValue.$tmpType;
						if($DEBUG) 
							echo "<BR>tmpInitValue=$tmpInitValue";
						if($sysType==2 && $eleType==3)//cnf
						{
							$tmp_subSysNo = floor($systemNo/2);
							$tmp_sysNo = $systemNo%2;
							
							if($eleType==3) //第一个cnf，高四位设置为0001
								$tmp_subSysNo = 1;
								
							$bin_subSysNo = omc_keep_length(decbin($tmp_subSysNo),'0',4);
							$bin_sysNo = omc_keep_length(decbin($tmp_sysNo),'0',4);
							$bin_systemNo = $bin_subSysNo.$bin_sysNo;
							$tolSystemNo = bindec($bin_systemNo);
							
							$tmpUnitHexValue=omc_keep_length(dechex($tolSystemNo),'0',2);
						}
						else
						{
							$bin_subSysNo = omc_keep_length(decbin($subSysNo),'0',4);
							$bin_sysNo = omc_keep_length(decbin($systemNo),'0',4);
							$bin_systemNo = $bin_subSysNo.$bin_sysNo;
							$tolSystemNo = bindec($bin_systemNo);
							$tmpUnitHexValue=omc_keep_length(dechex($tolSystemNo),'0',2);
						}
						$tmpInitValue=$tmpInitValue.$tmpUnitHexValue;
						if($DEBUG) 
							echo "<BR>tmpInitValue=$tmpInitValue";
						$tmpName=toHex($elementName);
						$tmpName=omc_keep_length($tmpName,"0",20,"0");
						if($sysType==2 && $eleType==3)//cnf 第一个
							$tmpInitValue=$tmpInitValue.'01'.$tmpName.'000000';
						else
							$tmpInitValue=$tmpInitValue.'00'.$tmpName.'000000';
						$tmpInitValue = strtoupper($tmpInitValue);
					}
					$updateSql="UPDATE $tmpParamTable SET initValue='$tmpInitValue'
								WHERE $levelWhere AND instanceNo='$tmpInstanceNo' ";
					if($DEBUG) 
						echo "<BR>updateSql=$updateSql";
	 				mysqli_query($pubConn,$updateSql);
					echo mysqli_error($pubConn);
				}//end linkset
				
				if($useSameCnfLinkset!=1)//tg
				{
					
					$tmpObjIdStr='2.1.4';
					$levelWhere = getLevelWhere($tmpObjIdStr);
					if($DEBUG) echo "<BR>levelWhere=$levelWhere";
					$tmpParamTable='OBJ_322.param_99';
					$getSql="SELECT $initValue,instanceNo FROM $tmpParamTable 
							WHERE $levelWhere
							";
					if($DEBUG) echo "<BR>getSql=$getSql";
					$result	=mysqli_query($pubConn,$getSql);
					echo mysqli_error($pubConn);
	
					while($rows=mysqli_fetch_array($result))
					{
						if($DEBUG)echo "<BR>initValue=$rows[initValue]";
						$tgFlag=getBitValue($rows[initValue],'4.0-4.0');//tgFlag
						if($tgFlag==0)
							break;
					}
					$tmpInstanceNo=$trunk_select;//$rows[instanceNo];
					$tgAssigned=$trunk_select;//$rows[instanceNo];
	
					$tmpInitValue=strtoupper(omc_keep_length(dechex($dpc),'0',8));
					if($sysType==1)//BSS
						$tmpInitValue=$tmpInitValue.'9F';//category  =SUB
					elseif($sysType==2)//AAS,(VSS,PCR,CNF)?
						$tmpInitValue=$tmpInitValue.'A7';//category  =IP
					$tmpNi=strtoupper(omc_keep_length(dechex($ni),'0',2));
					//echo "<br>tmpNi=$tmpNi";
					$tmpInitValue=$tmpInitValue.$tmpNi.'80FD0000000000000000';//Alternative TG =FD
																																			//80=(Circuit =Clockwise ;Back off =off; Location	=Both)
					if($DEBUG) echo "<BR>tmpInitValue=$tmpInitValue";
					$updateSql="UPDATE $tmpParamTable SET initValue='$tmpInitValue'
									WHERE $levelWhere AND instanceNo='$tmpInstanceNo'
								";
					if($DEBUG) echo "<BR>updateSql=$updateSql";
					
					mysqli_query($pubConn,$updateSql);
					echo mysqli_error($pubConn);
				}//end tg
				
				if($sysType==1)//LAC
				{
					$tmpObjIdStr='2.2.6';
					$levelWhere = getLevelWhere($tmpObjIdStr);
					if($DEBUG) echo "<BR>levelWhere=$levelWhere";
					$tmpParamTable='OBJ_322.param_99';
					$getSql="SELECT $initValue,instanceNo FROM $tmpParamTable 
							WHERE $levelWhere
							";
					if($DEBUG) echo "<BR>getSql=$getSql";
					$result	=mysqli_query($pubConn,$getSql);
					echo mysqli_error($pubConn);

					while($rows=mysqli_fetch_array($result))
					{
						if($DEBUG)echo "<BR>initValue=$rows[initValue]";
						$enableFlg=getBitValue($rows[initValue],'0.0-0.7');
						if($enableFlg==0)
							break;
					}
					$tmpInstanceNo=$rows[instanceNo];

					$tmpInitValue='01';
					$tmpHexValue=strtoupper(omc_keep_length(dechex($tgAssigned),'0',2));
					$tmpInitValue=$tmpInitValue.$tmpHexValue.'000000';
					if($DEBUG) 
						echo "<BR>tmpInitValue=$tmpInitValue";
					$updateSql="UPDATE $tmpParamTable SET initValue='$tmpInitValue'
									WHERE $levelWhere AND instanceNo='$tmpInstanceNo'
								";
					if($DEBUG) 
						echo "<BR>updateSql=$updateSql";
					if($DEBUG)
						exit();
					mysqli_query($pubConn,$updateSql);
					echo mysqli_error($pubConn);
				}//end LAC
				if($sysType==2)//set announcement;
				{					
					$tmpObjIdStr='2.1.6';
					$levelWhere = getLevelWhere($tmpObjIdStr);
					$tmpParamTable='OBJ_322.param_99';
					$tmpInitValue ="02000000020000000200000002000000020000000200000002006000020000000200000002000000020000000200000002000000020000000200000002000000";
					$updateSql="UPDATE $tmpParamTable SET initValue='$tmpInitValue'
								WHERE $levelWhere AND instanceNo='0' ";					
					mysqli_query($pubConn,$updateSql);
				}//end announcement
				break;
			}
			case 3://Switch;
			case 4://Application;
			{
				$sysId_arr=array(
					array('oid'=>'2.4.1',		'sysid'=> '222_99_99',		'selectsysid'=>'-1'),//mtp3
					array('oid'=>'2.11',		'sysid'=> '225_99_99',		'selectsysid'=>'-1'),//xapp
				);
				$SaveArr=array(
					array('oidstr'=>'3.7',	'setvalue'=>'02'	,'sysid'=>'222_99_99'),//mtp3	
					array('oidstr'=>'3.2',	'setvalue'=>'01'	,'sysid'=>'225_99_99'),//xapp		
				);
				if($sysType==3)
				{
					$sysId_arr[] = array('oid'=>'2.1.4', 'sysid'=> '322_99_99',	 'selectsysid'=>'-1');
					$SaveArr[] = array('oidstr'=>'3.2',	'setvalue'=>'B5'	,'sysid'=>'322_99_99');//MSC
				}
				if($sysType == 4)
				{
//					$sysId_arr[] = array('oid'=>'2.2', 'sysid'=> '223_99_99',	 'selectsysid'=>'-1');
//					$sysId_arr[] = array('oid'=>'2.4', 'sysid'=> '223_99_99',	 'selectsysid'=>'-1');
//					$SaveArr[] = array('oidstr'=>'3.2',	'setvalue'=>'02'	,'sysid'=>'223_99_99');//sccp
				}
				//linkset
				if(!($sysType==3 && $eleType==1))//(SS7 Switch/Application)
				{
					$tmpObjIdStr='2.4.1';
					$levelWhere = getLevelWhere($tmpObjIdStr);
					if($DEBUG) echo "<BR>levelWhere=$levelWhere";
					$tmpParamTable='OBJ_222.param_99';
				//	alert("neednewlinkset:".$needNewLinkset);
					if($needNewLinkset==1)
					{
						if(strlen($dpc)<=0)
						{
							$errorInfo='Please input the DPC';
							alertMsgAndGoLast($errorInfo);
						}
	
						for($i=0;$i<strlen($dpc);$i++)
						{
							if('0'>$dpc[$i]||'9'<$dpc[$i])
							{
								$errorInfo='The DPC is error';
								alertMsgAndGoLast($errorInfo);
							}
						}
						chkDPC($dpc,$ni);
						
						$getSql="SELECT $initValue,instanceNo FROM $tmpParamTable 
								WHERE $levelWhere ";
						if($DEBUG) echo "<BR>getSql=$getSql";
						$result	=mysqli_query($pubConn,$getSql);
						echo mysqli_error($pubConn);
	
						while($rows=mysqli_fetch_array($result))
						{
							if($DEBUG)echo "<BR>initValue=$rows[initValue]";
							$unitValue=getBitValue($rows[initValue],'4.0-4.7');
							if($unitValue==0)
								break;
						}
						//alert("linkset no".$linkset_select);
						//alert("trunk no".$trunk_select);
						$tmpInstanceNo=$linkset_select;//$rows[instanceNo];
						$lsAssigned=$linkset_select;//$rows[instanceNo];
	
						$tmpInitValue=omc_keep_length(dechex($dpc),'0',6);
						$tmpNi=omc_keep_length(decbin($ni),'0',2);
						//echo "<br>tmpNi=$tmpNi";
						$tmpUnitBinValue='0000'.'0'.'1'.$tmpNi;//reserved+loopback+flag+ni.
						$tmpUnitHexValue=omc_keep_length(dechex(bindec($tmpUnitBinValue)),'0',2);
						$tmpInitValue=$tmpInitValue.$tmpUnitHexValue;
						if($DEBUG) 
							echo "<BR>tmpInitValue=$tmpInitValue";
						if($sysType==3) $tmpType = '10';//16, SS7 Switch
						if($sysType==4) $tmpType = '12';//18, Application
						$tmpInitValue=$tmpInitValue.$tmpType;//device type.
						if($DEBUG) 
							echo "<BR>tmpInitValue=$tmpInitValue";
					
						$tmpUnitHexValue=omc_keep_length(dechex($systemNo),'0',2); //systemNo '5.0-5.7'
						$tmpInitValue=$tmpInitValue.$tmpUnitHexValue;
						if($DEBUG) 
							echo "<BR>tmpInitValue=$tmpInitValue";
						$tmpName=toHex($elementName);
						$tmpName=omc_keep_length($tmpName,'0',20,'0');	
						//$elementName=omc_keep_length($elementName,'0',10,'0');	
						$tmpInitValue=$tmpInitValue.'01'.$tmpName.'000000';
					}
					else
					{
						$tmpDecValue=hexdec(getBitValue($lsValue,'6.0-6.7'));//total elements in the linkset
						//echo "<br>tmpDecValue=$tmpDecValue";
						$tmpDecValue=$tmpDecValue+1;
						$tmpHexValue=omc_keep_length(dechex($tmpDecValue),'0',2);
						$tmpInitValue=setBitValue($lsValue,'6.0-6.7',$tmpHexValue);
						$tmpInitValue = strtoupper($tmpInitValue);
						$tmpInstanceNo=$lsInstNo;
					}
					if($sysType==3)
					{
						$tmpInitValue = setBitValue($tmpInitValue,'17.0-17.0',1);//set isSwitch flag.
					}
					$updateSql="UPDATE $tmpParamTable SET initValue='$tmpInitValue'
									WHERE $levelWhere AND instanceNo='$tmpInstanceNo'
								";
							
					if($DEBUG) 
						echo "<BR>updateSql=$updateSql";
					if($DEBUG)
						exit();
					mysqli_query($pubConn,$updateSql);
					echo mysqli_error($pubConn);		
				}//end linkset
				
				if($sysType==3)//Switch;
				{
					if($eleType==1)//ISDN Switch
					{
						$dpc = 0;
						$ni = 3;
						$needNewLinkset = 1;
					}
					$tmpObjIdStr='2.1.4';
					$levelWhere = getLevelWhere($tmpObjIdStr);
					if($DEBUG) echo "<BR>levelWhere=$levelWhere";
					$tmpParamTable='OBJ_322.param_99';
					$getSql="SELECT $initValue,instanceNo FROM $tmpParamTable 
							WHERE $levelWhere
							";
					if($DEBUG) echo "<BR>getSql=$getSql";
					$result	=mysqli_query($pubConn,$getSql);
					echo mysqli_error($pubConn);

					while($rows=mysqli_fetch_array($result)){
						if($DEBUG)echo "<BR>initValue=$rows[initValue]";
						$unitValue=getBitValue($rows[initValue],'4.0-4.0');
						if($unitValue==0)
							break;
					}
					$tmpInstanceNo=$trunk_select;//$rows[instanceNo];
					$tgAssigned =$trunk_select;// $rows[instanceNo];

					$tmpInitValue=strtoupper(omc_keep_length(dechex($dpc),'0',8));
					$tmpInitValue=$tmpInitValue.'87';//Loopback =enable
					$tmpNi=strtoupper(omc_keep_length(dechex($ni),'0',2));
					//echo "<br>tmpNi=$tmpNi";
					$tmpInitValue=$tmpInitValue.$tmpNi.'80FD0000000000000000';//Alternative TG =FD RAC=EE
					//alert($tmpInitValue);
					if($DEBUG) 
						echo "<BR>tmpInitValue=$tmpInitValue";
					$updateSql="UPDATE $tmpParamTable SET initValue='$tmpInitValue'
									WHERE $levelWhere AND instanceNo='$tmpInstanceNo'
								";
					//echo "$updateSql<br>";			
					//alert($updateSql);			
					if($DEBUG) 
						echo "<BR>updateSql=$updateSql";
					if($DEBUG)
						exit();
					mysqli_query($pubConn,$updateSql);
					echo mysqli_error($pubConn);			
					if($needNewLinkset!=1){//把switch挂载到Application时根据已有的E1link编号添加对应tg下的E1connect
						//查找linksetValue下的E1link
						/*
						$tmplinkset=strtoupper(omc_keep_length(dechex($lsInstNo),'0',2));
						$tmpObjIdStr='2.5.1';
						$levelWhere = getLevelWhere($tmpObjIdStr);						
						$tmpParamTable='OBJ_222.param_99';
						$getSql = " SELECT initValue,instanceNo FROM $tmpParamTable  
									WHERE $levelWhere AND initValue LIKE '$tmplinkset%' ORDER BY instanceNo	";
						$Result = mysqli_query($pubConn,$getSql);							
						$tmpWhere="(0";	
						while($Row = mysqli_fetch_array($Result)){
							$flag	= getBitValue($Row[initValue],'06.0-06.0');
							if($flag){
								if($tmpWhere=='(0')
									$tmpWhere="(instanceNo='$Row[instanceNo]'";
								else
									$tmpWhere=$tmpWhere." OR instanceNo='$Row[instanceNo]'";					
							}							
						}
						$tmpWhere=$tmpWhere.")";
						
						//添加E1connect						
						$tmpParamTable='OBJ_322.param_99';										
						
						$tmpObjIdStr='2.4.1';//interface = isup
						$levelWhere = getLevelWhere($tmpObjIdStr);						
						$updateSql="UPDATE $tmpParamTable SET initValue='01'
										WHERE $levelWhere AND $tmpWhere	";						
						mysqli_query($pubConn,$updateSql); 
														
						$tmpObjIdStr='2.4.2';//TG
						$levelWhere = getLevelWhere($tmpObjIdStr);						
						$setvalue=strtoupper(omc_keep_length(dechex($tgAssigned),'0',2));
						$updateSql="UPDATE $tmpParamTable SET initValue='$setvalue'
										WHERE $levelWhere AND $tmpWhere	";						
						mysqli_query($pubConn,$updateSql);		
						
						$objIdStr='2.4.4';
						$objWhereStr =getLevelWhere($objIdStr);
						$setValue = '03';
						$updSql = "UPDATE $tmpParamTable SET initValue = '$setValue'   
										WHERE $objWhereStr AND $tmpWhere ";
						if($DEBUG) echo "<BR>updSql=$updSql";
						mysqli_query($pubConn,$updSql);
						echo mysqli_error($pubConn);				
									*/					
					}
					if($eleType==0 && $needNewLinkset!=1)//把Application加载到Switch时, change tg=255 to tg=assigned tg; 
					{
						$tmpObjIdStr='2.11';
						$levelWhere = getLevelWhere($tmpObjIdStr);
						$tmpParamTable='OBJ_225.param_99';		
						
						$updEleInfoNoStr = rtrim($updEleInfoNoStr,'-');
						$updEleNoArr = explode('-',$updEleInfoNoStr);
						$tgOffset 		= '3.0-3.7';
						for($i=0; $i<sizeof($updEleNoArr); $i++)
						{
							$getSql="SELECT $initValue,instanceNo FROM $tmpParamTable 
										WHERE $levelWhere and instanceNo='$updEleNoArr[$i]'";
							if(0) echo "<BR>getSql=$getSql";
							$result	=mysqli_query($pubConn,$getSql);
							$rows=mysqli_fetch_array($result);
							echo mysqli_error($pubConn);
							$tmpSetValue = $rows[initValue];
							$tmpTG=strtoupper(omc_keep_length(dechex($tgAssigned),'0',2));
							$tmpSetValue = setBitValue($tmpSetValue,$tgOffset,$tmpTG);
							
							$updateSql="UPDATE $tmpParamTable SET initValue='$tmpSetValue'
								WHERE $levelWhere AND instanceNo='$updEleNoArr[$i]'";
							if(0) echo "<BR>updateSql=$updateSql";
							mysqli_query($pubConn,$updateSql);
						}
					}//end update element info tg.
				}//end Switch
				else if($sysType==4)//Application
				{
							
					if(1)
					{
						//====================close the type selection when sysType=GTT object==============
			
						$eleType=5;
						switch ($eleType)
						{
							case 0://msc
							{
								$addcount = 1;
								$addssn = '08';
								if($niTypeArr[$ni]==0)//ITU
								{
									$addnp[0] = '01';
									$TT[0] = '00';
								}
								else
								{
									$addnp[0] = '00';
									$TT[0] = '0E';
								}
								break;
							}
							case 1://hlr
							{
								$addcount = 3;
								$addssn = '06';
								if($niTypeArr[$ni]==0)//ITU
								{
									$addnp[0] = '01';
									$addnp[1] = '01';
									$addnp[2] = '06';
									$TT[0] = $TT[1] =$TT[2] ='00';
								}
								else
								{
									$addnp[0] = $addnp[1] =$addnp[2] ='00';
									$TT[0] = '0E';
									$TT[1] = '0E';
									$TT[2] = '09';
								}
								break;
							}
							case 2://vlr
							{
								$addcount = 1;
								$addssn = '07';
								if($niTypeArr[$ni]==0)//ITU
								{
									$addnp[0] = '01';
									$TT[0] = '00';
								}
								else
								{
									$addnp[0] = '00';
									$TT[0] = '0E';
								}
								break;
							}
							case 3://smsc
							{
								$addcount = 2;
								$addssn = '0B';
								if($niTypeArr[$ni]==0)//ITU
								{
									$addnp[0] = '01';
									$addnp[1] = '01';
									$TT[0] = $TT[1] = '00';
								}
								else
								{
									$addnp[0] = '00';
									$addnp[1] = '00';
									$TT[0] = $TT[1] = '0E';
								}
								break;
							}
							case 4://sgsn
							{
								$addcount = 1;
								$addssn = '00';
								if($niTypeArr[$ni]==0)//ITU
								{
									$addnp[0] = '01';
									$TT[0] = '00';
								}
								else
								{
									$addnp[0] = '00';
									$TT[0] = '0E';
								}
								break;
							}
							case 5://new
							{
								$addcount = 2;
								$addssn = '06';
								if($niTypeArr[$ni]==0)//ITU
								{
									$addnp[0] = '01';
									$addnp[1] = '06';
									$TT[0] = $TT[1] = '00';
								}
								else
								{
									$addnp[0] = $addnp[1] = '00';
									$TT[0] = '0E';
									$TT[1] = '09';
								}
								break;
							}
							default:
							{
								$addcount = 1;
								$addssn = '00';
								$addnp[0] = '00';
								break;
							}
						}		
						$tmpObjIdStr='2.2';
						$levelWhere = getLevelWhere($tmpObjIdStr);
						if($DEBUG) echo "<BR>levelWhere=$levelWhere";
						$tmpParamTable='OBJ_223.param_99';
						$getSql="SELECT $initValue,instanceNo FROM $tmpParamTable 
								WHERE $levelWhere AND initValue LIKE '00%'
								";
						if($DEBUG) 
							echo "<BR>getSql=$getSql";
						$result	=mysqli_query($pubConn,$getSql);
						echo mysqli_error($pubConn);
						$n=0;					
						while($rows=mysqli_fetch_array($result))
						{
							if($DEBUG)echo "<BR>initValue=$rows[initValue]";
							$tmpInstanceNo=$rows[instanceNo];
							{//set gtt attribution from 2.4
								if($eleType == 5) $bitFlag = 0;
								else	
								{
									if($n==0) //添加的第一个gtt为远端号码
										$bitFlag = 1;
									else
										$bitFlag = 0;
								}
								$setValue = '00000000000000000000000000000000';
								$tmpEleType = strtoupper(omc_keep_length(dechex($eleType),'0',2));
								$tmpGrpNo=strtoupper(omc_keep_length(dechex($setAppGrp),'0',2));
								$tmpGtFlag = strtoupper(omc_keep_length(dechex($bitFlag),'0',2));
								$setValue = setBitValue($setValue,$offsetAppType,$tmpEleType);
								$setValue = setBitValue($setValue,$offsetGrpNo,$tmpGrpNo);
								$setValue = setBitValue($setValue,$offsetBitFlag,$tmpGtFlag);
								
								$tmpEleName = omc_keep_length(toHex($elementName),"0",20,"0");
								$setValue = setBitValue($setValue,'3.0-12.7',$tmpEleName);
								
								$updSql = "update $tmpParamTable set initValue = '$setValue' where level_1='2' and level_2='4' and instanceNo='$tmpInstanceNo'";
								//mysqli_query($pubConn,$updSql);
								//echo mysqli_error($pubConn);
							}//end set gtt attribution from 2.4
								
							{//add a gtt
								$tmpInitValue='01';
								$tmpInitValue=$tmpInitValue.$addnp[$n];
								
								$tmpInitValue .= $TT[$n]; // TT
								$tmpInitValue=$tmpInitValue.'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF';
								$tmpNi=strtoupper(omc_keep_length(dechex($ni),'0',2));
								$tmpInitValue=$tmpInitValue.$tmpNi;
								$tmpHexValue=strtoupper(omc_keep_length(dechex($dpc),'0',6));
								$tmpInitValue=$tmpInitValue.$tmpHexValue;
								$tmpInitValue=$tmpInitValue.$addssn;
								$tmpInitValue=$tmpInitValue.'0007000000FFFFFFFFFFFFFFFFFFFF';
								if($DEBUG)echo "<br>tmpInitValue=$tmpInitValue";
								if($DEBUG)echo "<BR>tmpInitValue=$tmpInitValue";
								$updateSql="UPDATE $tmpParamTable SET initValue='$tmpInitValue'
												WHERE $levelWhere AND instanceNo='$tmpInstanceNo'
											";
								if($DEBUG) echo "<BR>updateSql=$updateSql";
								if($DEBUG) exit();
								//mysqli_query($pubConn,$updateSql); 
								//echo mysqli_error($pubConn);
							}//end add gtt
							$n++;
							if($n%$addcount==0)
								break;
						}
					}
				}//end Application
				break;
			}	
			default:
				break;
		}//end switch($sysType)
		
		if($sysType > 0)
		{//update elementInfo
			$tmpObjIdStr='2.11';
			$levelWhere = getLevelWhere($tmpObjIdStr);
			if($DEBUG) echo "<BR>levelWhere=$levelWhere";
			$tmpParamTable='OBJ_225.param_99';							
			$getSql="SELECT $initValue,instanceNo FROM $tmpParamTable 
						WHERE $levelWhere and initValue LIKE '00%'
						";
			if($DEBUG) echo "<BR>getSql=$getSql";
			$result	=mysqli_query($pubConn,$getSql);
			echo mysqli_error($pubConn);

			$rows=mysqli_fetch_array($result);
			$tmpInstanceNo=$rows[instanceNo];
			$tmpSetValue = '010000000000000000000000000000000000000000000000';
			
			$typeOffset 	= '1.0-1.7';
			$sysNoOffset 	= '2.0-2.3';
			$subSysNoOffset = '2.4-2.7';
			$tgOffset 		= '3.0-3.7';
			$lsOffset 		= '4.0-4.7';
			$appTypeOffset 	= '5.0-5.7';
			$appGrpOffset 	= '6.0-6.7';
			$nameOffset 	= '14.0-23.7';			
			if($sysType==1)//BSS
				$tmpType='01';
			else if($sysType==2)//Peripheral
			{
				if($eleType==0)//AAS
					$tmpType='02';
				else if($eleType==1)//VSS
					$tmpType='03';
				else if($eleType==2)//PCR
					$tmpType='04';
				else if($eleType==3)//CNF
					$tmpType='05';
				else if($eleType==4)//CNF Center
					$tmpType='06';
			}
			else if($sysType == 3)//switch
			{
				if($eleType==0)//ss7 switch
					$tmpType='10';
				else if($eleType==1)//ISDN switch
					$tmpType='11';
			}
			else if($sysType == 4)
				$tmpType = '12';
			else
				$tmpType='00';			
			$tmpSetValue = setBitValue($tmpSetValue,$typeOffset,$tmpType);
			
			$bin_sysNo = omc_keep_length(decbin($systemNo),'0',4);
			$tmpSetValue = setBitValue($tmpSetValue,$sysNoOffset,$bin_sysNo);
			
			$bin_subSysNo = omc_keep_length(decbin($subSysNo),'0',4);
			$tmpSetValue = setBitValue($tmpSetValue,$subSysNoOffset,$bin_subSysNo);
			if($sysType==4)
			{				
				$bin_appType = omc_keep_length(dechex($eleType),'0',2);
				$tmpSetValue = setBitValue($tmpSetValue,$appTypeOffset,$bin_appType);
				
				$bin_appGrp = omc_keep_length(dechex($setAppGrp),'0',2);
				$tmpSetValue = setBitValue($tmpSetValue,$appGrpOffset,$bin_appGrp);
			}
			if($sysType==4 && $needNewLinkset==1) $tgAssigned = 255;
			if($sysType==2 && $useSameCnfLinkset==1) 
			{
				$tgAssigned = $cnfTG;
				$lsAssigned = $cnfLS;
			}
			$tmpTG=strtoupper(omc_keep_length(dechex($tgAssigned),'0',2));
			$tmpSetValue = setBitValue($tmpSetValue,$tgOffset,$tmpTG);
			
			$tmpLs=strtoupper(omc_keep_length(dechex($lsAssigned),'0',2));
			if(($sysType==3 || $sysType==4)
				&&$needNewLinkset != 1)
				$tmpLs=strtoupper(omc_keep_length(dechex($lsInstNo),'0',2));
			$tmpSetValue = setBitValue($tmpSetValue,$lsOffset,$tmpLs);
			
			$tmpName=toHex($elementName);
			$tmpName=omc_keep_length($tmpName,'0',20,'0');	
			$tmpSetValue = setBitValue($tmpSetValue,$nameOffset,$tmpName);
					
			$updateSql="UPDATE $tmpParamTable SET initValue='$tmpSetValue'
							WHERE $levelWhere AND instanceNo='$tmpInstanceNo'";
			if(0){ 
				echo "<BR>updateSql=$updateSql";
				//exit();
			}
			mysqli_query($pubConn,$updateSql);
			echo mysqli_error($pubConn);		
		}//end update elementInfo
		//print_r($sysId_arr);
		SetParam($sysId_arr);
		SaveParam($SaveArr);

		echo "<br><br><h4><font color=\"#0000ff\">Finished!</font></h4>";
		echo "<br>";
		if($sysType==2 && $eleType==4)//after added cnf center, turn to cnf add page.
		{
			echo "<script language=\"javascript\">";
			$href="$PHP_SELF?sysType=2&eleType=3";
			echo "window.location.href='$href';";
			echo "</script>";
			exit();
		}
		echo "<script LANGUAGE=\"JavaScript\">";
		echo "\n window.location.href=\"./overview.php\";";
		echo "\n </script>";		
		//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();
	}
}//end POST
?>
<?php
/*check the element is exist*/
{//local element
	$localElementObjIdStr='2.1';
	$levelWhere = getLevelWhere($localElementObjIdStr);
	if($DEBUG) echo "<BR>levelWhere=$levelWhere";
	$localElementParamConfTable='OBJ_223.paramConf';
	for($i=0; $i<sizeof($locEleArr); $i++)
	{
		$getSql="SELECT $initValue FROM $localElementParamConfTable 
					WHERE $levelWhere and level_3='{$locEleArr[$i][sysTypeSSN]}'
				";
		if($DEBUG) echo "<BR>getSql=$getSql";
		$result	=mysqli_query($pubConn,$getSql);
		echo mysqli_error($pubConn);
		$rows=mysqli_fetch_array($result);
		if($DEBUG) echo "<BR>initValue=$rows[initValue]"; 
		$localElementDefaultValue[$i]=$rows[initValue];
	}
	$localElementParamTable='OBJ_223.param_99';
	$getSql="SELECT $initValue,level_3 FROM $localElementParamTable 
				WHERE $levelWhere
			";
	if($DEBUG) echo "<BR>getSql=$getSql";
	$result	=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	while($rows=mysqli_fetch_array($result))
	{	
		for($i=0;$i<sizeof($locEleArr);$i++)
		{
			if($rows[0]!=$localElementDefaultValue[$i]
			 &&$locEleArr[$i][sysTypeSSN]==$rows[level_3])
			{
				$locEleArr[$i][extFlg]=1;
			}
		}
	}
}
{//linkset value
	$othersElementObjIdStr='2.4.1';
	$levelWhere = getLevelWhere($othersElementObjIdStr);
	if($DEBUG) echo "<BR>levelWhere=$levelWhere";
	$othersElementParamTable='OBJ_222.param_99';
	$getSql="SELECT $initValue,instanceNo FROM $othersElementParamTable 
				WHERE $levelWhere ";
	if($DEBUG) echo "<BR>getSql=$getSql";
	$result	=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	
	while($rows=mysqli_fetch_array($result))
	{
		if($DEBUG)echo "<BR>initValue=$rows[initValue]";
		$lsFlag=getBitValue($rows[initValue],'3.2-3.2');//flag
		if($lsFlag==0)
			continue;
		$i = $rows[instanceNo];
		$lsArr[$i][lsValue] = $rows[initValue];
		$lsArr[$i][dpc]=hexdec(getBitValue($rows[initValue],'0.0-2.7'));		
		$lsArr[$i][ni]=bindec(getBitValue($rows[initValue],'3.0-3.1'));
		$lsArr[$i][isSwitch] = getBitValue($rows[initValue],'17.0-17.0');
		$lsArr[$i][name] = getBitValue($rows[initValue],'7.0-16.7');
		if($lsArr[$i][name]==0)
			$lsArr[$i][name]=$rows[instanceNo];
		else
			$lsArr[$i][name]=trim(toAscii($lsArr[$i][name]));
	}
}//end linkset value

{//others element
	$ElementInfoObjId='2.11';
	$levelWhere = getLevelWhere($ElementInfoObjId);
	if($DEBUG) echo "<BR>levelWhere=$levelWhere";
	$ElementInfoParamTable='OBJ_225.param_99';
	$getSql="SELECT $initValue,instanceNo FROM $ElementInfoParamTable 
				WHERE $levelWhere and initValue LIKE '01%' ";
	if($DEBUG) echo "<BR>getSql=$getSql";
	$result	=mysqli_query($pubConn,$getSql);
	echo mysqli_error($pubConn);
	$typeOffset 	= '1.0-1.7';
	$sysNoOffset 	= '2.0-2.3';
	$subSysNoOffset = '2.4-2.7';
	$tgOffset 		= '3.0-3.7';
	$lsOffset 		= '4.0-4.7';
	$appTypeOffset 	= '5.0-5.7';
	$appGrpOffset 	= '6.0-6.7';
	$nameOffset 	= '14.0-23.7';
	while($rows=mysqli_fetch_array($result))
	{
		if($DEBUG)echo "<BR>initValue=$rows[initValue]";
		$typeValue=hexdec(getBitValue($rows[initValue],$typeOffset));
		$sysNo	= bindec(getBitValue($rows[initValue],$sysNoOffset));
		$subsysNo	= bindec(getBitValue($rows[initValue],$subSysNoOffset));
		$tmpSystemNo= $sysNo;
		$assignedTg = hexdec(getBitValue($rows[initValue],$tgOffset));
		$assignedls = hexdec(getBitValue($rows[initValue],$lsOffset));
		$appType = hexdec(getBitValue($rows[initValue],$appTypeOffset));
		$appGrp = hexdec(getBitValue($rows[initValue],$appGrpOffset));
		$name = trim(toAscii(getBitValue($rows[initValue],$nameOffset)));
		$eleInfoNo = $rows[instanceNo];
		switch($typeValue)
		{
			case '1'://BSS			
				$othEleArr[1][0][$tmpSystemNo][extFlg]=1;				
				break;
			case '2'://AAS			
				$othEleArr[2][0][$sysNo][$subsysNo][extFlg]=1;
				break;
			case '3'://VSS			
				$othEleArr[2][1][$sysNo][$subsysNo][extFlg]=1;
				break;
			case '4'://PCR
				$othEleArr[2][2][$sysNo][$subsysNo][extFlg]=1;
				break;
			case '5'://CNF			
			{
				$othEleArr[2][3][$sysNo][$subsysNo][extFlg]=1;
				$cnfTG = $assignedTg;
				$cnfLS = $assignedls;
				$cnfLsValue = $lsArr[$assignedls][lsValue];
				break;
			}
			case '6'://CNF Center
			{
				$othEleArr[2][4][0][0][extFlg]=1;
				break;
			}
			case '16'://SS7 Switch
			{
				$othEleArr[3][0][$tmpSystemNo][extFlg]=1;
				$switchInfoNoArr[$assignedls][eleInfoNoStr] .= $eleInfoNo.'-';
				$switchInfoNoArr[$assignedls][assignedTg] = $assignedTg;
				break;
			}
			case '17'://ISDN Switch
			{
				$othEleArr[3][1][$tmpSystemNo][extFlg]=1;
				break;
			}
			case '18'://Application
			{
				$othEleArr[4][$appType][$appGrp][extFlg]=1;
				
				$AppInfoNoArr[$assignedls][eleInfoNoStr] .= $eleInfoNo.'-';
				$AppInfoNoArr[$assignedls][assignedTg] = $assignedTg;
				break;
			}
			default:
				break;
		}
	}
	$lsNum = 128;
	$sno=$ano=0;
	for($i=0; $i< $lsNum; $i++)
	{
		if(isset($switchInfoNoArr[$i][eleInfoNoStr]))
		{
			$switchLSArr[$sno][lsValue]=$lsArr[$i][lsValue];
			$switchLSArr[$sno][lsInstNo]=$i;
			$switchLSArr[$sno][dpc]=$lsArr[$i][dpc];
			$switchLSArr[$sno][ni]=$lsArr[$i][ni];
			$switchLSArr[$sno][name]=$lsArr[$i][name];
			$switchLSArr[$sno][eleInfoNoStr]=$AppInfoNoArr[$i][eleInfoNoStr];
			$switchLSArr[$sno][assignedTg]=$AppInfoNoArr[$i][assignedTg];
			$sno++;
		}
		if(isset($AppInfoNoArr[$i][eleInfoNoStr]))
		{
			$appLSArr[$ano][lsValue]=$lsArr[$i][lsValue];
			$appLSArr[$ano][lsInstNo]=$i;
			$appLSArr[$ano][dpc]=$lsArr[$i][dpc];
			$appLSArr[$ano][ni]=$lsArr[$i][ni];
			$appLSArr[$ano][isSwitch]=$lsArr[$i][isSwitch];
			$appLSArr[$ano][name]=$lsArr[$i][name];
			$appLSArr[$ano][eleInfoNoStr]=$AppInfoNoArr[$i][eleInfoNoStr];
			$appLSArr[$ano][assignedTg]=$AppInfoNoArr[$i][assignedTg];
			$ano++;
		}
	}
	
	$sno=0;
	$ano=0;
	for($i=0; $i<sizeof($appLSArr); $i++)
	{
		//if($appLSArr[$i][assignedTg]==255)
		if($appLSArr[$i][isSwitch]==0)
		{
			$switchSlcArr[$sno] = $appLSArr[$i];
			$sno++;
		}
		$appSlcArr[$ano] = $appLSArr[$i];
		$ano++;
	}
	for($i=0; $i<sizeof($switchLSArr); $i++)
	{
		$existed = 0;
		for($j=0; $j<sizeof($appSlcArr); $j++)
		{
			if($switchLSArr[$i][lsInstNo] == $appSlcArr[$j][lsInstNo])
			{
				$existed = 1;
				break;
			}
		}
		if($existed==1)
			continue;
		$appSlcArr[$ano] = $switchLSArr[$i];
		$ano++;
	}
}//end other elements
?>

<script LANGUAGE="JavaScript">  	
function slctSysType()
{      
	var base_url,url_add,url; 
	base_url='<?php echo "$PHP_SELF?sysType=";?>';
	url_add=document.editform.sysType.options[document.editform.sysType.selectedIndex].value;   
	//alert(url_add);
	//============================close the type selection when the systype is GTT object
	if(url_add==4)
		url_add=url_add+'&eleType=5';   
	url=base_url+url_add;
	window.location=url;
}

function slctEleType()
{      
	var base_url,url_add,url; 
	base_url='<?php echo "$PHP_SELF?sysType=$sysType&eleType=";?>';
	url_add=document.editform.eleType.options[document.editform.eleType.selectedIndex].value;      
	url=base_url+url_add;
	window.location=url;
}

function slctSysNo(flag)
{      
	var base_url,url_add,url; 
	base_url='<?php echo "$PHP_SELF?sysType=$sysType&eleType=$eleType&subSysNo=$subSysNo&systemNo=";?>';
	url_add=document.editform.systemNo.options[document.editform.systemNo.selectedIndex].value;      
	url=base_url+url_add;
	window.location=url;
}

function slctSubSysNo()
{      
	var base_url,url_add,url; 
	base_url='<?php echo "$PHP_SELF?sysType=$sysType&eleType=$eleType&systemNo=$systemNo&subSysNo=";?>';
	url_add=document.editform.subSysNo.options[document.editform.subSysNo.selectedIndex].value;      
	url=base_url+url_add;
	window.location=url;
}

function slctExistLs(item)
{      
	var base_url,url_add,url; 
	base_url='<?php echo "$PHP_SELF?sysType=$sysType&eleType=$eleType&subSysNo=$subSysNo&systemNo=$systemNo&slcLsNo=";?>';
	url_add=item.value;      
	url=base_url+url_add;
	window.location=url;
}
</script>

<body topmargin="0" leftmargin="12">
<form method="POST" name="editform" action="<?php echo"$PHP_SELF?"; ?>">
<?php
echo "<table border=\"0\" height=\"10%\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "Configuration > <a href=\"../overview/overview.php\">Network</a> > Add Element";
echo "</td>";
echo "<td width=\"50%\" align=\"right\" title=\"Help\">";
showHelp($helpId);
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"50%\">&nbsp;</td>";
echo "<td width=\"50%\" align=\"right\"><a href=\"./overview.php\">$strBack</td>";
echo "</tr>";
echo "</table>";
?>
<table border="1" width="100%" cellpadding="1" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF">
<?php
echo "<tr>";
echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">System</td>";
echo "<td width=\"70%\">";
$width="20%";
echo "<select style=width:\"$width\" onChange=\"javascript:slctSysType();\" name=\"sysType\">"; 
	if(!isset($sysType))
		echo "<option value=\"999\" selected>--</option>";
	else
		echo "<option value=\"999\">--</option>";
	for($i=1;$i<sizeof($sysTypeArr);$i++)
	{
		echo "<option value=\"$i\" ";
		if($sysType==$sysTypeArr[$i][id])
		{
			echo "selected";
		}
		echo ">{$sysTypeArr[$i][name]}</option>";
	}
echo "</select>"; 
echo "</td>";
echo "</tr>";

if($DEBUG)
	echo "<br>sysType=$sysType";
if(!isset($sysType)||$sysType==999)
	exit();

switch($sysType)
{
	case 0 ://local element
	{
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Element</td>";
		echo "<td width=\"70%\">";	
		echo "<select  style=width:\"$width\" onChange=\"javascript:slctEleType();\" name=\"eleType\">";
		if(!isset($eleType)) echo "<option value=\"999\" selected>--</option>";
		else echo "<option value=\"999\">--</option>";
		for($i=0;$i<sizeof($locEleArr);$i++)
		{
			if($locEleArr[$i][extFlg]==0)
			{
				echo "<option value=\"$i\" ";
				if(isset($eleType) && $eleType==$i)
				{
					echo "selected";
				}
				echo ">{$locEleArr[$i][sysTypeName]}</option>";
			}
		}
		echo "</select>"; 

		break;
	}
	case 1 ://bss
	{
		echo "<tr style=\"DISPLAY: none\">";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Element</td>";
		echo "<td width=\"70%\">";	
		echo "&nbsp;";
		echo "<input type=\"hidden\" name=\"eleType\" value=\"0\">";
		break;
	}
	case 2 ://peripheral
	{
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Type</td>";
		echo "<td width=\"70%\">";	
		echo "<select  style=width:\"$width\" onChange=\"javascript:slctEleType();\" name=\"eleType\">";
		if(!isset($eleType)) echo "<option value=\"999\" selected>--</option>";
		else echo "<option value=\"999\">--</option>";
		for($i=0;$i<sizeof($peripheEleArr);$i++)
		{
			$canAdd = array_search($peripheEleArr[$i][sysTypeNo], $existElementArr);
			if($canAdd == FALSE)
				continue;
			echo "<option value=\"$i\" ";
			if(isset($eleType) && $eleType==$i)
			{
				echo "selected";
			}
			echo ">{$peripheEleArr[$i][sysTypeName]}</option>";
		}
		echo "</select>"; 
		break;
	}
	case 3 ://switch
	{
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Type</td>";
		echo "<td width=\"70%\">";	
		echo "<select style=width:\"$width\" onChange=\"javascript:slctEleType();\" name=\"eleType\">";
		if(!isset($eleType)) echo "<option value=\"999\" selected>--</option>";
		else echo "<option value=\"999\">--</option>";
		for($i=0;$i<sizeof($switchEleArr);$i++)
		{
			echo "<option value=\"$i\" ";
			if(isset($eleType) && $eleType==$i)
			{
				echo "selected";
			}
			echo ">{$switchEleArr[$i][sysTypeName]}</option>";
		}
		echo "</select>"; 
		break;
	}
	case 4 ://Application
	{
		//===close the type selection when the sysType is GTT object================
		echo "<tr style=\"display:none\">";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Type</td>";
		echo "<td width=\"70%\">";		
		echo "<select  style=width:\"$width\" onChange=\"javascript:slctEleType();\" name=\"eleType\">";
		
		if(!isset($eleType)) echo "<option value=\"999\" selected>--</option>";
		else echo "<option value=\"999\">--</option>";
		for($i=0;$i<sizeof($appliEleArr);$i++)
		{
			echo "<option value=\"$i\" ";
			if(isset($eleType) && $eleType==$i)
			{
				echo "selected";
			}
			echo ">{$appliEleArr[$i][sysTypeName]}</option>";
		}
		echo "</select>"; 
		break;
	}
}
echo "</td>";
echo "</tr>";
if($sysType==1)
	$eleType=0;
if((!isset($eleType)||$eleType==999)
	&&($sysType==0||$sysType==2||$sysType==3||$sysType==4))
	exit();


if($sysType==0)
{
	echo "<tr style=\"DISPLAY: none\">";
	echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">System No.</td>";
	echo "<td width=\"70%\">";	
	echo "&nbsp;"; 
	echo "<input type=\"hidden\" name=\"systemNo\" value=\"0\">";
}
else if($sysType==1)
{

	echo "<tr style=\"DISPLAY: none\">";
	echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">System No.</td>";
	echo "<td width=\"70%\">";		
	for($i=0;$i<128;$i++)
	{
		if($othEleArr[$sysType][$eleType][$i][extFlg]!=1)
		{
			echo "$i";
			echo "<input type=\"hidden\" name=\"systemNo\" value=\"$i\">";
			$systemNo =$i;
			break;
		}
	}	
}
else if($sysType==2)
{
	switch($eleType)
	{
		case 0 : //AAS

			$elementsNum=2;
			$sysNum=2;
			$subSysNum=1;
			break;
		case 1 : //vss
		
			$elementsNum=10;
			$sysNum=10;
			$subSysNum=1;
			break;		
		case 2 ://pcr
		  
			$elementsNum=32;
			$sysNum=2;
			$subSysNum=16;
			break;
		case 3 ://cnf
		
			$elementsNum=4;
			$sysNum=1;
			$subSysNum=4;
			break;
		case 4 ://cnf center
			
			$elementsNum=1;
			$sysNum=1;
			$subSysNum=1;
			break;		
	}
	$allExist=1;
	for($i=0; $i< $sysNum; $i++)
	{
		for($j=0; $j< $subSysNum; $j++)
		{
			if($othEleArr[$sysType][$eleType][$i][$j][extFlg]!=1)
			{
				$allExist=0;
				break;
			}
		}
	}
	if($allExist)
	{
		echo "<script language=\"javascript\">";
		echo "alert('These Elements all Existed!');";
//		$href="$PHP_SELF?sysType=$sysType&eleType=4";
//		echo "window.location.href='$href';";
		echo "</script>";
		exit;
	}
	if($eleType==4)
	{
		echo "<input type=\"hidden\" name=\"systemNo\" value=\"0\">";
		echo "<input type=\"hidden\" name=\"subSysNo\" value=\"0\">";
		$systemNo=$subSysNo=0;
	}
	else
	{
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">sysNo.</td>";
		echo "<td width=\"70%\">";
		echo "<select  style=width:\"$width\" onChange=\"javascript:slctSysNo();\" name=\"systemNo\">";
		if(!isset($subSysNo))
		{
			for($i=0; $i< $sysNum; $i++)
			{
				for($j=0; $j< $subSysNum; $j++)
				{
					if($othEleArr[$sysType][$eleType][$i][$j][extFlg]!=1)
					{
						$subSysNo=$j;
						break;						
					}
				}
			}			
		}
		
		if(!isset($systemNo))
		{
			$first=0;
			for($i=0; $i< $sysNum; $i++)
			{
				if($othEleArr[$sysType][$eleType][$i][$subSysNo][extFlg]!=1)
				{
					echo "<option value=\"$i\" >$i</option>";
					$first++;
					if($first==1) $systemNo=$i;
				}
			}
		}
		else
		{
			for($i=0; $i< $sysNum; $i++)
			{
				if($othEleArr[$sysType][$eleType][$i][$subSysNo][extFlg]!=1)
				{
					echo "<option value=\"$i\" ";
						if($systemNo==$i) echo "selected";		
					echo ">$i</option>";
				}
			}
		}
		echo "</td>";
		echo "</tr>";
		
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">subSysNo.</td>";
		echo "<td width=\"70%\">";
		echo "<select  style=width:\"$width\" onChange=\"javascript:slctSubSysNo();\" name=\"subSysNo\">";
		if(!isset($systemNo))
		{
			for($i=0; $i< $sysNum; $i++)
			{
				for($j=0; $j< $subSysNum; $j++)
				{
					if($othEleArr[$sysType][$eleType][$i][$j][extFlg]!=1)
					{
						$systemNo=$i;
						break;						
					}
				}
			}			
		}
		
		if(!isset($subSysNo))
		{
			for($j=0; $j< $subSysNum; $j++)
			{
				if($othEleArr[$sysType][$eleType][$systemNo][$j][extFlg]!=1)
				{
					echo "<option value=\"$j\" >$j</option>";
				}
			}
		}
		else
		{
			for($j=0; $j< $subSysNum; $j++)
			{
				if($othEleArr[$sysType][$eleType][$systemNo][$j][extFlg]!=1)
				{
					echo "<option value=\"$j\" ";
						if($subSysNo==$j) echo "selected";		
					echo ">$j</option>";
				}
			}
		}
		echo "</tr>";
	}
	
}
else if($sysType==3)
{
	if($eleType==1)//ISDN switch
	{
		echo "<tr style=\"DISPLAY: none\">";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">System No.</td>";
		echo "<td width=\"70%\">";		
		for($i=0;$i<32;$i++)
		{
			if($othEleArr[$systemType][$eleType][$i][extFlg]!=1)
			{
				echo "$i";
				echo "<input type=\"hidden\" name=\"systemNo\" value=\"$i\">";
				$systemNo =$i;
				break;
			}
		}
	}
	else		//SS7 switch
	{
		
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Linkset</td>";
		echo "<td width=\"70%\">";
		for($i=0; $i<128; $i++)
			if($othEleArr[3][$eleType][$i][extFlg]!=1)
			{
				$tmp_systemNo = $i;
				break;
			}
		echo "<input type=\"hidden\" name=\"systemNo\" value=\"$tmp_systemNo\" >";
		echo "<input type=\"hidden\" name=\"subSysNo\" value=\"0\" >";
		$systemNo = $tmp_systemNo;
		$subSysNo = 0;
		
		echo "<select  style=width:\"$width\" onChange=\"javascript:slctExistLs(this);\" name=\"slcLsNo\">";	
		if(!isset($systemNo))
			echo "<option value=\"999\" selected>--</option>";
		else 
			echo "<option value=\"999\">--</option>";
		echo "<option value=\"888\" ";
		if($slcLsNo=='888')
		{
		  echo "selected";
			
		}
		echo ">New</option>";
		for($i=0; $i<sizeof($switchSlcArr); $i++)
		{
			echo "<option value=\"$i\" ";
			if(isset($slcLsNo) && $i==$slcLsNo)
				echo "selected";
			echo ">{$switchSlcArr[$i][name]}</option>";
		}
		echo "</select>";
	}
}
else if($sysType==4)
{
	echo "<tr>";
	echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Linkset</td>";
	echo "<td width=\"70%\">";
	for($i=0; $i< 256; $i++)
		if($othEleArr[4][$eleType][$i][extFlg]!=1)
		{
			echo "<input type=\"hidden\" name=\"setAppGrp\" value=\"$i\">";
			$setAppGrp = $i;
			$tmp_systemNo = $i;
			break;
		}	
	echo "<input type=\"hidden\" name=\"systemNo\" value=\"$tmp_systemNo\" >";
	echo "<input type=\"hidden\" name=\"subSysNo\" value=\"0\" >";
	$systemNo = $tmp_systemNo;
	$subSysNo = 0;
	
	echo "<select  style=width:\"$width\" onChange=\"javascript:slctExistLs(this);\" name=\"slcLsNo\">";	
	if(!isset($systemNo))
		echo "<option value=\"999\" selected>--</option>";
	else 
		echo "<option value=\"999\">--</option>";
	echo "<option value=\"888\" ";
	if($slcLsNo=='888') 
		echo "selected";
	echo ">New</option>";
	for($i=0; $i<sizeof($appSlcArr); $i++)
	{
		echo "<option value=\"$i\" ";
		if(isset($slcLsNo) && $i==$slcLsNo)
			echo "selected";
		echo ">{$appSlcArr[$i][name]}</option>";
	}
	echo "</select>";
}
echo "</td>";
echo "</tr>";

if(0)
{
	echo "<br>sysType:$sysType<br>eleType:$eleType<br>systemNo:$tmp_systemNo<br>subSysNo:$subSysNo";
	echo "<br>appType:$appType<br>setAppGrp:$setAppGrp<br>slcLsNo:$slcLsNo";
}
if((!isset($systemNo)||$systemNo==999)&&$sysType!=0)
	exit();


	//==========================get the disable Alinkset instanceNo========================
	$database="OBJ_222";
	$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=4 and level_3=1 ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	$disable_linkSet_num=0;
	if(!$rows)
			exit("No record");
				
	do{
		
		$Flag=getBitValue($rows[initValue],'3.2-3.2')+0;
		if($Flag==0)
		{
			$aa=$rows[instanceNo];
			//alert($aa." no use");
			$disable_linkset[$disable_linkSet_num]=$aa;
			$disable_linkSet_num++;			
		}
	}while($rows=mysqli_fetch_array($result));
	//===========================get the disable trunk group====================================
	$database="OBJ_322";
	$sql="select instanceNo,initValue from param_99 where level_1=2 and level_2=1 and level_3=4 ";
	$result=@mysqli_query($pubConn,$sql);
	$rows=@mysqli_fetch_array($result);
	$disable_trunk_num=0;
	if(!$rows)
			exit("No record");
				
	do{
		if($rows[instanceNo]==250||$rows[instanceNo]==251||$rows[instanceNo]==252||$rows[instanceNo]==253||$rows[instanceNo]==254||$rows[instanceNo]==255)
			continue;
		$Flag=getBitValue($rows[initValue],'4.0-4.0')+0;
		if($Flag==0)
		{
			$aa=$rows[instanceNo];
			//alert($aa." no use");
			$disable_trunk[$disable_trunk_num]=$aa;
			$disable_trunk_num++;			
		}
	}while($rows=mysqli_fetch_array($result));
//==============================end trunk and linkset====================================


if($sysType==0)
{
	echo "<tr style=\"DISPLAY: none\">";
	echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Network Indicator</td>";
	echo "<td width=\"70%\">";
	echo "<select  style=width:\"$width\" name=\"ni\">";
	for($i=0;$i<sizeof($niArr);$i++)
	{
		echo "<option value=\"$i\" ";
		if($ni==$i)
		{
			echo "selected";
		}
		echo ">{$niArr[$i][name]}</option>";
	}
	echo "</select>";
	echo "</td>";
	echo "</tr>";
}
elseif($sysType<3)
{
	//alert("hi");
	
	//=========================add linkset selection============================
	echo "<tr>";
	echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Linkset no.</td>";
	echo "<td width=\"70%\">";
		echo "<select  style=width:\"$width\" name=\"linkset_select\">";
		for($i=0;$i<$disable_linkSet_num;$i++)
		{
			echo "<option>{$disable_linkset[$i]}</option>";
		}	
		echo "</select>";
	echo "</td>";
	echo "</tr>";
	//=========================add trunk group==========================================
	echo "<tr>";
	echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Trunk group no.</td>";
	echo "<td width=\"70%\">";
		echo "<select  style=width:\"$width\" name=\"trunk_select\">";
		for($i=0;$i<$disable_trunk_num;$i++)
		{
			echo "<option>{$disable_trunk[$i]}</option>";
		}
		echo "</select>";
	echo "</td>";
	echo "</tr>";
	
	if($sysType==2)
	{
		if($eleType==3 && $othEleArr[2][4][0][0][extFlg]!=1) //cnf.( if cnf center have been added at first?)
		{
			echo "<script language=\"javascript\">";
			echo "alert('Add the CNF Center First, Please!');";
			$href="$PHP_SELF?sysType=$sysType&eleType=4";
			//echo "alert('$href');";
			echo "window.location.href='$href';";
			echo "</script>";
		}
	}
	for($i=0; $i<4; $i++)
	{
		if($othEleArr[2][3][0][$i][extFlg]==1)
		{
			$cnfExistFlag = 1;
			break;
		}
	}
	if($sysType==2 && $eleType==3 && $cnfExistFlag==1)
	{
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Element Name</td>";
		echo "<td width=\"70%\">";
		echo "<input style=width:\"$width\" type=\"text\" size=\"10\" maxlength=\"8\" name=\"elementName\" class=\"text\">";
		echo "</td>";
		echo "</tr>";	
		
			
		echo "<input type=\"hidden\" name=\"cnfTG\" value=\"$cnfTG\">";
		echo "<input type=\"hidden\" name=\"lsValue\" value=\"$cnfLsValue\">";
		echo "<input type=\"hidden\" name=\"cnfLS\" value=\"$cnfLS\">";
		echo "<input type=\"hidden\" name=\"useSameCnfLinkset\" value=\"1\">";
	}
	else
	{
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Network Indicator</td>";
		echo "<td width=\"70%\">";
		echo "<select  style=width:\"$width\" name=\"ni\">";
		for($i=0; $i < sizeof($niArr); $i++)
		{
			echo "<option value=\"$i\" ";
			if($ni==$i)
			{
				echo "selected";
			}
			echo ">{$niArr[$i][name]}</option>";
		}
		echo "</select>";
		echo "</td>";
		echo "</tr>";
	
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Element Name</td>";
		echo "<td width=\"70%\">";
		if($sysType==2 && $eleType==4)
		{
			echo "<input  style=width:\"$width\" type=\"text\" size=\"12\" maxlength=\"10\" name=\"elementName\" value=\"CNF Center\" class=\"text\" disabled>";
			echo "<input type=\"hidden\" name=\"elementName\" value=\"CNF Center\">";
		}
		else
			echo "<input  style=width:\"$width\" type=\"text\" size=\"12\" maxlength=\"8\" name=\"elementName\" class=\"text\">";
		echo "</td>";
		echo "</tr>";	
	
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">DPC</td>";
		echo "<td width=\"70%\">";
		echo "<input  style=width:\"$width\" type=\"text\" size=\"12\" maxlength=\"8\" name=\"dpc\" class=\"text\" onchange = checkInput(this,10,16777215)>";
		echo "</td>";
		echo "</tr>";
		if($sysType == 1 && $needBssIp==1) //bss ip
		{
			echo "<tr>";
			echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">IP</td>";
			echo "<td width=\"70%\">";
			echo "<input  style=width:\"$width\" type=\"text\" size=\"16\" maxlength=\"15\" name=\"bssIP\" class=\"text\">";
			echo "</td>";
			echo "</tr>";
		}//end bss ip
	}
}
elseif($sysType==3||$sysType==4)
{
	if($sysType==3 && $eleType==1)//ISDN switch
	{
		
		
		
		
		//=========================add linkset selection============================
		echo "<tr style=\"display:none\">";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Linkset no.</td>";
		echo "<td width=\"70%\">";
			echo "<select  style=width:\"$width\" name=\"linkset_select\">";
			for($i=0;$i<$disable_linkSet_num;$i++)
			{
				echo "<option>{$disable_linkset[$i]}</option>";
			}	
			echo "</select>";
		echo "</td>";
		echo "</tr>";
		//=========================add trunk group==========================================
		if($sysType==3)
		{
			echo "<tr>";
			echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Trunk group no.</td>";
			echo "<td width=\"70%\">";
				echo "<select  style=width:\"$width\" name=\"trunk_select\">";
				for($i=0;$i<$disable_trunk_num;$i++)
				{
					echo "<option>{$disable_trunk[$i]}</option>";
				}
				echo "</select>";
			echo "</td>";
			echo "</tr>";
		}
		
		
		
		
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Element Name</td>";
		echo "<td width=\"70%\">";
		echo "<input style=width:\"$width\" type=\"text\" size=\"12\" maxlength=\"8\" name=\"elementName\" class=\"text\">";
		echo "</td>";
		echo "</tr>";	
	}
	else if(!isset($slcLsNo) || $slcLsNo==999) exit;
	else if($slcLsNo==888)//new
	{
		//=========================add linkset selection============================
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Linkset no.</td>";
		echo "<td width=\"70%\">";
			echo "<select  style=width:\"$width\" name=\"linkset_select\">";
			for($i=0;$i<$disable_linkSet_num;$i++)
			{
				echo "<option>{$disable_linkset[$i]}</option>";
			}	
			echo "</select>";
		echo "</td>";
		echo "</tr>";
		//=========================add trunk group==========================================
		if($sysType==3)
		{
			echo "<tr>";
			echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Trunk group no.</td>";
			echo "<td width=\"70%\">";
				echo "<select  style=width:\"$width\" name=\"trunk_select\">";
				for($i=0;$i<$disable_trunk_num;$i++)
				{
					echo "<option>{$disable_trunk[$i]}</option>";
				}
				echo "</select>";
			echo "</td>";
			echo "</tr>";
		}
		/*
		if($sysType==3)
			alert("ss7 new");
		if($sysType==4)
			alert("gtt new");	
			*/
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Element Name</td>";
		echo "<td width=\"70%\">";
		echo "<input style=width:\"$width\" type=\"text\" size=\"12\" maxlength=\"8\" name=\"elementName\" class=\"text\">";
		echo "</td>";
		echo "</tr>";	
		
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Network Indicator</td>";
		echo "<td width=\"70%\">";
		echo "<select  style=width:\"$width\" name=\"ni\">";
		for($i=0;$i<sizeof($niArr);$i++)
		{
			echo "<option value=\"$i\" ";
			if($ni==$i)
			{
				echo "selected";
			}
			echo ">{$niArr[$i][name]}</option>";
		}
		echo "</select>";
		echo "</td>";
		echo "</tr>";


		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">DPC</td>";
		echo "<td width=\"70%\">";
		echo "<input style=width:\"$width\" type=\"text\" size=\"12\" maxlength=\"8\" name=\"dpc\" class=\"text\" onchange = checkInput(this,10,16777215)>";
		echo "</td>";
		echo "<input type=\"hidden\" name=\"needNewLinkset\" value=\"1\">";
	}
	else
	{
		if($sysType==3)
		{
		/*
		echo "<script language=\"JavaScript\">\n";
		echo "alert('hello');\n";
		echo "</script>\n";
		*/
			echo "<tr>";
			echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Trunk group no.</td>";
			echo "<td width=\"70%\">";
				echo "<select  style=width:\"$width\" name=\"trunk_select\">";
				for($i=0;$i<$disable_trunk_num;$i++)
				{
					echo "<option>{$disable_trunk[$i]}</option>";
				}
				echo "</select>";
			echo "</td>";
			echo "</tr>";
		}
		echo "<tr>";
		echo "<td width=\"30%\" bgcolor=\"#E6E6E6\">Element Name</td>";
		echo "<td width=\"70%\">";
		echo "<input style=width:\"$width\" type=\"text\" size=\"12\" maxlength=\"8\" name=\"elementName\" class=\"text\">";
		echo "</td>";
		echo "</tr>";	
		if($sysType==4)
		{
			echo "<input type=\"hidden\" name=\"ni\" value=\"{$appSlcArr[$slcLsNo][ni]}\">";
			echo "<input type=\"hidden\" name=\"dpc\" value=\"{$appSlcArr[$slcLsNo][dpc]}\">";
			echo "<input type=\"hidden\" name=\"lsValue\" value=\"{$appSlcArr[$slcLsNo][lsValue]}\">";
			echo "<input type=\"hidden\" name=\"lsInstNo\" value=\"{$appSlcArr[$slcLsNo][lsInstNo]}\">";
			echo "<input type=\"hidden\" name=\"updEleInfoNoStr\" value=\"{$appSlcArr[$slcLsNo][eleInfoNoStr]}\">";
		}
		else if($sysType==3)
		{
			echo "<input type=\"hidden\" name=\"ni\" value=\"{$switchSlcArr[$slcLsNo][ni]}\">";
			echo "<input type=\"hidden\" name=\"dpc\" value=\"{$switchSlcArr[$slcLsNo][dpc]}\">";
			echo "<input type=\"hidden\" name=\"lsValue\" value=\"{$switchSlcArr[$slcLsNo][lsValue]}\">";
			echo "<input type=\"hidden\" name=\"lsInstNo\" value=\"{$switchSlcArr[$slcLsNo][lsInstNo]}\">";
			echo "<input type=\"hidden\" name=\"updEleInfoNoStr\" value=\"{$switchSlcArr[$slcLsNo][eleInfoNoStr]}\">";
		}
	}
}
echo "</table>";
?>
<?php
echo "<br><table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"30%\" align=\"right\">"; 
echo "</td>";  
echo "<td width=\"70%\">";
echo "<input type=\"submit\" name=\"add\" value=\"Add\" style=\"width:$width\" class=\"button\">&nbsp"; 
echo "</td>";       
echo "</tr>";
echo "</table>";
?>
</form>
</body>
</html>
