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

     Installaties (objecten) van mode XXX die in de database dus een XY coordinaat hebben.

     IN: highlight, lijst van geselecteerde prj_ruimte_keys
*/%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="../SlnkDWF/Slnk2IMG.inc" -->
<!-- #include file="../SlnkDWF/DWFProperties.inc" -->
<!-- #include file="FGII.inc" -->
<%
var discs = getQParamIntArray("discs", []);
var highlight_arr  = getQParamIntArray("highlight", []); // Comma-separated room_key_list (terrains). Optional
var floorKey = getQParamInt("vKey", -1);

var outputmode = getQParamInt("outputmode", 0);
var showall = getQParamInt("showall", 0) == 1;

var transitParam = buildTransitParam(["discs", "highlight", "vKey"]);

var dwfPath = SetVerdPlanDWF(floorKey, 0/*inoutMode*/, 0);
if (dwfPath)
{
  dwfHandle = GetContoursHandle(dwfPath, S("fg_contourlayers"), S("fg_labellayers"),
                                         { minArea: S("fg_contour_minArea")
                                         , minmergedistance: S("fg_minmergedistance")
                                         , flags: S("fg_slnkdwf_flags")
                                         }
                                        );
}

// ==========================
//
// ==========================
if (floorKey > 0 && discs.length)
{
  var sql = "SELECT ins_deel_key, ins_deel_omschrijving, ins_deel_dwgX, ins_deel_dwgY, "
          + "  alg_ruimte_nr, cadlabel, " + lcl.xsqla('isd.ins_srtdeel_omschrijving', 'isd.ins_srtdeel_key')
          + "  FROM ins_deel id, alg_ruimte ar, ins_srtdeel isd,"
          +         S("fg_syncruimteview") + " sync"
          + " WHERE id.ins_srtdeel_key = isd.ins_srtdeel_key"
          + "   AND ins_deel_verwijder IS NULL"
          + "   AND id.ins_alg_ruimte_key = ar.alg_ruimte_key"
          + "   AND ar.alg_verdieping_key = " + floorKey
          + "   AND sync.alg_verdieping_key = " + floorKey
          + "   AND sync.alg_ruimte_key = ar.alg_ruimte_key"
          + "   AND id.ins_deel_dwgX iS NOT NULL and id.ins_deel_dwgY IS NOT NULL"
          + "   AND ins_discipline_key in (" + discs + ")"
          + " ORDER BY ins_deel_key";
}
else
{
  var sql = "SELECT * FROM DUAL WHERE 1=0";
}
%>

<html>
  <head>
<%  FCLTHeader.Generate({ outputmode: outputmode }); %>
    <script>
      function onClickObject(row)
      {
        FcltMgr.openDetail("appl/ins/ins_deel.asp?urole=bo&ins_key=" + row.getAttribute("ROWKEY"));
      }
      function cad_consi_reset()
      {
        FcltMgr.confirm(L("lcl_fg_consi_resetQ"), function() {
            var data = {};
            protectRequest.dataToken(data);
            $.post("rap_insXY_save.asp?x=x<%=transitParam%>",
                   data,
                   FcltCallbackRefresh,
                   "json");
        });
      }
    </script>
  </head>

  <body class="tabpage">
<%
      function foundRuimte(oRs)
      {
          var rnr = dwfHandle.FindInContour(oRs("ins_deel_dwgX").value, oRs("ins_deel_dwgY").value);
          if (rnr)
          {
            if (rnr == oRs("cadlabel").value)
              return L("lcl_ok");// oRs("alg_ruimte_nr").value;
            else
            {  // via sync-view vertalen naar herkenbaar ruimtelabel
              var sql = "SELECT alg_ruimte_nr"
                    + "  FROM alg_ruimte ar,"
                    +         S("fg_syncruimteview") + " sync"
                    + " WHERE ar.alg_verdieping_key = " + floorKey
                    + "   AND sync.alg_verdieping_key = " + floorKey
                    + "   AND sync.alg_ruimte_key = ar.alg_ruimte_key"
                    + "   AND cadlabel = " + safe.quoted_sql(rnr);
              var oRs = Oracle.Execute(sql);
              if (oRs.EOF)
              {
                rnr = "??" + rnr + "??"; // niet gevonden in sync-view
              }
              else
              {
                rnr = oRs("alg_ruimte_nr").Value;
              }
              oRs.Close();
              return "<span class='fginconsistent'>" + safe.html(rnr) + "</span>";
            }
          }
          return "<span class='fginconsistent'>"+L("lcl_fg_outsidecontours")+"</span>";
      }

      buttons = [];
      buttons.push({title: L("lcl_fg_consi_reset"), icon: "fa-fclt-cancel", action: "cad_consi_reset()" });
      var rst = new ResultsetTable({ keyColumn: "ins_deel_key",
                                     sql: sql,
                                     ID: "workTable",
                                     outputmode: outputmode,
                                     showAll: showall,
                                     buttons: buttons
                                   });

      rst.addColumn(new Column({caption: L("lcl_obj_identification"), content: "ins_deel_omschrijving"}));
      rst.addColumn(new Column({caption: L("lcl_obj_sort"), content: "ins_srtdeel_omschrijving"}));
      rst.addColumn(new Column({caption: L("lcl_fg_consi_tabel"), content: "alg_ruimte_nr"}));
      rst.addColumn(new Column({caption: L("lcl_fg_consi_teken"), content: foundRuimte}));

      rst.addAction({action: "onClickObject", caption: L("lcl_edit"), isDefault: true});

      var cnt = rst.processResultset();
%>
  </body>
</html>
<% ASPPAGE_END(); %>
