<script language="Javascript">
function MouseOverColor(obj)
{
	obj.bgColor="#ddddff";
}

function MouseOutColor(obj)
{
	obj.bgColor="white";
}


function correctPNG()  
{ 
	for(var i=0; i<document.images.length; i++) 
	{ 
	  var img = document.images[i] 
	  var imgName = img.src.toUpperCase() 
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 
	  { 
	   var imgID = (img.id) ? "id='" + img.id + "' " : "" 
	   var imgClass = (img.className) ? "class='" + img.className + "' " : "" 
	   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " 
	   var imgStyle = "display:inline-block;" + img.style.CSSText  
	   if (img.align == "left") imgStyle = "float:left;" + imgStyle 
	   if (img.align == "right") imgStyle = "float:right;" + imgStyle 
	   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle   
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle 
	   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
	  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
	   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"  
	   img.outerHTML = strNewHTML 
	   i = i-1 
	  } 
	} 
} 
window.attachEvent("onload", correctPNG); 

</script>
<?php

$PARAM_OID_PREFIX="2";
define(MAX_SHOW_ROW_NUM,4);

define(UNKNOWN_TYPE,-1);
define(LEAF_TYPE,0);
define(SCALAR_TABLE_TYPE,1);
define(COLUMN_TABLE_TYPE,2);
define(ENTRY_TYPE,3);

$type_label=array(-1=>"unknown",0=>"LEAF_TYPE",1=>"SCALAR_TABLE_TYPE",2=>"COLUMN_TABLE_TYPE",3=>"ENTRY_TYPE");

//access
define(ACCESS_TABLE_NAME,0);
define(ACCESS_ENTRY,21);
define(ACCESS_READ_WRITE,19);
define(ACCESS_READ_ONLY,18);
define(ACCESS_INDEX_CREATE_SPE,48);

//value type
define(VALUE_NONE,0);
define(VALUE_STRING,2);
define(VALUE_INT,3);
define(VALUE_IP,5);
define(VALUE_TIMESTAMP,8);
define(VALUE_OPAQUE,9);

//style
define(SHOW_HIDE,0);
define(SHOW_SELECT,1);
define(SHOW_TEXTBOX,2);
define(SHOW_LABEL,3);

//create method
define(MANUAL_CREATE,0);
define(AUTO_CREATE,1);

//nest table element
define(TABLE_ENTRY,0);
define(TABLE_ENTRIES,1);
define(TABLE_CREATE,2);

//sysTypeNo
define(SYSTYPENO_MSC,320);
define(SYSTYPENO_SMSC,350);
define(SYSTYPENO_SMPP,260);
define(SYSTYPENO_OPPS,375);
define(SYSTYPENO_PPS,360);
define(SYSTYPENO_MTP3,222);
define(SYSTYPENO_SCCP,223);
define(SYSTYPENO_AAS,311);
define(SYSTYPENO_VSS,390);
define(SYSTYPENO_VLR,325);
define(SYSTYPENO_HLR,330);
define(SYSTYPENO_AUC,340);
define(SYSTYPENO_SMEG,355);
define(SYSTYPENO_EIR,380);
define(SYSTYPENO_MRFC,385);
define(SYSTYPENO_PALIM,378);
define(SYSTYPENO_RLS,379);
define(SYSTYPENO_MHC,386);
define(SYSTYPENO_MNP,370);
define(SYSTYPENO_MTP3,222);
define(SYSTYPENO_XAPP,225);

function showParamInReadOnly($keyId,$sysId)
{
	global $objects;
	
	
	$sysIdArr=explode('_',$sysId);
	$sysTypeNo=$sysIdArr[0];
	$sysNo=$sysIdArr[1];
	$subSysNo=$sysIdArr[2];
	$objDb='OBJ_'.$sysTypeNo;
	$paraConfTable=$objDb.'.paramConf';
	if(checkIndependSystem($sysTypeNo))//Plat
		$paraTable=$objDb.".param_".$sysNo;
	else
		$paraTable=$objDb.".param_99";
	
	$oid=$objects[$keyId]['oid'];
	$oidwhere=getLevelWhere($oid);
	$sql="select initValue from $paraTable where $oidwhere and instanceNo='0000' ";
	
	if(checkPlatWhoHaveSubSysNo($sysTypeNo,$sysNo))
		$sql.="and subSysNo='$subSysNo' ";
	
	$res=@mysqli_query($pubConn,$sql);
	$num=@mysqli_num_rows($res);
	if($num != 0)
	{
		$row=@mysqli_fetch_array($res);
		$returnvalue=$row[initValue];
		if(($objects[$keyId]["style"] == SHOW_LABEL || $objects[$keyId]["style"] == SHOW_SELECT )&& $objects[$keyId]["valueType"] == VALUE_INT)
		{
			if(trim($objects[$keyId]["setTemplate_1"]) == "")
				return $returnvalue;
			$options=explode(";",$objects[$keyId]["setTemplate_1"]);
			for($ii=0;$ii<sizeof($options);$ii++)
			{
				$tmp=explode("=",$options[$ii]);
				$val=$tmp[0];
				$opt=$tmp[1];
				if($returnvalue == $opt)
					return $val;
			}
		}
	}
	else
	{
		$returnvalue="--";
	}
	
	//discard the postfix E of the opaque
	if($objects[$keyId]["valueType"] == 9)
	{
		$split=explode("[unit]",$objects[$keyId]["setTemplate_1"]);
		$len=sizeof($split);
		//only one unit
		//if($len == 2)
		{
			$split2=explode("keepHex-low-",$objects[$keyId]["setTemplate_1"]);
			$repl=substr($split2[1],0,1);
			$returnvalue=str_replace($repl," ",$returnvalue);
		}
	}
	
	if(trim($returnvalue) == "")
		$returnvalue="--";
	return $returnvalue;
}

