<?php


require("../../inc/header.inc");
require("logdb.inc");
require("function.php");
$DEBUG = 0;
if($DEBUG) echo "<br>正在调试中，给您的工作带来不便，请原谅！！：^_^";




echo "<table border=\"0\" width=\"100%\">";
echo "<tr>";
echo "<td width=\"50%\">";
echo "Configuration > <a href=\"JavaScript:backpage(1,'../overview/overview.php')\">Network</a>";
echo "> <a href=\"JavaScript:backpage(1,'./bssSpecific.php?bssid=$bssid')\">BSS Specific</a>";
echo "> <a href=\"JavaScript:backpage(1,'./bss_btsmgr.php?bssid=$bssid&btsid=$btsid')\">BtsMgr $btsid</a>";
echo "> Bts.$btsid.$cellid";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";

function flash($bssid,$btsid,$cellid)
{
	echo "<script language=\"javascript\">";
			$href="$PHP_SELF?bssid=$bssid&btsid=$btsid&cellid=$cellid";
	echo "window.location.href='$href';";
	echo "</script>";
}
if($addtype=='AdjHand')
{
	$nmicmd="create AdjHand ".$adjhand;
	$objectid="Bts.".$btsid.".".$cellid;
	putcommand($bssid,$objectid,$nmicmd);
	sleep(1);
	flash($bssid,$btsid,$cellid);
}
if($deltype=='AdjHand')
{
	$nmicmd="delete AdjHand ".$adjhand;
	$objectid="Bts.".$btsid.".".$cellid;
	putcommand($bssid,$objectid,$nmicmd);
	sleep(1);
	flash($bssid,$btsid,$cellid);
}

if($upload==1)
{
	$nmicmd="upload 12";
	$objectid="BssFunc";

	putcommand($bssid,$objectid,$nmicmd);
	sleep(3);
	flash($bssid,$btsid,$cellid);
}
$upload = 1;
echo "<table width=\"100%\"border=\"0\" width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" bordercolor=\"#666666\" bordercolordark=\"#FFFFFF\">";
	echo "<tr>";
		echo "<td width=\"75%\"></td>";
		echo "<td width=\"15%\">";
		echo "<INPUT type=button style='width: 85' value='Get All' name=upload style='width: 95' class=chinese" .
             " onClick=\"JavaScript:upload_data1('$upload','$bssid','$btsid')\">";
		echo "</td>";
		echo "<td width=\"10%\"><a href=\"JavaScript:backpage(1,'./bss_btsmgr.php?bssid=$bssid&btsid=$btsid')\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">Back</a><td>";//back
	echo "</tr>";
echo "</table>";
?>

<TABLE  border="1"  cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF" width="100%">
<?php
$sqlstring = "select engDisplayName,ObjectId from OMCR_BSSTREE where ObjectId like 'Trx.$btsid.$cellid%' and Presence=1 and bssid=$bssid";
			    //echo $sqlstring . "<BR>";
				$result = mysqli_query($pubConn,$sqlstring) or
				die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
				
				while($row = mysqli_fetch_row($result))
				{
					list($trx_disp_name[],$trx_object_name[]) =$row;
				}
				$no_of_trx = count($trx_object_name);//e.g RCarrier.0.0.4

