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

     File:        CAD/rap_mld.asp
     Description: Inhoud van het MLD-tabblad van FG
     Parameters:  floorKey (required)
                  highlight (optional list of room-keys to filter)
     Context:     -
     Note:        we hadden ook kunnen kiezen om mld_list aan te roepen. TODO Dat kan nog!
                  Ik kan me voorstellen dat hier de autorisaties goed gecheckt worden
*/%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/resultset_table_v2.inc" -->
<!-- #include file="../mld/mld.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 Ruimtenr"
      + ",       m.mld_melding_datum Datum"
      + ",       sd.ins_srtdiscipline_prefix || m.mld_melding_key Nr"
      + ",       m.mld_melding_key"
      + ", " + lcl.xsql('md.ins_discipline_omschrijving', 'md.ins_discipline_key')
             + "||'/'"
             + "||" + lcl.xsql('stdm.mld_stdmelding_omschrijving','stdm.mld_stdmelding_key')
             + " Melding"
      + ",       mld_melding_status"
      + ",       m.mld_melding_omschrijving omschrijving"
      + " FROM alg_ruimte r, mld_melding m, mld_stdmelding stdm"
      + ",     mld_discipline md, ins_srtdiscipline sd"
      + " WHERE  m.mld_alg_onroerendgoed_keys = r.alg_ruimte_key "
      + "   AND m.mld_stdmelding_key = stdm.mld_stdmelding_key"
      + "   AND stdm.mld_ins_discipline_key = md.ins_discipline_key"
      + "   AND md.ins_srtdiscipline_key = sd.ins_srtdiscipline_key"
      + "   AND r.alg_verdieping_key = " + floorKey
      + "   AND m.fac_activiteit_key IS NULL"
      + (highlight_arr.length > 0 && highlight_arr.join(",").indexOf("-1") == -1
        ? " AND r.alg_ruimte_key IN (" + highlight_arr.join(",") + ")"
        : "")
      + " AND m.mld_melding_status NOT IN (1,5,6)"
      + " ORDER BY 1, 3 DESC";
}
else
{
  sql = "SELECT * FROM DUAL WHERE 1 = 0";
}
%>

<html>
  <head>
<%  FCLTHeader.Generate({ outputmode: outputmode }); %>
    <script type="text/javascript">
      function onClickMelding(row)
      {
        FcltMgr.openDetail("appl/mld/mld_melding.asp?urole=bo&mld_key=" +  row.getAttribute("ROWKEY"), "");
      }
    </script>
  </head>

  <body class="tabpage">
<%
      function fncolStatus(oRs)
      {
        return mld.getmldstatustext(oRs("mld_melding_status").Value);
      }

    var rst = new ResultsetTable({ ID : "cadmldtable",
                                   keyColumn: "mld_melding_key",
                                   title: L("lcl_complains"),
                                   sql: sql,
                                   outputmode: outputmode,
                                   showAll: showall
                                 });

    rst.addColumn(new Column({caption: L("lcl_obj_inf_room"), content: "Ruimtenr"}));
    rst.addColumn(new Column({caption: L("lcl_date_time"), content: "Datum", datatype: "datetime", nowrap: true}));
    rst.addColumn(new Column({caption: L("lcl_call_number"), content: "Nr"}));
    rst.addColumn(new Column({caption: L("lcl_complain"), content: "Melding"}));
    rst.addColumn(new Column({caption: L("lcl_status"), content: fncolStatus, nowrap: true}));
    rst.addColumn(new Column({caption: L("lcl_descr"), content: "omschrijving"}));

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

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