function getLevel($objIdStr)
{
	$levelArr=explode('.',$objIdStr);
	for($j=0;$j<sizeof($levelArr);$j++){
		$levelNo=$j+1;
		${"level_$levelNo"}=$levelArr[$j];
		if($Debug) echo "<BR>levelArr[$j]={$levelArr[$j]}";
		if($j == 0){
			$levelWhere ="level_$levelNo='${"level_$levelNo"}'";
		}else{
			$levelWhere .=" AND level_$levelNo='${"level_$levelNo"}'";
		}
	}
	$levelNo+=2;
	if($levelNo<=10)
		$levelWhere.=" AND level_$levelNo=0 ";
	return($levelWhere);
}

function getParamValue($sysId,$oid,$instanceNo)
{
	$sysIdArr=explode('_',$sysId);
	$sysTypeNo=$sysIdArr[0];
	$sysNo=$sysIdArr[1];
	$subSysNo=$sysIdArr[2];
	$objDb='OBJ_'.$sysTypeNo;
	$paraConfTable=$objDb.'.paramConf';
	
	
	
	if(checkIndependSystem($sysTypeNo))//Plat
		$paraTable=$objDb.".param_".$sysNo;
	else
		$paraTable=$objDb.".param_99";
	$oidWhere=getLevelWhere($oid);	
		
	if(strstr($instanceNo,"."))
		$sql="select initValue from $paraTable where $oidWhere and instanceNo='$instanceNo' ";
	else
		$sql="select initValue from $paraTable where $oidWhere and instanceNo=$instanceNo ";

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


	$res=@mysqli_query($pubConn,$sql);
	$num=mysqli_num_rows($res);
	if($num == 0)
		return "--";
		
	$row=@mysqli_fetch_array($res);
	$originalValue=$row[initValue];
	
	return $originalValue;
}

function adjustTableName($name)
{
	$len=strlen($name);
	$result="";
	
	if($name[0]>='a' && $name[0]<='z')
		$result.=chr(ord($name[0])-32);	
	for($i=1;$i<$len;$i++)
	{	
		if($i != 1)
			if($name[$i]>='A' && $name[$i]<='Z' && $name[$i-1]>='a' && $name[$i-1]<='z')
				$result.=" ";
			
		if($name[$i]>='A' && $name[$i]<='Z' && $name[$i+1]>='a' && $name[$i+1]<='z' && $name[$i-1]>='A' && $name[$i-1]<='Z')
			$result.=" ";
				
		$result.=$name[$i];	
		
		if(($name[$i]<'0' || $name[$i]>'9')&& ($name[$i+1]>='0' && $name[$i+1]<='9'))
			$result.=" ";
		if(($name[$i]>='0' && $name[$i]<='9')&& ($name[$i+1]<'0' || $name[$i+1]>'9'))
			$result.=" ";
	}
	
	$result=str_replace("Table","",$result);
	$result=str_replace("Entry","",$result);
	
	return $result;
}

