<?php include("nocache.inc"); ?>
<HTML>
<HEAD>
<?php include("header.inc"); ?>
</HEAD>
<SCRIPT language="javascript" type="text/javascript">
    function show_status(status,alarm)
    {
        //
        // alarm and status display
        if ((typeof(alarm) != "undefined") && (alarm != ""))
        {
            window.status=alarm;
            alert(alarm);
        }
        else if ((typeof(status) != "undefined") && (status != ""))
        {
            window.status=status;
        }

    }
//window.status = "";
</SCRIPT>
<BODY onLoad='show_status("<?=$status?>","<?=$alarm?>");'>

<?php
if (!isset($language))
    $language = "eng";
$parameter="{$language}namearray";
if (!isset($bssid) || !isset($objectid))
{
    echo "The required information for this page is invalid.<br>\n";
    echo "</BODY>\n</HTML>";
    exit();
}

/************************************************
 * Retrieve the Bts Manager ID from object ID
 * AdjHand.11.0.12 --substr--> 11.0.12 --> 11
 ************************************************/
$btsmgrid = substr($objectid,8);
if ($btsmgrid[1] == '.')
{
    $btsmgrid=substr($btsmgrid,0,1);
}
else if ($btsmgrid[2] == '.')
{
    $btsmgrid=substr($btsmgrid,0,2);
}
else
{
    echo strlen($objectid) . ":Error Object ID:" . $objectid . "\n";
    return 0;
}

    include("adjhand.inc");
    include("login_parm.inc");
    $db = mysql_connect($hostname, $username, $password);
    mysql_select_db($dbname,$db);
    echo "<U><FONT color=#0000FF size=+3pt>=)AdjHand.$btsmgrid.0.*<FONT></U>";
    echo "<HR SIZE=1>\n";