for($i=0;$i<$no_of_trx;$i++)
{
//RCarrier >>>>>>>>>
$trx_cont = explode(".",$trx_object_name[$i]);
//echo ">>>>>$trx_$cont[0].$trx_cont[1].$trx_cont[2].$trx_cont[3]";
echo "<tr>";
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\"><b>RCarrier $trx_cont[3]</b></td>";

echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"20%\">Receive Mode</td>";
				echo "<td width=\"20%\">AdminState</td>";
				echo "<td width=\"20%\">OperState</td>";
				echo "<td width=\"20%\">AvailStatus</td>";
				echo "<td width=\"20%\"></td>";
				echo "</td>";
			echo "</tr>";

			$sqlstring = "select AdminState,OperState,AvailStatus,RxAntenna from OMCR_RCarrier where ObjectId='RCarrier.$trx_cont[1].$trx_cont[2].$trx_cont[3]' and bssid=$bssid";//$trx_object_name[$i]
			    //echo $sqlstring . "<BR>";
				$result = mysqli_query($pubConn,$sqlstring) or
				die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
				
				while($row = mysqli_fetch_row($result))
				{
					list($adminstate,$operstate,$availstatus,$rxmode) =$row;
				}

				if($adminstate==1)$adminstate="Locked";
				else if($adminstate==2)$adminstate="Unlocked";
				if($operstate==1)$operstate="Disable";
				else if($operstate==2)$operstate="Enable";
				if($availstatus==0)$availstatus="In_Test";
				else if($availstatus==1)$availstatus="Failed";
				else if($availstatus==2)$availstatus="Power_Off";
				else if($availstatus==3)$availstatus="Offline";
				else if($availstatus==4)$availstatus="Online";
				else if($availstatus==5)$availstatus="Dependency";
				else if($availstatus==6)$availstatus="Degraded";
				else if($availstatus==7)$availstatus="Not_Installed";
				if($rxmode==0)$rxmode="DIVERSITY";
				else if($rxmode==1)$rxmode="ANTENNA 1";
				else if($rxmode==2)$rxmode="ANTENNA 2";

			echo "<tr>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			
				echo "<td width=\"20%\"><a href=\"./objShow.php?language=$language&objectid=RCarrier.$trx_cont[1].$trx_cont[2].$trx_cont[3]&tablename=OMCR_RCarrier&bssid=$bssid\";>$rxmode</a>";
                      
				echo "</td>";
				
				echo "<td width=\"20%\">$adminstate</td>";
				echo "<td width=\"20%\">$operstate</td>";
				echo "<td width=\"20%\">$availstatus</td>";
                echo "<td width=\"20%\"></td>";
			    echo "</table>";
            echo "</tr>"; 
echo "</td>";
echo "</tr>";
//Trx ..............
$sqlstring="select AdminState,OperState,AvailStatus,trxDiagResult from OMCR_Trx where bssid=$bssid and ObjectId like 'Trx.$trx_cont[1].$trx_cont[2].$trx_cont[3]'";
//echo "$sqlstring<br>";
$result = mysqli_query($pubConn,$sqlstring) or
				die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
				
				while($row = mysqli_fetch_row($result))
				{
					list($adminstate,$operstate,$availstatus,$rxresult) =$row;
				}

				if($adminstate==1)$adminstate="Locked";
				else if($adminstate==2)$adminstate="Unlocked";
				if($operstate==1)$operstate="Disable";
				else if($operstate==2)$operstate="Enable";
				if($availstatus==0)$availstatus="In_Test";
				else if($availstatus==1)$availstatus="Failed";
				else if($availstatus==2)$availstatus="Power_Off";
				else if($availstatus==3)$availstatus="Offline";
				else if($availstatus==4)$availstatus="Online";
				else if($availstatus==5)$availstatus="Dependency";
				else if($availstatus==6)$availstatus="Degraded";
				else if($availstatus==7)$availstatus="Not_Installed";
				//Failed=0;Passed=1;Not Performed=2
				if($rxresult==0)$rxresult="Failed";
				else if($rxresult==1)$rxresult="Passed";
				else if($rxresult==2)$rxresult="Not Performed";

echo "<tr>";
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\"><b>Trx $trx_cont[3]</b></td>";
echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"20%\">Diagnostic Result</td>";
				echo "<td width=\"20%\">AdminState</td>";
				echo "<td width=\"20%\">OperState</td>";
				echo "<td width=\"20%\">AvailStatus</td>";
				echo "<td width=\"20%\"></td>";
				echo "</td>";
			echo "</tr>";

			
			echo "<tr>";
			
				echo "<td width=\"20%\"><a href=\"./objShow.php?language=$language&objectid=Trx.$trx_cont[1].$trx_cont[2].$trx_cont[3]&tablename=OMCR_Trx&bssid=$bssid\";>$rxresult</td>";
				
				echo "<td width=\"20%\">$adminstate</td>";
				echo "<td width=\"20%\">$operstate</td>";
				echo "<td width=\"20%\">$availstatus</td>";
                echo "<td width=\"20%\"></td>";
			  
            echo "</tr>";
            //TrxCh========
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"20%\">No</td>";
				echo "<td width=\"20%\">AdminState</td>";
				echo "<td width=\"20%\">OperState</td>";
				echo "<td width=\"20%\">AvailStatus</td>";
				echo "<td width=\"20%\">Usage Status</td>";
			//echo "</td>";	
			echo "</tr>";
			
			for($j=0;$j<8;$j++)
			{
				$sqlstring="select AdminState,OperState,AvailStatus,UsageState from OMCR_TrxCh where bssid=$bssid and ObjectId like 'TrxCh.$btsid.$cellid.$trx_cont[3].$j'";
				//echo $sqlstring . "<BR>";
				$result = mysqli_query($pubConn,$sqlstring) or
				die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
				while($row = mysqli_fetch_row($result))
				{
					list($adminstate,$operstate,$availstatus,$usagestate) =$row;
				}

				if($adminstate==1)$adminstate="Locked";
				else if($adminstate==2)$adminstate="Unlocked";
				if($operstate==1)$operstate="Disable";
				else if($operstate==2)$operstate="Enable";
				if($availstatus==0)$availstatus="In_Test";
				else if($availstatus==1)$availstatus="Failed";
				else if($availstatus==2)$availstatus="Power_Off";
				else if($availstatus==3)$availstatus="Offline";
				else if($availstatus==4)$availstatus="Online";
				else if($availstatus==5)$availstatus="Dependency";
				else if($availstatus==6)$availstatus="Degraded";
				else if($availstatus==7)$availstatus="Not_Installed";
				//IDLE=0;ACTIVE=1;BUSY=2 
				if($usagestate==0)$usagestate="IDLE";
				else if($usagestate==1)$usagestate="ACTIVE";
				else if($usagestate==2)$usagestate="BUSY";

					echo "<tr onMouseOver=\"this.bgColor='#D2F0FF'\" onMouseOut=\"this.bgColor='#ffffff'\">";
			    	echo"<td width=\"20%\"><a href=\"./objShow.php?language=$language&objectid=TrxCh.$trx_cont[1].$trx_cont[2].$trx_cont[3].$j&tablename=OMCR_TrxCh&bssid=$bssid\";>TRXCH $j</a></td>";
					
   				    echo "<td width=\"20%\">$adminstate</td>";
				    echo "<td width=\"20%\">$operstate</td>";
				    echo "<td width=\"20%\">$availstatus</td>";
                    echo "<td width=\"20%\">$usagestate</td>";
					echo "</tr>";
			}
			echo "</td>";
			echo "</table>";

echo "</tr>";
}
//PowerControl
echo "<tr>";
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\"><b>Power Control</b></td>";

echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"25%\">MsTxPwrMin</td>";
				echo "<td width=\"25%\">BtsTxPwrMin</td>";
				echo "<td width=\"25%\">Averging window for Level</td>";
				echo "<td width=\"25%\">Averging window for Quality</td>";
				
				echo "</td>";
			echo "</tr>";
			$sqlstring="select MsTxPwrMin,BtsTxPwrMin,PcAveragingLevelParamHreqave,PcAveragingQualParamHreqave from OMCR_PwrCont where bssid=$bssid and ObjectId like 'PwrCont.$btsid.$cellid.0'";
			$result = mysqli_query($pubConn,$sqlstring) or
				die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
				
				while($row = mysqli_fetch_row($result))
				{
					list($mtpm,$btpm,$alph,$aqph) =$row;
				}
			
			echo "<tr>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			
				echo "<td width=\"25%\"><a href=\"./objShow.php?&language=$language&objectid=PwrCont.$btsid.$cellid.0&tablename=OMCR_PwrCont&btsid=$btsid&bssid=$bssid\";>$mtpm</a></td>";
				
				echo "<td width=\"25%\"><a href=\"./objShow.php?&language=$language&objectid=PwrCont.$btsid.$cellid.0&tablename=OMCR_PwrCont&btsid=$btsid&bssid=$bssid\";>$btpm</a></td>";
				echo "<td width=\"25%\"><a href=\"./objShow.php?&language=$language&objectid=PwrCont.$btsid.$cellid.0&tablename=OMCR_PwrCont&btsid=$btsid&bssid=$bssid\";>$alph</a></td>";
				echo "<td width=\"25%\"><a href=\"./objShow.php?&language=$language&objectid=PwrCont.$btsid.$cellid.0&tablename=OMCR_PwrCont&btsid=$btsid&bssid=$bssid\";>$aqph</a></td>";
				
			    echo "</table>";
            echo "</tr>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\"><b>Handover Control</b></td>";

echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"25%\">Uplink RxLev Threshold</td>";
				echo "<td width=\"25%\">Uplink RxQual Threshold</td>";
				echo "<td width=\"25%\">Downlink RxLev Threshold</td>";
				echo "<td width=\"25%\">Downlink RxQual Threshold</td>";
				
				echo "</td>";
			echo "</tr>";
			$sqlstring="select HoThresholdLevUl,HoThresholdQualUl,HoThresholdLevDl,HoThresholdQualDl from OMCR_HandCont where bssid=$bssid and ObjectId like 'HandCont.$btsid.$cellid.0'";

			$result = mysqli_query($pubConn,$sqlstring) or
				die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
				
				while($row = mysqli_fetch_row($result))
				{
					list($htlu,$htqu,$htld,$htqd) =$row;
				}
			
			echo "<tr>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			
			   echo "<td width=\"25%\"><a	href=\"./objShow.php?&language=$language&objectid=HandCont.$btsid.$cellid.0&tablename=OMCR_HandCont&btsid=$btsid&bssid=$bssid\";>$htlu</a></td>";
				echo "<td width=\"25%\"><a href=\"./objShow.php?&language=$language&objectid=HandCont.$btsid.$cellid.0&tablename=OMCR_HandCont&btsid=$btsid&bssid=$bssid\";>$htqu</a></td>";
				echo "<td width=\"25%\"><a href=\"./objShow.php?&language=$language&objectid=HandCont.$btsid.$cellid.0&tablename=OMCR_HandCont&btsid=$btsid&bssid=$bssid\";>$htld</a></td>";
				echo "<td width=\"25%\"><a href=\"./objShow.php?&language=$language&objectid=HandCont.$btsid.$cellid.0&tablename=OMCR_HandCont&btsid=$btsid&bssid=$bssid\";>$htqd</a></td>";
                
			    echo "</table>";
            echo "</tr>";
echo "</td>";
echo "</tr>";
//AdjHand >>>>>>>>>
echo "<tr>";
//Check AdjHand is ok.......
$sqlstring = "select ObjectId from OMCR_BSSTREE where ObjectId like 'AdjHand.$btsid.$cellid%' and engDisplayName='' and Presence=1 and bssid=$bssid";
//echo $sqlstring . "<BR>";
$result = mysqli_query($pubConn,$sqlstring) or
          die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
while($row = mysqli_fetch_row($result))
{
	list($adjhand_object[]) =$row;
}
//echo "$adjhand_object[0]";
$no_of_adj = count($adjhand_object);
$array = array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31);
//print_r($array);

for($n=0;$n<$no_of_adj;$n++)
{
	$adj_num = explode(".",$adjhand_object[$n]);
	$num[$n] = $adj_num[3];
	unset($array[$num[$n]]);
}
$array = array_values($array);
//print_r($array);
$adjhand = $array[0];
$objectid = "AdjHand.".$btsid.".".$cellid.".".$adjhand;
$addtype = "AdjHand";
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\">";
echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" ><tr >";
echo "<td align=left><b>Adjacent Hand</b></td>";
			echo "<td align=\"right\"><a href=javascript:addAdj('$bssid','$objectid','$btsid','$cellid','$adjhand','$addtype')>+</a></td>";
