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

    File:               contour_update.asp
    Description:        Kopieert de oppervlaktes uit CAD_IMP_CONTOUR naar ALG_RUIMTE
                        en de tekening vanuit de conceptfolder 'omhoog'
    Parameters:
        location_key
        building_key
        floor_key
    Context:            Ajax vanuit contour-overzicht-lijst
    Note:
*/
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file='./contour_update.inc' -->

<%
var message = L("lcl_fg_contour_synced");
var submitting = getQParamInt("submit", 0) == 1;
var doorvoeren_opp = (getFParam("cad_doorvoeren_opp", "off") == "on");
var doorvoeren_tek = (getFParam("cad_doorvoeren_tek", "off") == "on");
var message = doorvoeren_opp && doorvoeren_tek? L("lcl_cad_doorgevoerd_tekopp") : (doorvoeren_tek? L("lcl_cad_doorgevoerd_tek"): (doorvoeren_opp? L("lcl_cad_doorgevoerd_opp") : ""))

var location_key  = getQParamInt("location_key", -1);
var TransitParam = buildTransitParam(["mode", "location_key", "building_key", "floor_key", "bttype", "urole"]);

var building_key  = getQParamInt("building_key", -1);
var floor_key   = getQParamInt("floor_key", -1);
var bttype = getQParam("bttype", "");
var inoutMode = bttype == "T"? MODE_OUT : MODE_IN;

var urole = getQParamSafe("urole", "");
var autfunction = (urole == "bo" ? "WEB_CADBOF" : "");
var authparams = user.checkAutorisation(autfunction);

var hasConcept = false;
if (floor_key > 0 || (building_key > 1 && bttype == "T")) // alvast een en ander bepalen
{
    var sql = "SELECT cad_tekening_key"
            + "     , cad_tekening_filenaam"
            + "     , cad_tekening_key"
            + "  FROM cad_tekening ct"
            + " WHERE cad_tekening_verwijder IS NULL"
            + "   AND cad_tekening_type = 'P'"
            + (floor_key > 0
              ? " AND ct.alg_verdieping_key = " + floor_key
              : " AND ct.alg_locatie_key = " + location_key
                + " AND ct.alg_verdieping_key IS NULL");
    oRs = Oracle.Execute(sql);
    var cad_tek_key = oRs("cad_tekening_key").value;
    var fname = oRs("cad_tekening_filenaam").value;
    fname = fname.replace(/\.dwg$/i,'');
    fname = fname.replace(/\.dwf$/i,'');
    var fullnameActual = S("flexfilespath") + "/cad/" + fname + ".dwf";
    var fullnameConcept = S("flexfilespath") + "/cad/concept/" + fname + ".dwf";
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    hasConcept = fso.FileExists(fullnameConcept);
    oRs.Close();
}
%>
<html>
  <head>
<%  FCLTHeader.Generate(); %>

<%  if (submitting)
    {
      protectRequest.validateToken();
      // eerst de tekening, voor het geval beide vinkjes zijn gezet
      if (doorvoeren_tek && hasConcept) {
          contour.make_actual(cad_tek_key, fname);
      }

      if (doorvoeren_opp) {
          contour.doorvoeren_opp(inoutMode, { location_key: location_key, building_key: building_key, floor_key: floor_key });
      }
%>
      <script type="text/javascript">
        FcltMgr.closeDetail( window,
                             { warning: "<%=safe.jsstring(message)%>"
                             });
      </script>
<%
      Response.End;
    }
    else // gewone formulier
    { %>
      <script type="text/javascript">

        function cad_cancel()
        {
            FcltMgr.closeDetail(window, { cancel: true } );
        }

        async function cad_close(close)
        {
          if (!await validateForm("u2"))
            return false;

          document.doorvoerenform.submit();
          result = true;
        }

        $(function()
        {
          FcltMgr.resized(window);
        });

      </script>
<%  } %>
  </head>

  <body class="fclt-modal" id="mod_caddoorvoeren">
    <% MODAL_START(); %>
    <form id="doorvoerenform" name="doorvoerenform" action="contour_update.asp?submit=1<%=TransitParam%>" method="post">
<%    MODAL_BLOCK_START("cadDoorvoeren", L("lcl_cad_doorvoeren"), { "icon": "fa-layer-plus" });
if (hasConcept) {
%>    <tr>
        <td>
          <% CHECKBOX("fldcaddoorvoeren", "cad_doorvoeren_tek", 1 ); %>
        </td><td>
          <label for="cad_doorvoeren_tek"><%=L("lcl_cad_tek_concept_to_actueel")%></label>
        </td>
      </tr>
<% } %>
      <tr>
        <td>
          <% CHECKBOX("fldcaddoorvoeren", "cad_doorvoeren_opp", 1 ); %>
        </td><td>
          <label for="cad_doorvoeren_opp"><%=L("lcl_cad_opp_concept_to_actueel")%></label>
        </td>
      </tr>
<%    MODAL_BLOCK_END();
      var buttons =  [ {title: L("lcl_doorvoeren"), icon: "fa-fclt-save", action: "cad_close()", singlepress: true, id:"btn_cad_submit", importance: 1}
                     , {title: L("lcl_cancel"), icon: "fa-fclt-cancel", action: "cad_cancel()", importance: 3} ];
      SIMPLE_BLOCK_START();
      CreateButtons(buttons);
      SIMPLE_BLOCK_END();
IFACE.FORM_END();
%>
    </form>
    <% MODAL_END(); %>
  </body>
</html>
<% ASPPAGE_END(); %>
