<?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;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 addObject(createMethod,sysId,table_id,sub_table_id,table_level,instanceNo,createOid,updateOid,indexOid,oldtableOid)
{
	if(createMethod == 0)
		createIndex=document.getElementById('index_select').value;

	else
		createIndex=1;
	window.location.href="param_edit.php?realcreate=1&createMethod="+createMethod+"&createIndex="+createIndex+"&sysId="+sysId+"&table_id="+table_id+"&sub_table_id="+sub_table_id+"&table_level="+table_level+"&instanceNo="+instanceNo+"&createOid="+createOid+"&updateOid="+updateOid+"&indexOid="+indexOid+"&oldtableOid="+oldtableOid;
}

function openNITZ(sysId,table_id,sub_table_id,table_level,instanceNo,param_oid)
{
	URL="./mscNITZ.php?sysId="+sysId+"&table_id="+table_id+"&sub_table_id="+sub_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 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 isButtonCommand=0;
var bt_oid;
var bt_val;
function buttonOpt()
{
	console.log("12")
	if(isButtonCommand)
	{
		document.myform.button_oid.value=bt_oid;
		document.myform.button_value.value=bt_val;
		return true;
	}
	return true;
}

function controlBatch(createMethod,sysId,table_id,sub_table_id,table_level,instanceNo,createOid,updateOid,indexOid,oldtableOid)
{
	
	var batchNum=document.getElementById('batch_num').value;
	console.log("num="+batchNum);
	//don't realcreate=1
	if(createMethod == 0)
	createIndex=document.getElementById('index_select').value;
	else
		createIndex=1;
	window.location.href="param_edit.php?needBatch=1&batch_num="+batchNum+"&createMethod="+createMethod+"&createIndex="+createIndex+"&sysId="+sysId+"&table_id="+table_id+"&sub_table_id="+sub_table_id+"&table_level="+table_level+"&instanceNo="+instanceNo+"&createOid="+createOid+"&updateOid="+updateOid+"&indexOid="+indexOid+"&oldtableOid="+oldtableOid;
}

</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");	
$userInfo = $_SESSION['userInfo'];
$canwrite_flag=checkWritePrivilege();
//echo "canwrite_flag=$canwrite_flag<br>";
//*****
$url_temp=$_SERVER["REQUEST_URI"];
//echo "This page URL:$url_temp<br>";
if (!isset($batch_num)) $batch_num=$_REQUEST['batch_num'];
if (!isset($needBatch)) $needBatch=$_REQUEST['needBatch'];

if (!isset($create)) $create=$_REQUEST['create'];
if (!isset($sysId)) $sysId=$_REQUEST['sysId'];
if (!isset($table_id)) $table_id=$_REQUEST['table_id'];
if (!isset($sub_table_id)) $sub_table_id=$_REQUEST['sub_table_id'];
if (!isset($instanceNo)) $instanceNo=$_REQUEST['instanceNo'];
if (!isset($createOid)) $createOid=$_REQUEST['createOid'];
if (!isset($updateOid)) $updateOid=$_REQUEST['updateOid'];
if (!isset($oldtableOid)) $oldtableOid=$_REQUEST['oldtableOid'];
if (!isset($table_level)) $table_level=$_REQUEST['table_level'];
if (!isset($createIndex)) $createIndex=$_REQUEST['createIndex'];





//*****
//$url_temp=$_SERVER["REQUEST_URI"];
//echo "This page URL:$url_temp<br>";
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 "<form name=\"myform\" method=\"POST\" action=\"$PHP_SELF\" onsubmit=\"return buttonOpt();\">";
echo "<input type=\"hidden\" name=\"button_oid\" value=\"0\">";
echo "<input type=\"hidden\" name=\"button_value\" value=\"0\">";

$realcreate = $_REQUEST['realcreate'];
$createMethod = $_REQUEST['createMethod'];
$createIndex = $_REQUEST['createIndex'];
$objDbConn = mysqli_connect($OMC_server[0]['host'],$OMC_server[0]['user'],$OMC_server[0]['password'],$objDb);	
$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";

$tabConf=GetTabConf($sysTypeNo);
$tableOid=$tabConf[$table_id][OID];
$subTabConf=GetSubTabConf($sysTypeNo,$tableOid);
$singleTabConf=$subTabConf[ColumnTable][$sub_table_id];
$singleTabInfo=GetSingleTableInfo($singleTabConf,$sysTypeNo);

$sql="select sysTypeName from OMC_PUB.sysConf where sysTypeNo='$sysTypeNo' ";
$res=@mysqli_query($pubConn,$sql);
$row=@mysqli_fetch_array($res);
 //print_r($row);
$module_name=$row[sysTypeName];
if(0)
{
	echo "<pre>";
	print_r($singleTabInfo);
	echo "</pre>";
}

//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);

$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((($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}','0000','1','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}','0000','1','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}','0000','1','{$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}','0000','1','{$i}');\">";
			echo "&nbsp;{$subTabConf[ColumnTable][$i][ShowName]}&nbsp;";
			echo "</span>";
		}
	}
	echo "<br>";
}