function getShowNameOfTable($name,$keyId)
{
	global $objects;
	
	if($keyId != -1 && strstr($objects[$keyId]['desc_1'],"Name:"))
	{
		$new_name=explode("Name:",$objects[$keyId]['desc_1']);
		return str_replace(";","",$new_name[sizeof($new_name)-1]);
	}
	
	$len=strlen($name);
	$result="";
	
	if($name[0]>='a' && $name[0]<='z')
		$result.=chr(ord($name[0])-32);	
	for($i=1;$i<$len;$i++)
	{	
		if($i != 1)
			if($name[$i]>='A' && $name[$i]<='Z' && $name[$i-1]>='a' && $name[$i-1]<='z')
				$result.=" ";
			
		if($name[$i]>='A' && $name[$i]<='Z' && $name[$i+1]>='a' && $name[$i+1]<='z' && $name[$i-1]>='A' && $name[$i-1]<='Z')
			$result.=" ";
				
		$result.=$name[$i];	
		
		if(($name[$i]<'0' || $name[$i]>'9')&& ($name[$i+1]>='0' && $name[$i+1]<='9'))
			$result.=" ";
		if(($name[$i]>='0' && $name[$i]<='9')&& ($name[$i+1]<'0' || $name[$i+1]>'9'))
			$result.=" ";
	}
	
	$result=str_replace("Table","",$result);
	$result=str_replace("Entry","",$result);
	
	return $result;
}

function getShowNameOfField($name,$keyId)
{
	global $objects;
	
	if($keyId != -1 && strstr($objects[$keyId]['desc_1'],"Name:"))
	{
		$new_name=explode("Name:",$objects[$keyId]['desc_1']);
		return str_replace(";","",$new_name[sizeof($new_name)-1]);
	}
	
	$len=strlen($name);
	$result="";
	
	for($j=0;$j<$len;$j++)
	{
		if($name[$j]>='A' && $name[$j]<='Z')
			break;
	}
	for($i=$j;$i<$len;$i++)
	{
		if($name[$i]>='A' && $name[$i]<='Z' && $name[$i-1]>='a' && $name[$i-1]<='z')
			$result.=" ";
			
		if($name[$i]>='A' && $name[$i]<='Z' && $name[$i+1]>='a' && $name[$i+1]<='z' && $name[$i-1]>='A' && $name[$i-1]<='Z')
			$result.=" ";
				
		$result.=$name[$i];	
		
		if(($name[$i]<'0' || $name[$i]>'9')&& ($name[$i+1]>='0' && $name[$i+1]<='9'))
			$result.=" ";
		if(($name[$i]>='0' && $name[$i]<='9')&& ($name[$i+1]<'0' || $name[$i+1]>'9'))
			$result.=" ";
	}
	
	return $result;
}

function translateValueToOpt($operType,$valueType,$template,$value)
{
	
	if(($operType == SHOW_LABEL || $operType == SHOW_SELECT) && $valueType == VALUE_INT)
	{
		if(trim($template) == "")
				return $value;
			$options=explode(";",$template);
			for($ii=0;$ii<sizeof($options);$ii++)
			{
				$tmp=explode("=",$options[$ii]);
				$val=$tmp[0];
				$opt=$tmp[1];
				if($value == $opt)
					return $val;
			}
	}
	return $value;
}

function getOIDByRow($row)
{
	$oid="";
	for($i=1;$i<=10;$i++)
	{
		$level="level_".$i;
		if($row[$level] == 0)
		{
			break;
		}
		else
		{
			$oid.=$row[$level].".";
		}
	}
	$oid=substr($oid,0,strlen($oid)-1);
	return $oid;
}

function getTableNameByOid($sysId,$oid)
{
	$sysIdArr=explode('_',$sysId);
	$sysTypeNo=$sysIdArr[0];
	$sysNo=$sysIdArr[1];
	$subSysNo=$sysIdArr[2];
	$objDb='OBJ_'.$sysTypeNo;
	$paraConfTable=$objDb.'.paramConf';
	
	$oidWhere=getLevelWhere($oid);
	$sql="select name_1 from $paraConfTable where $oidWhere ";
	$res=@mysqli_query($pubConn,$sql);
	$num=mysqli_num_rows($res);
	if($num == 0)
		return "--";
	
	$row=@mysqli_fetch_array($res);
	return $row[name_1];
}

function checkTableNest($sysId,$table_oid)
{
	$sysIdArr=explode('_',$sysId);
	$sysTypeNo=$sysIdArr[0];
	$sysNo=$sysIdArr[1];
	$subSysNo=$sysIdArr[2];
	$objDb='OBJ_'.$sysTypeNo;
	$paraConfTable=$objDb.'.paramConf';
	
	$tmpwhere=getLevelWhere($table_oid);
	
	$sql="select * from $paraConfTable where $tmpwhere and name_1 like '%CreateEntry%' ";
	//echo "$sql<hr>";
	$res=@mysqli_query($pubConn,$sql);
	$num=mysqli_num_rows($res);
	if($num > 0)
		return 1;
	else
		return 0;
}

