<?php require_once('Connections/osense.php'); ?>
<?php
#mysql_select_db($database_osense, $osense);
$query_lsense = "SELECT * FROM lightsense ORDER BY node_no ASC";
#$lsense = mysql_query($query_lsense, $osense) or die(mysql_error());
$lsense = mysqli_query( $osense,$query_lsense);
$row_lsense = mysqli_fetch_assoc($lsense);
$totalRows_lsense = mysqli_num_rows($lsense);

$numOfCol = 17;
$numOfRow = 9;
$numOfCellInGrid = $numOfCol * $numOfRow;
$critical = 78;
//echo $totalRows_lsense
?>
<html>
<head>
<title>NetEye Light Sensor</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.style1 {
	font-size: xx-large;
	font-weight: bold;
	color: #336666;
}
.border {
	border: medium solid #336666;
}
.con {background-color:#669966;}
.coff {background-color:#FF3333;}
-->
</style>
<link rel="stylesheet" type="text/css" href="sdmenu/sdmenu.css" />
<script type="text/javascript" src="sdmenu/sdmenu.js"></script>
<script type="text/javascript" src="jquery-1.2.2.pack.js"></script>

	<script type="text/javascript">
	    // <![CDATA[
    	var myMenu;
	    window.onload = function() {
		    myMenu = new SDMenu("my_menu");
		    myMenu.init();
    	};
	    // ]]>
	</script>

<script type="text/javascript">
<!-- Begin
function reFresh() {
  location.reload(true)
}
/* Set the number below to the amount of delay, in milliseconds,
you want between page reloads: 1 minute = 60000 milliseconds. */
window.setInterval("reFresh()",1500);
// End -->
</script>

<style type="text/css">
<!--
.STYLE3 {font-size: xx-large}
-->
</style>
</head>

<body>
<table width="1000" height="673" align="center" class="border">
  <tr>
    <td width="150" height="91"><div align="center"><img src="wname.jpg" width="150"><span class="style1"> </span></div></td>
    <td width="679"><div align="center"><span class="style1 STYLE3">NetEye</span></div></td>
    <td width="149"><span class="style1"><img src="wicon.jpg" width="124" height="71"></span></td>
  </tr>
  <tr height="640">
    <td width="150">
	<div style="float: left" id="my_menu" class="sdmenu">
      <div>
        <span>NetEye</span>
        <a href="home.php">Home</a>
        <a href="topology.php">Topology</a>
		<a href="registration.php">Registration Form</a>

      </div>
      <div>
        <span>MySpace</span>
        <a href="login.php">Login</a> 
      </div>

      <div>
        <span>Support</span>
        <a href=http://www.cs.wayne.edu/saifullah/CRI_Lab.html>CRI Research Lab</a>
      </div>

    </div>
	</td>
	<td colspan="2"><div align="center">
	  <p><strong>The light sensor meaurements in different machines are.......</strong></p>
	</div>
      <table width="250" height="302" border="1" align="center">
	  
	  		<tr>
			<td>&nbsp;</td>
			 <?php 
			  $i = 0;
			  do {
				echo "<td>".$i."</td>";			  				  
				$i = $i + 1;
			  } while($i < $numOfCol); ?>
			<td>&nbsp;</td>                 
        </tr>

		<?php
			$rowIndex = 0;
			$cellId = 0;		
			do {										    
				$rowIndex = floor($cellId / $numOfCol);
				
				$inRowPos = $cellId % $numOfCol;
								
				$posX = $rowIndex;
				$posY = $inRowPos;				
				$query_status = 
					"SELECT node_no, ligval 
					 FROM lightsense 
					 where pos_X = ".$posX." and pos_Y = ".$posY.";";
				#$qset = mysql_query($query_status, $osense) or die(mysql_error());
	$qset = mysqli_query($osense,$query_status);
				
				$noPosCode = -99;
				$node_no = $noPosCode;												
				$status = $noPosCode; // node does not exist
				if($row = mysqli_fetch_assoc($qset)) {
					$node_no = $row['node_no'];
					if($row['ligval'] < $critical ){
						$status = 1;
					} else {
						$status = 0;
					}										
				} else {
				  // node does not exist
				}		
					 
				if ($inRowPos == 0) {
					echo "<tr>"; 
					echo "<td>".$rowIndex."</td>";
					if ($status == $noPosCode) echo "<td>&nbsp;</td>";
					if ($status == 0) echo "<td><div align='center' class='con'>".$node_no."<img src='lon.jpg' width='30' height='29'></div></td>";
					if ($status == 1) echo "<td><div align='center' class='coff'>".$node_no."<img src='loff.jpg' width='30' height='29'></div></td>";
				} else if($inRowPos == ($numOfCol - 1)){
					if ($status == $noPosCode) echo "<td>&nbsp;</td>";
					if ($status == 0) echo "<td><div align='center' class='con'>".$node_no."<img src='lon.jpg' width='30' height='29'></div></td>";
					if ($status == 1) echo "<td><div align='center' class='coff'>".$node_no."<img src='loff.jpg' width='30' height='25'></div></td>";
					echo "<td>".$rowIndex."</td>";
					echo "</tr>";
				} else {
					if ($status == $noPosCode) echo "<td>&nbsp;</td>";
					if ($status == 0) echo "<td><div align='center' class='con'>".$node_no."<img src='lon.jpg' width='30' height='29'></div></td>";
					if ($status == 1) echo "<td><div align='center' class='coff'>".$node_no."<img src='loff.jpg' width='30' height='29'></div></td>";
				}
				
				$cellId++;
			} while ($cellId < $numOfCellInGrid);
			
			//mysql_close(lsense);
		?>
	  
		<tr>
			<td>&nbsp;</td>
			 <?php 
			  $i = 0;
			  do {
				echo "<td>".$i."</td>";			  				  
				$i = $i + 1;
			  } while($i < $numOfCol); ?>
			<td>&nbsp;</td>                 
        </tr>
	  
      </table></td>
  </tr>
</table>
</body>
</html>
<?php
mysqli_free_result($lsense);
?>
