<?php
//
// Created on: 22 Feb 2001
// Usage: btsmeasurements.php
//        btsmeasurements.php?language="eng|gb"
//                            [&bssid=0]
//                            [&offset=XXX]
//                            [&perBssid=XXX]
//                            [&perCellid=XXX]
//                            [&perStartPeriod=XXX]
//                            [&perEndPeriod=XXX]
//                       
// Function: Display BSS Statistics from offset to offset+stepsize
//           Stepsize for each page ($stepsize) is default to 14
//
// Filter  : Support filter per bssid, per cellid, time
//                       
// MySQL table involved: OMCR_GeneralReport, OMCR_Meta_Statistics
//
?>
<?php
include("nocache.inc");
include("btsmeasurements.inc");
if (!isset($language))
    $language="eng";
$parameter = "${language}namearray";	// use of variable variables
$stepsize=14;
?>
<HTML>
<HEAD>
<META HTTP-EQUIV="Refresh" content="10">
<?php include("header.inc"); ?>
<SCRIPT language="JavaScript" type="text/javascript">
<!--
    function show_status(status, alarm)
    {
       if (typeof(status) == "undefined" );
    }


    function go_to_webpage(myForm)
    {
        if (myForm.gotopage.value == '')
            myForm.gotopage.value = 1;
        else if (myForm.gotopage.value <= 0)
            myForm.gotopage.value = 1;

<?php
        echo "window.location.href=\"btsmeasurements.php?language=$language";
        echo (isset($bssid)? "&bssid=$bssid":"") .
        (isset($perBssid)? "&perBssid=$perBssid":"") .
        (isset($perCellid)? "&perCellid=$perCellid":"") .
        (isset($perStartPeriod)? "&perStartPeriod=$perStartPeriod":"") .
        (isset($perEndPeriod)? "&perEndPeriod=$perEndPeriod":"");
        echo "&offset=\" + $stepsize * (myForm.gotopage.value - 1);";
?>

    }
//-->
</SCRIPT>
<TITLE> ALARM EVENT </TITLE>
</HEAD>
<BODY onLoad='show_status("<?=$status?>","<?=$alarm?>");'>
<FORM name='stattable'>
<?php

$status="";

include("login_parm.inc");

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

$sqlstring = "select count(*) from OMCR_GeneralReport WHERE Cellid>0 and Time>0" .
             (isset($perBssid)? " AND Bssid=$perBssid":"") .
             (isset($perCellid)? " AND Cellid=$perCellid":"") .
             (isset($perStartPeriod)? " AND Time>='$perStartPeriod'":"") .
             (isset($perEndPeriod)? " AND Time<='$perEndPeriod'":"");
echo $sqlstring . "<BR>";
$result = mysql_query($sqlstring,$db) or
          die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
list($no_of_records) = mysqli_fetch_row($result);
mysql_free_result($result);

if (!isset($offset))
{
    $offset = 0;
}

echo "<TABLE border=1 cellspacing=0 cellpadding=0 bordercolor=#000000 " .
     "bordercolordark=#FFFFFF bordercolorlight=#000000 width=800>\n";
echo "<TR>\n";
echo "<TD width=20%>\n";
echo ${$parameter}[total] . ": " .$no_of_records . " " . ${$parameter}[pages];
echo "</TD>\n";
echo "<TD width=15%>\n";
echo "$stepsize " . ${$parameter}[record] . "/" . ${$parameter}[pages];
echo "</TD>\n";
echo "<TD width=35%>\n";
if ($no_of_records)
     echo (floor($offset/$stepsize) + 1) . "/" .
          (ceil($no_of_records/$stepsize)) . " " . ${$parameter}[pages];
else
     echo "0/0 " . ${$parameter}[pages];
echo "</TD>\n";
echo "<TD width=30%>\n";
echo "<INPUT type=button value={${$parameter}[go]} onClick='go_to_webpage(this.document.stattable);'>";
echo "<INPUT type=TEXT name=gotopage size=4> ";
echo "{${$parameter}[pages]}&nbsp&nbsp&nbsp";

//echo $offset . "-" . $stepsize;
    if ($offset > $stepsize-1)
    {
        //if ($offset < $stepsize) $offset=0;
        echo "<INPUT type=image value='<-' src='images/st_minus.gif' onClick='" .
             "javascript:window.location.href=\"btsmeasurements.php?" .
             "language=$language" .
             (isset($bssid)? "&bssid=$bssid":"") .
             (isset($perBssid)? "&perBssid=$perBssid":"") .
             (isset($perCellid)? "&perCellid=$perCellid":"") .
             (isset($perStartPeriod)? "&perStartPeriod=$perStartPeriod":"") .
             (isset($perEndPeriod)? "&perEndPeriod=$perEndPeriod":"") .
             "&offset=" . ($offset-$stepsize) . "\"'>";
    }
    else
    {
        echo "<INPUT type=image value='>-' src='images/gt_minus.gif' onClick='" .
             "javascript:window.location.href=\"btsmeasurements.php?" .
             "language=$language" .
             (isset($bssid)? "&bssid=$bssid":"") .
             (isset($perBssid)? "&perBssid=$perBssid":"") .
             (isset($perCellid)? "&perCellid=$perCellid":"") .
             (isset($perStartPeriod)? "&perStartPeriod=$perStartPeriod":"") .
             (isset($perEndPeriod)? "&perEndPeriod=$perEndPeriod":"") .
             "&offset=" . $offset . "\"'>";
    }
