<?php
require("../../inc/header.inc");
require("../sub_inc/operWebFunc.inc");
require("./param_comm.inc");
?>
<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('down');" onresize="javascript:adjust_frame('down');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

<script language="Javascript">
document.write("<div id='EMS_TIP_WINDOW' style=\"z-index:1000;display:none;position:absolute;border-color:#000000;border-style:solid;border-width:1px;padding:2px;\" ></div>");
	
function getEvent()
{  
	if(document.all)   
		return window.event; 	
	func=getEvent.caller; 	

	while(func!=null){  
		var arg0=func.arguments[0];
		if(arg0)
		{
			if((arg0.constructor==Event || arg0.constructor ==MouseEvent) || (typeof(arg0)=="object" && arg0.preventDefault && arg0.stopPropagation)) 
				return arg0;
              
		}
		func=func.caller;
	}
	return null;
}

function showTipWindow(tip)
{
	if(tip.length == 0)
		return;
	var pos_x;
	var pos_y;
	var event=getEvent();
	if (navigator.appName=='Microsoft Internet Explorer') 
	{
		pos_x=event.x;
		pos_y=event.y+document.body.scrollTop;
	}
	else if (navigator.appName=='Netscape') 
	{
		pos_x=event.pageX;
		pos_y=event.pageY;
	}

	document.getElementById("EMS_TIP_WINDOW").style.top=pos_y;
	document.getElementById("EMS_TIP_WINDOW").style.left=pos_x+40;
	document.getElementById("EMS_TIP_WINDOW").style.backgroundColor='#eeeeee';
	document.getElementById("EMS_TIP_WINDOW").style.display='';
	document.getElementById("EMS_TIP_WINDOW").innerHTML=tip;
}

function hideTipWindow()
{
	document.getElementById("EMS_TIP_WINDOW").style.display='none';
}
function deleteObject(sysId,table_id,table_level,instanceNo,deleteOid,updateOid,getTableOid,deleteIndex,control)
{
	var reply=confirm("Do you want to delete the selected?");
	if(reply == true)
	{
		window.location.href="param_show_table.php?delete=1&sysId="+sysId+"&table_id="+table_id+"&table_level="+table_level+"&instanceNo="+instanceNo+"&deleteOid="+deleteOid+"&updateOid="+updateOid+"&getTableOid="+getTableOid+"&deleteIndex="+deleteIndex;
	}
	else
	{
		control.checked=false;
	}
}

function lockTimeSlot(sysId,instanceNo,oidStr,table_id,table_level,opt)
{
	URL="./lockTimeSlot.php?sysId="+sysId+"&oidStr="+oidStr+"&instanceNo="+instanceNo+"&table_id="+table_id+"&table_level="+table_level+"&opt="+opt;
	//window.alert(URL);
	var msgWindow = open(URL, 'newWin', 'toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,width=400,height=350');
	msgWindow.focus();
}

function updateTab(tabid)
{
	//parent.param_show_up.tab_sel=tabid;
	parent.param_show_up.adjust_tab(tabid);
	//alert('click me '+tabid);
}

var isConfirm=0;
function buttonOpt()
{
	if(isConfirm)
	{
		isConfirm=0;
		var res=confirm('Are you sure to do this operation?');
		if(res == true)
			return true;
		else
			return false;
	}
	else
	{
		return true;
	}
}

</script>

<?php
adjust_head_frame("down");
adjust_title_head_frame("down");
adjust_title_tail_frame("down");

adjust_content_head_frame("down");	

if(!isset($table_id))
	$table_id=0;
$canwrite_flag=checkWritePrivilege();
//*****
//$url_temp=$_SERVER["REQUEST_URI"];
//echo "This page URL:$url_temp<br>";

$sysIdArr=explode('_',$sysId);
$sysTypeNo=$sysIdArr[0];
$sysNo=$sysIdArr[1];
$subSysNo=$sysIdArr[2];
$objDb='OBJ_'.$sysTypeNo;
$paraConfTable=$objDb.'.paramConf';
$pubDb='OMC_PUB';
if(checkIndependSystem($sysTypeNo))//Plat
	$paraTable=$objDb.".param_".$sysNo;
else
	$paraTable=$objDb.".param_99";

