<?php
//
// Created on: 22 Feb 2001
// This is only used by BSSOMC only case
// For integration with TS_OMC, use dropbss.php instead
// 
// Usage: mydropbss.php?language="gb|eng"
//                      &bssid=0
//                      &ip=172.18.250.100
//
?>
<?php
include("nocache.inc");
include("header.inc");
include("login_parm.inc");

$db = mysql_connect($hostname, $username, $password);
mysql_select_db($dbname,$db);


$sqlstring = "SELECT row_no FROM OMCR_COMMAND WHERE status=0 " .
             "ORDER BY seqNum ASC LIMIT 10";
//echo "$sqlstring<BR>";
$res = mysql_query($sqlstring ,$db) or
          die("Invalid query:$sqlstring\n" . mysqli_error($pubConn));
while (list($row_no[]) = mysqli_fetch_row($res));
$no_of_rows = mysqli_num_rows($res);
mysql_free_result($res);

$sqlstring = "SELECT ip FROM OMCR_BSSTABLE WHERE bssid=$bssid";
//echo "$sqlstring<BR>";
$res = mysql_query($sqlstring ,$db) or
          die("Invalid query:$sqlstring\n" . mysqli_error($pubConn));
list($ip) = mysqli_fetch_row($res);
mysql_free_result($res);

if ( $no_of_rows <= 0 || ($no_of_rows > 10) )
{
    //
    // No available row in OMCR_COMMAND
    // Send error to MySQL()
    //
    header("Location: " .
        "objects.php?language=$language&bssid=$bssid&objectid=$objectid" .
        "&tablename=$tablename" .
        "&status='Command table is full: Wait and send the command again'"
    );
    return;
}

//
// Insert the delete bss commands in OMCR_COMMAND out of 10 available rows
//
$i=0;
do
{
    if ($row_no[$i] != '')
    {
        $sqlstring = "REPLACE INTO OMCR_COMMAND VALUES(" .
            "{$row_no[$i]},-1,'dropbss $bssid $ip',null,255,-1,null,null,null)";
        $res       = mysql_query($sqlstring ,$db) or
                     die("Invalid query:$sqlstring\n" . mysqli_error($pubConn));
    }
    $i++;
} while ($i<10 && mysql_affected_rows() != 2);
if ($i<10)
    echo "BSS deletion is successful";
else
    echo "BSS deletion is failed";
?>

