<?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 updateTab(tabid)
{
	//parent.param_show_up.tab_sel=tabid;
	parent.param_show_up.adjust_tab(tabid);
	//alert('click me '+tabid);
}

function select_sub_menu(sysId,table_id,instanceNo,table_level,sub_table_id)
{
	window.location.href="./param_show_table.php?sysId="+sysId+"&table_id="+table_id+"&instanceNo="+instanceNo+"&table_level="+table_level+"&sub_table_id="+sub_table_id;
}

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

function deleteObject(sysId,table_id,sub_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+"&sub_table_id="+sub_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,sub_table_id,table_level,opt)
{
	URL="./lockTimeSlot.php?sysId="+sysId+"&oidStr="+oidStr+"&instanceNo="+instanceNo+"&table_id="+table_id+"&sub_table_id="+sub_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();
}

</script>

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

adjust_content_head_frame("down");	

$userInfo = $_SESSION['userInfo'];
//echo "writeFlag=$canwrite_flag<br>";

$sysId = $_REQUEST['sysId'];
//echo "<br>sysId=$sysId<br>";
$canwrite_flag=checkWritePrivilege();
//echo "writeFlag=$canwrite_flag<br>";
//*****

$url_temp=$_SERVER["REQUEST_URI"];
//*****
//$url_temp=$_SERVER["REQUEST_URI"];
//echo "This page URL:$url_temp<br>";
$TEST=$_REQUEST;

if(0)
{
	echo "<pre>";
	print_r($TEST);
	echo "</pre>";
}
echo "<form name=\"myform\" method=\"POST\" action=\"$PHP_SELF\" onsubmit=\"return buttonOpt();\">";
$sysId=$_REQUEST['sysId'];
if (isset($sysId))
{

	$sysIdArr=explode('_',$sysId);
	$sysTypeNo=$sysIdArr[0];
	//echo "sysTypeNo=$sysTypeNo<br>";
	$sysNo=$sysIdArr[1];
	$subSysNo=$sysIdArr[2];
}
// echo "sys=$sysTypeNo";

$objDb='OBJ_'.$sysTypeNo;
//$objDbConn = mysqli_connect($OMC_server[0]['host'],$OMC_server[0]['user'],$OMC_server[0]['password'], "OMC_PUB");
$objDbConn = mysqli_connect($OMC_server[0]['host'],$OMC_server[0]['user'],$OMC_server[0]['password'],$objDb);	




$paraConfTable=$objDb.'.paramConf';
$pubDb='OMC_PUB';
if(checkIndependSystem($sysTypeNo))//Plat
{

	$paraTable=$objDb.".param_".$sysNo;
}


else{
	$paraTable=$objDb.".param_99";

}

	
CheckSystemStatus($sysTypeNo,$sysNo,$subSysNo);

$tabConf=GetTabConf($sysTypeNo);
//echo"tab=GetTabConf($sysTypeNo)<br>";
$table_id = $_REQUEST['table_id'];
//echo"table_id=GetTabConf($table_id)<br>";
$sub_table_id=$_REQUEST['sub_table_id'];
//echo "sub_table_id=$sub_table_id<br>";
$table_level = $_REQUEST['table_level'];
$instanceNo = $_REQUEST['instanceNo'];
$deleteOid = $_REQUEST['deleteOid'];
$updateOid = $_REQUEST['updateOid'];
$getTableOid = $_REQUEST['getTableOid'];
$deleteIndex = $_REQUEST['deleteIndex'];
$delete=$_REQUEST['delete'];
//echo "num=$tableOid<br>";

$tableOid=$tabConf[$table_id]['OID'];

//echo "num=$tableOid<br>";

$subTabConf=GetSubTabConf($sysTypeNo,$tableOid);
//print_r($subTabConf) ;
//echo "num=$tableOid";


