<%@language = "javascript" %>
<% /*
    $Revision$
    $Id$

    File:           sensor.asp
    Description:    Change the state of a sensor
    Parameters:
        new_state   New state of sensor
    Globals:
    Context:        Called from the portal
    Note:

*/

%>
<!-- #include file="../../appl/Shared/common.inc"-->
<!-- #include file="../../Appl/shared/iface.inc"-->
<%

FCLTHeader.Requires({ plugins: ["jQuery"],
                      js: [] });
%>
<html>
  <head>
<%  FCLTHeader.Generate({ root: "../../appl/" });

    var submitting = getQParamInt("submit", 0) == 1;
    var new_state = getFParam("state", "1");
    var message = "";
    var state = ""

    sql = "SELECT ins_deel_state"
        + "  FROM ins_deel"
        + " WHERE ins_deel_key = 27004";
    oRs = Oracle.Execute(sql);

    if (!oRs.eof)
       var state = oRs("ins_deel_state").value;

    if (submitting)
    {
        sql = "UPDATE ins_deel "
            + "   SET ins_deel_state = " + safe.quoted_sql(new_state) + ','
            + "       ins_deel_statedate = SYSDATE "
            + " WHERE ins_deel_key = 27004";
        oRs = Oracle.Execute(sql);

        if (new_state == "0")
           message = "Sensor in ruimte Huiskamer is uitgeschakeld.";
        else
           message = "Sensor in ruimte Huiskamer is ingeschakeld.";

      %>
      <script type="text/javascript">
        FcltMgr.closeDetail( window,
                             {
                               warning: "<%=safe.jsstring(message)%>",
                               success: true
                             });
      </script>
<%
      Response.End;
    }
%>
<script type="text/javascript">
    function doSubmit(state)
    {
        $("#state").val(state);
        document.forms.u2.submit();
    }
    $(document).ready(function () {
        <%


          if (state == "1") { %>
                  if (confirm("Sensor in Huiskamer uitschakelen?")) // when no schedule action is present, add one
                    doSubmit('0');
          <% } else { %>
                if (confirm("Sensor in Huiskamer inschakelen?"))
                    doSubmit('1');
          <% } %>
    });
</script>

</head>
<body id="mod_export" style="width:400px">
    <form name=u2 action="sensor.asp?submit=1" method="post">
        <input type='hidden' id='state' name='state' value='UIT'>
<% IFACE.FORM_END(); %>
    </form>
</body>
