<?php
//
// Created on: 22 Feb 2001
// Usage     : bssstatus.php?bssid=0
//
// Function  : To display updated alarm status for a BSS
//
// Remarks   : 1. This page is required to refresh until dismiss
//             2. Critical and major alarms are represented by "down" image.
//                Minor alarms are represented by "warning" image.
//                Warning is not seen on the status diagram.
//
// bssfunc.php ___ bssstatus.php   (upper)
//             \__ bssfuncinfo.php (bottom)
//
//  ________________________    ____   ___
// |100|101|200|201|300|301| .. |k01|   ^
// |   |102|   |202|   |302|    |k02|   |
//  ------------------------     ---    |
// |110|111|210|211|310|311|    |k11|   |
// |   |112|   |212|   |312|    |k12| j rows
//  ..  ..  ..  ..  ..  ..              |
//  ..  ..  ..  ..  ..  ..              |
// |1j0|1j1|2j0|2j1|3j0|3j1|    |kj1|   |
// |   |1j2|   |2j2|   |3j2|    |kj2|   v
// `------------------------    ----   --- 
//
//  ________________________    ____   ___
// |400|401|500|501|600|601| .. |k01|   ^
// |   |402|   |502|   |602|    |k02|   |
//  ------------------------     ---    |
// |410|411|510|511|610|611|    |k11|   |
// |   |412|   |512|   |612|    |k12| j rows
//  ..  ..  ..  ..  ..  ..              |
//  ..  ..  ..  ..  ..  ..              |
// |4j0|4j1|5j0|5j1|6j0|6j1|    |kj1|   |
// |   |4j2|   |5j2|   |6j2|    |kj2|   v
// `------------------------    ----   --- 
?>
<?php
include("nocache.inc");
include("bssstatus.inc");
if (!isset($language))
    $language="eng";
$parameter="${language}namearray";
include("header.inc");
?>
<HTML>
<HEAD>
<META HTTP-EQUIV="Refresh" content="10">
<title>BSS Status</title>
</HEAD>
<BODY>

<B><FONT color="#0000FF"><?=${$parameter}[bssstatus]?></FONT></B><BR> 
<?php
include("login_parm.inc");
include("alarmimage.inc");

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

$sqlstring = "SELECT ObjectId, Signal_Element, MaxSeverity " .
             "from OMCR_BSSTREE WHERE bssid=$bssid AND Presence=1";
//echo "$sqlstring <BR>";
$result = mysql_query($sqlstring,$db) or
          die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
while ( $row = mysqli_fetch_row($result) )
{
    list($objectid[],$signal_element[],$maxseverity[]) = $row;
}
$no_of_objects = mysqli_num_rows($result);

// Get the max severity for each display entity
for ($i=0;$i<$no_of_objects;$i++)
{
    //
    // if not exist, simple set it
    // or update alarm level if there is no alarm now
    // or update the alarm level if more severity alarm is found
    //
    if (!isset($alarmslot[$signal_element[$i]]))
        $alarmslot[$signal_element[$i]] = $maxseverity[$i];
    else if ($alarmslot[$signal_element[$i]] == 0)
        $alarmslot[$signal_element[$i]] = $maxseverity[$i];
    else if (($alarmslot[$signal_element[$i]] > $maxseverity[$i]) && ($maxseverity[$i] <>0))
        $alarmslot[$signal_element[$i]] = $maxseverity[$i];
}
if (!isset($alarmslot))
    return;

//while (list($key,$val) = each($alarmslot))
//    echo "$key => $val <br>";

$no_of_daisychain=4;
$no_of_iwbox=3; // BSC+BTS1+BTS2+BTS3
$no_of_slots=5; // IWP+E1+E1+TRX4+TRX6 = 5 slots
$no_of_bsc_slots=9;
echo "<TABLE border=0 cellspacing=0 cellpadding=0>\n";
echo "<TR>";
echo "<TD width=25%>";
echo "<TABLE border=0 cellspacing=0 cellpadding=0>\n";

