<?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 ">BtsMgr $btsid";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";
//run add or del
function flash($bssid,$btsid)
{
	echo "<script language=\"javascript\">";
			$href="$PHP_SELF?bssid=$bssid&btsid=$btsid";
	echo "window.location.href='$href';";
	echo "</script>";
}
if($addtype=='Bts')
{
	if($cellid > 2)
			{
				echo "<script LANGUAGE=\"JavaScript\">";
		        echo "alert(\"Cell number is too big!\");";
		        echo "</script>";
			}
	else
	{
	$nmicmd="create Bts ".$cellid;
	$objectid="BtsMgr.".$btsid;
	putcommand($bssid,$objectid,$nmicmd);
	sleep(2);
	flash($bssid,$btsid);
	}
}
/*
if($deltype=='Bts')
{
	$nmicmd="delete Bts ".$cellid;
	$objectid="BtsMgr.".$btsid;
	echo "obj=$objectid";
	putcommand($bssid,$objectid,$nmicmd);
	flash($bssid,$btsid);
}
*/
//display table

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='Add Bts' name=addcell style='width: 95' class=chinese" .
        //     " onClick=\"JavaScript:AddCell('$bssid','$objectid','$btsid','$cellid','$addtype')\">";
		echo "</td>";
		echo "<td width=\"10%\"><a href=\"JavaScript:backpage(1,'./bssSpecific.php?bssid=$bssid')\"><img align=absBottom border=0 src=\"../../images/left.gif\" width=\"14\" height=\"14\">Back</a><td>";
	echo "</tr>";
echo "</table>";
?>

<TABLE  border="1"  cellpadding="2" cellspacing="0" bordercolor="#666666" bordercolordark="#FFFFFF" bgcolor="#FFFFFF" width="100%">
<?php
//AbisMgr==================>>>
echo "<tr>";
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\"><b>AbisMgr</b></td>";
echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
			    echo "<td width=\"8%\">Slot</td>";
				echo "<td width=\"8%\">Port</td>";
				echo "<td width=\"9%\">Chan</td>";
				echo "<td width=\"20%\">AdminState</td>";
				echo "<td width=\"20%\">OperaState</td>";
				echo "<td width=\"20%\">AvailStatus</td>";
				echo "<td width=\"15%\"></td>";
			echo "</tr>";
			$sqlstring = "select AdminState,OperState,AvailStatus,E1Port,E1Slot,E1Chan from OMCR_AbisMgr where ObjectId='AbisMgr.$btsid.0' 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($adminstate,$operstate,$availstatus,$e1port,$e1slot,$e1chan) =$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";

			echo "<tr>";
			    echo "<td width=\"8%\"><a href=\"./objShow.php?language=$language&objectid=AbisMgr.$btsid.0&tablename=OMCR_AbisMgr&bssid=$bssid\";>$e1slot</a></td>";
				echo "<td width=\"8%\"><a href=\"./objShow.php?language=$language&objectid=AbisMgr.$btsid.0&tablename=OMCR_AbisMgr&bssid=$bssid\";>$e1port</a></td>";
				echo "<td width=\"9%\"><a href=\"./objShow.php?language=$language&objectid=AbisMgr.$btsid.0&tablename=OMCR_AbisMgr&bssid=$bssid\";>$e1chan</a></td>";
				echo "<td width=\"20%\">$adminstate</td>";
				echo "<td width=\"20%\">$operstate</td>";
				echo "<td width=\"20%\">$availstatus</td>";
				echo "<td width=\"15%\"></td>";
				echo "</table>";
			echo "</tr>";
echo "</td>";
echo "</tr>";
////////////////////////////////////////////////////////////////////////////////////////////////
//Bts.......................................>
echo "<tr>";
//echo "<td width=\"20%\" bgcolor=\"#E6E6E6\"><a href=\"./bss_bts.php?btsid=$btsid&bssid=$bssid\";><b>Bts</b></a></td>";
$sqlstring = "select ObjectId from OMCR_BSSTREE where ObjectId like 'Bts.$btsid%' 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($cell_object[]) =$row;
}
$no_of_cell = count($cell_object);
$array = array(0,1,2,3);


