<%@ 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.*"%>

<html>
<head>
	<title>Untitled</title>
</head>
<jsp:useBean id="em" scope="session" class="EntrakMain"/>
<jsp:useBean id="sql" scope="session" class="SQLStatement"/>
<body>

<form method="post" action="display_current_temp.jsp">
<h2> Current Indoor Climate Parameters</h2>

<table border ="1">
<tr>
       <td>Zone name</td>	   
       <td><select name ='zone_id' > <option  value ='living-01'> living-01(ebox) <option selected value='bed_room_1' >bed_room_1</select> </td>
       <td>Parameters</td>
       <td><select name ='ic_item' > <option selected value ='temp'> Temp <option  value='MV' >MV(Adam)<option  value='RV' >RV(Adam)</select> </td>	
</td>
</tr>
</table>

<br><br>



<table border ="1"  align="left" cellspacing ="1" cellpadding="10" width="160" >
<tr> 
  <td><b> Zone name</b></td><td><b> Date  </b></td>
  <td><b>Time</b></td><td><b>Item</b></td><td><b>Temperature ('C)</b?</td>
</tr>     
<%

    
    sql = new SQLStatement(em.con);
	
	String clName = ClassLoaderName.getName(getClassLoader().toString());
	
	String zone_id = request.getParameter("zone_id");
	String ic_item = request.getParameter("ic_item");
				
    sql.setClassLoaderName(clName);  
	String command ="select zone_id, date, time, ic_item,value from smarthome.indoor_climate " +
		                 " where zone_id = " +"'"+ zone_id +"'"+" AND " + " ic_item =" + "'"+ic_item+"'" +
						 " order by date DESC, time DESC limit 5 ";
    ResultSet rs = sql.executeSqlRs(command);
    System.out.println(" command :" +command); 						 
	
	while (rs.next()){ 
	     
         String zone_idString = rs.getString("zone_id");		 
		 
		 String dateString = rs.getString("date");
		 
		 String timeString =rs.getString("time");
		 String itemString =rs.getString("ic_item");

		 String valueString =rs.getString("value");
%>
       <tr>
	      <td><%=zone_idString %></td>
		  <td><%=dateString %></td>
		  <td><%=timeString %></td>
		   <td><%=itemString %></td>
		  <td><%=valueString %></td>
	  </tr>
	  <%	  		  	 		 		 		 
		}	 
    
	  	 			 
%>
<!--</table>
<br>
<table  >
-->
<tr>
       <td  colspan="5"  >
	   <center>
	   <input name="pagemode" type="hidden" value="submit" > 	
	   <input type="submit" value="Refresh" >
	   
	   <input type="button" value="Back" onClick="window.location.href='hw_monitoring_environ_current.jsp'">  

	    </center>
</td>
      
</tr>
</table>

</form>
</body>
</html>