if (!isset($modified_data))
{
    /************************************************
     * Step 1: Display the present neighbor list
     ************************************************/

    /************************************************
     * Generate the Neighbor cell list from SQL DB
     ************************************************/
    $sqlstring = "select Label,CellGlobalIdentityLaiMcc,CellGlobalIdentityLaiMnc," .
                 "LocationAreaCodes,CellGlobalIdentityCi,BcchFrequency,BsIdentityCode," .
                 "NeighbourType,ObjectId from OMCR_AdjHand " .
                 "where bssid=$bssid and BcchFrequency<>-1 and CellGlobalIdentityLaiMcc<>0 " .
                 "and CellGlobalIdentityLaiMnc<>0 and  CellGlobalIdentityCi<>0 " .
                 "and LocationAreaCodes<>0 and ObjectId LIKE 'AdjHand.$btsmgrid.0.%' " .
                 "ORDER BY (0+SUBSTRING_INDEX(ObjectId,'.',-1))";
    //echo $sqlstring . "<BR>";
    $result = mysql_query($sqlstring,$db) or
              die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
    $no_of_fields=mysql_num_fields($result);
    echo "<TABLE border=1 cellspacing=0 cellpadding=0" .
         "bordercolor=#000000 bordercolordark=#FFFFFF bordercolorlight=#000000 width=100%>\n";
    
    echo "<TR>\n";
    echo "<TD width=15%>{${$parameter}[cellname]}</TD>\n";
    echo "<TD width=12%>{${$parameter}[mcc]}</TD>\n";
    echo "<TD width=10%>{${$parameter}[mnc]}</TD>\n";
    echo "<TD width=10%>{${$parameter}[lac]}</TD>\n";
    echo "<TD width=10%>{${$parameter}[cellid]}</TD>\n";
    echo "<TD width=5%>{${$parameter}[bcch]}</TD>\n";
    echo "<TD width=10%>{${$parameter}[bsic]}</TD>\n";
    echo "<TD width=20%>{${$parameter}[neighbortype]}</TD>\n";
    echo "<TD width=8%>{${$parameter}[control]}</TD>\n";
    echo "</TR>\n";
    $num=0;
    while ( $row = mysqli_fetch_row($result) )
    {
	$num++;
	echo "<TR>\n";
	//echo "<TD>$num</TD>\n";
	echo "<TD>" . ($row[0]==''?"-":rawurldecode($row[0])) . "</TD>\n";
	//echo "<TD>$row[0]</TD>\n";
	echo "<TD>$row[1]</TD>\n";
	echo "<TD>$row[2]</TD>\n";
	echo "<TD>$row[3]</TD>\n";
	echo "<TD>$row[4]</TD>\n";
	echo "<TD>$row[5]</TD>\n";
	echo "<TD>$row[6]</TD>\n";
        switch($row[7])
        {
	    case 0:
                echo "<TD>{${$parameter}[activeonly]}</TD>\n";
                break;
	    case 1:
                echo "<TD>{${$parameter}[activeidle]}</TD>\n";
                break;
	    case 2:
                echo "<TD>{${$parameter}[idleonly]}</TD>\n";
                break;
        }
	echo "<TD><A href='javascript:window.location.href=\"modify.php?" .
             "url=adjhand.php" .
             "&language=$language" .
             "&bssid=$bssid" .
             "&objectid=$row[8]" .
             "&nmicommand=set CellGlobalIdentityLaiMcc=0 CellGlobalIdentityLaiMnc=0 CellGlobalIdentityCi=0 LocationAreaCodes=0 BcchFrequency=-1\"" .
             "'>{${$parameter}[delete]}</A>|" .
	     "<A href='javascript:window.location.href=\"objects.php?" .
             "url=adjhand.php" .
             "&language=$language" .
             "&bssid=$bssid" .
             "&objectid=$row[8]" .
             (isset($x)?"&x=$x":"") .
             (isset($y)?"&y=$y":"") .
             "&tablename=OMCR_AdjHand\"" .
             "'>{${$parameter}[modify]}</A></TD>\n";
	echo "</TR>\n";
    }
    if (mysqli_num_rows($result) == 0)
    {
        $no_of_fields += 1;
	echo "<TR><TD align=center colspan=$no_of_fields><FONT color=cyan>" .
             ${$parameter}[noneighbor] . "</FONT></TD></TR>";
    }
    echo "</TABLE>";

    /************************************************
     * Find out the next available Adjhand object ID 
     ************************************************/
    if (mysqli_num_rows($result)<32)
    {
        $sqlstring = "select MIN(0+SUBSTRING_INDEX(ObjectId,'.',-1)) from OMCR_AdjHand where bssid=$bssid and (BcchFrequency=-1 or CellGlobalIdentityLaiMcc=0 or CellGlobalIdentityLaiMnc=0 or CellGlobalIdentityCi=0 or LocationAreaCodes=0) and ObjectId LIKE 'AdjHand.$btsmgrid.0.%'";
        //echo $sqlstring . "<BR>";
        $result = mysql_query($sqlstring,$db) or
              die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
        $row = mysqli_fetch_row($result);
        echo "<HR size=1>\n";
        echo "<FORM name=neighbor_form>";
        echo "<INPUT type=button name=addneighbor value='{${$parameter}[addneighbor]}'" .
             " onClick='javascript:location.href=\"objects.php?" .
             "language=$language" .
             "&bssid=$bssid" .
             "&objectid=AdjHand.$btsmgrid.0.$row[0]" .
             (isset($x)?"&x=$x":"") .
             (isset($y)?"&y=$y":"") .
             "&tablename=OMCR_AdjHand" .
             "\"'>\n";

        echo "<INPUT type=button name='add_neighbor_from_list' value='{${$parameter}[selneighbor]}'" .
             " onClick='javascript:location.href=\"adjhandlist.php?" .
             "language=$language" .
             "&bssid=$bssid" .
             "&objectid=AdjHand.$btsmgrid.0.$row[0]" .
             (isset($x)?"&x=$x":"") .
             (isset($y)?"&y=$y":"") .
             "&tablename=OMCR_AdjHand" .
             "\"'>\n";

        echo "<INPUT type=hidden name='modified_data' value=''>\n";
        echo "<INPUT type=hidden name='bssid' value=$bssid>\n";
        echo "<INPUT type=hidden name='objectid' value=AdjHand.$btsmgrid.0.$row[0]>\n";
        echo "<INPUT type=hidden name='tablename' value=OMCR_AdjHand>\n";
        echo "</FORM>";
    }
}
?>
</BODY>
</HTML>