//Get the columnTable conf
$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($objDbConn,$sql);
$num=@mysqli_num_rows($res);
//echo "num=$num";
//var_dump($sql);
$scalarTableIndex=0;
$columnTableIndex=0;
$scalarItemIndex=0;
$scalarItemReadCount=0;
for($i=0;$i<$num;$i++)
{
	$row=@mysqli_fetch_array($res);

	if($row[$lastlevel] == 0)
	{
		if($row[maxAccess] == ACCESS_ENTRY && strstr($row[name_2],"Table"))
		{
			$columnTable[$columnTableIndex][Name]=adjustTableName($row[name_2]);
			$columnTable[$columnTableIndex][OID]=getOIDByRow($row);
			$columnTable[$columnTableIndex][ShowName]=$columnTable[$columnTableIndex][Name];
			if(strstr($row[desc_2],"Name:"))
			{
				$new_name=explode("Name:",$row[desc_2]);
				$columnTable[$columnTableIndex][ShowName]=str_replace(";","",$new_name[sizeof($new_name)-1]);
			}
			
			$columnTableIndex++;
		}
	}
}


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

if(0)
{
	echo "<pre>";
	print_r($subTabConf);
	echo "</pre>";
}
if(!isset($table_id))
	$table_id=0;
if(!isset($sub_table_id))
{
	if($subTabConf[ButtonCount] > 0 || $subTabConf[ScalarParamDisplayCount] > 0)
		$sub_table_id=999;
	else
		$sub_table_id=0;
}

if(0)
{
	echo "sysId=$sysId<br>";
	echo "table_id=$table_id<br>";
	echo "instanceNo=$instanceNo<br>";
	echo "table_level=$table_level<br>";
	echo "sub_table_id=$sub_table_id<br>";
}
$instanceNo = $_REQUEST['instanceNo'];
$table_level = $_REQUEST['table_level'];
echo "<input type=hidden name=\"sysId\" value=\"{$sysId}\">";
echo "<input type=hidden name=\"table_id\" value=\"{$table_id}\">";
echo "<input type=hidden name=\"instanceNo\" value=\"{$instanceNo}\">";
echo "<input type=hidden name=\"table_level\" value=\"{$table_level}\">";
echo "<input type=hidden name=\"sub_table_id\" value=\"{$sub_table_id}\">";

if((($subTabConf[ButtonCount] > 0 || $subTabConf[ScalarParamDisplayCount] > 0) && $subTabConf[SubMenuCount] > 0) || ($subTabConf[ButtonCount] == 0 && $subTabConf[ScalarParamDisplayCount] == 0 && $subTabConf[SubMenuCount] > 1))
{
	if($subTabConf[ButtonCount] > 0 || $subTabConf[ScalarParamDisplayCount] > 0)
	{
		if($sub_table_id == 999)
			echo "<span style=\"border-style:double;border-width:3px;border-color:#cecece;background-color:#ababab;cursor:hand;\" onClick=\"javascript:select_sub_menu('{$sysId}','{$table_id}','{$instanceNo}','{$table_level}','999');\">";
		else
			echo "<span style=\"border-style:double;border-width:3px;border-color:#cecece;background-color:#efefef;cursor:hand;\" onClick=\"javascript:select_sub_menu('{$sysId}','{$table_id}','{$instanceNo}','{$table_level}','999');\">";
		echo "&nbsp;{$subTabConf[ShowName]}&nbsp;";
		echo "</span>";
	}
	for($i=0;$i<$subTabConf[ColumnTableCount];$i++)
	{
		if($subTabConf[ColumnTable][$i][SubMenuFlag] == 1)
		{
			if($i == $sub_table_id)
				echo "<span style=\"border-style:double;border-width:3px;border-color:#cecece;background-color:#ababab;cursor:hand;\" onClick=\"javascript:select_sub_menu('{$sysId}','{$table_id}','{$instanceNo}','{$table_level}','{$i}');\">";
			else
				echo "<span style=\"border-style:double;border-width:3px;border-color:#cecece;background-color:#efefef;cursor:hand;\" onClick=\"javascript:select_sub_menu('{$sysId}','{$table_id}','{$instanceNo}','{$table_level}','{$i}');\">";
			echo "&nbsp;{$subTabConf[ColumnTable][$i][ShowName]}&nbsp;";
			echo "</span>";
		}
	}
	echo "<br>";
}
echo "<br>";

