<%@ 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>
<script language="JavaScript">
 
 function loadFrame(url,target) {
       var newWin=window.open(url,target, 'status=yes,top=1,left=1,dependent=yes,scrollbars=yes,resizable=yes,width=490,height=380,menubar=no');		
        newWin.location.replace(url);
     	//updated from newWin.location.reload();
    } //function loadFrame(url,target)
</script>

<SCRIPT language="JavaScript">
    function underConstruction() {
        alert("This option is under construction");
    }
</SCRIPT>

<jsp:useBean id="em" scope="session" class="EntrakMain"/>
<jsp:useBean id="sql" scope="session" class="SQLStatement"/>

<body>
 <font color="blue"  > <b> Indoor Climate Condition </B><br> 
 Current Time :  
<!--img src="temp_html/hw_monitoring_environ_current.jpg"   border="0"-->
<%
  
   sql = new SQLStatement(em.con);
 
   String actionButtonName = request.getParameter("action");
   String temp= "20";
   String hmd = "51";
   String dateString ="00";
   String intervalTerm =" 1 MINUTE";
   
   String sqlCommand ="select m_item, datetime,  value  from  smarthomes.monitored "+
                     " where  ((NOW() - INTERVAL 1 MINUTE)  <= datetime )" +
                           " AND ((NOW()) >= datetime )" +
                      " and  m_id =\'A062166112\' and (m_item = \'tmp25\'"+
					  " or  m_item = \'hmd26\' )"+
                      " order by datetime asc";
					  				  
    ResultSet rs = sql.executeSqlRs(sqlCommand); 		
	while (rs.next()){ 
		 dateString = rs.getString("datetime");		 		 
		 String itemString =rs.getString("m_item");
		 if(itemString.startsWith("tmp25"))
     		 temp=rs.getString("value");
	     else if(itemString.startsWith(	"hmd26") )
		     hmd=rs.getString("value"); 
   }
  
   if(actionButtonName != null) {
      if (actionButtonName.equals("MOULD ANALYSIS")) {
	        System.out.println("Mould OK");
			temp=request.getParameter("temp");		
			hmd=request.getParameter("hmd");															
  		  %>
            <script>
             loadFrame("mouldmonitor16.jsp?temp=<%=temp%>&hmd=<%=hmd%>", "_blank");
             </script>                            
          <% 
    } 
	 else {
	      rs = sql.executeSqlRs(sqlCommand); 		
        while (rs.next()){ 
		   dateString = rs.getString("datetime");		 		 
		   String itemString =rs.getString("m_item");
		   if(itemString.startsWith("tmp25"))
     		 temp=rs.getString("value");
	       else if(itemString.startsWith(	"hmd26"))
		     hmd=rs.getString("value");  
			 
	  //System.out.println( dateString +" "+temp+ ":" +temp+" hmd:"+hmd);  
	  }
   
	 } // else//if 
	  
	} // if != null
	else 
	   // System.out.println(" Action Null");
	%>

<%=dateString%>  
<form METHOD="post">
<table >
<tr> 
<td>  <font color="blue" size ="2"> Temperature  ('C)  </font>  <input TYPE="text" NAME="temp" VALUE=  <%=temp%> > 
</td> 
 
<td> <font color="blue" size ="2">
Relative Humidity (%)</font> 
   <input TYPE="text" NAME="hmd" VALUE= <%=hmd%> > 
   </td> 
   <td>
   <input type="submit" name ="action" value="MOULD ANALYSIS"  > 
   </td>
   <td>
   <input type="submit" name ="action" value="Refresh Data"  > 
   </td>
</tr>
   </form> 

</table>

 
</body>
</html>