//check the system whether exist
$sysConfTable = 'sysConf';
$sysInfoTable = 'sysInfo';
if(($sysNo == '99') || ($subSysNo == '99')){
	if($sysNo == '99'){
		$sysIdSql ="SELECT sysTypeName,$sysInfoTable.sysTypeNo,sysNo,subSysNo,sysAlias  
				FROM $sysInfoTable,$sysConfTable 
				WHERE $sysInfoTable.sysTypeNo=$sysConfTable.sysTypeNo 
				AND $sysInfoTable.sysTypeNo = '$sysTypeNo'
				";
	
	}else{
		$sysIdSql ="SELECT sysTypeName,$sysInfoTable.sysTypeNo,sysNo,subSysNo,sysAlias  
				FROM $sysInfoTable,$sysConfTable 
				WHERE $sysInfoTable.sysTypeNo=$sysConfTable.sysTypeNo 
				AND $sysInfoTable.sysTypeNo = '$sysTypeNo'
				AND sysNo = '$sysNo'
				";
	}
	if($DEBUG)echo "sysIdSql(1) = $sysIdSql<br>";
	$result = mysqli_query($pubConn,$sysIdSql);
	echo mysqli_error($pubConn);
	$rowsNum=mysqli_num_rows($result);
	$rows=mysqli_fetch_array($result);
	$sysTypeName=$rows[sysTypeName];
	if($rowsNum < 1){
		echo "&nbsp;</td></tr></table>$strUninstalled<br>";
		exit();
	}
}else{
	$sysIdSql ="SELECT sysTypeName,$sysInfoTable.sysTypeNo,sysNo,subSysNo,sysAlias  
			FROM $sysInfoTable,$sysConfTable 
			WHERE $sysInfoTable.sysTypeNo=$sysConfTable.sysTypeNo 
			AND $sysInfoTable.sysTypeNo = '$sysTypeNo'
			AND sysNo = '$sysNo'
			AND subSysNo = '$subSysNo'
			";
	if($DEBUG) echo "sysIdSql(2) = $sysIdSql<br>";
	$result = mysqli_query($pubConn,$sysIdSql);
	echo mysqli_error($pubConn);
	$rowsNum=mysqli_num_rows($result);
	$rows=mysqli_fetch_array($result);
	$sysTypeName=$rows[sysTypeName];
	if($rowsNum < 1){
		echo "&nbsp;</td></tr></table>$strUninstalled<br>";
		exit();
	}
}	


$tabConf=GetTabConf($sysTypeNo);
$tableOid=$tabConf[$table_id][OID];

if(0)
{
	echo "<pre>";
	print_r($tabConf);
	echo "</pre>";
}

/**********************************************/
//echo "tableOid=$tableOid<br>";
//Gommand

if($delete == 1)
{
	if(0)
	{
		//echo "delete<br>";
		//echo "sysId=$sysId,table_id=$table_id,table_level=$table_level,instanceNo=$instanceNo,deleteOid=$deleteOid,updateOid=$updateOid,getTableOid=$getTableOid,deleteIndex=$deleteIndex<br>";
	}
	//Set the value=6 in the db
	$tmpwhere=getLevelWhere($deleteOid);
	$sql="update $paraTable set initValue='6' where $tmpwhere and instanceNo='$deleteIndex' ";
	if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
		$sql.="and subSysNo='$subSysNo' ";
	mysqli_query($pubConn,$sql);
	
	//Send delete command
	$commIdStr=oidSysCommSend($sysId,3,$deleteOid,-1,$deleteIndex);
	checkState($commIdStr,"./param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=$instanceNo");

	//Update the entries field
	if(trim($updateOid)!="")
	{
		$commIdStr=oidSysCommSend($sysId,0,$updateOid,-1,$instanceNo);
		checkState($commIdStr,"./param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=$instanceNo");
	}
	
	//Get the table
	$tmpArr[0][sysId]=$sysId;
	$tmpArr[0][oid]=$getTableOid;
	if($instanceNo=="0000")
		$tmpArr[0][instanceNo]="";
	else
		$tmpArr[0][instanceNo]=$instanceNo;
	getParam($tmpArr);
	
	//delete the sub table object
	DeleteSubTableData($sysTypeNo,$deleteIndex,$getTableOid,$paraTable);
}

if($_SERVER['REQUEST_METHOD'] == "POST")
{
	$delSql="delete from $paraTable where instanceNo='' ";
	if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
		$delSql.="and subSysNo='$subSysNo' ";		
	mysqli_query($pubConn,$delSql);

echo "\n<script language=\"JavaScript\">\n";
echo "adjust_frame('down');\n";
echo "</script>\n";
echo "<br>";

	if($scalar_item_get)
	{
		getParam($getArr);
	}
	else if($scalar_item_set)
	{
		$len=sizeof($setArr);
		$commIdStr="";
		for($i=0;$i<$len;$i++)
		{
			$tmpCommIdStr=oidSysCommSend($setArr[$i][sysId],3,$setArr[$i][oid],-1);		
			$commIdStr=$commIdStr.$tmpCommIdStr;
		}
		if($len>0)
			checkState($commIdStr,"./param_show_table.php?sysId=$sysId&table_id=$table_id&instanceNo=$instanceNo");
	}
	else if($column_table_get)
	{
		//Get the timeslot parameter from the plat(trunk group id)
		$trunk_table_oid=GetOIDByName(SYSTYPENO_MSC,"channelEntry");		
		for($i=0;$i<sizeof($commInfoArr);$i++)
		{
			if($sysTypeNo == SYSTYPENO_MSC && $commInfoArr[$i][oid] == $trunk_table_oid)
			{
				$tmps=explode(".",$instanceNo);
				$grounp_id=GetTrunkGroupID($tmps[0]+0,$tmps[1]+0);
				if($grounp_id == 1)
					$commInfoArr[$i][sysId]="320_1_0";
				else
					$commInfoArr[$i][sysId]="320_0_0";
				if(!GetSystemStatus(SYSTYPENO_MSC,$grounp_id))
					$commInfoArr[$i][sysId]="320_99_99";
				break;
			}
		}
		
		getParam($commInfoArr);
	}
	
	$commlen=sizeof($commands);
	for($i=0;$i<$commlen;$i++)
	{
		$paraName="command_id_".$i;
		if($$paraName)
		{
			$tmpwhere=getLevelWhere($commands[$i][oid]);
			$oidstr=str_replace(".",",",$commands[$i][oid]);
			$oidsep=explode(".",$commands[$i][oid]);
			$oidlen=sizeof($oidsep);
			$valuestr="";
			for($oi=0;$oi<$oidlen;$oi++)
			{
				$valuestr.="level_".($oi+1);
				if($oi != ($oidlen-1))
					$valuestr.=",";
			}
			$delSql="delete from $paraTable where $tmpwhere and instanceNo='0000' ";
			if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
				$delSql.="and subSysNo='$subSysNo' ";
			
			mysqli_query($pubConn,$delSql);
			$insertSql="insert into $paraTable($valuestr,instanceNo,initValue,readValue) values($oidstr,'0000',{$commands[$i][val]},{$commands[$i][val]}) ";
			
			if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
				$insertSql="insert into $paraTable($valuestr,instanceNo,initValue,readValue,subSysNo) values($oidstr,'0000',{$commands[$i][val]},{$commands[$i][val]},{$subSysNo}) ";
				
			mysqli_query($pubConn,$insertSql);
			echo mysqli_error($pubConn);
	
			//echo "send command {$commands[$ci][oid]} {$commands[$ci][val]}<br>";
			$commIdStr=oidSysCommSend($sysId,3,$commands[$i][oid],-1,"0000");
			checkState($commIdStr,"./param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=0000");
			
			break;
		}
	}
}

