<?php
require("../../inc/header.inc");
require("../sub_inc/operWebFunc.inc");
require("param_comm.inc");

//$url_temp=$_SERVER["REQUEST_URI"];
//echo "This page URL:$url_temp<br>";
//echo "instanceNo=$instanceNo,tableOid=$tableOid<br>";

?>

<script language="Javascript">
function deleteObject(sysId,oid,instanceNo,tableOid,control)
{
	var reply=confirm("Do you want to delete the selected?");
	if(reply == true)
	{
		window.location.href="param_show_down.php?delete=1&sysId="+sysId+"&deleteOid="+oid+"&deleteInstanceNo="+instanceNo+"&tableOid="+tableOid+"&table_type=0";
	}
	else
	{
		control.checked=false;
	}
}

function clickOnMoreHide(where,num,oper)
{
	var cmd;
	//to change the more button to hide button or reverse
	if(oper=='show')
	{
		cmd="document.all.show"+where+".style.display='none'";
		eval(cmd);
		cmd="document.all.hide"+where+".style.display=''";
		eval(cmd);
			
		for(var i=4;i<num;i++)
		{
			cmd="document.all."+where+i+".style.display=''";
			eval(cmd);
		}
		
	}
	else
	{
		cmd="document.all.show"+where+".style.display=''";
		eval(cmd);
		cmd="document.all.hide"+where+".style.display='none'";
		eval(cmd);
		
		for(var i=4;i<num;i++)
		{
			cmd="document.all."+where+i+".style.display='none'";
			eval(cmd);
		}
	}
}
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>

<body leftmargin="15" rightmargin="10" onload="javascript:adjust_frame('down');" onresize="javascript:adjust_frame('down');" style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;">

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

adjust_content_head_frame("down");	
echo "<br>";
$sysIdArr=explode('_',$sysId);
$sysTypeNo=$sysIdArr[0];
$sysNo=$sysIdArr[1];
$subSysNo=$sysIdArr[2];
$objDb='OBJ_'.$sysTypeNo;
$paraConfTable=$objDb.'.paramConf';
$pubDb='OMC_PUB';
$sysConfTable = 'sysConf';
$sysInfoTable = 'sysInfo';

$sql="select sysTypeName from OMC_PUB.sysConf where sysTypeNo='$sysTypeNo' ";
$res=@mysqli_query($pubConn,$sql);
$row=@mysqli_fetch_array($res);
$module_name=$row[sysTypeName];

if(checkIndependSystem($sysTypeNo))//Plat
	$paraTable=$objDb.".param_".$sysNo;
else
	$paraTable=$objDb.".param_99";
	
//check the system whether exist
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();
	}
}
//echo "sysId=$sysId<br>";
//echo "paraConfTable=$paraConfTable,paraTable=$paraTable<br>";

//delete
if($delete == 1)
{
	//echo "Now delete the object,deleteOid=$deleteOid,deleteInstanceNo=$deleteInstanceNo";
	$deleteOid=trim($deleteOid);
	$tmpwhere=getLevelWhere($deleteOid);
	$sql="update $paraTable set initValue= '6' where $tmpwhere and instanceNo='$deleteInstanceNo' ";
	
	if($sysTypeNo == 260 && $sysNo != 99 && $subSysNo != 99)
		$sql.="and subSysNo='$subSysNo' ";
	
	mysqli_query($pubConn,$sql);
	$commIdStr=oidSysCommSend($sysId,3,$deleteOid,$selectedSysId=-1,$deleteInstanceNo);
	checkState($commIdStr,"./param_show_down.php?sysId=$sysId");
	
	//command success,delete the record in the db
	$etmp=explode(".",$deleteOid);
	$elen=sizeof($etmp);
	$deleteTableOid="";
	for($ti=0;$ti<$elen-1;$ti++)
		$deleteTableOid.=$etmp[$ti].".";
	$deleteTableOid=substr($deleteTableOid,0,strlen($deleteTableOid)-1);
	//echo "deleteTableOid=$deleteTableOid<br>";
	$tmpwhere=getLevelWhere($deleteTableOid);
	$sql="delete from $paraTable where $tmpwhere and instanceNo=$deleteInstanceNo ";
	
	if($sysTypeNo == 260 && $sysNo != 99 && $subSysNo != 99)
		$sql.="and subSysNo='$subSysNo' ";
		
	//echo "$sql<br>";
	mysqli_query($pubConn,$sql);
	
	//When delete an object, then get all the table 
	$getArr[0][sysId]=$sysId;
	$getArr[0][oid]=$deleteTableOid;
	$getArr[0][instanceNo]="";
	getParam($getArr);
}