/*
	tableName: the name of the table, rountingSelection for example. case-ignored
	$type: TABLE_ENTRY, TABLE_ENTRIES, TABLE_CREATE
*/
function findRelationOid($tableName,$type,$sysTypeNo)
{
	$tableName=strtolower($tableName);
	$dbtable="OBJ_".$sysTypeNo.".paramConf";
	if($type == TABLE_ENTRY)
		$likestr=$tableName."Entry";
	else if($type == TABLE_ENTRIES)
		$likestr=$tableName."Entries";
	else if($type == TABLE_CREATE)
		$likestr="CreateEntry".$tableName;
		
	$sql="select * from $dbtable where name_1 like '%$likestr%' ";
	//echo "<br>$sql<br>";
	$res=@mysqli_query($pubConn,$sql);
	$num=mysqli_num_rows($res);
	if($num == 0)
		return "";
	$row=@mysqli_fetch_array($res);
	$findOid="";
	for($i=1;$i<=10;$i++)
	{
		if($row["level_".$i] == '0')
			break;
		$findOid.=$row["level_".$i].".";
	}
	$findOid=substr($findOid,0,strlen($findOid)-1);
	//PrintInfo("tableName=$tableName,dbtable=$dbtable,oid=$findOid");
	return $findOid;
}

function getTableLevel($tableOid,$sysTypeNo)
{
	$tableWhere=getLevelWhere($tableOid);
	$database="OBJ_".$sysTypeNo.".paramConf";
	$sql="select desc_1 from $database where $tableWhere ";
	$res=@mysqli_query($pubConn,$sql);
	$row=@mysqli_fetch_array($res);
	$desc_1=$row[desc_1];
	$tmp=explode("level:",$desc_1);
	$level=$tmp[1]+0;
	return $level;
}

function showNavigateTitle($table_id,$table_level,$sysId,$columnTable,$instanceNo,$type)
{
	if(0)
	{
		echo "<pre>";
		print_r($columnTable);
		echo "</pre>";
	}
	
	if($type == "show")
	{
		if($table_level == 1)
		{
			echo "<b>{$columnTable[0][Name]}</b>";
		}
		if($table_level == 2)
		{
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo=0000\">";
			echo "{$columnTable[0][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			echo "<b><a href=\"param_edit.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo=$instanceNo\">";
			echo ($instanceNo+0);
			echo "</a></b>";
			
			echo "&nbsp;>&nbsp;";
			echo "<b>{$columnTable[1][Name]}</b>";
		}
		else if($table_level == 3)
		{
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo=0000\">";
			echo "{$columnTable[0][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			$tmp=explode(".",$instanceNo);
			echo "<b><a href=\"param_edit.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo={$tmp[0]}\">";
			echo ($tmp[0]+0);
			echo "</a></b>";
			
			echo "&nbsp;>&nbsp;";
			
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=2&instanceNo={$tmp[0]}\">";
			echo "{$columnTable[1][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			echo "<b><a href=\"param_edit.php?sysId=$sysId&table_id=$table_id&table_level=2&instanceNo={$instanceNo}\">";
			echo ($tmp[1]+0);
			echo "</a></b>";
			
			echo "&nbsp;>&nbsp;";
			
			echo "<b>";
			echo "{$columnTable[2][Name]}";
			echo "</b>";
		}
	}
	else if($type == "edit")
	{
		if($table_level == 1)
		{
			echo "<b><a href=\"param_show_table.php?table_id=$table_id&sysId=$sysId&table_level=1&instanceNo=0000\">";
			echo "{$columnTable[0][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			echo "<b>";
			echo ($instanceNo+0);
			echo "</b>";
		}
		if($table_level == 2)
		{
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo=0000\">";
			echo "{$columnTable[0][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			$tmp=explode(".",$instanceNo);
			echo "<b><a href=\"param_edit.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo={$tmp[0]}\">";
			echo ($tmp[0]+0);
			echo "</a></b>";
			
			echo "&nbsp;>&nbsp;";
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=2&instanceNo={$tmp[0]}\">";
			echo "{$columnTable[1][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			echo "<b>";
			echo ($tmp[1]+0);
			echo "</b>";
		}
		else if($table_level == 3)
		{
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo=0000\">";
			echo "{$columnTable[0][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			$tmp=explode(".",$instanceNo);
			echo "<b><a href=\"param_edit.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo={$tmp[0]}\">";
			echo ($tmp[0]+0);
			echo "</a></b>";
			
			echo "&nbsp;>&nbsp;";
			
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=2&instanceNo={$tmp[0]}\">";
			echo "{$columnTable[1][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			echo "<b><a href=\"param_edit.php?sysId=$sysId&table_id=$table_id&table_level=2&instanceNo={$tmp[0]}.{$tmp[1]}\">";
			echo ($tmp[1]+0);
			echo "</a></b>";
			
			echo "&nbsp;>&nbsp;";
			
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=3&instanceNo={$tmp[0]}.{$tmp[1]}\">";
			echo "{$columnTable[2][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			echo "<b>";
			echo ($tmp[2]+0);
			echo "</b>";
		}
	}
	else
	{
		if($table_level == 1)
		{
			echo "<b><a href=\"param_show_table.php?table_id=$table_id&sysId=$sysId&table_level=1&instanceNo=0000\">";
			echo "{$columnTable[0][Name]}";
			echo "</a></b>";
			
		}
		if($table_level == 2)
		{
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo=0000\">";
			echo "{$columnTable[0][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			$tmp=explode(".",$instanceNo);
			echo "<b><a href=\"param_edit.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo={$tmp[0]}\">";
			echo ($tmp[0]+0);
			echo "</a></b>";
			
			echo "&nbsp;>&nbsp;";
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=2&instanceNo={$tmp[0]}\">";
			echo "{$columnTable[1][Name]}";
			echo "</a></b>";
		}
		else if($table_level == 3)
		{
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo=0000\">";
			echo "{$columnTable[0][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			$tmp=explode(".",$instanceNo);
			echo "<b><a href=\"param_edit.php?sysId=$sysId&table_id=$table_id&table_level=1&instanceNo={$tmp[0]}\">";
			echo ($tmp[0]+0);
			echo "</a></b>";
			
			echo "&nbsp;>&nbsp;";
			
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=2&instanceNo={$tmp[0]}\">";
			echo "{$columnTable[1][Name]}";
			echo "</a></b>";
			
			echo "&nbsp;";
			
			echo "<b><a href=\"param_edit.php?sysId=$sysId&table_id=$table_id&table_level=2&instanceNo={$tmp[0]}.{$tmp[1]}\">";
			echo ($tmp[1]+0);
			echo "</a></b>";
			
			echo "&nbsp;>&nbsp;";
			
			echo "<b><a href=\"param_show_table.php?sysId=$sysId&table_id=$table_id&table_level=3&instanceNo={$tmp[0]}.{$tmp[1]}\">";
			echo "{$columnTable[2][Name]}";
			echo "</a></b>";
		}
	}
}