echo "<form name=\"myform\" method=\"POST\" action=\"$PHP_SELF\" onsubmit=\"return buttonOpt();\">";

//Get the sub oid of the table
$oidwhere=getLevelWhere($tableOid);
$size=sizeof(explode(".",$tableOid));
$oidwhere.=" AND level_".($size+1).">0 ";
$lastlevel="level_".($size+2);
$sql="select * from $paraConfTable where $oidwhere order by level_1,level_2,level_3,level_4,level_5,level_6,level_7,level_8,level_9,level_10 ";
$res=@mysqli_query($pubConn,$sql);
$num=@mysqli_num_rows($res);

$scalarTableIndex=0;
$columnTableIndex=0;
$scalarItemIndex=0;
$scalarItemReadCount=0;
for($i=0;$i<$num;$i++)
{
	$row=@mysqli_fetch_array($res);
	if($row[$lastlevel] == 0)
	{
		//scalar table
		if($row[maxAccess] == ACCESS_TABLE_NAME && $row[operType] == 2)
		{
			$scalarTable[$scalarTableIndex][Name]=adjustTableName($row[name_2]);
			$scalarTable[$scalarTableIndex][OID]=getOIDByRow($row);
			$scalarTableIndex++;
		}
		//column table
		else if($row[maxAccess] == ACCESS_ENTRY && strstr($row[name_2],"Table"))
		{
			$columnTable[$columnTableIndex][Name]=adjustTableName($row[name_2]);
			$columnTable[$columnTableIndex][OID]=getOIDByRow($row);
			if(strstr($row[desc_2],"Name:"))
			{
				$new_name=explode("Name:",$row[desc_2]);
				$columnTable[$columnTableIndex][Name]=str_replace(";","",$new_name[sizeof($new_name)-1]);
			}
			
			$columnTableIndex++;
		}
		//scalar item
		else
		{
			$scalarItem[$scalarItemIndex][Name]=adjustTableName($row[name_2]);
			$scalarItem[$scalarItemIndex][RawName]=$row[name_2];
			$scalarItem[$scalarItemIndex][OID]=getOIDByRow($row);
			$scalarItem[$scalarItemIndex][MaxAccess]=$row[maxAccess]+0;
			$scalarItem[$scalarItemIndex][Style]=$row[operType]+0;
			$scalarItem[$scalarItemIndex][ValueType]=$row[valueType]+0;
			$scalarItem[$scalarItemIndex][MinValue]=$row[minValue]+0;
			$scalarItem[$scalarItemIndex][MaxValue]=$row[maxValue]+0;
			$scalarItem[$scalarItemIndex][Template]=$row[setTemplate_2];
			$scalarItem[$scalarItemIndex][Tip]=$row[note_2];
			$scalarItem[$scalarItemIndex][Desc]=$row['desc_2'];
			if(strstr($row['desc_2'],"Name:"))
			{
				$new_name=explode("Name:",$row['desc_2']);
				$scalarItem[$scalarItemIndex][Name]=str_replace(";","",$new_name[sizeof($new_name)-1]);
			}
			
			if($scalarItem[$scalarItemIndex][MaxAccess] != ACCESS_ENTRY && !strstr($scalarItem[$scalarItemIndex][Desc],"Hidden Parameter") && !stristr($scalarItem[$i][Name],"Command"))
				$scalarItemReadCount++;
			
			$scalarItemIndex++;
		}
	}
}

if(0)
{
	echo "<pre>";
	print_r($scalarItem);
	echo "</pre>";
}