echo "</tr></table>";

//////////////////////////////AdjHand Parametet//////////////////////////////////////////
echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"12.5%\">Name</td>";
				echo "<td width=\"12.5%\">MCC</td>";
				echo "<td width=\"12.5%\">MNC</td>";
				echo "<td width=\"12.5%\">LAC</td>";
				echo "<td width=\"12.5%\">Cell Id</td>";
				echo "<td width=\"12.5%\">BSIC</td>";
				echo "<td width=\"12.5%\">BCCH</td>";
				echo "<td width=\"12.5%\">Delete</td>";
				echo "</td>";
			echo "</tr>";

for($i=0;$i<$no_of_adj;$i++)
{
		$adjconts = explode(".",$adjhand_object[$i]);
		$sqlstring = "select Label,CellGlobalIdentityLaiMcc,CellGlobalIdentityLaiMnc,LocationAreaCodes,CellGlobalIdentityCi,BsIdentityCodes,BcchFrequency from OMCR_AdjHand where bssid=$bssid and ObjectId like 'AdjHand.$btsid.$adjconts[2].$adjconts[3]'";
				//echo $sqlstring . "<BR>";
				$result = mysqli_query($pubConn,$sqlstring) or
				die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
				
				while($row = mysqli_fetch_row($result))
				{
					list($cellname,$mcc,$mnc,$lac,$cellid,$bsic,$bcch) =$row;
				}			
			echo "<tr>";
			//echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			
				$objectid = "AdjHand.".$btsid.".".$adjconts[2].".".$adjconts[3];
				$deltype  = "AdjHand";
				$adjhand  = $adjconts[3];
				$cellid = $adjconts[2];
				echo "<td width=\"12.5%\"><a href=\"./objShow.php?language=$language&objectid=AdjHand.$btsid.$adjconts[2].$adjconts[3]&tablename=OMCR_AdjHand&bssid=$bssid&cellid=$cellid\";>\"$cellname\"</td>";
				echo "<td width=\"12.5%\"><a href=\"./objShow.php?language=$language&objectid=AdjHand.$btsid.$adjconts[2].$adjconts[3]&tablename=OMCR_AdjHand&bssid=$bssid\";>$mcc</td>";
				echo "<td width=\"12.5%\"><a href=\"./objShow.php?language=$language&objectid=AdjHand.$btsid.$adjconts[2].$adjconts[3]&tablename=OMCR_AdjHand&bssid=$bssid\";>$mnc</td>";
				echo "<td width=\"12.5%\"><a href=\"./objShow.php?language=$language&objectid=AdjHand.$btsid.$adjconts[2].$adjconts[3]&tablename=OMCR_AdjHand&bssid=$bssid\";>$lac</td>";
                echo "<td width=\"12.5%\"><a href=\"./objShow.php?language=$language&objectid=AdjHand.$btsid.$adjconts[2].$adjconts[3]&tablename=OMCR_AdjHand&bssid=$bssid\";>$cellid</td>";
				echo "<td width=\"12.5%\"><a href=\"./objShow.php?language=$language&objectid=AdjHand.$btsid.$adjconts[2].$adjconts[3]&tablename=OMCR_AdjHand&bssid=$bssid\";>$bsic</td>";
				echo "<td width=\"12.5%\"><a href=\"./objShow.php?language=$language&objectid=AdjHand.$btsid.$adjconts[2].$adjconts[3]&tablename=OMCR_AdjHand&bssid=$bssid\";>$bcch</td>";
				
				echo "<td width=\"12.5%\">";
				echo "<input type=\"checkbox\" name=\"select this\" title=\"Select this to delete\"  value=\"1\" onClick=\"javascript:delAdj('$bssid','$objectid','$btsid','$cellid','$adjhand','$deltype',this)\"></td>";
				echo "</tr>";
}
echo "</table>";
echo "</td>";
echo "</tr>";

?>