function GetOIDByName($sysTypeNo,$name)
{
	$database="OBJ_".$sysTypeNo.".paramConf";
	$sql="select * from $database where name_2 like '%$name%' ";
	$res=@mysqli_query($pubConn,$sql);
	$row=@mysqli_fetch_array($res);
	$oids="";
	for($i=1;$i<=10;$i++)
	{
		$tmpN="level_".$i;
		$tmpV=$row[$tmpN]+0;
		if($tmpV == 0)
			break;
			
		$oids.=$tmpV.".";
		
	}
	if($i>1)
		$oids=substr($oids,0,strlen($oids)-1);
	
	return $oids;
}

/*
	This function is for the special issue of getting msc timeslot
	Get the timeslot parameter from plat which the Group ID specify in trunk
*/
function GetTrunkGroupID($tgno,$trunkno)
{
	$trunk_table_oid=GetOIDByName(SYSTYPENO_MSC,"trunkEntry");
	
	$tgno_w=omc_keep_length($tgno,"0",4);
	$trunkno_w=omc_keep_length($trunkno,"0",4);
	$instance=$tgno_w.".".$trunkno_w;
	
	oidSysCommSend("320_99_99", 0, $trunk_table_oid, -1, $instance);
	
	$trunkGroupID_oid=GetOIDByName(SYSTYPENO_MSC,"trunkGroupID");
	$oidWhere=getLevelWhere($trunkGroupID_oid);
	
	$sql="select * from OBJ_320.param_99 where $oidWhere and instanceNo= '$instance' ";
	$res=@mysqli_query($pubConn,$sql);
	$row=@mysqli_fetch_array($res);
	$value=$row[readValue]+0;
	
	return $value;
}

