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

<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;\" ></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 addObject(createMethod,sysId,table_id,table_level,instanceNo,createOid,updateOid,indexOid,oldtableOid)
{
	if(createMethod == 0)
		createIndex=document.myform.index_select.value;
	else
		createIndex=1;
		
	window.location.href="param_edit.php?realcreate=1&createMethod="+createMethod+"&createIndex="+createIndex+"&sysId="+sysId+"&table_id="+table_id+"&table_level="+table_level+"&instanceNo="+instanceNo+"&createOid="+createOid+"&updateOid="+updateOid+"&indexOid="+indexOid+"&oldtableOid="+oldtableOid;
}

function openNITZ(sysId,table_id,table_level,instanceNo,param_oid)
{
	URL="./mscNITZ.php?sysId="+sysId+"&table_id="+table_id+"&table_level="+table_level+"&instanceNo="+instanceNo+"&param_oid="+param_oid;
	var setWindow = open(URL, 'newWin', 'toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,status=yes,width=400,height=350');
	//setWindow.focus();
}

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

</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");	
//*****
//$url_temp=$_SERVER["REQUEST_URI"];
//echo "This page URL:$url_temp<br>";
global $OMC_server;

$canwrite_flag=checkWritePrivilege();
$sysId = $_REQUEST['sysId'];
$table_id = $_REQUEST['table_id'];
$table_level = $_REQUEST['table_level'];
$instanceNo = $_REQUEST['instanceNo'];
$need_get_again = $_REQUEST['need_get_again'];
$getTableOid = $_REQUEST['getTableOid'];

$sysIdArr=explode('_',$sysId);
$sysTypeNo=$sysIdArr[0];
$sysNo=$sysIdArr[1];
$subSysNo=$sysIdArr[2];
$objDb='OBJ_'.$sysTypeNo;
$paraConfTable=$objDb.'.paramConf';
$pubDb='OMC_PUB';
$objConn = mysqli_connect($OMC_server[0]['host'],$OMC_server[0]['user'],$OMC_server[0]['password'], $objDb);

if(checkIndependSystem($sysTypeNo))//Plat
	$paraTable=$objDb.".param_".$sysNo;
else
	$paraTable=$objDb.".param_99";

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

$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(0)
{
	echo "<pre>";
	print_r($tabConf);
	echo "</pre>";
}

if($need_get_again)
{
	echo "need_get_again=$need_get_again<br>";
	$commIdStr=oidSysCommSend($sysId,0,$getTableOid,-1,$instanceNo);
	echo "<script language=\"JavaScript\">\n";
	echo "window.location.href='$PHP_SELF?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=$instanceNo';\n";
	echo "</script>\n";
}

if($_SERVER['REQUEST_METHOD'] == "POST")
{
	echo "<br>";
	$set = $_REQUEST['set'];
	$get = $_REQUEST['get'];
	$lock = $_REQUEST['lock'];
	$unlock = $_REQUEST['unlock'];
	$adminStatOid = $_REQUEST['adminStatOid'];
	if($set)
	{
		$commIdStr=oidSysCommSend($sysId,3,$getTableOid,-1,$instanceNo);	
		checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=$instanceNo&need_get_again=1&get=1&getTableOid=$getTableOid");
	}
	else if($get)
	{
		//Get the timeslot parameter from the plat(trunk group id)
		$timeslot_table_oid=GetOIDByName(SYSTYPENO_MSC,"channelEntry");
		if($sysTypeNo == SYSTYPENO_MSC && $getTableOid == $timeslot_table_oid)
		{
			$tmps=explode(".",$instanceNo);
			$grounp_id=GetTrunkGroupID($tmps[0]+0,$tmps[1]+0);
			if($grounp_id == 1)
				$tmpSysId="320_1_0";
			else
				$tmpSysId="320_0_0";

			if(!GetSystemStatus(SYSTYPENO_MSC,$grounp_id))
				$tmpSysId="320_99_99";

				
			$commIdStr=oidSysCommSend($tmpSysId,0,$getTableOid,-1,$instanceNo);
			checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=$instanceNo");
		}
		else
		{
			$commIdStr=oidSysCommSend($sysId,0,$getTableOid,-1,$instanceNo);
			checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=$instanceNo");
		}
	}
	else if($lock || $unlock)
	{
		$tmpWhere=getLevelWhere($adminStatOid);
		if($lock)
			$initValue=0;
		else
			$initValue=1;
				
		$updateSql="UPDATE $paraTable SET initValue=$initValue WHERE $tmpWhere AND instanceNo=$instanceNo ";		
		
		if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
			$updateSql.="and subSysNo='$subSysNo' ";
		
		mysqli_query($objConn,$updateSql);
		$commIdStr=oidSysCommSend($sysId,3,$adminStatOid,-1,$instanceNo);
		checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=$instanceNo");
	}
}