if($getAll)
{

echo "\n<script language=\"JavaScript\">\n";
echo "adjust_frame('down');\n";
echo "</script>\n";
for($i = 1; $i <= 4096; $i++ ) print("  ");
echo "<br>";

	//Insert record when the scalar item is not exist
	$scalar_oids=GetAllOIDArr($sysTypeNo,SCALAR_ITEM_OID);
	$scalar_oids_num=sizeof($scalar_oids);

 
	for($i=0;$i<$scalar_oids_num;$i++)
	{
		$checkoid=$scalar_oids[$i].".0";
		$oidwhere=getLevelWhere($checkoid);
		$checksql="select * from $paraTable where $oidwhere and instanceNo='0000' ";
		$checkres=@mysqli_query($pubConn,$checksql);
		$checknum=@mysqli_num_rows($checkres);
		if($checknum == 0)
		{
			$insertlevel=str_replace("AND",",",$oidwhere);
			$insertsql="replace into $paraTable set initValue='',instanceNo='0000',$insertlevel ";
			if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
				$insertsql="replace into $paraTable set subSysNo='$subSysNo',initValue='',instanceNo='0000',$insertlevel ";
			//echo "$insertsql<br>";
			mysqli_query($pubConn,$insertsql);
			echo mysqli_error($pubConn);
		}
	}

	
	$getAllArr=GetAllOIDArr($sysTypeNo);
	if(0)
	{
		echo "<pre>";
		print_r($getAllArr);
		echo "</pre>";
	}
	$get_count=sizeof($getAllArr);

	for($i=0;$i<$get_count;$i++)
	{
		$tmpArr[$i][sysId]=$sysId;
		$tmpArr[$i][oid]=$getAllArr[$i];
		$tmpArr[$i][instanceNo]="";
	}
	getParam($tmpArr,1);
}

//Scalar item
$scalarItemCommandCount=0;
$scalarItemWriteCount=0;
$setArrNo=0;
$getArrNo=0;
if($scalarItemIndex > 0)
{
	echo "<br>";
	echo "<table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	if($scalarItemReadCount)
		echo "<tr bgcolor=\"#e6e6e6\"><td width=50%>Parameter</td><td width=50%>Value</td>";
	for($i=0;$i<$scalarItemIndex;$i++)
	{
		if($scalarItem[$i][MaxAccess] == ACCESS_ENTRY)
			continue;
		if(strstr($scalarItem[$i][Desc],"Hidden Parameter"))
			continue;
		if(stristr($scalarItem[$i][Name],"Command"))
		{
			$scalarItemCommandIndexes[$scalarItemCommandCount]=$i;
			$scalarItemCommandCount++;
			continue;
		}
		if($scalarItem[$i][MaxAccess] == ACCESS_READ_WRITE)
		{
			echo "<input type=\"hidden\" name=\"setArr[$setArrNo][sysId]\" value=\"$sysId\">";
			echo "<input type=\"hidden\" name=\"setArr[$setArrNo][oid]\" value=\"{$scalarItem[$i][OID]}\">";
			echo "<input type=\"hidden\" name=\"setArr[$setArrNo][instanceNo]\" value=\"\">";
			$setArrNo++;
			$scalarItemWriteCount++;
		}
		echo "<input type=\"hidden\" name=\"getArr[$getArrNo][sysId]\" value=\"$sysId\">";
		echo "<input type=\"hidden\" name=\"getArr[$getArrNo][oid]\" value=\"{$scalarItem[$i][OID]}\">";
		echo "<input type=\"hidden\" name=\"getArr[$getArrNo][instanceNo]\" value=\"\">";
		$getArrNo++;
		
		echo "<tr>";
		echo "<td width=\"50%\" onMouseOver=\"javascript:showTipWindow('{$scalarItem[$i][Tip]}');\" onMouseOut=\"javascript:hideTipWindow();\">{$scalarItem[$i][Name]}</td>";
		echo "<td>";
		//if the scalar leaf not exist in the db, insert it first
		$checklevel=getLevelWhere($scalarItem[$i][OID]);
		$checksql="select * from $paraTable where $checklevel and instanceNo='0000' ";
		if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
			$checksql.="and subSysNo='$subSysNo' ";
		$checkres=mysqli_query($pubConn,$checksql);
		echo mysqli_error($pubConn);
		$checknum=mysqli_num_rows($checkres);
		if($checknum == 0)
		{
			$insertlevel=str_replace("AND",",",$checklevel);
			$insertsql="replace into $paraTable set initValue='',instanceNo='0000',$insertlevel ";
			if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
				$insertsql="replace into $paraTable set subSysNo='$subSysNo',initValue='',instanceNo='0000',$insertlevel ";
			mysqli_query($pubConn,$insertsql);
			echo mysqli_error($pubConn);
		}
				
		if($scalarItem[$i][ValueType] == VALUE_OPAQUE)
			showParameter($sysId,$scalarItem[$i][OID],'0000');
		else	
			showParameterAdv($sysId,$scalarItem[$i][OID],'0000');
		echo "</td>";
		echo "</tr>";
	}
	echo "</table>";
	
	if($scalarItemReadCount > 0)
		echo "<input id=\"scalar_item_get_id\" type=\"submit\" name=\"scalar_item_get\" value=\" $strGet \" class=\"button\" style=\"$buttonStyle\">";
	echo "&nbsp;&nbsp;";
	if($scalarItemWriteCount > 0)
	{
		if($canwrite_flag)
			echo "<input id=\"scalar_item_set_id\" type=\"submit\" name=\"scalar_item_set\" value=\" $strSet \" class=\"button\" style=\"$buttonStyle\">";
		else
			echo "<input id=\"scalar_item_set_id\" type=\"submit\" disabled name=\"scalar_item_set\" value=\" $strSet \" class=\"button\" style=\"$buttonStyle\">";
	}
	echo "&nbsp;";
	$command_index=0;
	for($i=0;$i<$scalarItemCommandCount;$i++)
	{
		$index=$scalarItemCommandIndexes[$i];
		$template=trim($scalarItem[$index][Template]);
		$options=explode(";",$template);
		for($ii=0;$ii<sizeof($options);$ii++)
		{
			$tmp=explode("=",$options[$ii]);
			$val=$tmp[0];
			$opt=$tmp[1];
			//echo "$val - $opt<br>";
			$showName=getShowNameOfTable($val,-1);
			echo "&nbsp;";
			if($canwrite_flag)
				echo "<input id=\"scalar_item_command_id_{$command_index}\" type=\"submit\" onclick=\"isConfirm=1;\" name=\"command_id_{$command_index}\" value=\"$showName\" class=\"button\" style=\"$buttonStyle\">";
			else
				echo "<input id=\"scalar_item_command_id_{$command_index}\" type=\"submit\" disabled onclick=\"isConfirm=1;\" name=\"command_id_{$command_index}\" value=\"$showName\" class=\"button\" style=\"$buttonStyle\">";
			echo "<input type=\"hidden\" name=\"commands[$command_index][oid]\" value=\"{$scalarItem[$index][OID]}\">";
			echo "<input type=\"hidden\" name=\"commands[$command_index][val]\" value=\"$opt\">";
			//echo "<input type=\"hidden\" name=\"commInfoArr[0][instanceNo]\" value=\"\">";
			$command_index++;
		}
	}
}