/************************** Operation ********************************/
if($_SERVER['REQUEST_METHOD'] == "POST")
{
	$delSql="delete from $paraTable where instanceNo='' ";
	if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
		$delSql.="and subSysNo='$subSysNo' ";		
	
	mysqli_query($objDbConn,$delSql);
	echo "\n<script language=\"JavaScript\">\n";
	echo "adjust_frame('down');\n";
	echo "</script>\n";
	echo "<br>";
	if($_REQUEST['get'])
	{
		if($DEBUG) echo "<br>sub_table_id:$sub_table_id sysId:$sysId<br>";
				//get scalar table
		if($sub_table_id == 999)
		{
			if($subTabConf[ScalarParamDisplayCount] > 0)
			{
				$count=0;
				for($i=0;$i<$subTabConf[ScalarParamCount];$i++)
				{
					if($subTabConf[ScalarParam][$i][GetFlag] == 1)
					{
						$getArr[$count][sysId]=$sysId;
						$getArr[$count][oid]=$subTabConf[ScalarParam][$i][OID];
						$getArr[$count][instanceNo]="";
						$count++;
					}
				}
				if($count > 0)
					getParam($getArr);
			}
		}
		//get column table
		else
		{		
			$getArr[0][sysId]=$sysId;
			$getArr[0][oid]=$subTabConf[ColumnTable][$sub_table_id][OID];
			//echo `sub_table_id:`.$getArr[0][oid];


			if($instanceNo=="0000")
				$getArr[0][instanceNo]="";
			else
				$getArr[0][instanceNo]=$instanceNo;
				
			//Get the timeslot parameter from the plat(trunk group id)
			if($sysTypeNo == SYSTYPENO_MSC)
			{
				//echo "<br>sub_table_id:$sub_table_id sysId:$sysId<br>";
				$trunk_table_oid=GetOIDByName(SYSTYPENO_MSC,"channelEntry");		
				if($getArr[0][oid] == $trunk_table_oid)
				{
					$tmps=explode(".",$instanceNo);
					$grounp_id=GetTrunkGroupID($tmps[0]+0,$tmps[1]+0);
					if($grounp_id == 1)
						$getArr[0][sysId]="320_1_0";
					else
						$getArr[0][sysId]="320_0_0";
					if(!GetSystemStatus(SYSTYPENO_MSC,$grounp_id))
						$getArr[0][sysId]="320_99_99";
				}
			}
			getParam($getArr);

		}
	}
	else if($_REQUEST['set'])
	{
		//fj
        	if(0)
        	{
                	echo "<pre>";
                	print_r($sub_table_id);
        	        echo "</pre>";
	        }

		if($sub_table_id == 999)
		{
			if($subTabConf[ScalarSetParamCount] > 0)
			{
				$commIdStr="";
				for($i=0;$i<$subTabConf[ScalarParamCount];$i++)
				{
					if($subTabConf[ScalarParam][$i][SetFlag] == 1)
					{
						$tmpCommIdStr=oidSysCommSend($sysId,3,$subTabConf[ScalarParam][$i][OID],-1);		
						$commIdStr=$commIdStr.$tmpCommIdStr;
						$count++;
					}
				}	

		// fj
                if(0)
                {
                        echo "<pre>";
                        print_r($commIdStr);
                        echo "</pre>";
                }
				if($count > 0)
					checkState($commIdStr,"./param_show_table.php?sysId=$sysId&table_id=$table_id&instanceNo=$instanceNo&table_level=$table_level&sub_table_id=$sub_table_id");
			}
		}
	}
	else if($_REQUEST['buttonOperate'])
	{	
		$commandIndex=$_POST['commandIndex'];
		//echo "buttonOperate=$buttonOperate,commandIndex=$commandIndex<br>";
		$oid=$subTabConf[Button][$commandIndex][OID];
		$tmpwhere=getLevelWhere($oid);
		$oidstr=str_replace(".",",",$oid);
		$oidsep=explode(".",$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($objDbConn,$delSql);
		$insertSql="insert into $paraTable($valuestr,instanceNo,initValue,readValue) values($oidstr,'0000',{$subTabConf[Button][$commandIndex][Value]},{$subTabConf[Button][$commandIndex][Value]}) ";
		
		if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
			$insertSql="insert into $paraTable($valuestr,instanceNo,initValue,readValue,subSysNo) values($oidstr,'0000',{$subTabConf[Button][$commandIndex][Value]},{$subTabConf[Button][$commandIndex][Value]},{$subSysNo}) ";
		//debug_log("/tmp/debug.txt",$insertSql);
		mysqli_query($objDbConn,$insertSql);
		echo mysqli_error($objDbConn);
	
		$commIdStr=oidSysCommSend($sysId,3,$oid,-1,"0000");
		checkState($commIdStr,"./param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=0000&sub_table_id=$sub_table_id");	
	}
	
}

if($_REQUEST['delete']  == 1)
{
	if(0)
	{
		echo "sysId=$sysId<br>";
		echo "table_id=$table_id<br>";
		echo "sub_table_id=$sub_table_id<br>";
		echo "table_level=$table_level<br>";
		echo "instanceNo=$instanceNo<br>";
		echo "deleteOid=$deleteOid<br>";
		echo "updateOid=$updateOid<br>";
		echo "getTableOid=$getTableOid<br>";
		echo "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($objDbConn,$sql);
	
	//Send delete command
	$commIdStr=oidSysCommSend($sysId,3,$deleteOid,-1,$deleteIndex);
	checkState($commIdStr,"./param_show_table.php?sysId=$sysId&table_id=$table_id&sub_table_id=$sub_table_id&table_level=$table_level&instanceNo=$instanceNo");
	//Update the entries field
	if(strlen(trim($updateOid)) > 0)
	{
		$commIdStr=oidSysCommSend($sysId,0,$updateOid,-1,$instanceNo);
		checkState($commIdStr,"./param_show_table.php?sysId=$sysId&table_id=$table_id&sub_table_id=$sub_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);
}
$getAll = $_REQUEST['getAll'];
if($DEBUG) echo "<br>getAll:$getAll<br>";
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);
	//echo "scalar_oids=$scalar_oids";
	$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($objDbConn,$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($objDbConn,$insertsql);
			echo mysqli_error($objDbConn);
		}
	}

	
	$getAllArr=GetAllOIDArr($sysTypeNo);
	if(0)
	{
		echo "<pre>";
		print_r($getAllArr);
		echo "</pre>";
	}
	if (is_array($getAllArr))
	$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);
}