//************************* Operation *******************************
if($_SERVER['REQUEST_METHOD'] == "POST")

{
	echo "<br>";
	$DEBUG = 0;
	$get = $_REQUEST['get'];
	$set = $_REQUEST['set'];
	$lock = $_REQUEST['lock'];
	$unlock = $_REQUEST['unlock'];
	$podUpdateToPod = $_REQUEST['podUpdateToPod'];
	if($_REQUEST['get'])
	{
		//Get the timeslot parameter from the plat(trunk group id)
		$timeslot_table_oid=GetOIDByName(SYSTYPENO_MSC,"channelEntry");
		if($sysTypeNo == SYSTYPENO_MSC && $singleTabInfo[TableEntryOID] == $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,$singleTabInfo[TableEntryOID],-1,$instanceNo);
			checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&sub_table_id=$sub_table_id&table_level=$table_level&instanceNo=$instanceNo");
		}
		else
		{
			$commIdStr=oidSysCommSend($sysId,0,$singleTabInfo[TableEntryOID],-1,$instanceNo);
			checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&sub_table_id=$sub_table_id&table_level=$table_level&instanceNo=$instanceNo");
		}
	}
	else if($_REQUEST['set'])
	{
		$commIdStr=oidSysCommSend($sysId,3,$singleTabInfo[TableEntryOID],-1,$instanceNo);	
		checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&sub_table_id=$sub_table_id&table_level=$table_level&instanceNo=$instanceNo&need_get_again=1&get=1&getTableOid=$getTableOid");
	}
	else if($_REQUEST['lock'] || $_REQUEST['unlock'])
	{
		$adminStatOid = $_REQUEST['adminStatOid'];
		//echo $adminStatOid;
		$tmpWhere=getLevelWhere($adminStatOid);
		if($_REQUEST['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($objDbConn,$updateSql);
		//echo "oidSysCommSend($sysId,3,$adminStatOid,-1,$instanceNo)";
		$commIdStr=oidSysCommSend($sysId,3,$adminStatOid,-1,$instanceNo);

		checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&sub_table_id=$sub_table_id&table_level=$table_level&instanceNo=$instanceNo");
	}
	else if($_REQUEST['podUpdateToPod'])
        {
                $tmpWhere=getLevelWhere($podUpdateToPodOid);
                //if($lock)
                        $initValue=1;
                //else
                  //      $initValue=1;

                $updateSql="UPDATE $paraTable SET initValue=$initValue WHERE $tmpWhere AND instanceNo='{$instanceNo}' ";

                if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
                        $updateSql.="and subSysNo='$subSysNo' ";

                mysqli_query($objDbConn,$updateSql);
                $commIdStr=oidSysCommSend($sysId,3,$podUpdateToPodOid,-1,$instanceNo);
                checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&sub_table_id=$sub_table_id&table_level=$table_level&instanceNo=$instanceNo");
        }
	else if($_REQUEST['buttonOptFlag'])
	{
		//echo "button_oid=$button_oid,button_value=$button_value<br>";
		$tmpWhere=getLevelWhere($button_oid);
		$initValue=$button_value;
		$updateSql="UPDATE $paraTable SET initValue=$initValue WHERE $tmpWhere AND instanceNo='{$instanceNo}' ";		
		
		if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
			$updateSql.="and subSysNo='$subSysNo' ";
		
		mysqli_query($objDbConn,$updateSql);
		$commIdStr=oidSysCommSend($sysId,3,$button_oid,-1,$instanceNo);
		checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&sub_table_id=$sub_table_id&table_level=$table_level&instanceNo=$instanceNo");
	}
}

//Oper batch add
if($needBatch){
	echo "<form id='redirectForm' action='param_show_table.php' method='post'>";
	echo "<input type='hidden' name='sysId' value='$sysId'>";
	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='table_level' value='$table_level'>";
	echo "<input type='hidden' name='instanceNo' value='$oldInstanceNo'>";
	echo "<input type='hidden' name='get' value='Get'>";
	echo "</form>";

	$oldInstanceNo=$instanceNo;
	for($k=0;$k<$batch_num;$k++)
	{

		usleep(200000);  // 0.2 sec
		if($singleTabInfo[TableLevel] == 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',readValue='',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($objDbConn,$sql);
		mysqli_error($objDbConn);
		//send create command
		$commIdStr=oidSysCommSend($sysId,9,$createOid,-1,$createInstanceNo);
	
		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($objDbConn,$indexSql);
			$indexrow=@mysqli_fetch_array($indexres);
			$newIndex=$indexrow[readValue]+0;
			
			$newInstanceNo=omc_keep_length($newIndex,'0',4);
			if($singleTabInfo[TableLevel] == 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);
		}
		
		//get the table
		if($oldInstanceNo=="0000" && $singleTabInfo[TableLevel] == 1)
		{
			$commIdStr=oidSysCommSend($sysId,5,$oldtableOid,-1,"");

		}
		else{
			$commIdStr=oidSysCommSend($sysId,5,$oldtableOid,-1,$oldInstanceNo);

		}
		}
		//send table Get Button
		echo "<form id='redirectForm' action='param_show_table.php' method='post'>";
		echo "<input type='hidden' name='sysId' value='$sysId'>";
		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='table_level' value='$table_level'>";
		echo "<input type='hidden' name='instanceNo' value='$oldInstanceNo'>";
		echo "<input type='hidden' name='get' value='Get'>";
		echo "</form>";
		?>
		<script type="text/javascript">
		document.getElementById('redirectForm').submit();		
		</script>
	<?php
	}


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($singleTabInfo[TableLevel] == 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',readValue='',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($objDbConn,$sql);
	mysqli_error($objDbConn);
	//send create command
	$commIdStr=oidSysCommSend($sysId,9,$createOid,-1,$createInstanceNo);
	checkState($commIdStr,"./param_edit.php?sysId=$sysId&table_id=$table_id&sub_table_id=$sub_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($objDbConn,$indexSql);
		$indexrow=@mysqli_fetch_array($indexres);
		$newIndex=$indexrow[readValue]+0;
		
		$newInstanceNo=omc_keep_length($newIndex,'0',4);
		if($singleTabInfo[TableLevel] == 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&sub_table_id=$sub_table_id&table_level=$table_level&instanceNo=$oldInstanceNo&create=1&createOid=$createOid&updateOid=$updateOid&indexOid=$indexOid&oldtableOid=$oldtableOid");
	}
	
	//get the table
	if($oldInstanceNo=="0000" && $singleTabInfo[TableLevel] == 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&sub_table_id=$sub_table_id&table_level=$table_level&instanceNo=$oldInstanceNo&create=1&createOid=$createOid&updateOid=$updateOid&indexOid=$indexOid&oldtableOid=$oldtableOid");
	
}

//PPS COS table
if($sysTypeNo == SYSTYPENO_PPS && $table_id == 1 && $realcreate == 1)
{
	echo "\n<script language=\"JavaScript\">\n";
	echo "window.location.href=\"./param_show_table.php?table_id=1&sysId=$sysId&instanceNo=0000&table_level=1\";\n";
	echo "</script>\n";
}

echo "<br>";
if($create)
	showNavigateTitle($table_id,$sub_table_id,$table_level,$sysId,$columnTable,$instanceNo,"create");
else
	showNavigateTitle($table_id,$sub_table_id,$table_level,$sysId,$columnTable,$instanceNo,"edit");
echo "<br>";
if(!$create || $_SERVER['REQUEST_METHOD'] == "POST")
	echo "<br>";
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($objDbConn,$createsql);
	$createnum=@mysqli_num_rows($createres);
	//echo "sql=$createsql";
	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)
	{
		//MSC-tg-trunk
		if($createOid=='2.4.1.1.34'){
			echo "<td>Batch Num:</td>";
			echo "<td><input  id=\"batch_num\" type=\"text\" class=\"text\" size=\"3\" maxLength=\"3\"></td>";
			echo "</tr>";
			echo "</table>";
			echo "<input id=\"add_id\" type=\"button\" onClick=\"javascript:controlBatch('$auto','$sysId','$table_id','$sub_table_id','$table_level','$instanceNo','$createOid','$updateOid','$indexOid','$oldtableOid');\" name=\"add\" value=\"Batch Add\" class=\"button\" style=\"$buttonStyle\">&nbsp&nbsp;";

		}else{
			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','$sub_table_id','$table_level','$instanceNo','$createOid','$updateOid','$indexOid','$oldtableOid');\" name=\"add\" value=\"$strAdd\" class=\"button\" style=\"$buttonStyle\">&nbsp&nbsp;";
		}

	}
	else
	{
		//echo "tmpwhere=$indexOid";
		$tmpwhere=getLevelWhere($_REQUEST['indexOid']);
		
		//echo "instanceNo=$instanceNo";
		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($objDbConn,$sql);
		// $test=@mysqli_fetch_array($res);
		// echo $test;
		// print_r($test);
		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\" id=\"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','$sub_table_id','$table_level','$instanceNo','$createOid','$updateOid','$indexOid','$oldtableOid');\" name=\"add\" value=\"$strAdd\" class=\"button\" style=\"$buttonStyle\">";
		}
	}

	exit();
}