$i=0;
for ($j=0;$j<$no_of_bsc_slots;$j++)
{
    echo "<TR>\n";
    for ($k=0;$k<=1;$k++)
    {
        $persignal_element[$k]="";		// reset to empty in each round
        $perseverity[$k]="";		// reset to empty in each round
        $index="${i}${j}${k}";
		//echo "index=$index;";
        if ( !isset($alarmslot[$index]) )  // Not presence
            $image[$k] = "";
            //$image[$k] = $white;
        else if (( $alarmslot[$index] == 0) || // No alarm/warning/minor
                 ($alarmslot[$index] > 2))
        {
            $imagename = "img${index}_up";
            $image[$k] = ${$imagename};
        }
        else if ( $alarmslot[$index] == 1)  // Alarmed if Critical
        {
            $imagename = "img${index}_down";
			//echo "imagename=$imagename";
            $image[$k] = ${$imagename};
            $persignal_element[$k]="&perSignal_Element=$index";
            //$perseverity[$k]="&perSeverity=1";
            $perseverity[$k]=htmlspecialchars("&perSeverity==1");
        }
        else if ( $alarmslot[$index] == 2)  // warned if Major
        {
            $imagename = "img${index}_warn";
            $image[$k] = ${$imagename};
            $persignal_element[$k]="&perSignal_Element=$index";
            //$perseverity[$k]="&perSeverity=2";
            $perseverity[$k]=htmlspecialchars("&perSeverity==2");
        }
    }

    // if the machine exist, print empty slot for not existing object
    if (( $image[0] == "") && isset($alarmslot["${i}00"]))
    {
       echo "<TD rowspan=2 width=87 height=15>$slot</TD>\n";
       //echo "<TD rowspan=2 width=87 height=15>${i}00</TD>\n";
    }
    else
    {
       if ($persignal_element[0] == "")
           echo "<TD rowspan=2 width=87 height=15>$image[0]</TD>\n";
       else
           echo "<TD rowspan=2 width=87 height=15><A onClick='javascript:parent.parent.location.href=\"alarmframe.php?language=$language&bssid=$bssid&perBssid=$bssid$persignal_element[0]$perseverity[0]\"'>$image[0]</A></TD>\n";
    }
    if ($persignal_element[1] == "")
        echo "<TD width=87 height=7>$image[1]</TD>\n";
    else
        echo "<TD width=87 height=7><A onClick='javascript:parent.parent.location.href=\"alarmframe.php?language=$language&bssid=$bssid&perBssid=$bssid$persignal_element[1]$perseverity[1]\"'>$image[1]</A></TD>\n";

    echo "</TR>\n";
    echo "<TR>\n";

    $k = 2;
    $index="${i}${j}${k}";
    if ( !isset($alarmslot[$index]) )  // Not presence
        $image[$k] = "";
        //$image[$k] = $white;
    else if (( $alarmslot[$index] == 0) || // No alarm
            ( $alarmslot[$index] >= 3))
    {
        $imagename = "img${index}_up";
        $image[$k] = ${$imagename};
    }
    else if ( $alarmslot[$index] < 3)  // Alarmed
    {
        $imagename = "img${index}_down";
        $image[$k] = ${$imagename};
    }
    else if ( $alarmslot[$index] > 0)  // warning
    {
        $imagename = "img${index}_warn";
        $image[$k] = ${$imagename};
    }
    echo "<TD width=87 height=7>$image[2]</TD>\n";
    echo "</TR>\n";
}