//Scalar table(suspend)

//Column table
//$table_level=3;
//$instanceNo="0005.0001";
if(!isset($table_level))
	$table_level=1;
for($i=0;$i<$columnTableIndex;$i++)
{
	//echo "{$columnTable[$i][Name]} {$columnTable[$i][OID]}<br>";
	$oidwhere=getLevelWhere($columnTable[$i][OID]);
	$size=sizeof(explode(".",$columnTable[$i][OID]));
	$oidwhere.=" AND level_".($size+1)."=1 ";
	$sql="select * from $paraConfTable where $oidwhere order by level_1,level_2,level_3,level_4,level_5,level_6,level_7,level_8,level_9,level_10 ";
	$res=@mysqli_query($pubConn,$sql);
	$num=@mysqli_num_rows($res);
	$tableObject[$i][FieldCount]=$num;
	$tableObject[$i][EntriesCount]=0;
	$tableObject[$i][DeleteOID]=-1;
	for($j=0;$j<$num;$j++)
	{
		$row=@mysqli_fetch_array($res);
		$tableObject[$i][$j][RawName]=$row[name_2];
		$tableObject[$i][$j][Name]=getShowNameOfField($row[name_2],-1);
		$tableObject[$i][$j][MaxAccess]=$row[maxAccess];
		$tableObject[$i][$j][Style]=$row[operType];
		$tableObject[$i][$j][ValueType]=$row[valueType];
		$tableObject[$i][$j][MinValue]=$row[minValue];
		$tableObject[$i][$j][MaxValue]=$row[maxValue];
		$tableObject[$i][$j][Template]=$row[setTemplate_2];
		$tableObject[$i][$j][Desc]=$row[desc_2];
		$tableObject[$i][$j][Tip]=$row[note_2];
		$tableObject[$i][$j][OID]=getOIDByRow($row);
		
		if(strstr($tableObject[$i][$j][Desc],"Key Parameter"))
			$tableObject[$i][$j][KeyFlag]=1;
		else
			$tableObject[$i][$j][KeyFlag]=0;
		
		if(strstr($tableObject[$i][$j][Name],"Entry") && $tableObject[$i][$j][MaxAccess] == ACCESS_ENTRY)
		{
			$tableObject[$i][$j][Name]=getShowNameOfTable($row[name_2],-1);
			$tableObject[$i][EntryIndex]=$j;
		}
		else if(strstr($tableObject[$i][$j][Name],"Entries"))
		{
			$tableObject[$i][Entries][$tableObject[$i][EntriesCount]][RawName]=$tableObject[$i][$j][RawName];
			$tableObject[$i][Entries][$tableObject[$i][EntriesCount]][Name]=$tableObject[$i][$j][Name];
			$tableObject[$i][Entries][$tableObject[$i][EntriesCount]][OID]=$tableObject[$i][$j][OID];
			$tableObject[$i][EntriesCount]++;
		}
		if(strstr($tableObject[$i][$j][RawName],"RowStatus"))
		{
			$tableObject[$i][$j][Name]="Delete";
			if($tableObject[$i][$j][KeyFlag] == 0)
				$tableObject[$i][DeleteOID]=-1;
			else
				$tableObject[$i][DeleteOID]=$tableObject[$i][$j][OID];
		}
		if(strstr($tableObject[$i][$j][RawName],"Index"))
			$tableObject[$i][IndexIndex]=$j;
		
		if(strstr($tableObject[$i][$j][Desc],"Name:"))
		{
			$new_name=explode("Name:",$tableObject[$i][$j][Desc]);
			$tableObject[$i][$j][Name]=str_replace(";","",$new_name[sizeof($new_name)-1]);
		}
		
		//echo "$i $j {$tableObject[$i][$j][Name]} {$tableObject[$i][$j][OID]}<br>";
	}
	//Table level
	if(strstr($tableObject[$i][$tableObject[$i][EntryIndex]][Desc],"level"))
	{
		$tmp=explode("level:",$tableObject[$i][$tableObject[$i][EntryIndex]][Desc]);
		$tableObject[$i][TableLevel]=$tmp[1]+0;
	}
	else
	{
		$tableObject[$i][TableLevel]=1;
	}
}
$thisTableIndex=-1;
for($i=0;$i<$columnTableIndex;$i++)
{
	if($tableObject[$i][TableLevel] == $table_level)
		$thisTableIndex=$i;
	//Create index
	$tableObject[$i][CreateOID]=-1;
	if($tableObject[$i][TableLevel] == 1)
	{
		for($j=0;$j<$tableObject[$i][FieldCount];$j++)
		{
			if(strstr($tableObject[$i][$j][Name],"Index"))
			{
				if($tableObject[$i][$j][MaxAccess] == ACCESS_INDEX_CREATE_SPE)
					$tableObject[$i][CreateOID]=$tableObject[$i][$j][OID];
				break;
			}
		}
	}
	else
	{
		$lastCreateLabel="CreateEntry".str_replace("Entry","",$tableObject[$i][$tableObject[$i][EntryIndex]][RawName]);
		$lastEntriesLabel=str_replace("Entry","",$tableObject[$i][$tableObject[$i][EntryIndex]][RawName])."Entries";
		$lastLevel=$tableObject[$i][TableLevel]-1;
		for($j=0;$j<$columnTableIndex;$j++)
		{
			if($tableObject[$j][TableLevel] == $lastLevel)
				break;
		}
		if($j != $columnTableIndex)
		{
			for($z=0;$z<$tableObject[$j][FieldCount];$z++)
			{
				if(stristr($tableObject[$j][$z][RawName],$lastCreateLabel))
				{
					$tableObject[$i][CreateOID]=$tableObject[$j][$z][OID];
					break;
				}
			}
			for($z=0;$z<$tableObject[$j][EntriesCount];$z++)
			{
				if(stristr($tableObject[$j][Entries][$z][RawName],$lastEntriesLabel))
				{
					$tableObject[$i][CreateDeleteRelateOID]=$tableObject[$j][Entries][$z][OID];
					break;
				}
			}
		}
		else
		{
			echo "<font color=red>Some table hasn't configure the level</font><br>";
			exit();
		}
	}
}
if($columnTableIndex > 0)
{
	if(0)
	{
		echo "<pre>";
		print_r($tableObject);
		echo "</pre>";
	}
	
	if($thisTableIndex == -1)
	{
		exit("thisTableIndex error");
	}
	$thisTableConf=$tableObject[$thisTableIndex];
	if(0)
	{
		echo "<pre>";
		print_r($thisTableConf);
		echo "</pre>";
	}
	
	$oidwhere=getLevelWhere($thisTableConf[$thisTableConf[EntryIndex]][OID]);
	
	if($thisTableConf[TableLevel] == 1)
		$instanceCond=" LENGTH(instanceNo)=4 ";
	else if($thisTableConf[TableLevel] == 2)
		$instanceCond=" LENGTH(instanceNo)=9 and instanceNo like '{$instanceNo}.%' ";
	else if($thisTableConf[TableLevel] == 3)
		$instanceCond=" LENGTH(instanceNo)=14 and instanceNo like '{$instanceNo}.%' ";
	else
		exit("The table nest count > 3");
		
	$sql="select * from $paraTable where $oidwhere and {$instanceCond} ";
	$res=@mysqli_query($pubConn,$sql);
	$num=@mysqli_num_rows($res);
	//echo "$sql<br>";
	
	for($i=0;$i<$num;$i++)
	{
		$row=@mysqli_fetch_array($res);
		$oid=getOIDByRow($row);
		$fieldIndex=sizeof(explode(".",$oid));
		$fieldPos=$row["level_".$fieldIndex]+0;
		$instanceValue=substr($row[instanceNo],strlen($row[instanceNo])-4,4)+0;
		$showObject[$instanceValue][$fieldPos]=$row[initValue];
	}
	

	if(0)
	{
		echo "<pre>";
		print_r($showObject);
		echo "</pre>";
	}
	
	echo "<br>";
	if($scalarItemIndex > 0)
		echo "<br><br>";

	showNavigateTitle($table_id,$table_level,$sysId,$columnTable,$instanceNo,"show");
	echo "<br><br><table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	echo "<tr bgcolor=\"#e6e6e6\">";
	$showFieldCount=0;
	$availStatePos=-1;




	
	
	if(!isset($ascFlag))
		$ascFlag=2;
	else
		$ascFlag=($ascFlag+1)%2;
		
	if($_SERVER['REQUEST_METHOD'] == "POST" && $column_table_get)
		$ascFlag=1;

	
	for($i=0;$i<$thisTableConf[FieldCount];$i++)
	{
		if(strstr($thisTableConf[$i][RawName],"AvailState"))
			$availStatePos=$i;
		if($thisTableConf[$i][KeyFlag] == 1)
		{
			$tmp=explode(".",$thisTableConf[$i][OID]);
			$ni=$tmp[sizeof($tmp)-1]+0;
			$thisTableConf[KeyFieldIndexList][$i]=$ni;
			if($thisTableConf[$i][Name] == "Delete")
				echo "<td width=20 align=\"right\">Delete</td>";				
			else
			{
				echo "<td><a href=\"$PHP_SELF?table_id=$table_id&sysId=$sysId&table_level=$table_level&instanceNo=$instanceNo&order=$ni&ascFlag=$ascFlag\">";
				echo $thisTableConf[$i][Name];
				echo "</a></td>";
			}
			$showFieldCount++;
		}
	}
	echo "</tr>";

	if($num > 0)
	{
		//bubble order
		$objectCount=sizeof($showObject);
		if(!isset($order))
			$order=$thisTableConf[IndexIndex];
		
		$instance_list_num=0;
		foreach($showObject as $instance => $obj)
		{
			$instance_list[]=$instance;
			$instance_list_num++;
		}
		for($i=0;$i<$instance_list_num;$i++)
		{
			for($j=$i;$j<$instance_list_num;$j++)
			{
				$index1=$instance_list[$i];
				$index2=$instance_list[$j];
				if($ascFlag)
				{
					if($showObject[$index1][$order] > $showObject[$index2][$order])
					{
						//echo "$order index1=$index1,{$showObject[$index1][$order]},index2=$index2,{$showObject[$index2][$order]}<br>";
						$tmp=$showObject[$index1];
						$showObject[$index1]=$showObject[$index2];
						$showObject[$index2]=$tmp;
					}
				}
				else
				{
					if($showObject[$index1][$order] < $showObject[$index2][$order])
					{
						//echo "$order index1=$index1,{$showObject[$index1][$order]},index2=$index2,{$showObject[$index2][$order]}<br>";
						$tmp=$showObject[$index1];
						$showObject[$index1]=$showObject[$index2];
						$showObject[$index2]=$tmp;
					}
				}
			}
		}
		//echo "order=$order,{$thisTableConf[$order][Name]} $instance_list_num<br>";
	
		foreach($showObject as $instance => $obj)
		{
			$newIndex=$obj[$thisTableConf[IndexIndex]];
			if($thisTableConf[TableLevel]==1)
				$nextInstance=omc_keep_length($newIndex,"0",4);
			else if($thisTableConf[TableLevel]==2)
				$nextInstance=$instanceNo.".".omc_keep_length($newIndex,"0",4);
			else if($thisTableConf[TableLevel]==3)
				$nextInstance=$instanceNo.".".omc_keep_length($newIndex,"0",4);
			if($availStatePos != -1 && $obj[$availStatePos] == 3)
				echo "<tr style=\"color:#000000;\" onMouseOver=\"javascript:MouseOverColor(this);\" onMouseOut=\"javascript:MouseOutColor(this);\">";
			else
				echo "<tr onMouseOver=\"javascript:MouseOverColor(this);\" onMouseOut=\"javascript:MouseOutColor(this);\">";
			for($i=0;$i<$thisTableConf[FieldCount];$i++)
			{
				$ni=$thisTableConf[KeyFieldIndexList][$i];

				if($thisTableConf[$i][KeyFlag] == 1)
				{
					if($ni == $thisTableConf[IndexIndex])
					{
						echo "<td><a href=\"param_edit.php?table_id=$table_id&sysId=$sysId&table_level=$table_level&instanceNo=$nextInstance\">{$obj[$ni]}</a></td>";
					}
					else if(strstr($thisTableConf[$i][RawName],"Entries"))
					{
						$next_table_level=$table_level+1;
						echo "<td><a href=\"$PHP_SELF?table_id=$table_id&sysId=$sysId&table_level=$next_table_level&instanceNo=$nextInstance\">{$obj[$ni]}</a></td>";
					}
					else if($thisTableConf[$i][Name] == "Delete")
					{
						echo "<td align=\"right\">";
						if($canwrite_flag)
							echo "<input type=\"checkbox\" style=\"width=12px;height:12px;\" onClick=\"javascript:deleteObject('$sysId','$table_id','$table_level','$instanceNo','{$thisTableConf[DeleteOID]}','{$thisTableConf[CreateDeleteRelateOID]}','{$thisTableConf[0][OID]}','$nextInstance',this);\">";
						else
							echo "<input type=\"checkbox\" style=\"width=12px;height:12px;\" disabled onClick=\"javascript:deleteObject('$sysId','$table_id','$table_level','$instanceNo','{$thisTableConf[DeleteOID]}','{$thisTableConf[CreateDeleteRelateOID]}','{$thisTableConf[0][OID]}','$nextInstance',this);\">";
						echo "</td>";
					}
					//RelationPoint
					else if(strstr($thisTableConf[$i][Desc],"RelationPoint"))
					{
						echo "<td>";
						
						$tmp1=strstr($thisTableConf[$i][Desc],"RelationPoint:");
						$tmp2=explode(";",$tmp1);
						$tmp3=explode("RelationPoint:",$tmp2[0]);
						$rTableOid=$tmp3[1];
						
						$showvalue=$obj[$ni];
						
						if(trim($showvalue) == "--" || trim($showvalue)=="")
						{
							echo "--";
						}
						else
						{
							$tmp1=explode(" ",$showvalue);
							$tmp2=$tmp1[1];
							$tmp3=explode("-",$tmp2);
							$tmp4=omc_keep_length($tmp3[0],'0',4);
							$tmp5=omc_keep_length($tmp3[1],'0',4);
							$rInstanceNo=$tmp4.".".$tmp5;
							$rWhere=getLevelWhere($rTableOid);
							$rsql="select * from $paraTable where instanceNo='$rInstanceNo' and $rWhere ";
							$rres=mysqli_query($pubConn,$rsql);
							$rnum=mysqli_num_rows($rres);
							//echo "$rsql";
							if($rnum == 0)
								echo "--";
							else
							{
								$new_table_level=getTableLevel($rTableOid,$sysTypeNo);
								$tmp1=explode(".",$rTableOid);
								$new_table_id=$tmp1[1]-1;
								//echo "rInstanceNo=$rInstanceNo,rTableOid=$rTableOid,new_table_level=$new_table_level,new_table_id=$new_table_id";
								echo "<a href=\"./param_edit.php?sysId=$sysId&table_id=$new_table_id&table_level=$new_table_level&instanceNo=$rInstanceNo\" onClick=\"updateTab('{$new_table_id}');\">$showvalue</a>";
							}
						}
						
						echo "</td>";
					}
					else if(trim($obj[$ni]) == "")
					{
						echo "<td>--</td>";
					}
					else
					{
						$showValue=translateValueToOpt($thisTableConf[$i][Style],$thisTableConf[$i][ValueType],$thisTableConf[$i][Template],$obj[$ni]);
						echo "<td>{$showValue}</td>";
					}
				}
			}
			echo "</tr>";
		}
	}
	
	//Create new object
	if($thisTableConf[CreateOID] != -1 && $canwrite_flag)
	{
		echo "<tr>";
		echo "<td><a href=\"./param_edit.php?create=1&sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=$instanceNo&createOid={$thisTableConf[CreateOID]}&updateOid={$thisTableConf[CreateDeleteRelateOID]}&indexOid={$thisTableConf[$thisTableConf[IndexIndex]][OID]}&oldtableOid={$thisTableConf[0][OID]}\">";
		echo "New";
		echo "</a></td>";
		for($i=0;$i<$showFieldCount-1;$i++)
			echo "<td>--</td>";
		echo "</tr>";
	}

	echo "</table>";
	
	//Get button
	echo "<input id=\"column_table_get_id\" type=\"submit\" name=\"column_table_get\" value=\" $strGet \" class=\"button\" style=\"$buttonStyle\">";
	echo "<input type=\"hidden\" name=\"commInfoArr[0][sysId]\" value=\"$sysId\">";
	echo "<input type=\"hidden\" name=\"commInfoArr[0][oid]\" value=\"{$thisTableConf[0][OID]}\">";
	//for get the instance 0
	if($instanceNo=="0000")
		echo "<input type=\"hidden\" name=\"commInfoArr[0][instanceNo]\" value=\"\">";
	else
		echo "<input type=\"hidden\" name=\"commInfoArr[0][instanceNo]\" value=\"$instanceNo\">";
	
	//lock the channel
	if($sysTypeNo == SYSTYPENO_MSC && $thisTableConf[0][OID] == '2.4.3.1')
	{
		echo "<input id=\"Lock\" type=\"button\" name=\"locktimeslot\" value=\"Lock\" class=\"button\" style=\"$buttonStyle\" onClick=\"Javascript:lockTimeSlot('$sysId','$instanceNo','','$table_id','$table_level','lock');\">";
		echo "<input id=\"Unlock\" type=\"button\" name=\"unlocktimeslot\" value=\"Unlock\" class=\"button\" style=\"$buttonStyle\" onClick=\"Javascript:lockTimeSlot('$sysId','$instanceNo','','$table_id','$table_level','unlock');\">";
	}
	
	//if not get channel, get the channel first
	if($sysTypeNo == SYSTYPENO_MSC && $thisTableConf[0][OID] == "2.4.3.1")
	{
		echo "<input type=hidden name=\"table_id\" value=\"{$table_id}\">";
		echo "<input type=hidden name=\"sysId\" value=\"{$sysId}\">";
		echo "<input type=hidden name=\"instanceNo\" value=\"{$instanceNo}\">";
		echo "<input type=hidden name=\"table_level\" value=\"{$table_level}\">";
		$dualTableLevelWhere="T1.level_1=T2.level_1 AND
							  T1.level_2=T2.level_2 AND
							  T1.level_3=T2.level_3 AND
							  T1.level_4=T2.level_4 AND
							  T1.level_5=T2.level_5 AND
							  T1.level_6=T2.level_6 AND
							  T1.level_7=T2.level_7 AND
							  T1.level_8=T2.level_8 AND
							  T1.level_9=T2.level_9 AND
							  T1.level_10=T2.level_10";
		$count=0;
		$database="OMC_PUB";
		$selSql = "SELECT T1.* FROM $paraTable AS T1,$paraConfTable AS T2 WHERE $dualTableLevelWhere AND T2.name_2='tsIndex' and instanceNo like '$instanceNo.%' ";
		$selRes = @mysqli_query($pubConn,$selSql);
		$count=mysqli_num_rows($selRes);
		if($count==0)
		{
			if($hasEnter!=1)
			{
				$hasEnter=1;
				echo "<input type=\"hidden\" name=\"hasEnter\" value=\"1\">";	
				echo "\n<script language=\"JavaScript\">\n";
				echo "document.getElementById(\"column_table_get_id\").click();\n";
				echo "</script>\n";
			
			}
		}
	}

}

echo "<input type=hidden name=\"table_id\" value=\"{$table_id}\">";
echo "<input type=hidden name=\"sysId\" value=\"{$sysId}\">";
echo "<input type=hidden name=\"instanceNo\" value=\"{$instanceNo}\">";
echo "<input type=hidden name=\"table_level\" value=\"{$table_level}\">";
echo "<input type=hidden name=\"ascFlag\" value=\"{$ascFlag}\">";


echo "</form>";
adjust_content_tail("down");
?>