function GetSystemStatus($sysTypeNo,$sysNo,$subSysNo=0)
{
	$due_date	= date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s")-60,date("m"),date("d"),date("Y")));
	$ove_date	= date("Y-m-d H:i:s",mktime(date("H"),date("i"),date("s")+60,date("m"),date("d"),date("Y")));
	
	$sql="select * from OMC_PUB.sysInfo where sysTypeNo=$sysTypeNo and sysNo=$sysNo and subSysNo=$subSysNo ";	
	$res=@mysqli_query($pubConn,$sql);
	$num=mysqli_num_rows($res);
	if($num == 0)
		return 0;
	
	$row=@mysqli_fetch_array($res);
	$baseStat=$row[baseStat]+0;
	if($baseStat == 0)
		return 0;
		
	$updateTime=$row[updateTime];
	if($updateTime < $due_date || $updateTime > $ove_date)
		return 0;
		
	return 1;
}
function DeleteSubTableData($sysTypeNo,$instanceNo,$tableOid,$paraTable)
{
	//echo "DeleteSubTableData($sysTypeNo,$instanceNo,$tableOid)<br>";
	$where=getLevelWhere($tableOid);
	$sql="delete from $paraTable where $where and instanceNo like '{$instanceNo}%'";
	@mysqli_query($pubConn,$sql);
	
	$where=getLevelWhere($tableOid);
	$table="OBJ_{$sysTypeNo}.paramConf";
	$sql="select * from $table where name_2 like '%Entries' and $where ";
	$res=@mysqli_query($pubConn,$sql);
	$num=mysqli_num_rows($res);
	for($i=0;$i<$num;$i++)
	{
		$row=@mysqli_fetch_array($res);
		$entriesName=$row[name_2];
		$len=strlen($entriesName);
		for($j=0;$j<$len;$j++)
		{
			if($entriesName[$j]<'a'||$entriesName[$j]>'z')
				break;
		}
		$entriesName=substr($entriesName,$j);
		$entriesName=str_replace("Entries","",$entriesName);
		$entryoid=findRelationOid($entriesName,TABLE_ENTRY,$sysTypeNo);
		
		DeleteSubTableData($sysTypeNo,$instanceNo,$entryoid,$paraTable);
	}
}

function PrintInfo($info)
{
	$command="echo '$info' >> /tmp/omcdebug.txt ";
	system($command);
}
?>


<?php
$glo_id=0;
function GetGlobalID()
{
	global $glo_id;
	$tmp=$glo_id;
	$glo_id++;
	return $tmp;
}

function GetTabConf($sysTypeNo)
{
	$sql="select * from OBJ_{$sysTypeNo}.paramConf where maxAccess=0 and name_2 <> 'parameter' order by level_1,level_2,level_3,level_4,level_5,level_6,level_7,level_8,level_9,level_10 ";
	$res=@mysqli_query($pubConn,$sql);
	$num=@mysqli_num_rows($res);
	//echo "$sql<br>";
	for($i=0;$i<$num;$i++)
	{
		$row=@mysqli_fetch_array($res);
		$tabConf[$i][Name]=adjustTableName($row[name_2]);
		$tabConf[$i][OID]=getOIDByRow($row);
		
		$checkoid=$tabConf[$i][OID].".1.1.0";
		$checkwhere=getLevelWhere($checkoid);
		$checksql="select desc_2 from OBJ_{$sysTypeNo}.paramConf where $checkwhere";
		$checkres=@mysqli_query($pubConn,$checksql);
		$checknum=@mysqli_num_rows($checkres);
		if($checknum == 1)
		{
			$checkrow=@mysqli_fetch_array($checkres);
			$desc=$checkrow[desc_2];
			if(strstr($desc,"Name:"))
			{
				$new_name=explode("Name:",$desc);
				$tabConf[$i][Name]=str_replace(";","",$new_name[sizeof($new_name)-1]);
			}
		}
		
	}
	if($num == 0)
		return 0;
	return $tabConf;
}