//echo $offset . "-" . $stepsize;
    if ($no_of_records > $offset + $stepsize)
    {
        echo "<INPUT type=image value='->' src='images/minus_gt.gif' onClick='" .
             "javascript:window.location.href=\"btsmeasurements.php?" .
             "language=$language" .
             (isset($bssid)? "&bssid=$bssid":"") .
             (isset($perBssid)? "&perBssid=$perBssid":"") .
             (isset($perCellid)? "&perCellid=$perCellid":"") .
             (isset($perStartPeriod)? "&perStartPeriod=$perStartPeriod":"") .
             (isset($perEndPeriod)? "&perEndPeriod=$perEndPeriod":"") .
             "&offset=" . ($offset+$stepsize) . "\"'>";
    }
    else
    {
        echo "<INPUT type=image value='-<' src='images/minus_st.gif' onClick='" .
             "javascript:window.location.href=\"btsmeasurements.php?" .
             "language=$language" .
             (isset($bssid)? "&bssid=$bssid":"") .
             (isset($perBssid)? "&perBssid=$perBssid":"") .
             (isset($perCellid)? "&perCellid=$perCellid":"") .
             (isset($perStartPeriod)? "&perStartPeriod=$perStartPeriod":"") .
             (isset($perEndPeriod)? "&perEndPeriod=$perEndPeriod":"") .
             "&offset=" . $offset . "\"'>";
    }
echo "</TD>\n";
echo "</TR>\n";
//echo "</TABLE>\n";
echo "<TR><TD colspan=4>\n";
echo "<TABLE border=1 cellspacing=0 cellpadding=0 bordercolor=#000000 " .
     "bordercolordark=#FFFFFF bordercolorlight=#000000 width=800>\n";

$sqlstring = "select ${language}DisplayName,FieldName,${language}Remarks " .
             "from OMCR_Meta_Statistics";
//echo "$sqlstring<BR>";
$result = mysql_query($sqlstring,$db) or
          die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
echo "<TR>\n";
echo "<TD nowrap bgcolor=#D0D0D0>{${$parameter}[bssid]}</TD>";
echo "<TD nowrap bgcolor=#D0D0D0>{${$parameter}[cellidentity]}</TD>";
echo "<TD nowrap bgcolor=#D0D0D0>{${$parameter}[time]}</TD>";
while ( $row = mysqli_fetch_row($result) )
{
    $fieldname[] = $row[1];
    echo "<TD nowrap bgcolor=#D0D0D0 title='{$row[2]}'>";
    echo "$row[0]";
    echo "</TD>\n";
}
echo "</TR>\n";
mysql_free_result($result);

$sqlstring = "select Bssid,Cellid,Time," . join(",",$fieldname) .
             " from OMCR_GeneralReport where Cellid>0 and Time>0" .
             (isset($perBssid)? " AND Bssid=$perBssid":"") .
             (isset($perCellid)? " AND Cellid=$perCellid":"") .
             (isset($perStartPeriod)? " AND Time>='$perStartPeriod'":"") .
             (isset($perEndPeriod)? " AND Time<='$perEndPeriod'":"");
if ($offset >= 0)
{
    $sqlstring .= " ORDER BY Time DESC LIMIT $offset,$stepsize";
}
else
{
    $sqlstring .= " ORDER BY Time DESC LIMIT 0," .  ($stepsize+$offset);
}

//echo $sqlstring . "<BR>";
$result = mysql_query($sqlstring,$db) or
          die("Invalid query: $sqlstring\n" . mysqli_error($pubConn));
$no_of_fields = mysql_num_fields($result);

while ( $row = mysqli_fetch_row($result) )
{
    echo "<TR>";
    for ($i=0;$i<$no_of_fields;$i++)
    {
        printf("<TD height=30>%s</TD>\n",(isset($row[$i])? $row[$i]:"-"));
    }
    echo "</TR>\n";
}
echo "</TABLE>\n";
if (mysqli_num_rows($result) == 0)
   echo "<BR><CENTER><FONT color=cyan>{${$parameter}[norecord]}</FONT></CENTER><BR>";
echo "</TD>\n";
echo "</TR>\n";
echo "</TABLE>\n";
echo "</FORM>\n";

mysql_free_result($result);
?>
</BODY>
</HTML>