/******************************** Show *******************************/
//show scalar parameter
//echo $sub_table_id;
// echo "<pre>";
// print_r($subTabConf);
// echo "</pre>";
if($sub_table_id == 999)
{
	if($subTabConf['ScalarParamDisplayCount'] > 0)
	{
		echo "<table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
		echo "<tr bgcolor=\"e6e6e6\">";
		echo "<td width=\"50%\">";
		echo "Parameter";
		echo "</td>";
		echo "<td width=\"50%\">";
		echo "Value";
		echo "</td>";
		echo "</tr>";
		
		for($i=0;$i<$subTabConf[ScalarParamCount];$i++)
		{
			if($subTabConf[ScalarParam][$i][MaxAccess] == 999)
				continue;
			
			//if the scalar leaf not exist in the db, insert it first
			$checklevel=getLevelWhere($subTabConf[ScalarParam][$i][OID]);
			$checksql="select * from $paraTable where $checklevel and instanceNo='0000' ";
			if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
				$checksql.="and subSysNo='$subSysNo' ";
			$checkres=mysqli_query($objDbConn,$checksql);
			//var_dump($checksql);
			//echo "checksql:$checksql<br>";
			echo mysqli_error($objDbConn);
			$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($objDbConn,$insertsql);
				//echo "<br>$insertsql";
				echo mysqli_error($objDbConn);
			}

			echo "<tr onmouseover=\"javascript:showTipWindow('{$subTabConf[ScalarParam][$i][Tip]}');\" onmouseout=\"javascript:hideTipWindow();\">";
			echo "<td>{$subTabConf[ScalarParam][$i][ShowName]}</td>";
			echo "<td>";
			if($subTabConf[ScalarParam][$i][ValueType] == VALUE_OPAQUE)
			{
				

				showParameter($sysId,$subTabConf[ScalarParam][$i][OID],'0000');

			}	
			else	{
				showParameterAdv($sysId,$subTabConf[ScalarParam][$i][OID],'0000');

			}
			echo "</td>";
			echo "</tr>";
		}
		echo "</table>";
	}
	//get button
	if($subTabConf[ScalarParamDisplayCount] > 0)
	{
		echo "<input type=\"submit\" name=\"get\" value=\" $strGet \" class=\"button\" style=\"$buttonStyle\">&nbsp;&nbsp;";
	}
	//set button
	if($subTabConf[ScalarSetParamCount] > 0)
	{
		if($canwrite_flag)
			echo "<input type=\"submit\" name=\"set\" value=\" $strSet \" class=\"button\" style=\"$buttonStyle\">&nbsp;&nbsp;";
		else
			echo "<input type=\"submit\" disabled name=\"set\" value=\" $strSet \" class=\"button\" style=\"$buttonStyle\">&nbsp;&nbsp;";
	}
	//other button
	echo "<input type=hidden name=\"commandIndex\" value=\"0\">";
	if($subTabConf[ButtonCount] > 0)
	{
		
		for($i=0;$i<$subTabConf[ButtonCount];$i++)
		{
			if($canwrite_flag)
				echo "<input type=\"submit\" name=\"buttonOperate\" value=\"{$subTabConf[Button][$i][ShowName]}\" class=button style=\"$buttonStyle\" onClick=\"commandIndexJS={$i};isConfirm=1;\">&nbsp;";
			else
				echo "<input type=\"submit\" disabled name=\"buttonOperate\" value=\"{$subTabConf[Button][$i][ShowName]}\" class=button style=\"$buttonStyle\" onClick=\"commandIndexJS={$i};isConfirm=1;\">&nbsp;";
		}
	}
}
//column table
else
{
	//echo "AAA=$sub_table_id";

	$singleTabConf=$subTabConf[ColumnTable][$sub_table_id];
	if(0)
	{
		echo "<pre>";
		print_r($singleTabConf);
		echo "</pre>";
	}
	$singleTabInfo=GetSingleTableInfo($singleTabConf,$sysTypeNo);
	if(0)
	{
		echo"AA<br>";
		echo "<pre>";
		print_r($singleTabInfo);
		echo "</pre>";
	}
	
	//PPS COS table
	if($sysTypeNo == SYSTYPENO_PPS && $table_level == 1 && $table_id == 1)
	{
		//-------------- TariffEntries => MOTariffID -----------
		$tariff_id=2;
		$singleTabInfo[ColumnParam][$tariff_id][EntriesFlag]=0;
		$singleTabInfo[ColumnParam][$tariff_id][NestEntryOID]="";
    $singleTabInfo[ColumnParam][$tariff_id][RawName]="tariffMOTariffID";
    $singleTabInfo[ColumnParam][$tariff_id][ShowName]="MO Tariff ID";
    //-------------- ServiceControlEntries => smsNotificationWhenRecharge -----------
		$tariff_id=3;
		$singleTabInfo[ColumnParam][$tariff_id][EntriesFlag]=0;
		$singleTabInfo[ColumnParam][$tariff_id][NestEntryOID]="";
    $singleTabInfo[ColumnParam][$tariff_id][RawName]="smsNotificationWhenRecharge";
    $singleTabInfo[ColumnParam][$tariff_id][ShowName]="Notification When Recharge";
    //-------------- AccountValidityEntries => smsChargeWhenInquiryBySMS -----------
		$tariff_id=4;
		$singleTabInfo[ColumnParam][$tariff_id][EntriesFlag]=0;
		$singleTabInfo[ColumnParam][$tariff_id][NestEntryOID]="";
    $singleTabInfo[ColumnParam][$tariff_id][RawName]="smsChargeWhenInquiryBySMS";
    $singleTabInfo[ColumnParam][$tariff_id][ShowName]="Charge When Inquiry By SMS";
    //-------------- SMSNotificationInquiryEntries => smsNotificationWhenCleanBalance -----------
		$tariff_id=5;
		$singleTabInfo[ColumnParam][$tariff_id][EntriesFlag]=0;
		$singleTabInfo[ColumnParam][$tariff_id][NestEntryOID]="";
    $singleTabInfo[ColumnParam][$tariff_id][RawName]="smsNotificationWhenCleanBalance";
    $singleTabInfo[ColumnParam][$tariff_id][ShowName]="Notification When Clean Balance";
	}
	
	showNavigateTitle($table_id,$sub_table_id,$table_level,$sysId,$columnTable,$instanceNo,"show");
	echo "<br>";
	echo "<br>";
	echo "<table width=\"100%\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	//table header
	echo "<tr bgcolor=\"#e6e6e6\">";
	$showFieldCount=0;
	for($i=0;$i<$singleTabInfo[ColumnParamCount];$i++)
	{
		if($singleTabInfo[ColumnParam][$i][KeyFlag] == 0)
			continue;
		$showFieldCount++;
		if($i == $singleTabInfo[TableDeletePos])
		{
			echo "<td width=20>";
			echo "Delete";
			echo "</td>";
		}
		else
		{
			echo "<td>";
			echo "<a href=\"$PHP_SELF?sysId=$sysId&table_id=$table_id&sub_table_id=$sub_table_id&table_level=$table_level&instanceNo=$instanceNo&order={$singleTabInfo[ColumnParam][$i][LastOID]}\">";
			echo "{$singleTabInfo[ColumnParam][$i][ShowName]}";
			echo "</a>";
			echo "</td>";
		}
	}
	echo "</tr>";
	//table row object
	$showObject=GetAllRowData($singleTabInfo,$paraTable,$instanceNo,$sysId);
	
	if(!isset($order))
		$order=$singleTabInfo[ColumnParam][$singleTabInfo[TableIndexPos]][LastOID];
	$ascFlag=1;
	
	if(0)
	{
		echo "<pre>";
		print_r($showObject);
		echo "</pre>";
	}
	
	//PPS COS table
	if($sysTypeNo == SYSTYPENO_PPS && $table_level == 1 && $table_id == 1)
	{
		if(sizeof($showObject) > 0)
		{
			foreach($showObject as $instance => $obj)
			{
				$cos_instance=omc_keep_length($instance,"0",4);
				if($_SERVER['REQUEST_METHOD'] == "POST" && $get)
				{
					$getParam_showFinishResultFlag=0;
					$getArr[0][instanceNo]=$cos_instance;
					$getArr[0][oid]="2.2.51.1";
					$getArr[0][sysId]=$sysId;
					
					$getArr[1][instanceNo]=$cos_instance;
					$getArr[1][oid]="2.2.52.1";
					$getArr[1][sysId]=$sysId;
					
					$getArr[2][instanceNo]=$cos_instance;
					$getArr[2][oid]="2.2.53.1";
					$getArr[2][sysId]=$sysId;
					
					$getArr[3][instanceNo]=$cos_instance;
					$getArr[3][oid]="2.2.54.1";
					$getArr[3][sysId]=$sysId;
					
					$getArr[4][instanceNo]=$cos_instance;
					$getArr[4][oid]="2.2.55.1";
					$getArr[4][sysId]=$sysId;
					
					$getArr[5][instanceNo]=$cos_instance;
					$getArr[5][oid]="2.2.56.1";
					$getArr[5][sysId]=$sysId;
					
					$getArr[6][instanceNo]=$cos_instance;
					$getArr[6][oid]="2.2.57.1";
					$getArr[6][sysId]=$sysId;
					
					$getArr[7][instanceNo]=$cos_instance;
					$getArr[7][oid]="2.2.58.1";
					$getArr[7][sysId]=$sysId;
					
					$getArr[8][instanceNo]=$cos_instance;
					$getArr[8][oid]="2.2.59.1";
					$getArr[8][sysId]=$sysId;
					
					$getArr[9][instanceNo]=$cos_instance;
					$getArr[9][oid]="2.2.60.1";
					$getArr[9][sysId]=$sysId;
					
					getParam($getArr);
					$getParam_showFinishResultFlag=1;
				}
				
				$value=getParamValue($sysId,"2.2.51.1.4","{$cos_instance}.0000");
				$showObject[$instance][3]=$value;
				//echo "$instance,$showValue<br>";
				
				$value=getParamValue($sysId,"2.2.54.1.4","{$cos_instance}.0000");
				$showValue=translateValueToOpt(1,3,"disable=0;enable=1",$value);
				$showObject[$instance][4]=$showValue;
				
				$value=getParamValue($sysId,"2.2.54.1.10","{$cos_instance}.0000");
				$showValue=translateValueToOpt(1,3,"notCharge=0;charge=1",$value);
				$showObject[$instance][5]=$showValue;
				
				$value=getParamValue($sysId,"2.2.54.1.12","{$cos_instance}.0000");
				$showValue=translateValueToOpt(1,3,"disable=0;enable=1",$value);
				$showObject[$instance][6]=$showValue;
			}
		}
	}
	
	$showObject=BubbleOrder($showObject,$order,$ascFlag);
	
	if(sizeof($showObject) > 0)
	{
		foreach($showObject as $instance => $obj)
		{	
			if($obj[1] === null || $obj[1] === ''||$obj[1]==='Error:NoSuchInstance'){
			continue;
			}
			echo "<tr onMouseOver=\"javascript:MouseOverColor(this);\" onMouseOut=\"javascript:MouseOutColor(this);\">";

			for($i=0;$i<$singleTabInfo[ColumnParamCount];$i++)
			{
				if($singleTabInfo[ColumnParam][$i][KeyFlag] == 0)
					continue;
				
				$LastOID=$singleTabInfo[ColumnParam][$singleTabInfo[TableIndexPos]][LastOID];
				$newIndex=$obj[$LastOID];
				if($singleTabInfo[TableLevel]==1)
					$nextInstance=omc_keep_length($newIndex,"0",4);
				else if($singleTabInfo[TableLevel]==2)
					$nextInstance=$instanceNo.".".omc_keep_length($newIndex,"0",4);
				else if($singleTabInfo[TableLevel]==3)
					$nextInstance=$instanceNo.".".omc_keep_length($newIndex,"0",4);
				
				if($i == $singleTabInfo[TableDeletePos])
				{
					echo "<td align=\"right\">";
					if($canwrite_flag)
						echo "<input type=\"checkbox\" style=\"width=12px;height:12px;\" onClick=\"javascript:deleteObject('$sysId','$table_id','$sub_table_id','$table_level','$instanceNo','{$singleTabInfo[DeleteOID]}','{$singleTabInfo[DeleteUpdateOID]}','{$singleTabInfo[TableEntryOID]}','$nextInstance',this);\">";
					else
						echo "<input type=\"checkbox\" disabled style=\"width=12px;height:12px;\" onClick=\"javascript:deleteObject('$sysId','$table_id','$sub_table_id','$table_level','$instanceNo','{$singleTabInfo[DeleteOID]}','{$singleTabInfo[DeleteUpdateOID]}','{$singleTabInfo[TableEntryOID]}','$nextInstance',this);\">";
					echo "</td>";
				}
				else if($singleTabInfo[ColumnParam][$i][EntriesFlag] == 1)
				{
					$LastOID=$singleTabInfo[ColumnParam][$i][LastOID];
					$value=$obj[$LastOID];
					
					$next_table_level=$singleTabInfo[TableLevel]+1;
					
					$thisTableName=$singleTabInfo[ColumnParam][$i][RawName];
					$tmpnum=strlen($thisTableName);
					for($tmpi=0;$tmpi<$tmpnum;$tmpi++)
					{
						if($thisTableName[$tmpi] < 'a' || $thisTableName[$tmpi] > 'z')
							break;
					}
					$thisTableName=substr($thisTableName,$tmpi);
					$thisTableName=trim(str_replace("Entries","",$thisTableName));
					$thisTableName=getShowNameOfField($thisTableName,-1);
					$tmpnum=count($columnTable);
					for($tmpi=0;$tmpi<$tmpnum;$tmpi++)
					{
						//echo "+$thisTableName+ +{$columnTable[$tmpi][Name]}+<br>";
						if(strcasecmp($thisTableName,trim($columnTable[$tmpi][Name])) == 0)
							break;
					}
					$new_sub_table_id=$tmpi;
					//$new_sub_table_id=$sub_table_id+1;
					echo "<td>";
					echo "<a href=\"$PHP_SELF?table_id=$table_id&sub_table_id=$new_sub_table_id&sysId=$sysId&table_level=$next_table_level&instanceNo=$nextInstance\">";
					echo "$value";
					echo "</a>";
					echo "</td>";
				}
				else if($i == $singleTabInfo[TableIndexPos])
				{
					$LastOID=$singleTabInfo[ColumnParam][$i][LastOID];
					$value=$obj[$LastOID];
					echo "<td>";
					//PPS COS table
					if($sysTypeNo == SYSTYPENO_PPS && $table_level == 1 && $table_id == 1)
						echo "<a href=\"cos_edit.php?table_id=$table_id&sub_table_id=$sub_table_id&sysId=$sysId&table_level=$table_level&instanceNo=$nextInstance\">{$value}</a>";
					else
						echo "<a href=\"param_edit.php?table_id=$table_id&sub_table_id=$sub_table_id&sysId=$sysId&table_level=$table_level&instanceNo=$nextInstance\">{$value}</a>";
					echo "</td>";
				}
				//RelationPoint
				else if(strstr($singleTabInfo[ColumnParam][$i][Description],"RelationPoint"))
				{
					echo "<td>";
					$LastOID=$singleTabInfo[ColumnParam][$i][LastOID];
					$value=$obj[$LastOID];
					
					$tmp1=strstr($singleTabInfo[ColumnParam][$i][Description],"RelationPoint:");
					$tmp2=explode(";",$tmp1);
					$tmp3=explode("RelationPoint:",$tmp2[0]);
					$rTableOid=$tmp3[1];
					
					$showvalue=$value;
					
					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($objDbConn,$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&sub_table_id=1&table_level=$new_table_level&instanceNo=$rInstanceNo\" onClick=\"updateTab('{$new_table_id}');\">$showvalue</a>";
						}
					}
					
					echo "</td>";
				}
				else
				{	
					echo "<td>";
					$LastOID=$singleTabInfo[ColumnParam][$i][LastOID];
					$value=$obj[$LastOID];
					$value=translateValueToOpt($singleTabInfo[ColumnParam][$i][OperType],$singleTabInfo[ColumnParam][$i][ValueType],$singleTabInfo[ColumnParam][$i][Template],$value);
					if(strlen(trim($value)) == 0)
						$value="--";
					echo "$value";
					echo "&nbsp;</td>";
				}
			}
			echo "</tr>";
		}
	}
	
	//new object
	if(strlen(trim($singleTabInfo[CreateOID])) > 0 && $canwrite_flag)
	{
		echo "<tr>";
		echo "<td>";
		$indexOid=$singleTabInfo[ColumnParam][$singleTabInfo[TableIndexPos]][OID];
		
		echo "<a href=\"./param_edit.php?create=1&sysId=$sysId&table_id=$table_id&sub_table_id=$sub_table_id&table_level=$table_level&instanceNo=$instanceNo&createOid={$singleTabInfo[CreateOID]}&updateOid={$singleTabInfo[CreateUpdateOID]}&indexOid={$indexOid}&oldtableOid={$singleTabInfo[TableEntryOID]}\">";
		echo "New";
		echo "</a>";
		
		
		echo "</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=\"get\" value=\" $strGet \" class=\"button\" style=\"$buttonStyle\">&nbsp;&nbsp;";
	
	//lock the channel
	if($sysTypeNo == SYSTYPENO_MSC && $singleTabInfo[TableEntryOID] == '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','$sub_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','$sub_table_id','$table_level','unlock');\">";
	}

	//if not get channel, get the channel first
	if($sysTypeNo == SYSTYPENO_MSC && $singleTabInfo[TableEntryOID] == "2.4.3.1")
	{
		echo "<input type=hidden name=\"table_id\" value=\"{$table_id}\">";
		echo "<input type=hidden name=\"sub_table_id\" value=\"{$sub_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($objDbConn,$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";
			
			}
		}
	}
	
}

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

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