//Get all
if($_SERVER['REQUEST_METHOD'] == "POST")
{
	if($get)
	{
		getParam($commInfoArr);
	}
	
	if($set)
	{
		//print_r($commInfoArr);
		$commIndex=0;
		for($i=0;$i<sizeof($commInfoArr);$i++)
		{
			$oidwhere=getLevelWhere($commInfoArr[$i][oid]);
			$sql="select name_1,desc_1,maxAccess from $paraConfTable where $oidwhere ";
			$res=@mysqli_query($pubConn,$sql);
			$row=@mysqli_fetch_array($res);
			if($row[maxAccess] == ACCESS_ENTRY && strstr($row[desc_1],"Table Parameter"))
			{
				$oidwhere=str_replace("level","T1.level",$oidwhere);
				$checksql="SELECT T1.level_1,T1.level_2,T1.level_3,T1.level_4,T1.level_5,T1.level_6,T1.level_7,T1.level_8,T1.level_9,T1.level_10,T1.instanceNo,T1.initValue,T1.readValue,T2.valueType FROM $paraTable AS T1,$paraConfTable AS T2  WHERE $oidwhere AND 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  AND T2.maxAccess='19' ORDER BY  T1.level_1,T1.level_2,T1.level_3,T1.level_4,T1.level_5,T1.level_6,T1.level_7,T1.level_8,T1.level_9,T1.level_10,instanceNo ";
				
				if($sysTypeNo == 260 && $sysNo != 99 && $subSysNo != 99)
					$checksql="SELECT T1.level_1,T1.level_2,T1.level_3,T1.level_4,T1.level_5,T1.level_6,T1.level_7,T1.level_8,T1.level_9,T1.level_10,T1.instanceNo,T1.initValue,T1.readValue,T2.valueType FROM $paraTable AS T1,$paraConfTable AS T2  WHERE $oidwhere AND T1.subSysNo='$subSysNo' AND 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  AND T2.maxAccess='19' ORDER BY  T1.level_1,T1.level_2,T1.level_3,T1.level_4,T1.level_5,T1.level_6,T1.level_7,T1.level_8,T1.level_9,T1.level_10,instanceNo ";
				
				
				$checkres=@mysqli_query($pubConn,$checksql);
				$num=@mysqli_num_rows($checkres);
				if($num==0)
					continue;
				
				$setCommInfoArr[$commIndex][sysId]=$sysId;
				$setCommInfoArr[$commIndex][oid]=$commInfoArr[$i][oid];
				$setCommInfoArr[$commIndex][instanceNo]='';
				$commIndex++;
				//echo "{$commInfoArr[$i][sysId]} {$commInfoArr[$i][oid]} {$commInfoArr[$i][instanceNo]}<br>";
			}
			
			if($row[maxAccess] == ACCESS_READ_WRITE && !strstr($row[name_1],"Command"))
			{
				$setCommInfoArr[$commIndex][sysId]=$sysId;
				$setCommInfoArr[$commIndex][oid]=$commInfoArr[$i][oid];
				$setCommInfoArr[$commIndex][instanceNo]='';
				$commIndex++;
				//echo "{$commInfoArr[$i][sysId]} {$commInfoArr[$i][oid]} {$commInfoArr[$i][instanceNo]}<br>";
			}
		}
		/*
		for($i=0;$i<sizeof($setCommInfoArr);$i++)
		{
			echo "{$setCommInfoArr[$i][sysId]} {$setCommInfoArr[$i][oid]} {$setCommInfoArr[$i][instanceNo]}<br>";
		}
		*/
		
		setParam($setCommInfoArr);
	}
	
	//command button
	$commlen=sizeof($commands);
	for($ci=0;$ci<$commlen;$ci++)
	{
		$paraName="command_id_".$ci;
		if($$paraName)
		{
			$tmpwhere=getLevelWhere($commands[$ci][oid]);
			$oidstr=str_replace(".",",",$commands[$ci][oid]);
			$oidsep=explode(".",$commands[$ci][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($sysTypeNo == 260 && $sysNo != 99 && $subSysNo != 99)
				$delSql.="and subSysNo='$subSysNo' ";
			
			mysqli_query($pubConn,$delSql);
			$insertSql="insert into $paraTable($valuestr,instanceNo,initValue,readValue) values($oidstr,'0000',{$commands[$ci][val]},{$commands[$ci][val]}) ";
			
			if($sysTypeNo == 260 && $sysNo != 99 && $subSysNo != 99)
				$insertSql="insert into $paraTable($valuestr,instanceNo,initValue,readValue,subSysNo) values($oidstr,'0000',{$commands[$ci][val]},{$commands[$ci][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[$ci][oid],$selectedSysId=-1,"0000");
			checkState($commIdStr,"./param_show_down.php?sysId=$sysId");
			break;
		}
	}
}
$keyId=0;
showTable($PARAM_OID_PREFIX);


for($i=0;$i<$keyId;$i++)
{
	if(!$objects[$i]['type'] == LEAF_TYPE && !strstr($objects[$i]['name_1'],"Entry") && !strstr($objects[$i]['name_1'],"Table"))
	{
		$objects[$i]['table_type']=SCALAR_TABLE_TYPE;
	}
	if($objects[$i]['type'] == UNKNOWN_TYPE)
	{
		$objects[$i]['type']=SCALAR_TABLE_TYPE;
	}
}
//*************************************************************************
$table_level=0;
$commInfoArrNo=0;
//command button
$commandCount=0;
echo "<form name=\"myform\" method=\"POST\" action=\"$PHP_SELF\" onsubmit=\"return buttonOpt();\">";
for($index=0;$index<$keyId;$index++)
{
	$level_count[$table_level]--;
	$pre=strlen($objects[$index-1]['oid']);
	$now=strlen($objects[$index]['oid']);
	//echo "pre=$pre,now=$now<br>";
	
	switch($objects[$index]["type"])
	{
		
		case SCALAR_TABLE_TYPE:
			//echo "SCALAR_TABLE_TYPE {$objects[$index]['name_1']}<br>";
			$table_level++; 
			$level_count[$table_level]=$objects[$index]['nest_num'];
			$table_type[$table_level]=SCALAR_TABLE_TYPE;
			$table_name[$table_level]=$objects[$index]['name_1'];
			$table_oid[$table_level]=$objects[$index]["oid"];
			
			if($objects[$index]['name_1'] == "parameter")
			{
				//echo "<b>$module_name</b>";
				continue;
			}
			echo "<table border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\"  bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\"  >";
			$rownum=$level_count[$table_level]+1;
			$showName=getShowNameOfTable($table_name[$table_level],$index);
			if($objects[$index+1]["type"] != COLUMN_TABLE_TYPE)
			{
				$countWhere=getLevelWhere($objects[$index]['oid']);
        $countSql="select * from $paraConfTable where $countWhere and Not (desc_1 = 'Hidden Parameter' or name_1 like '%Command%') "; 
        $countRes=mysqli_query($pubConn,$countSql);
        echo mysqli_error($pubConn);
        $countNum=mysqli_num_rows($countRes);
        if($countNum > 1)
        	echo "<tr><td width=10% rowspan=1 bgcolor=#cecece><b>$showName</b></td>";
			}
			
			$table_title_id[$table_level]="title_".$table_name[$table_level]."_id";
			
			if($DEBUG)
			{
				for($s=0;$s<$table_level;$s++)
					echo "..";
				echo "start table({$objects[$index]['name_1']}) {$table_level}<br>";
			}
			break;
		case COLUMN_TABLE_TYPE:
			//echo "COLUMN_TABLE_TYPE {$objects[$index]['name_1']}<br>"; 
			$table_level++; 
			$level_count[$table_level]=$objects[$index+1]['nest_num']+1;
			$table_type[$table_level]=COLUMN_TABLE_TYPE;
			$table_name[$table_level]=$objects[$index]['name_1'];
			
			$nlevel=getTableLevel($objects[$index]['oid'].".1",$sysTypeNo);

			if($nlevel > 1)
			{
				echo "<table style=\"display:none\" border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\"  bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\"  >";
			}
			else
			{
				echo "<table border=\"1\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\"  bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\"  >";
			}
			//echo "<caption>{$table_name[$table_level]}</caption>";
		
			$rownum=$level_count[$table_level]+1;
			$showName=getShowNameOfTable($table_name[$table_level],$index);
			echo "<tr><td width=10%><b>$showName</b></td><td>";
			
			if($DEBUG)
			{
				for($s=0;$s<$table_level;$s++)
					echo "..";
				echo "start table({$objects[$index]['name_1']}) {$table_level}<br>";
			}
			break;
		case ENTRY_TYPE:
			//echo "ENTRY_TYPE {$objects[$index]['name_1']}<br>"; 
			$table_oid[$table_level]=$objects[$index]["oid"];
			
			//skip the timeslot
			if($sysTypeNo == SYSTYPENO_MSC && $objects[$index]["oid"] == "2.4.3.1")
				break;
				
			echo "<input type=\"hidden\" name=\"commInfoArr[$commInfoArrNo][sysId]\" value=\"$sysId\">";
			echo "<input type=\"hidden\" name=\"commInfoArr[$commInfoArrNo][oid]\" value=\"{$objects[$index]['oid']}\">";
			echo "<input type=\"hidden\" name=\"commInfoArr[$commInfoArrNo][instanceNo]\" value=\"\">";
			$commInfoArrNo++;
			break;
		case LEAF_TYPE:
			//not accessable
			if($objects[$index]['maxAccess'] == ACCESS_ENTRY)
				break;
			if($table_type[$table_level] == SCALAR_TABLE_TYPE)
			{
				//$table_oid[$table_level]
				if(strstr($objects[$index]['desc_1'],"Hidden Parameter"))
					continue;
				//command button
				if(stristr($objects[$index]['name_1'],"Command"))
				{
					$commandKeyIdList[$commandCount]=$index;
					$commandCount++;
					continue;
				}
				
				$showValue=showParamInReadOnly($index,$sysId);
				echo "<tr><td>";
				echo "<table border=\"0\" width=\"100%\" cellpadding=\"2\" cellspacing=\"0\"  bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\"  >";
					$showName=getShowNameOfTable($objects[$index]['name_1'],$index);
					echo "<tr><td width=30%>$showName</td>";
					echo "<td><a class=text href=\"param_edit.php?tableOid={$table_oid[$table_level]}&sysId=$sysId&instanceNo=0000&table_type=0\"><font color=blue>$showValue</font></td>";
				echo "</table>";
				echo "</td></tr>";
				
				//if the scalar leaf not exist in the db, insert it first
				$checklevel=getLevelWhere($objects[$index]['oid']);
				$checksql="select * from $paraTable where $checklevel and instanceNo='0000' ";
				
				if($sysTypeNo == 260 && $sysNo != 99 && $subSysNo != 99)
					$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($sysTypeNo == 260 && $sysNo != 99 && $subSysNo != 99)
						$insertsql="replace into $paraTable set subSysNo='$subSysNo',initValue='',instanceNo='0000',$insertlevel ";
					
					mysqli_query($pubConn,$insertsql);
					echo mysqli_error($pubConn);
				}
				
				echo "<input type=\"hidden\" name=\"commInfoArr[$commInfoArrNo][sysId]\" value=\"$sysId\">";
				echo "<input type=\"hidden\" name=\"commInfoArr[$commInfoArrNo][oid]\" value=\"{$objects[$index]['oid']}\">";
				echo "<input type=\"hidden\" name=\"commInfoArr[$commInfoArrNo][instanceNo]\" value=\"\">";
				$commInfoArrNo++;

			}
			else if($table_type[$table_level] == COLUMN_TABLE_TYPE)
			{
				
				if(strstr($objects[$index]['name_1'],"Index"))
				{
					$showKeyIdListIndex=0;
					if($table_hide_flag[$table_level] == 1)
						echo "<table cellpadding=\"3\" cellspacing=\"0\" style=\"display:none\" border=0 width=100%>";
					else
						echo "<table cellpadding=\"3\" cellspacing=\"0\" border=0 width=100%>";
					echo "<tr bgcolor=\"#cecece\">";
				}
				
				$showName=getShowNameOfField($objects[$index]['name_1'],$index);
				
				if(strstr($objects[$index]['desc_1'],"Key Parameter"))
				{
					if(strstr($objects[$index]['name_1'],"RowStatus"))
					{
						$table_delete_flags[$table_level]=1;
						echo "<td align=right>Delete</td>";
					}
					else
					{
						echo "<td>";
						echo "<a href=\"param_show_table.php?tableOid={$table_oid[$table_level]}&sysId=$sysId&table_type=1&sort=$showKeyIdListIndex&instanceNo=0000\">";
						echo "{$showName}</a></td>";
					}
					$showKeyIdList[$showKeyIdListIndex]=$index;
					$showKeyIdListIndex++;
				}
				
				if(strstr($objects[$index]['name_1'],"RowStatus"))
				{
					echo "</tr>";
					echo "<td>";
					if($table_hide_flag[$table_level] == 1)
						continue;
					$indexKeyId=-1;
					$entries_count=0;
					
					for($tt=0;$tt<$showKeyIdListIndex;$tt++)
					{
						$id=$showKeyIdList[$tt];
						if(strstr($objects[$id]['name_1'],"Index"))
							$indexKeyId=$id;
						else if(strstr($objects[$id]['name_1'],"RowStatus"))
							$rowstatusKeyId=$id;
						else if(strstr($objects[$id]['name_1'],"Entries"))
						{
							$entriesKeyIds[$entries_count]=$id;
							
							//get table name
							$tb=$objects[$id][name_1];
							$tlen=strlen($tb);
							$fg=0;
							$tb1="";
							for($ti=0;$ti<$tlen;$ti++)
							{
								if($tb[$ti] >= 'A' && $tb[$ti] <= 'Z')
									$fg=1;
								if($fg==1)
									$tb1.=$tb[$ti];
							}
							$tb2=explode("Entries",$tb1);
							$tb3=$tb2[0];
							//PrintInfo("table3=".$tb3);
							$entriesOid=findRelationOid($tb3,TABLE_ENTRY,$sysTypeNo);
							$entries_oids[$entries_count]=$entriesOid;
							$entries_count++;
						}
						else
							$select_list.=$objects[$id]['name_1'].",";
					}
					
					$tmplevel=getLevelWhere($objects[$indexKeyId]['oid']);
					//and instanceNo <> '0000'
					$sql="select instanceNo from $paraTable where $tmplevel order by instanceNo ";
					
					if($sysTypeNo == 260 && $sysNo != 99 && $subSysNo != 99)
						$sql.="and subSysNo='$subSysNo' ";
					
					$res=@mysqli_query($pubConn,$sql);
					$instanceCount=0;
					while($row=@mysqli_fetch_array($res))
					{
						$instanceList[$instanceCount]=$row[instanceNo];
						$instanceCount++;
					}
					$tableName=$table_name[$table_level];
					for($tt=0;$tt<$instanceCount;$tt++)
					{
						if($tt>MAX_SHOW_ROW_NUM-1)
							echo "\n<tr id=\"$tableName$tt\" style=\"display:none\" onMouseOver=\"javascript:MouseOverColor(this);\" onMouseOut=\"javascript:MouseOutColor(this);\">";
						else
							echo "\n<tr id=\"$tableName$tt\" onMouseOver=\"javascript:MouseOverColor(this);\" onMouseOut=\"javascript:MouseOutColor(this);\">";
						//echo "<tr>";
						for($jj=0;$jj<$showKeyIdListIndex;$jj++)
						{
							
							$id=$showKeyIdList[$jj];
							$tmplevel=getLevelWhere($objects[$id]['oid']);
							$sql="select initValue from $paraTable where instanceNo='{$instanceList[$tt]}' and $tmplevel ";
							
							if($sysTypeNo == 260 && $sysNo != 99 && $subSysNo != 99)
								$sql.="and subSysNo='$subSysNo' ";
							
							$res=@mysqli_query($pubConn,$sql);
							$row=@mysqli_fetch_array($res);
							$rowObj[$tt][$jj]=$row[initValue];
							if($id == $indexKeyId)
							{
								echo "<td>";
								echo "<a href=\"param_edit.php?tableOid={$table_oid[$table_level]}&sysId=$sysId&table_type=1&instanceNo={$instanceList[$tt]}\">";
								echo "{$rowObj[$tt][$jj]}";
								echo "</a>";
							}
							//$table_delete_flags[$table_level]=1;
							else if($id == $rowstatusKeyId)
							{
								echo "<td align=right>";
								if($table_delete_flags[$table_level] == 1)
								{
									echo "<input type=\"checkbox\" onClick=\"javascript:deleteObject('$sysId','{$objects[$id]['oid']}','{$instanceList[$tt]}','2',this);\">";
								}
							}
							//feake
							else if($entries_count>0 && in_array($id,$entriesKeyIds))
							{								
								$sizet=sizeof($entriesKeyIds);
								//PrintInfo("entries=".$entriesKeyIds[0]);
								for($si=0;$si<$sizet;$si++)
								{
									if($id == $entriesKeyIds[$si])
									{
										//printf("keyId=".$entriesKeyIds[$si]);
										$tmpOid=$entries_oids[$si];
										break;
									}
								}
								
								echo "<td>";
								echo "<a href=\"param_show_table.php?tableOid={$tmpOid}&sysId=$sysId&table_type=1&instanceNo={$instanceList[$tt]}\">";
								echo "{$rowObj[$tt][$jj]}";
								echo "</a>";
							}
							else
							{
								echo "<td>";
								if(trim($rowObj[$tt][$jj]) == "")
									echo "--";
								else
								{
									$showValue=translateValueToOpt($id,$rowObj[$tt][$jj]);
									echo "{$showValue}";
								}
							}
							echo "</td>";
						}
						echo "</tr>";
					}
					
					echo "</td></tr>";

					if($objects[$indexKeyId]['maxAccess'] == ACCESS_INDEX_CREATE_SPE)
					{
						echo "<tr><td><a href=\"param_edit.php?createpage=1&sysId=$sysId&tableOid={$table_oid[$table_level]}&instanceNo=0000&table_type=1\">New</a></td>";
						for($si=0;$si<$showKeyIdListIndex-1;$si++)
						{
								echo "<td>--</td>";
						}
						echo "</tr>";
					}
										
					if($instanceCount>MAX_SHOW_ROW_NUM)
					{
						echo "<tr id='show$tableName' style=\"display:block\"><td><a href=\"javascript:clickOnMoreHide('$tableName','$instanceCount','show')\"><nobr>More >></a></td></tr>"; 
						echo "<tr id='hide$tableName' style=\"display:none\"><td><a href=\"javascript:clickOnMoreHide('$tableName','$instanceCount','hide')\"><nobr><< Hide </a></td></tr>"; 
					}
					echo "</table>";
					echo "</td></tr>";
				}
				
			}
			if($DEBUG)
			{
				for($s=0;$s<$table_level+1;$s++)
					echo "..";
				echo "LEAF_TYPE {$objects[$index]['name_1']}<br>";
			}
			break;
		default:
			echo "UNKNOWN_TYPE {$objects[$index]['name_1']}<br>"; 
			break;
	}
	
	
	if($table_level>1 &&($index)<$keyId && strlen($objects[$index+1]['oid']) < strlen($objects[$index]['oid']))
	{
		echo "</table><p>";
		if($DEBUG)
		{
			for($s=0;$s<$table_level;$s++)
					echo "..";
			echo "close table level=$table_level<br>";
		}
		$table_level--;
	}
	if($level_count[$table_level] <= 0)
	{
		echo "</table><p>";
		if($DEBUG)
		{
			for($s=0;$s<$table_level;$s++)
					echo "..";
			echo "close table level=$table_level<br>";
		}
		$table_level--;
	}
}

if($table_level == 1)
{
	echo "</table>";
	if($DEBUG)
	{
		echo "..";
		echo "close table level=$table_level<br>";
	}
	$table_level--;
}

echo "<input id=\"get_id\" type=\"submit\" name=\"get\" value=\"$strGet\" class=\"button\">";

//whether have set all button
$sql="select * from OMC_PUB.sysMibConf where sysTypeNo='$sysTypeNo' and setAllFlag='1' ";
$res=@mysqli_query($pubConn,$sql);
$num=@mysqli_num_rows($res);
if($num > 0)
	echo "<input id=\"set_id\" type=\"submit\" name=\"set\" value=\"$strSet\" class=\"button\">";


echo "<input type=\"hidden\" name=\"tableOid\" value=\"$tableOid\">";
echo "<input type=\"hidden\" name=\"sysId\" value=\"$sysId\">";
echo "<input type=\"hidden\" name=\"table_type\" value=\"$table_type\">";
echo "<input type=\"hidden\" name=\"instanceNo\" value=\"$instanceNo\">";

//command button
$command_index=0;
for($i=0;$i<$commandCount;$i++)
{
	$keyId=$commandKeyIdList[$i];
	//echo "command-$i {$objects[$keyId]['name_1']}<br>";
	
	
	$template=trim($objects[$keyId]["setTemplate_1"]);
	$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;";
		echo "<input id=\"command_id_{$command_index}\" type=\"submit\" onclick=\"isConfirm=1;\" name=\"command_id_{$command_index}\" value=\"$showName\" class=\"button\">";
		
		echo "<input type=\"hidden\" name=\"commands[$command_index][oid]\" value=\"{$objects[$keyId][oid]}\">";
		echo "<input type=\"hidden\" name=\"commands[$command_index][val]\" value=\"$opt\">";
		//echo "<input type=\"hidden\" name=\"commInfoArr[0][instanceNo]\" value=\"\">";
		$command_index++;
	}

}


echo "</form>";
//=============test

$DEBUG=0;
if($DEBUG)
{
	echo "<p>============================test========================<br>";
	echo "keyId=$keyId<br>";
	$test_oid_flag=1;
	$test_name_flag=1;
	$test_nest_flag=1;
	$test_type_flag=1;
	
	for($i=0;$i<$keyId;$i++)
	{
		//if($objects[$i]['type'] != LEAF_TYPE && $objects[$i]['type'] != ENTRY_TYPE)
		{
			echo "$i-";
			if($test_oid_flag)
				echo "oid-{$objects[$i]['oid']}, ";
			if($test_name_flag)
			 	echo "name-{$objects[$i]['name_1']}, ";
			if($test_nest_flag)
				echo "nestNum-{$objects[$i]['nest_num']},  ";
			if($test_type_flag)
				echo "type-{$type_label[$objects[$i]['type']]}, ";
				
			echo "<br>";
		}
	}
}
adjust_content_tail("down");
?>