//************************** Show ***********************************
	
//show the edit table
echo "<table border=\"1\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\" bgcolor=\"#FFFFFF\">";
for($i=0;$i<$singleTabInfo[ColumnParamCount];$i++)
{
	if($singleTabInfo[ColumnParam][$i][MaxAccess] == ACCESS_ENTRY)
		continue;
	if(strstr($singleTabInfo[ColumnParam][$i][RawName],"RowStatus"))
		continue;
	if(strstr($singleTabInfo[ColumnParam][$i][RawName],"CreateEntry"))
		continue;
	if(strstr($singleTabInfo[ColumnParam][$i][RawName],"Command"))
		continue;

	echo "<tr>";
	echo "<td onMouseOver=\"javascript:showTipWindow('{$singleTabInfo[ColumnParam][$i][Tip]}');\" onMouseOut=\"javascript:hideTipWindow();\">";
	echo "{$singleTabInfo[ColumnParam][$i][ShowName]}";
	echo "</td>";
	echo "<td>";
	if($singleTabInfo[ColumnParam][$i][ValueType] == VALUE_OPAQUE)
	{
		if(stristr($singleTabInfo[ColumnParam][$i][RawName],"NITZ"))
		{
			$mscTable="OBJ_320.param_99";
			$levels=getLevelWhere($singleTabInfo[ColumnParam][$i][OID]);
			$sql="SELECT * FROM $mscTable WHERE $levels AND instanceNo=$instanceNo";
			$res=mysqli_query($objDbConn,$sql);
			$rows=@mysqli_fetch_array($res);
			$initValue=$rows[initValue];
			$readValue=$rows[readValue];
			if($initValue == '')
				$initValue="--";
			echo "<a href=# onClick=\"javascript:openNITZ('$sysId','$table_id','$sub_table_id','$table_level','$instanceNo','{$singleTabInfo[ColumnParam][$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,$singleTabInfo[ColumnParam][$i][OID],$instanceNo);
		}
	}
	else if(strstr($singleTabInfo[ColumnParam][$i][Description],"RelationPoint"))
	{
		$tmp1=strstr($singleTabInfo[ColumnParam][$i][Description],"RelationPoint:");
		$tmp2=explode(";",$tmp1);
		$tmp3=explode("RelationPoint:",$tmp2[0]);
		$rTableOid=$tmp3[1];
			
		$showvalue=getParamValue($sysId,$singleTabInfo[ColumnParam][$i][OID],$instanceNo);
		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);
			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>";
			}
		}
	}
	else if($singleTabInfo[ColumnParam][$i][EntriesFlag] == 1)
	{
		$nextLevel=$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;
		$value=getParamValue($sysId,$singleTabInfo[ColumnParam][$i][OID],$instanceNo);
		echo "<a href=\"param_show_table.php?table_id=$table_id&sub_table_id=$new_sub_table_id&sysId=$sysId&table_level=$nextLevel&instanceNo=$instanceNo\">{$value}</a>";
	}
	else
	{
		showParameterAdv($sysId,$singleTabInfo[ColumnParam][$i][OID],$instanceNo);
	}
	echo "</td>";
}
echo "</table>";