function InitTab($sysTypeNo)
{
	echo "\n<script language=\"JavaScript\">\n";
	echo "var tab_count=0;\n";
	echo "var tab_len=new Array();\n";
	echo "var tab_start=0;\n";
	echo "var tab_sel=0;\n";
	echo "function mouseovertab(itemid)\n";
	echo "{\n";
	echo "document.getElementById(itemid).style.color='#0000ff';\n";
	echo "}\n";
	
	echo "function mouseouttab(itemid)\n";
	echo "{\n";
	echo "document.getElementById(itemid).style.color='#000000';\n";
	echo "}\n";
	
	echo "function clicktab(itemid)\n";
	echo "{\n";
	echo "var sysId=document.selectform.system_id_select.value;\n";
	//echo "tab_sel=itemid;\n";
	//echo "alert(itemid);\n";
	echo "adjust_tab(itemid);\n";
	echo "parent.param_show_table.location.href='./param_show_table.php?table_id='+itemid+'&sysId='+sysId+'&instanceNo=0000';\n";
	
	echo "return;\n";
	echo "}\n";
	
	echo "function adjust_firefox()\n";
	echo "{\n";
	echo "var browserr=navigator.appName;\n";
	echo "if(browserr != 'Microsoft Internet Explorer')\n";
	echo "{\n";
	echo "for(i=0;i<tab_count;i++)\n";
	echo "{\n";
	echo "document.getElementById(i).style.top='41px';\n";
	echo "document.getElementById('ano_'+i).style.top='41px';\n";
	echo "}\n";
	echo "document.getElementById('left_id').style.top='41px';\n";
	echo "document.getElementById('right_id').style.top='41px';\n";
	echo "document.getElementById('left_id').style.height='28px';\n";
	echo "document.getElementById('right_id'),style.height='28px';\n";
	echo "}\n";
	echo "}\n";

	echo "function left_tab()\n";
	echo "{\n";
	echo "if(tab_start == 0)\n";
	echo "return;\n";
	echo "tab_start--;\n";
	echo "adjust_tab(tab_sel);\n";
	echo "}\n";
	
	echo "function right_tab()\n";
	echo "{\n";
	echo "if(tab_start == tab_count)\n";
	echo "return;\n";
	echo "tab_start++;\n";
	echo "adjust_tab(tab_sel);\n";
	echo "}\n";
	
	echo "function adjust_tab(itemid)\n";
	echo "{\n";	
	echo "var total_width=document.getElementById('img_up').width+10;\n";
	echo "var cur_width=0;\n";
	echo "var left_width;\n";
	echo "var hasRight=0;\n";
	
	echo "if(tab_sel != null)\n";
	echo "{\n";
	//echo "alert(document.getElementById(tab_sel));\n";
	echo "document.getElementById(tab_sel).style.zIndex=tab_sel;\n";
	echo "document.getElementById('ano_'+tab_sel).style.zIndex=tab_sel;\n";
	echo "}\n";
	
	echo "if(itemid == -1)\n";
	echo "itemid=tab_sel;\n";
	echo "tab_sel=itemid;\n";
	echo "document.getElementById(tab_sel).style.zIndex=1000;\n";
	echo "document.getElementById('ano_'+tab_sel).style.zIndex=1000;\n";
	echo "for(i=0;i<tab_count;i++)\n";
	echo "{\n";
	echo "document.getElementById(i).style.display='none';\n";
	echo "document.getElementById('ano_'+i).style.display='none';\n";
	echo "}\n";
	echo "if(tab_start>0)\n";
	echo "{\n";
	echo "document.getElementById('left_id').style.display='';\n";
	echo "left_width=20;\n";
	echo "}\n";
	echo "else\n";
	echo "{\n";
	echo "document.getElementById('left_id').style.display='none';\n";
	echo "left_width=0;\n";
	echo "}\n";
	echo "cur_width=left_width;\n";
	
	echo "for(i=tab_start;i<tab_count;i++)\n";
	echo "{\n";
	echo "if(cur_width + tab_len[i] > total_width+30)\n";
	echo "{\n";
	echo "hasRight=1;\n";
	echo "break;\n";
	echo "}\n";
	echo "cur_width+=tab_len[i];\n";
	echo "}\n";
	echo "if(tab_sel>=tab_start && tab_sel<i)\n";
	echo "{\n";
	echo "document.getElementById(tab_sel).style.display='none';\n";
	echo "document.getElementById('ano_'+tab_sel).style.display='';\n";
	echo "}\n";
	echo "cur_width=left_width;\n";
	echo "for(i=tab_start;i<tab_count;i++)\n";
	echo "{\n";
	echo "if(cur_width + tab_len[i] > total_width+30)\n";
	echo "break;\n";
	echo "document.getElementById(i).style.display='';\n";
	echo "if(i>tab_start)\n";
	echo "{\n";
	echo "document.getElementById(i).style.left=(cur_width-16*(i-tab_start))+'px';\n";
	echo "document.getElementById('ano_'+i).style.left=(cur_width-16*(i-tab_start))+'px';\n";
	echo "}\n";
	echo "else\n";
	echo "{\n";
	echo "document.getElementById(i).style.left=cur_width+'px';\n";
	echo "document.getElementById('ano_'+i).style.left=cur_width+'px';\n";
	echo "}\n";
	echo "cur_width+=tab_len[i];\n";
	echo "}\n";
	echo "if(hasRight == 1)\n";
	echo "{\n";
	echo "document.getElementById('right_id').style.display='';\n";
	echo "document.getElementById('right_id').style.left=(total_width-47)+'px';\n";
	echo "}\n";
	echo "else\n";
	echo "{\n";
	echo "document.getElementById('right_id').style.display='none';\n";
	echo "document.getElementById('right_id').style.left=(total_width-47)+'px';\n";
	echo "}\n";
	echo "}\n";
	
	echo "</script>\n";
}
$previous_left=20;
function AddTab($id,$value,$lable,$image_1,$image_2,$imageWidth,$imageHeight)
{
	global $previous_left;
	echo "<span ";
	echo "onmouseover=\"javascript:mouseovertab('$id');\" ";
	echo "onmouseout=\"javascript:mouseouttab('$id');\" ";
	echo "onclick=\"javascript:clicktab('$id');\" ";
	echo "id=\"$id\" ";
	$z=100+$id*5;
	$imagedir="./images/";
	
	$chrlen=strlen($lable)+1;
	$lable="&nbsp;".$lable;
	$imageheight=17;
	if($chrlen <= 4)
	{
		$imagefile1=$imagedir."tab_dark_4.gif";
		$imagefile2=$imagedir."tab_light_4.gif";
		$imagewidth=68;
	}
	else if($chrlen <= 10)
	{
		$imagefile1=$imagedir."tab_dark_8.gif";
		$imagefile2=$imagedir."tab_light_8.gif";
		$imagewidth=98;
	}
	else if($chrlen <= 16)
	{
		$imagefile1=$imagedir."tab_dark_12.gif";
		$imagefile2=$imagedir."tab_light_12.gif";
		$imagewidth=133;
	}
	else if($chrlen <= 22)
	{
		$imagefile1=$imagedir."tab_dark_16.gif";
		$imagefile2=$imagedir."tab_light_16.gif";
		$imagewidth=170;
	}
	else if($chrlen <= 28)
	{
		$imagefile1=$imagedir."tab_dark_20.gif";
		$imagefile2=$imagedir."tab_light_20.gif";
		$imagewidth=206;
	}
	else if($chrlen <= 34)
	{
		$imagefile1=$imagedir."tab_dark_24.gif";
		$imagefile2=$imagedir."tab_light_24.gif";
		$imagewidth=243;
	}
	else
	{
		$lable=substr($lable,0,34);
		$imagefile1=$imagedir."tab_dark_24.gif";
		$imagefile2=$imagedir."tab_light_24.gif";
		$imagewidth=243;
	}
	
	$left=$previous_left;

	echo "style=\"FILTER:chroma(color:#ffffff);z-index:{$z};";
	echo "background-repeat:no-repeat;";
	echo "position:absolute;top:36px;left:{$left}px;width:{$imagewidth}px;height:{$imageheight}px;";
	echo "background-image:url({$imagefile2});";
	echo "white-space:nowrap;cursor:hand;color:black;padding:4px;\">";
	echo "{$lable}</span>";
	
	echo "<span id=\"ano_{$id}\" ";
	$z=100+$id*5;
	$left=$previous_left;
	$previous_left=$previous_left+$imagewidth-16;
	echo "style=\"FILTER:chroma(color:#ffffff);z-index:{$z};";

	echo "background-repeat:no-repeat;";
	echo "display:none;";
	echo "position:absolute;top:36px;left:{$left}px;width:{$imagewidth}px;height:{$imageheight}px;";
	echo "background-image:url({$imagefile1});";
	echo "white-space:nowrap;cursor:hand;color:black;padding:4px;\">";
	echo "{$lable}</span>";
	
	echo "\n<script language=\"JavaScript\">\n";
	echo "tab_len[tab_count]=$imagewidth;\n";
	echo "tab_count++;\n";
	echo "</script>\n";
}
define(GET_OID,0);
define(SCALAR_ITEM_OID,1);
function GetAllOIDArr($sysTypeNo,$get_type=0)
{
	$tabConf=GetTabConf($sysTypeNo);
	if(0)
	{
		echo "<pre>";
		print_r($tabConf);
		echo "</pre>";
	}
	$tab_id_count=sizeof($tabConf);
	for($table_id=0;$table_id<$tab_id_count;$table_id++)
	{
		$tableOid=$tabConf[$table_id][OID];
		//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 OBJ_{$sysTypeNo}.paramConf where $oidwhere order by level_1,level_2,level_3,level_4,level_5,level_6,level_7,level_8,level_9,level_10 ";
		$res=@mysqli_query($pubConn,$sql);
		$num=@mysqli_num_rows($res);
		
		$scalarTableIndex=0;
		$columnTableIndex=0;
		$scalarItemIndex=0;
		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)
				{
					$scalarTableIndex++;
				}
				//column table
				else if($row[maxAccess] == ACCESS_ENTRY && strstr($row[name_2],"Table"))
				{
					//only get the top two level table
					if($columnTableIndex < 2)
						$oidArr[]=getOIDByRow($row).".1";					
					$columnTableIndex++;
				}
				//scalar item
				else
				{
					$scalarItemIndex++;
					if(stristr($row[name_2],"Command"))
						continue;
					if($row[maxAccess] == ACCESS_ENTRY)
						continue;
					if(strstr($row['desc_2'],"Hidden Parameter"))
						continue;
					$tmpss=getOIDByRow($row);
					$oidArr[]=$tmpss;
					$scalar_oids[]=$tmpss;
				}
			}
		}
	}
	
	if($get_type == SCALAR_ITEM_OID)
		return $scalar_oids;
	else
		return $oidArr;
}
?>