echo "<form name=\"myform\" method=\"POST\" action=\"$PHP_SELF\">";


//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($objConn,$sql);
$num=@mysqli_num_rows($res);

$scalarTableIndex=0;
$columnTableIndex=0;
$scalarItemIndex=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][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]);
			}
			
			$scalarItemIndex++;
		}
	}
}

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

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($objConn,$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>";
	}
	
	$realcreate = $_REQUEST['realcreate'];
	$createIndex = $_REQUEST['createIndex'];
	$create = $_REQUEST['create'];
	$createOid = $_REQUEST['createOid'];
	$updateOid = $_REQUEST['updateOid'];
	$indexOid = $_REQUEST['indexOid'];
	$oldtableOid = $_REQUEST['oldtableOid'];

	if($realcreate)
	{
		//echo "sysId=$sysId,table_id=$table_id,table_level=$table_level,instanceNo=$instanceNo<br>";
		//echo "createIndex=$createIndex,createOid=$createOid,updateOid=$updateOid,indexOid=$indexOid,tableOid=$tableOid<br>";
		$oldInstanceNo=$instanceNo;
		if($table_level == 1)
		{
			$createInstanceNo=omc_keep_length($createIndex,'0',4);
			$instanceNo=$createInstanceNo;
		}
		else
		{
			$createInstanceNo=$instanceNo.".".omc_keep_length($createIndex,'0',4);
			$instanceNo=$createInstanceNo;
		}
		
		if($createMethod == AUTO_CREATE)
			$createIndex=1;
		$sql="replace into $paraTable set initValue='$createIndex',instanceNo='$createInstanceNo'";
		if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
			$sql.=",subSysNo='$subSysNo' ";
		
		$indexOidArr=explode(".",$createOid);
		for($i=0;$i<sizeof($indexOidArr);$i++)
			$sql=$sql.",level_".($i+1)."=".$indexOidArr[$i];
		//echo "$sql<br>";
		mysqli_query($objConn,$sql);
		
		//send create command
		$commIdStr=oidSysCommSend($sysId,9,$createOid,-1,$createInstanceNo);
		checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=$oldInstanceNo&create=1&createOid=$createOid&updateOid=$updateOid&indexOid=$indexOid&oldtableOid=$oldtableOid");
	
		if($createMethod == AUTO_CREATE)
		{
			$indexLevelWhere=getLevelWhere($createOid);
			$indexSql="select * from $paraTable where $indexLevelWhere and instanceNo='$createInstanceNo' ";
			if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
				$indexSql.="and subSysNo='$subSysNo' ";
			
			$indexres=@mysqli_query($pubConn,$indexSql);
			$indexrow=@mysqli_fetch_array($indexres);
			$newIndex=$indexrow[readValue]+0;
			
			$newInstanceNo=omc_keep_length($newIndex,'0',4);
			if($table_level == 1)
				$instanceNo=$newInstanceNo;
			else
				$instanceNo=$oldInstanceNo.".".$newInstanceNo;
			//echo "oldInstanceNo=$oldInstanceNo,newIndex=$newIndex,instanceNo=$instanceNo<br>";
		}
		
		
		//update the entries
		if(trim($updateOid)!="")
		{
			$commIdStr=oidSysCommSend($sysId,0,$updateOid,-1,$oldInstanceNo);
			checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=$oldInstanceNo&create=1&createOid=$createOid&updateOid=$updateOid&indexOid=$indexOid&oldtableOid=$oldtableOid");
		}
		
		//get the table
		if($oldInstanceNo=="0000" && $table_level == 1)
			$commIdStr=oidSysCommSend($sysId,5,$oldtableOid,-1,"");
		else
			$commIdStr=oidSysCommSend($sysId,5,$oldtableOid,-1,$oldInstanceNo);
		checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&table_level=$table_level&instanceNo=$oldInstanceNo&create=1&createOid=$createOid&updateOid=$updateOid&indexOid=$indexOid&oldtableOid=$oldtableOid");
		
	}
	
	$oidwhere=getLevelWhere($thisTableConf[$thisTableConf[EntryIndex]][OID]);
	$sql="select * from $paraTable where $oidwhere and instanceNo='$instanceNo' ";
	//echo "$sql<br>";
	$res=@mysqli_query($objConn,$sql);
	$num=@mysqli_num_rows($res);
	for($i=0;$i<$num;$i++)
	{
		$row=@mysqli_fetch_array($res);
		$oid=getOIDByRow($row);
		$fieldIndex=sizeof(explode(".",$oid));
		$fieldPos=$row["level_".$fieldIndex]+0;
		$recordData[$fieldPos]=$row[initValue];
	}
	if(0)
	{
		echo "<pre>";
		print_r($recordData);
		echo "</pre>";
	}
	
	echo "<br>";
	if($create)
		showNavigateTitle($table_id,$table_level,$sysId,$columnTable,$instanceNo,"create");
	else
		showNavigateTitle($table_id,$table_level,$sysId,$columnTable,$instanceNo,"edit");
	
	if($create)
	{
		echo "<br>";
		//echo "table_level=$table_level,instanceNo=$instanceNo,createOid=$createOid,updateOid=$updateOid,indexOid=$indexOid,tableOid=$tableOid<br>";
		$createwhere=getLevelWhere($createOid);
		$createsql="select * from $paraConfTable where $createwhere ";
		$createres=@mysqli_query($objConn,$createsql);
		$createnum=@mysqli_num_rows($createres);
		if($createnum == 0)
			exit("Can not find the create index $createOid");
		$createrow=@mysqli_fetch_array($createres);
		$auto=0;
		if(strstr($createrow[setTemplate_2],"create=1"))
			$auto=1;
			
		$minValue=$createrow[minValue]+0;
		$maxValue=$createrow[maxValue]+0;
		echo "<br>";
		echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
		echo "<tr>";
		if($auto)
		{
			echo "<td>Index is assigned by $module_name</td>";
			echo "<td><input DISABLED type=\"text\" class=\"text\" size=\"3\" maxLength=\"3\"></td>";
			echo "</tr>";
			echo "</table>";
			echo "<input id=\"add_id\" type=\"button\" onClick=\"javascript:addObject('$auto','$sysId','$table_id','$table_level','$instanceNo','$createOid','$updateOid','$indexOid','$oldtableOid');\" name=\"add\" value=\"$strAdd\" class=\"button\" style=\"$buttonStyle\">";
		}
		else
		{
			$tmpwhere=getLevelWhere($indexOid);
			if($instanceNo != "0000")
				$sql="select initValue from $paraTable where $tmpwhere and instanceNo like '$instanceNo.%' ";
			else
				$sql="select initValue from $paraTable where $tmpwhere ";
			if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
				$sql.="and subSysNo='$subSysNo' ";
			//echo "$sql<br>";
			$res=@mysqli_query($objConn,$sql);
			while($row=@mysqli_fetch_array($res))
				$index_use_flags[$row[initValue]+0]=1;
			
			echo "<td>Please input the index No.</td>";
			echo "<td>";
			echo "<select name=\"index_select\">";
			for($i=$minValue;$i<=$maxValue;$i++)
			{
				if($index_use_flags[$i] != 1)
				{
					echo "<option value=$i>$i</option>";
					$no_use_count++;
				}
			}
			echo "</select>";
			echo "</td>";
			echo "</tr>";
			echo "</table>";
			
			if($no_use_count == 0)
			{
				echo "<input disabled id=\"add_id\" type=\"submit\" name=\"add\" value=\"$strAdd\" class=\"button\" style=\"$buttonStyle\">";
				echo "<p><table border=\"1\" cellpadding=\"2\" cellspacing=\"0\"  bordercolor=\"#666666\" bordercolordark=\"#cecece\" bgcolor=\"#cecece\">";
				echo "<tr><td>";
				echo "Note: The table is full";
				echo "</td></tr></table>";
			}
			else
			{
				echo "<input id=\"add_id\" type=\"button\" onClick=\"javascript:addObject('$auto','$sysId','$table_id','$table_level','$instanceNo','$createOid','$updateOid','$indexOid','$oldtableOid');\" name=\"add\" value=\"$strAdd\" class=\"button\" style=\"$buttonStyle\">";
			}
		}

		exit();
	}
	echo "<br><br>";
	echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
	for($i=0;$i<$thisTableConf[FieldCount];$i++)
	{
		if($thisTableConf[$i][MaxAccess] == ACCESS_ENTRY)
			continue;
		if($thisTableConf[$i][Name] == "Delete")
			continue;
		if(strstr($thisTableConf[$i][RawName],"CreateEntry"))
			continue;
			
		$tmp=explode(".",$thisTableConf[$i][OID]);
		$ni=$tmp[sizeof($tmp)-1]+0;
		
		echo "<tr>";
		echo "<td onMouseOver=\"javascript:showTipWindow('{$thisTableConf[$i][Tip]}');\" onMouseOut=\"javascript:hideTipWindow();\">";
		echo $thisTableConf[$i][Name];
		echo "</td>";
		if(strstr($thisTableConf[$i][RawName],"Entries"))
		{
			$nextLevel=$table_level+1;
			echo "<td><a href=\"param_show_table.php?table_id=$table_id&sysId=$sysId&table_level=$nextLevel&instanceNo=$instanceNo\">{$recordData[$ni]}</a></td>";
		}
		else if(strstr($thisTableConf[$i][Desc],"RelationPoint"))
		{
			$tmp1=strstr($thisTableConf[$i][Desc],"RelationPoint:");
			$tmp2=explode(";",$tmp1);
			$tmp3=explode("RelationPoint:",$tmp2[0]);
			$rTableOid=$tmp3[1];
			
			$showvalue=$recordData[$ni];
			echo "<td>";
			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($objConn,$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($thisTableConf[$i][MaxAccess] == ACCESS_READ_ONLY)
		{
			$showValue=translateValueToOpt($thisTableConf[$i][Style],$thisTableConf[$i][ValueType],$thisTableConf[$i][Template],$recordData[$ni]);
			echo "<td>{$showValue}</td>";
		}
		else if($thisTableConf[$i][ValueType] == VALUE_OPAQUE)
		{
			echo "<td>";
			if(stristr($thisTableConf[$i][RawName],"NITZ"))
			{
				$mscTable="OBJ_320.param_99";
				$levels=getLevelWhere($thisTableConf[$i][OID]);
				$sql="SELECT * FROM $mscTable WHERE $levels AND instanceNo=$instanceNo";
				$res=mysqli_query($objConn,$sql);
				$rows=@mysqli_fetch_array($res);
				$initValue=$rows[initValue];
				$readValue=$rows[readValue];
				if($initValue == '')
					$initValue="--";
				echo "<a href=# onClick=\"javascript:openNITZ('$sysId','$table_id','$table_level','$instanceNo','{$thisTableConf[$i][OID]}');\" >";
				if(strlen($initValue)>8)
					$showValue=substr($initValue,0,8);
				if($initValue == $readValue)
					echo "<font class=text color=#0000ff>$showValue</font>";		
				else
					echo "<font class=text color=#008000>$showValue</font>";		
				echo "</a>";
			}
			else
			{
				showParameter($sysId,$thisTableConf[$i][OID],$instanceNo);
			}
			echo "</td>";
		}
		else
		{
			echo "<td>";
			showParameterAdv($sysId,$thisTableConf[$i][OID],$instanceNo);
			echo "</td>";
		}
		
		echo "</tr>";
	}
	echo "</table>";
	
	//lock and unlock button
	for($i=0;$i<$thisTableConf[FieldCount];$i++)
	{
		if(strstr($thisTableConf[$i][RawName],"AdministrationState") )
		{
			if($canwrite_flag)
				echo "<input type=\"submit\" name=\"lock\" value=\"$strLock\" class=\"button\" style=\"$buttonStyle\">";
			else
				echo "<input type=\"submit\" name=\"lock\" disabled value=\"$strLock\" class=\"button\" style=\"$buttonStyle\">";
			echo "&nbsp;&nbsp;";
			if($canwrite_flag)
				echo "<input type=\"submit\" name=\"unlock\" value=\"$strUnlock\" class=\"button\" style=\"$buttonStyle\">";	
			else
				echo "<input type=\"submit\" name=\"unlock\" disabled value=\"$strUnlock\" class=\"button\" style=\"$buttonStyle\">";	
			echo "&nbsp;&nbsp;";
			echo "<input type=hidden name=\"adminStatOid\" value=\"{$thisTableConf[$i][OID]}\">";
			break;
		}
	}
	
	
	echo "<input id=\"get_id\" type=\"submit\" name=\"get\" value=\" $strGet \" class=\"button\" style=\"$buttonStyle\">";
	echo "&nbsp;&nbsp;";
	if($canwrite_flag)
		echo "<input id=\"set_id\" type=\"submit\" name=\"set\" value=\" $strSet \" class=\"button\" style=\"$buttonStyle\">";
	else
		echo "<input id=\"set_id\" type=\"submit\" disabled name=\"set\" value=\" $strSet \" class=\"button\" style=\"$buttonStyle\">";
}

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=\"getTableOid\" value=\"{$thisTableConf[0][OID]}\">";

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