//lock and unlock button
for($i=0;$i<$singleTabInfo[ColumnParamCount];$i++)
{
	if(strstr($singleTabInfo[ColumnParam][$i][RawName],"AdministrationState"))
	{
	//	echo "i'm administrationstate";
		if($canwrite_flag)
			echo "<input type=\"submit\" name=\"lock\" value=\"$strLock\" class=\"button\" style=\"$buttonStyle\">";
		else
			echo "<input type=\"submit\" disabled name=\"lock\" 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\" disabled name=\"unlock\" value=\"$strUnlock\" class=\"button\" style=\"$buttonStyle\">";	
		echo "&nbsp;&nbsp;";
		echo "<input type=hidden name=\"adminStatOid\" value=\"{$singleTabInfo[ColumnParam][$i][OID]}\">";
		break;
	}
	if(strstr($singleTabInfo[ColumnParam][$i][RawName],"podUpdateToPod"))
	{
		echo "<input type=\"submit\" name=\"podUpdateToPod\" value=\"Update to Pod\" class=\"button\" style=\"$buttonStyle\">";
		echo "&nbsp;&nbsp;";
		echo "<input type=hidden name=\"podUpdateToPodOid\" value=\"{$singleTabInfo[ColumnParam][$i][OID]}\">";
		break;
	}
}

