<?php

require("../../inc/header.inc");
require("logdb.inc");
require("function.php");

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 "> AssignTrx for Bts.$btsid.$cellid</td>";
echo "</tr>";
echo "</table>";
echo "<br>";

function flash($bssid,$btsid,$cellid)
{
	$sqlstring = "select ObjectId from OMCR_BSSTREE where ObjectId like 'Trx.$btsid%' and Presence=1 and ObjectId not like 'Trx.$btsid.$cellid%' and bssid=$bssid";
			    //echo $sqlstring . "<BR>";
				$result = mysqli_query($pubConn,$sqlstring) or
				die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
			
	echo "<script language=\"javascript\">";
			$href="./bss_assigntrx.php?bssid=$bssid&btsid=$btsid&cellid=$cellid";
	echo "window.location.href='$href';";
	echo "</script>";
}
if($deltype=='AssignTrx')
{
	$nmicmd="action 9:4 ".$trxnum;
	$objectid="Bts.".$btsid.".".$cellid;
	putcommand($bssid,$objectid,$nmicmd);
/*	$sqlstring = "select ObjectId from OMCR_BSSTREE where ObjectId like 'Trx.$btsid%' 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_object_name[]) =$row;
	}
	for($i=0;$i<count($trx_object_name);$i++)
	{
		$nmicmd = "get";
		$objectid = $trx_object_name[$i];
		putcommand($bssid,$objectid,$nmicmd);
		
	}*/
//	$nmicmd="upload 12";
//	$objectid="BssFunc";
//	putcommand($bssid,$objectid,$nmicmd);
	sleep(3);
	flash($bssid,$btsid,$cellid);
	
//	flash($bssid,$btsid,$cellid);
}


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 "</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

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

echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"25%\">BtsMgrNumber</td>";
				echo "<td width=\"25%\">BtsNumber</td>";
				echo "<td width=\"25%\">TrxNumber</td>";
				echo "<td width=\"25%\">Assign to Bts.$btsid.$cellid</td>";
				echo "</td>";
			echo "</tr>";

			$sqlstring = "select ObjectId from OMCR_BSSTREE where ObjectId like 'Trx.$btsid%' and Presence=1 and ObjectId not like 'Trx.$btsid.$cellid%' 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_object_name[]) =$row;
				}
				$no_of_trx = count($trx_object_name);//e.g RCarrier.0.0.4

          for($i=0;$i<$no_of_trx;$i++)
         {
			  $trx_cont = explode(".",$trx_object_name[$i]);
			  echo "<tr>";
			  echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			
				
				echo "<td width=\"25%\">BtsMgr $trx_cont[1]</td>";
				echo "<td width=\"25%\">Bts $trx_cont[2]</td>";
				echo "<td width=\"25%\">Trx $trx_cont[3]</td>";
				echo "<td width=\"25%\">";
				$trxnum = $trx_cont[3];
				$objectid = "Bts.".$btsid.".".$cellid;
				$deltype = "AssignTrx";
				echo "<input type=\"checkbox\" name=\"select this\" title=\"Select this to assign\"  value=\"1\" onClick=\"javascript:AssignTrx('$bssid','$objectid','$btsid','$cellid','$trxnum','$deltype',this)\"></td>";
				echo "</tr>";
		 }
			    echo "</table>";
            echo "</tr>"; 
echo "</td>";
echo "</tr>";

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

echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
		/*	echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"25%\">BtsMgrNumber</td>";
				echo "<td width=\"25%\">BtsNumber</td>";
				echo "<td width=\"25%\">TrxNumber</td>";
				echo "<td width=\"25%\"></td>";
				echo "</td>";
			echo "</tr>";
*/
			$sqlstring = "select 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_object[]) =$row;
				}
				$no_of_trx_1 = count($trx_object);//e.g RCarrier.0.0.4

          for($i=0;$i<$no_of_trx_1;$i++)
         {
			  $trx_cont = explode(".",$trx_object[$i]);
			  echo "<tr>";
			  echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			
				
				echo "<td width=\"25%\">BtsMgr $trx_cont[1]</td>";
				echo "<td width=\"25%\">Bts $trx_cont[2]</td>";
				echo "<td width=\"25%\">Trx $trx_cont[3]</td>";
				echo "<td width=\"25%\"></td>";
				
				echo "</tr>";
		 }
			    echo "</table>";
            echo "</tr>"; 
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>Note: If you want to assign trx,you must <b>Lock AbisMgr</b> !";
?>