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

    File:        rap_mld.asp
    Description: Als originele cad/rap_mld.asp maar dan strengere autorisatiecontrole
    Parameters:
    Context:
    Note:

*/%>
<!-- #include file="../../appl/Shared/common.inc"-->
<!-- #include file="../../appl/Shared/discx3d.inc"-->
<!-- #include file="../../appl/Shared/resultset_table_v2.inc" -->
<!-- #include file="../../appl/cad/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="";

    autfunction = "WEB_MLDBAC";

    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"
                + ", MD.ins_discipline_omschrijving||'/'||STDM.mld_stdmelding_omschrijving Melding"
                + ", ST.mld_statuses_omschrijving Status"
                + ", M.mld_melding_omschrijving omschrijving"
                + " FROM alg_district D, alg_locatie L, alg_gebouw G, alg_verdieping V, alg_ruimte R, mld_melding M, mld_stdmelding STDM"
                + ", mld_statuses ST, mld_discipline MD, ins_srtdiscipline SD "
                + " WHERE  D.alg_district_key = L.alg_district_key"
                + " AND L.alg_locatie_key = G.alg_locatie_key"
                + " AND G.alg_gebouw_key = V.alg_gebouw_key"
                + " AND V.alg_verdieping_key = R.alg_verdieping_key"
                + " AND m.MLD_ALG_ONROERENDGOED_KEYS= r.alg_ruimte_key "
                + " AND m.mld_stdmelding_key=STDM.mld_stdmelding_key"
                + " AND m.MLD_MELDING_STATUS=ST.mld_statuses_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"
        if (highlight_arr.length > 0 && highlight_arr.join(",").indexOf("-1") == -1)
            sql += " AND r.alg_ruimte_key IN (" + highlight_arr.join(",") + ")"

           sql += " AND M.mld_melding_status IN (2,3,4,7)";

           sql = discx3d (sql, "md.ins_discipline_key", "d.alg_regio_key",  "l.alg_district_key",
                      "l.alg_locatie_key", "v.alg_gebouw_key", "r.alg_verdieping_key",
                      "r.alg_ruimte_key", "none", "none",
                      autfunction, "", 0);

           sql = sql + " ORDER BY 1,3 DESC";
        } else {
            sql = "SELECT * FROM DUAL WHERE 1=0";
        }

%>
<html>
<head>
<%  FCLTHeader.Generate({root: "../../appl/", 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">
<%
    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"}));
    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: "Status"}));
    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>
