<?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 " > AIf ";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<br>";
?>
<?php
function flash($bssid)
{
	echo "<script language=\"javascript\">";
			$href="$PHP_SELF?bssid=$bssid";
	echo "window.location.href='$href';";
	echo "</script>";
}
if($addtype=='ALink')
{
	if($linkno > 3)
			{
				echo "<script LANGUAGE=\"JavaScript\">";
		        echo "alert(\"ALink number is too big!\");";
		        echo "</script>";
			}
			else
	{
		$nmicmd="create ALink ".$linkno;
		$objectid="ALinkSet.0.0";
		putcommand($bssid,$objectid,$nmicmd);
		sleep(1);
		flash($bssid);
	}
	
}
if($deltype=='ALink')
{
	//echo "ALink is OK!<br>";
	$nmicmd="delete ALink ".$linkno;
	$objectid="ALinkSet.0.0";
	putcommand($bssid,$objectid,$nmicmd);
	flash($bssid);
}
//$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_data('$upload','$bssid')\">";
		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

echo "<tr>";
echo "<td width=\"20%\" bgcolor=\"#E6E6E6\"><b>LinkSet</b></td>";
echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			echo "<tr bgcolor=\"#E6E6E6\">";
				echo "<td width=\"20%\">SPC</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>";

			echo "<tr>";
				$sqlstring = "select AdminState,OperState,AvailStatus,TheirPC from OMCR_ALinkSet where 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,$theirpc) =$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 "<td width=\"20%\"><a href=\"./objShow.php?language=$language&objectid=ALinkSet.0.0&tablename=OMCR_ALinkSet&bssid=$bssid\";<b>$theirpc</b></a></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>";

echo "<tr>" ;
		$sqlstring = "select ObjectId from OMCR_BSSTREE where engDisplayName like 'ALink%' 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($object[])=$row;//e.g ALink.0.0.(0~3)
				}
				$no_of_link=count($object);
				$array = array(0, 1, 2, 3, 4);
//print_r($array);

for($n=0;$n<$no_of_link;$n++)
{
	$link_num = explode(".",$object[$n]);
	$num[$n] = $link_num[3];
	unset($array[$num[$n]]);
}
$array = array_values($array);
//print_r($array);

		echo "<td bgcolor=\"#E6E6E6\">";
			$linkno = $array[0];
			
			$addtype =  'ALink';
			$objectid = 'ALinkSet.0.0';
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\" ><tr >";
			echo "<td align=left><b>ALink</b></td>";
			echo "<td align=\"right\"><a href=\"javascript:addTheObj('$bssid','$objectid','-1','-1','$linkno','$addtype')\">+</a></td>";
			echo "</tr></table>";
		echo "</td>";
echo "<td>";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
			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%\">Delete</td>";
				echo "</td>";
			echo "</tr>";
			for($i=0;$i<$no_of_link;$i++)
			{
				$alink = explode(".",$object[$i]);
				
				$alinkno = $alink[3];
				$sqlstring = "select AdminState,OperState,AvailStatus from OMCR_ALink where ObjectId='Alink.0.0.$alinkno' 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) =$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 onMouseOver=\"this.bgColor='#D2F0FF'\" onMouseOut=\"this.bgColor='#ffffff'\">";
			echo "<table width=\"100%\" cellpadding=\"1\" cellspacing=\"0\">";
				
				echo "<td width=\"20%\"><a href=\"./objShow.php?language=$language&objectid=ALink.0.0.$alinkno&tablename=OMCR_ALink&bssid=$bssid\";>$alinkno</a></td>";
				
				echo "<td width=\"20%\">$adminstate</td>";
				echo "<td width=\"20%\">$operstate</td>";
				echo "<td width=\"20%\">$availstatus</td>";
				
						$deltype="ALink";
						$linkno = $i;
						$objectid = "ALinkSet.0.0";
				echo "<td width=\"20%\">";
				echo "<input type=\"checkbox\" name=\"select this\" title=\"Select this to delete\"  value=\"1\" onClick=\"javascript:delTheObj('$bssid','$objectid','-1','-1','$linkno','$deltype',this)\"></td>";
				
			   
            echo "</tr>";
			}
			echo "</table>";
echo "</td>";
echo "</tr>";

echo "</tr>";
?>

