<%@ page language="java" import="java.util.*,java.sql.*,java.sql.Date,java.sql.Time,java.net.*,java.awt.*,java.awt.image.*,javax.swing.*,java.io.*"%>

<%
    String timespan;
    String environmentParameter;
	String eboxId;
	%>
	
<html>
<head>
<title>Current Data for All monitored items</title>
</head>
<jsp:useBean id="em" scope="session" class="EntrakMain"/>
<jsp:useBean id="sql" scope="session" class="SQLStatement"/>
<script>
  function loadFrame(url,target) {
        var newWin=window.open(url,target);		
        newWin.location.replace(url);
		//updated from newWin.location.reload();
    } //function loadFrame(url,target)
</script>
<body>
<%
			timespan=request.getParameter("resolution");
			eboxId=request.getParameter("eboxId");
%>
<table BORDER ="1"  ALIGN="center" CELLSPACING ="1" CELLPADDING="2" WIDTH="400" >
  <tr> 
	<!--td><b>Zone name</b></td-->
	<td><b> Date time</b></td>	
	<td><b>Item</b></td>
	<td><b>Value</b> </td>
  </tr>
  <%
	String intervalTerm = "3 HOUR";

    sql = new SQLStatement(em.con);
	
	String clName = ClassLoaderName.getName(getClassLoader().toString());
				
    sql.setClassLoaderName(clName);
	
   // String rel_refString = eboxId;  
	String command ="select datetime, m_item,value from smarthomes.monitored" +
                " where ((NOW() - INTERVAL " + intervalTerm + ") <= datetime )" +
                " AND ( NOW() >= datetime )" +
				" AND m_id = "+ "\'"+ eboxId + "\'"+ 
				" order by datetime DESC limit 100";

    ResultSet rs = sql.executeSqlRs(command); 		
	
	int count=0;				 
	
	while (rs.next()){ 
	     
		 String dateString = rs.getString("datetime");		 		 
		 String itemString =rs.getString("m_item");
		 String valueString =rs.getString("value");
%>
  <tr> 
	 
	<td><%=dateString %></td>

	<td><%=itemString %></td>
	<td><%=valueString %></td>
  </tr>
  <%	  		  	 		 		 		 
      count++;
		}	  
if(count ==0) { 		 	 					
%><script>
    
    loadFrame("message_info.jsp?message=No Data available. Check Connection","imgFrame_c");
 </script>
       
<% 
}
%>
</table>
</body>
</html>