for($n=0;$n<$no_of_cell;$n++)
{
	$cell_num = explode(".",$cell_object[$n]);
	$num[$n] = $cell_num[2];
	unset($array[$num[$n]]);
}
$array = array_values($array);
//print_r($array);
$cellid = $array[0];
$objectid = "Bts.".$btsid.".".$cellid;
$addtype = "Bts";

echo "<td width=\"20%\" bgcolor=\"#E6E6E6\">";
echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" ><tr >";
echo "<td align=left><b>Cell</b></td>";
			echo "<td align=\"right\"><a href=javascript:AddCell('$bssid','$objectid','$btsid','$cellid','$addtype')>+</a></td>";
echo "</tr></table>";

echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"8%\">No</td>";
				echo "<td width=\"17%\">Cell Name</td>";
				echo "<td width=\"20%\">AdminState</td>";
				echo "<td width=\"20%\">OperState</td>";
				echo "<td width=\"20%\">AvailStatus</td>";
				echo "<td width=\"15%\"></td>";
				echo "</td>";
			echo "</tr>";
			for($i=0;$i<$no_of_cell;$i++)
			{
				$cellconts = explode(".",$cell_object[$i]);
				$sqlstring = "select AdminState,OperState,AvailStatus,Label from OMCR_Bts where ObjectId='Bts.$btsid.$cellconts[2]' 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($adminstate,$operstate,$availstatus,$cellname) =$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";
			/*	$sqlstring = "select ObjectId from OMCR_BSSTREE where ObjectId like 'Trx.$btsid.$cellconts[2]%' 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_list[]) =$row;
				}
				$no_of_trx = count($trx_list);
			*/
			echo "<tr>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
				$cellid = $cellconts[2];
				echo "<td width=\"8%\"><a href=\"./bss_bts.php?btsid=$btsid&bssid=$bssid&cellid=$cellid\";><b>$cellconts[2]</b></a></td>";
				echo "<td width=\"17%\"><a href=\"./objShow.php?language=$language&objectid=Bts.$btsid.$cellconts[2]&tablename=OMCR_Bts&btsid=$btsid&bssid=$bssid\";>\"$cellname\"</a></td>";
				
				echo "<td width=\"20%\">$adminstate</td>";
				echo "<td width=\"20%\">$operstate</td>";
				echo "<td width=\"20%\">$availstatus</td>";
				//echo "<td width=\"4%\">$no_of_trx</td>";
				/*echo "<td width=\"4%\">";
				$deltype = "Bts";
				
				$objectid = "Bts.".$btsid.".".$cellid;
				echo "<input type=\"checkbox\" name=\"select this\" title=\"Select this to delete\"  value=\"1\" onClick=\"javascript:delCell('$bssid','$objectid','$btsid','$cellid','$deltype',this)\"></td>";
				*/
				echo "<td width=\"15%\">";
				
				echo "<INPUT type=button style='width: 88' value='AssignTrx' name=upload style='width: 35' class=chinese ".
				" onClick=\"JavaScript:backpage(1,'./bss_assigntrx.php?bssid=$bssid&btsid=$btsid&cellid=$cellid')\"></td>";
			
			}//end for...
			    echo "</table>";
            echo "</tr>";
echo "</td>";
echo "</tr>";