echo "</TABLE>\n";
echo "</TD>";
echo "<TD>";
echo "<TABLE border=0 cellspacing=0 cellpadding=0>\n";
for ($l=0;$l<$no_of_daisychain;$l++)
{
    for ($j=0;$j<$no_of_slots;$j++)
    {
        echo "<TR>\n";
        for ($i=1;$i<=$no_of_iwbox;$i++)
        {
            for ($k=0;$k<=1;$k++)
            {
                $persignal_element[$k]="";		// reset to empty in each round
                $btsno=$i+$l*$no_of_iwbox;
                $index="${btsno}${j}${k}";
                if ( !isset($alarmslot[$index]) )  // Not presence
                    $image[$k] = "";
                    //$image[$k] = $white;
                else if (( $alarmslot[$index] == 0) || // No alarm/warning/minor
                         ($alarmslot[$index] > 2))
                {
                    $imagename = "img${index}_up";
                    $image[$k] = ${$imagename};
                }
                else if ( $alarmslot[$index] == 1)  // Alarmed if Critical
                {
                    $imagename = "img${index}_down";
                    $image[$k] = ${$imagename};
                    $persignal_element[$k]="&perSignal_Element=$index";
                    //$perseverity[$k]="&perSeverity=1";
                    $perseverity[$k]=htmlspecialchars("&perSeverity==1");
                }
                else if ( $alarmslot[$index] == 2)  // warned if Major
                {
                    $imagename = "img${index}_warn";
                    $image[$k] = ${$imagename};
                    $persignal_element[$k]="&perSignal_Element=$index";
                    //$perseverity[$k]="&perSeverity=2";
                    $perseverity[$k]=htmlspecialchars("&perSeverity==2");
                }
            }
    
            // if the machine exist, print empty slot for not existing object
            if ( $image[0] == "")
            {
                if (isset($alarmslot["${btsno}00"]))
                {
                    echo "<TD rowspan=2 width=87 height=15>$slot</TD>\n";
                    //echo "<TD rowspan=2 width=87 height=15>${i}00</TD>\n";
                }
                else
                {
                    if ($j == 0)
                        echo "<TD rowspan=2>$whiteslot</TD>\n";
                    else
                        echo "<TD rowspan=2 width=87 height=15></TD>\n";
                }
            }
            else
            {
                if ($persignal_element[0] == "")
                    echo "<TD rowspan=2 width=87 height=15>$image[0]</TD>\n";
                else
                    echo "<TD rowspan=2 width=87 height=15><A onClick='javascript:parent.parent.location.href=\"alarmframe.php?language=$language&bssid=$bssid&perBssid=$bssid$persignal_element[0]$perseverity[0]\"'>$image[0]</A></TD>\n";
            }

            if ( $image[1] == "")
            {
                if ($j == 0)
                    echo "<TD width=87>$white</TD>\n";
                else
                    echo "<TD width=87 height=7></TD>\n";
            }
            else
            {
                if ($persignal_element[1] == "")
                    echo "<TD width=87 height=7>$image[1]</TD>\n";
                else
                    echo "<TD width=87 height=7><A onClick='javascript:parent.parent.location.href=\"alarmframe.php?language=$language&bssid=$bssid&perBssid=$bssid$persignal_element[1]$perseverity[1]\"'>$image[1]</A></TD>\n";
            }
        }
        /* end_of_for ($i=1;$i<=$no_of_iwbox;$i++) */
    
        echo "</TR>\n";
        echo "<TR>\n";
        for ($i=1;$i<=$no_of_iwbox;$i++)
        {
            $k = 2;
            $index="${i}${j}${k}";
            if ( !isset($alarmslot[$index]) )  // Not presence
            {
                $image[$k] = "";
                //$image[$k] = $white;
            }
            else if (( $alarmslot[$index] == 0) || ( $alarmslot[$index] >= 3)) // No alarm
            {
                $imagename = "img${index}_up";
                $image[$k] = ${$imagename};
            }
            else if ( $alarmslot[$index] < 3)  // Alarmed
            {
                $imagename = "img${index}_down";
                $image[$k] = ${$imagename};
            }
            else if ( $alarmslot[$index] > 0)  // warning
            {
                $imagename = "img${index}_warn";
                $image[$k] = ${$imagename};
            }
            echo "<TD width=87 height=7>$image[2]</TD>\n";
        }
        /* end_of_for ($i=1;$i<=$no_of_iwbox;$i++) */
        echo "</TR>\n";
    }
    /* end_of_for ($j=0;$j<$no_of_slots;$j++) */
    
    echo "<TR>\n";
    //if (isset($alarmslot["100"]))
    //   echo "<TD align=center>BSC</TD><TD></TD>\n";
    //else
    //   echo "<TD></TD><TD></TD>\n";
 
    for ($i=1;$i<=$no_of_iwbox;$i++)
    {
        $btsno=$i+$l*$no_of_iwbox;
        if (isset($alarmslot["${btsno}00"]))
            echo "<TD align=center>BTS " . $btsno .  "</TD><TD></TD>\n";
        else
            echo "<TD></TD><TD></TD>\n";
    }
    echo "</TR>";
}   
echo "</TABLE>";
echo "</TD>";
echo "</TR>";
echo "</TABLE>";
echo "<CENTER>";
//echo "______________________<BR>";
echo "|<FONT color=red>{${$parameter}[critical]}</FONT>|<FONT color=orange>{${$parameter}[major]}</FONT>|<FONT color=blue>{${$parameter}[normal]}</FONT>|";
echo "</CENTER>";
?>
</BODY>    
</HTML>    
