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

     File:        CAD/rap_sle.asp
     Description: Inhoud van het SLE-tabblad van FG
     Parameters:  floorKey (required)
                  highlight (optional list of room-keys to filter)
     Context:     -
     Note:        -
*/ %>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="FGII.inc" -->
<%
var floorKey = getQParamInt("vKey", -1);
var highlight_arr = getQParamIntArray("highlight", []); // Comma-separated room_key_list (terrains). Optional
var outputmode = getQParamInt("outputmode", 0);
var showall = getQParamInt("showall", 0) == 1;
var sql = "";
if (floorKey != -1)
{
  sql = "SELECT r.alg_ruimte_nr, "
      +         lcl.xsql('ssle.ins_srtdeel_omschrijving', 'ssle.ins_srtdeel_key') + " || ' (' || ssle.ins_srtdeel_code || ')' sleutelset, "
      + "       sle.ins_deel_omschrijving sleutel, "
      + "       " + S("prs_pers_string") + " bezitter, "
      + "       ssle.ins_srtdeel_key"
      + "  FROM ins_srtdeel_srtdeel ss,"
      + "       ins_v_aanwezigsrtdeel ssle,"
      + "       ins_v_aanwezigdeel sle,"
      + "       prs_v_aanwezigperslid p,"
      + "       ins_v_aanwezigsrtdeel scil,"
      + "       ins_v_aanwezigdeel cil,"
      + "       alg_ruimte r "
      + "  WHERE ss.ins_srtdeel_key_2 = ssle.ins_srtdeel_key "
      + "    AND ssle.ins_srtdeel_key = sle.ins_srtdeel_key "
      + "    AND ssle.ins_srtgroep_key = " + S("sle_ins_srt_groep_key")
      + "    AND sle.ins_alg_ruimte_type = 'P' "
      + "    AND sle.ins_alg_ruimte_key = p.prs_perslid_key "
      + "    AND ss.ins_srtdeel_key_1 = scil.ins_srtdeel_key "
      + "    AND scil.ins_srtdeel_key = cil.ins_srtdeel_key "
      + "    AND scil.ins_srtgroep_key = " + S("cil_ins_srt_groep_key")
      + "    AND cil.ins_alg_ruimte_key_org IS NOT NULL "
      + "    AND cil.ins_alg_ruimte_type = 'R' "
      + "    AND cil.ins_alg_ruimte_key = r.alg_ruimte_key "
      + "    AND cil.ins_alg_ruimte_key IN ( "
      + "        SELECT room.alg_ruimte_key "
      + "          FROM alg_v_aanwezigruimte room "
      + "         WHERE room.alg_verdieping_key ="+floorKey+")"
      + (highlight_arr.length > 0
        ? " AND r.alg_ruimte_key IN (" + highlight_arr.join(",") + ")"
        : "")
      + " ORDER BY 1, 2, 3 ";
}
else
{
  sql = "SELECT * FROM DUAL WHERE 1 = 0";
}
%>

<html>
  <head>
<%  FCLTHeader.Generate({ outputmode: outputmode }); %>
    <script type="text/javascript">
      function onClickToegang(row)
      {
        FcltMgr.openDetail("appl/sle/sle_srtdeel.asp?ins_srtdeel_key=" +  row.getAttribute("ROWKEY"), "");
      }
    </script>
  </head>

  <body class="tabpage">
<%
    var rst = new ResultsetTable({ID : "cadsletable",
                                   keyColumn: "ins_srtdeel_key",
                                   title: L("lcl_sle_toegang"),
                                   sql: sql,
                                   outputmode: outputmode,
                                   showAll: showall
                                });

    rst.addColumn(new Column({caption: L("lcl_obj_inf_room"), content: "alg_ruimte_nr"}));
    rst.addColumn(new Column({caption: L("lcl_sle_sleutel_set"), content: "sleutelset"}));
    rst.addColumn(new Column({caption: L("lcl_sle_sleutel"), content: "sleutel"}));
    rst.addColumn(new Column({caption: L("lcl_person"), content: "bezitter"}));

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

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