//Shelf for BtsMgr (1~11)=====
if($btsid != 0){
echo "<tr>";
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\"><b>SHELF</b></td>";
echo "<td>";
$sqlstring = "select DoorInterlockEnable,bssUplinkVolumeControl,bssDownlinkVolumeControl from OMCR_Wavex where ObjectId like 'BtsMgr_Shelf.$btsid.0' 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($dooralarm,$uvc,$dvc) =$row;
				}
				//-6dB=0;-4dB=1;-2dB=2;normal  =3;+2dB=4;+4dB=5;+6dB=6;+8dB=7 
				if($dooralarm==0)$dooralarm="Disable";
				else if($dooralarm==1)$dooralarm="Enable";
				if($uvc==0)$uvc="-6dB";
				else if($uvc==1)$uvc="-4dB";
				else if($uvc==2)$uvc="-2dB";
				else if($uvc==3)$uvc="normal";
				else if($uvc==4)$uvc="+2dB";
				else if($uvc==5)$uvc="+4dB";
				else if($uvc==6)$uvc="+6dB";
				else if($uvc==7)$uvc="+8dB";
				if($dvc==0)$dvc="-6dB";
				else if($dvc==1)$dvc="-4dB";
				else if($dvc==2)$dvc="-2dB";
				else if($dvc==3)$dvc="normal";
				else if($dvc==4)$dvc="+2dB";
				else if($dvc==5)$dvc="+4dB";
				else if($dvc==6)$dvc="+6dB";
				else if($dvc==7)$dvc="+8dB";

			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"25%\">Door Alarm</td>";
				echo "<td width=\"40%\">Uplink Volume Control</td>";
				echo "<td width=\"30%\">Downlink Volume Control</td>";
				echo "</td>";
			echo "</tr>";
			
           
				echo "<td width=\"25%\"><a href=\"./objShow.php?language=$language&objectid=BtsMgr_Shelf.$btsid.0&tablename=OMCR_Wavex&bssid=$bssid\";>$dooralarm</a></td>";
				echo "<td width=\"35%\"><a href=\"./objShow.php?language=$language&objectid=BtsMgr_Shelf.$btsid.0&tablename=OMCR_Wavex&bssid=$bssid\";>$uvc</a></td>";
				echo "<td width=\"35%\"><a href=\"./objShow.php?language=$language&objectid=BtsMgr_Shelf.$btsid.0&tablename=OMCR_Wavex&bssid=$bssid\";>$dvc</a></td>";
			
                echo "</tr>";
                