//other command button button
for($i=0;$i<$singleTabInfo[ButtonCount];$i++)
{
	$showName=$singleTabInfo[Button][$i][ShowName];
	$value=$singleTabInfo[Button][$i][Value];
	$oid=$singleTabInfo[Button][$i][OID];
	//echo "<br>ShowName=$showName,$value,$oid<br>";
	echo "<input type=\"submit\" name=\"buttonOptFlag\" value=\" $showName \" class=\"button\" style=\"$buttonStyle\" onClick=\"isButtonCommand=1;bt_oid='{$oid}';bt_val={$value};\">&nbsp;&nbsp;";
}

//get button
echo "<input id=\"get_id\" type=\"submit\" name=\"get\" value=\" $strGet \" class=\"button\" style=\"$buttonStyle\">";
echo "&nbsp;&nbsp;";


//set button
if($singleTabInfo[ColumnParamSetCount] > 0)
{
	if($canwrite_flag)
		echo "<input id=\"set_id\" type=\"submit\" name=\"set\" value=\" $strSet \" class=\"button\" style=\"$buttonStyle\">";
	else
		echo "<input id=\"set_id\" disabled type=\"submit\" name=\"set\" value=\" $strSet \" class=\"button\" style=\"$buttonStyle\">";
}

echo "<input type=\"hidden\" name=\"sysId\" value=\"$sysId\">";
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=\"table_level\" value=\"$table_level\">";
echo "<input type=\"hidden\" name=\"instanceNo\" value=\"$instanceNo\">";

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