/************************************************************************************************************/
//BtsMgr_Shelf_Card_Port.$btsid.0.1.0
			$sqlstring="select Presence from OMCR_BSSTREE where engDisplayName like 'Card%' and ObjectId like 'BtsMgr_Shelf_Card.$btsid.0%' 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($presence) =$row;
			}
		if($presence==1){
			echo "<tr>";
            
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
			    
				echo "<td width=\"25%\">No</td>";
				echo "<td width=\"20%\">AdminState</td>";
				echo "<td width=\"20%\">OperState</td>";
				echo "<td width=\"20%\">AvailStatus</td>";
                echo "<td width=\"15%\">Interface</td>";
            echo "</tr>";

			echo "<tr onMouseOver=\"this.bgColor='#D2F0FF'\" onMouseOut=\"this.bgColor='#ffffff'\">";

			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			
				echo "<td width=\"12%\">Card 1";
                $sqlstring="select AdminState,OperState,AvailStatus,INTERFACE from OMCR_E1port where bssid=$bssid and ObjectId = 'BtsMgr_Shelf_Card_Port.$btsid.0.1.0'";
				//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,$interface) =$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($interface==0)$interface="Unused";
				else if($interface==1)$interface="AIF";
				else if($interface==2)$interface="ABIS";
				else if($interface==5)$interface="R2";
				echo "<td width=\"13%\"><a href=\"./objShow.php?language=$language&objectid=BtsMgr_Shelf_Card_Port.$btsid.0.1.0&tablename=OMCR_E1port&bssid=$bssid\";>Port 0</a>";

				echo "</td>";
				echo "<td width=\"20%\">$adminstate</td>";
				echo "<td width=\"20%\">$operstate</td>";
				echo "<td width=\"20%\">$availstatus</td>";
                echo "<td width=\"15%\">$interface</td>";
			
            echo "</tr>";

			echo "<tr onMouseOver=\"this.bgColor='#D2F0FF'\" onMouseOut=\"this.bgColor='#ffffff'\">";

			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			
				echo "<td width=\"12%\"></td>";
				$sqlstring="select AdminState,OperState,AvailStatus,INTERFACE from OMCR_E1port where bssid=$bssid and ObjectId = 'BtsMgr_Shelf_Card_Port.$btsid.0.1.1'";
				//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,$interface) =$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($interface==0)$interface="Unused";
				else if($interface==1)$interface="AIF";
				else if($interface==2)$interface="ABIS";
				else if($interface==5)$interface="R2";
				echo "<td width=\"13%\"><a href=\"./objShow.php?language=$language&objectid=BtsMgr_Shelf_Card_Port.$btsid.0.1.1&tablename=OMCR_E1port&bssid=$bssid\";>Port 1</a>";

				echo "</td>";
				echo "<td width=\"20%\">$adminstate</td>";
				echo "<td width=\"20%\">$operstate</td>";
				echo "<td width=\"20%\">$availstatus</td>";
                echo "<td width=\"15%\">$interface</td>";
				echo "</tr>";
//Clock Module
$sqlstring = "select Presence from OMCR_BSSTREE where ObjectId='BtsMgr_Shelf_Card.$btsid.0.17' 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))
				{
					$presence =$row[0];
				}
			if($presence==1){
			
			echo "<tr>";
				echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
		
				echo "<td width=\"25%\"><a href=\"./objShow.php?language=$language&objectid=BtsMgr_Shelf_Card.$btsid.0.17&tablename=OMCR_ClockMod&bssid=$bssid\";>ClockModule</a></td>";
				echo "<td width=\"20%\">--</td>";
				echo "<td width=\"20%\">--</td>";
				echo "<td width=\"20%\">--</td>";
				echo "<td width=\"15%\">--</td>";
				echo "</tr>";
			}//if presence==1
	
		}//if card presence==1
echo "</table>";
echo "</td>";
echo "</tr>";
}//end btsid!=0
$sqlstring = "select Presence from OMCR_BSSTREE where ObjectId='BtsMgr_Software.$btsid.0' 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))
				{
					$presence =$row[0];
				}

//Software
if($presence==1){
echo "<tr>";
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\"><b>Software</b></td>";
echo "<td>";
$sqlstring = "select CurrentFlashVersion,PrimaryFlashVersion,SecondaryFlashVersion from OMCR_Software where bssid=$bssid and ObjectId like 'BtsMgr_Software.$btsid.0'";
			    //echo $sqlstring . "<BR>";
				$result = mysqli_query($pubConn,$sqlstring) or
				die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
				
				while($row = mysqli_fetch_row($result))
				{
					list($cfv,$pfv,$sfv) =$row;
				}
				echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"25%\">CurrentFlashVersion</td>";
				echo "<td width=\"40%\">PrimaryFlashVersion</td>";
				echo "<td width=\"30%\">SecondaryFlashVersion</td>";
				echo "</td>";
			echo "</tr>";
			
           
				echo "<td width=\"25%\"><a href=\"./objShow.php?language=$language&objectid=BtsMgr_Software.$btsid.0&tablename=OMCR_Software&bssid=$bssid\";>\"$cfv\"</a></td>";
				echo "<td width=\"35%\"><a href=\"./objShow.php?language=$language&objectid=BtsMgr_Software.$btsid.0&tablename=OMCR_Software&bssid=$bssid\";>\"$pfv\"</a></td>";
				echo "<td width=\"35%\"><a href=\"./objShow.php?language=$language&objectid=BtsMgr_Software.$btsid.0&tablename=OMCR_Software&bssid=$bssid\";>\"$sfv\"</a></td>";
			    echo "</table>";
                echo "</tr>";
}//end presence==1

?>
