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

    File:           melding_new.asp
    Description:    Kies een stdmelding voor een nieuwe melding
    Parameters:     // impliciet mld_key=-1 voor nieuwe melding
                    // stdm_key bepalen we hier. Als je die hebt spring je maar rechtstreeks naar melding.asp
                    stdm_keys  lijst met komma gescheiden stdmelding keys
                    ins_key
                    ruimte_key
                    -
                    rest optioneel

    Note:           We kiezen hier puur alleen de stdmelding. De rest
                    wordt gewoon via melding.asp gedaan

*/ %>

<% REGISTERMENU_Disable = true; %>
<!-- #include file="../shared/common.inc" -->
<!-- #include file="./resultset_table.inc" -->
<!-- #include file="./mobile.inc" -->
<!-- #include file="../prs/prs.inc" -->
<!-- #include file="../mld/mld.inc" -->
<!-- #include file="./iface.inc" -->
<!-- #include file="../shared/suggest/stdmeldingFilter.inc" -->
<!-- #include file="../shared/suggest/disciplinefilter.inc" -->

<%
var mld_key = getQParamInt("mld_key", -1);  // -1 betekent nieuwe
var zoom = getQParamFloat("zoom", 2);
var ruimte_key = getQParamInt("ruimte_key", -1);  // -1 means unknown
var verdieping_key = getQParamInt("verdieping_key", -1);
var gebouw_key = getQParamInt("gebouw_key", -1);
var locatie_key = getQParamInt("locatie_key", -1);
var caddwgx = getQParamFloat("caddwgx", null); // x coördinaat van een specifieke plek in de ruimte die gehighlight moet worden.
var caddwgy = getQParamFloat("caddwgy", null); // y coördinaat van een specifieke plek in de ruimte die gehighlight moet worden.
var ins_key = getQParamInt("ins_key", -1);  // -1 means unknown
var qrc = getQParamInt("qrc", 0) != 0;
var action = getQParam("action", "");
var urole = getQParamSafe("urole", "");
var stdmgroep_keys = getQParamIntArray("stdmgroepkey", []);
var stdm_keys = getQParamIntArray("stdm_keys", []);
var start_key = getQParamInt("start_key", -1);
var has_divider = getQParamInt("divider", 1) == 1;
var has_alg_query_params = (verdieping_key > -1 || gebouw_key > -1 || locatie_key > -1);
var objPlaats = { loc_key: -1,
                  bld_key: -1,
                  flr_key: -1,
                  parms: function()
                         {
                           return (objPlaats.loc_key > 0 ? "&loc_key="+objPlaats.loc_key : "") +
                                  (objPlaats.bld_key > 0 ? "&bld_key="+objPlaats.bld_key : "") +
                                  (objPlaats.flr_key > 0 ? "&flr_key="+objPlaats.flr_key : "");
                         }
                };

if (urole == "")  // fallback naar FO indien geautoriseerd en urole niet meegegeven
{
  var authparams = user.checkAutorisation("WEB_MLDFOF", true);
  if (authparams && authparams.ALGwritelevel < 9)
      urole = 'fo';
  else
      urole = 'fe';
}
var fronto = urole == "fo";
var backo  = urole == "bo";
var minfo  = urole == "mi";
var frontend = (!fronto && !backo && !minfo);

var autfunction = "";
if (fronto)
  autfunction = "WEB_MLDFOF";
else if (minfo)
  autfunction = "WEB_MLDBAC";
else if (backo)
  autfunction = "WEB_MLDBOF";   // twijfel - PF
else
  autfunction = "WEB_MLDUSE";

var authparams = user.checkAutorisation(autfunction, true);
var autlevel = authparams ? authparams.ALGwritelevel : 9;
var transitParam = buildTransitParam(["zoom", "mld_key", "ruimte_key", "ins_key", "action", "urole", "disc", "srtdisc", "stdm", "stdmgroepkey", "ins_key", "loc_key", "bld_key", "flr_key", "roo_key", "meldbronkey", "deelsrtcont_key", "start_key"] );

// Verplicht:
var srtdisc_keys = getQParamIntArray("srtdisc", []);
var disc_keys = getQParamIntArray("disc", []);
var stdm_key = getQParamInt("stdm", -1);

if (disc_keys.length == 0 && stdm_key.length > 0)
{   // Bepaal de srtdisc_keys bij de disc_keys.
    var sql = "SELECT mld_ins_discipline_key"
            + "  FROM mld_stdmelding"
            + " WHERE mld_stdmelding_key = " + stdm_key;
    var oRs = Oracle.Execute(sql);
    disc_keys.push(oRs("mld_ins_discipline_key").Value);
    oRs.Close();
}

if (srtdisc_keys.length == 0 && disc_keys.length > 0)
{   // Bepaal de srtdisc_keys bij de disc_keys.
    var sql = "SELECT ins_srtdiscipline_key"
            + "  FROM mld_discipline"
            + " WHERE ins_discipline_key IN (" + disc_keys.join(",") + ")";
    var oRs = Oracle.Execute(sql);
    srtdisc_keys.push(oRs("ins_srtdiscipline_key").Value);
    oRs.Close();
}

// Optioneel
var ins_key = getQParamInt("ins_key", -1);  // test UWVA:11525 Het kan zijn dat ik vanuit de lijst deze meekrijg om een nieuwe aan te maken

var autfunction = [];
if (urole == "fo") autfunction.push("WEB_MLDFOF");
if (user.has("WEB_MLDUSE")) autfunction.push("WEB_MLDUSE"); // voor urole=fe en eventueel ook nog fo.

if (srtdisc_keys.length)
    lcl.set_dialect(srtdisc_keys[0], "MLD_SRTDISCIPLINE_KEY");

// determine required level through mld_stdmelding
var stdm_info = stdm_key > 0 ? mld.mld_stdmeldinginfo(stdm_key) : "";

var requiredlevel = -1;
if (stdm_info == "")
{
  var next_asp = "melding_new.asp"; // until disc_key is present
}
else
{
  if (!stdm_info.ins_srtdiscipline_alg || stdm_info.alg_onrgoed_niveau == "H" || !stdm_info.alg_onrgoed_niveau || ruimte_key > 0 || ins_key > 0) // ins_key/ruimte_key > 0 means the issue is issued from a object/room
  {
    var next_asp = "melding.asp"; // no place selection required, back without place selected
  }
  else
  {
    var next_asp = "plaatsselector.asp"; // via place selector
    switch (stdm_info.alg_onrgoed_niveau)
    {
      case "L" : requiredlevel = 2; break;
      case "G" : requiredlevel = 3; break;
      case "V" : requiredlevel = 4; break;
      case "R" : requiredlevel = 5; break;
    }

    if (has_alg_query_params)
    { // Vul plaatsgegevens met meegekregen parameters
      var alg_level = -1; // location
      var alg_key = -1;
      if      (ruimte_key > 0)     {alg_level = 5; alg_key = ruimte_key;}
      else if (verdieping_key > 0) {alg_level = 4; alg_key = verdieping_key;}
      else if (gebouw_key > 0)     {alg_level = 3; alg_key = gebouw_key;}
      else if (locatie_key > 0)    {alg_level = 2; alg_key = locatie_key; }
      // Aanvullen alg_keys
      var sql = "SELECT alg_locatie_key"
              + "     , alg_terreinsector_key"
              + "     , alg_gebouw_key"
              + "     , alg_verdieping_key"
              + "     , alg_ruimte_key"
              + "  FROM alg_v_allonroerendgoed"
              + " WHERE alg_onroerendgoed_keys = " + alg_key;
      var oRs = Oracle.Execute(sql);
      if (!oRs.EOF)
      {
        ruimte_key     = oRs("alg_ruimte_key").Value     || -1;
        verdieping_key = oRs("alg_verdieping_key").Value || -1;
        gebouw_key     = oRs("alg_gebouw_key").Value     || -1;
        locatie_key    = oRs("alg_locatie_key").Value    || -1;
      }
      oRs.Close();
      // determine how to handle place selection
      var startlevel = 2; // location
      { // autofill real estate place up to required level
        switch (requiredlevel)
        {
          case 5:
          case 4: if (alg_level >= 4) { objPlaats.flr_key = verdieping_key; }
          case 3: if (alg_level >= 3) { objPlaats.bld_key = gebouw_key; }
          case 2: if (alg_level >= 2) { objPlaats.loc_key = locatie_key; }
        }
        if (alg_level >= requiredlevel) { var next_asp = "melding.asp"; }
      }
    }
    else
    { // Vul plaatsgegevens vanuit werkplekgegevens gebruiker
      // Determine user's workplace
      var thisUser = prs.prs_perslid(user_key, { withWL: true })
      var alg_level = -1; // location
      if (thisUser.werklocatie)
      {
        if (thisUser.werklocatie.alg_verdieping_key && thisUser.werklocatie.alg_verdieping_key > 0)
          alg_level = 4; // floor
        else if (thisUser.werklocatie.alg_gebouw_key && thisUser.werklocatie.alg_gebouw_key > 0)
          alg_level = 3; // building
        else if (thisUser.werklocatie.alg_locatie_key && thisUser.werklocatie.alg_locatie_key > 0)
          alg_level = 2; // location
      }

      // determine how to handle place selection
      var startlevel = 2; // location
      if (S("mld_mobile_place_handler") == "2")
      { // autofill user's workplace up to required level
        switch (requiredlevel)
        {
          case 5:
          case 4: if (alg_level >= 4) { objPlaats.flr_key = thisUser.werklocatie.alg_verdieping_key; }
          case 3: if (alg_level >= 3) { objPlaats.bld_key = thisUser.werklocatie.alg_gebouw_key; }
          case 2: if (alg_level >= 2) { objPlaats.loc_key = thisUser.werklocatie.alg_locatie_key; }
        }
        if (alg_level >= requiredlevel) { var next_asp = "melding.asp"; }
      }
    }
  }
}
%>
<html>
  <head>
<% FCLTMHeader.Generate({title:  L("lcl_mobile_newmelding") }); %>
    <script type="text/javascript">

<%
        // autlevel opnieuw berekenen met inachtneming van de discipline
        if (disc_keys.length)
        {
            autfunction = ["WEB_MLDUSE"];
            if (urole == "fo")
                autfunction.push("WEB_MLDFOF");

            autparams = user.checkAutorisation(autfunction, true, disc_keys);

            if (autparams != null)
            {
                var autparams_urole = user.checkAutorisation("WEB_MLDFOF", true, disc_keys);
                urole =  autparams_urole != null && autparams_urole.ALGwritelevel < 9 ? "fo" : "fe"; // fo is stronger then fe
                autlevel = autparams.ALGwritelevel;
            }
            else
                autlevel = 9;
        }
%>

        function mld_new(disc_keys, stdm_key, urole)
        {
          var pstart_key = <%=start_key%>;
<%        if (next_asp == "melding.asp")
          {
%>
              var purl = "melding.asp"
                       + "?mld_key=-1"
                       + "&start_key=<%=start_key%>"
                       + (pstart_key != -1 ? "&mld_continue=1" : "")
                       + "&disc_key="+disc_keys
                       + "&stdm_key=" + stdm_key
                       + "&zoom=<%=zoom%>"
                       + "<%=ruimte_key > 0 ? '&ruimte_key=' + ruimte_key : ''%>"
                       + "<%=ins_key > 0 ? '&ins_key=' + ins_key : ''%>"
                       + "<%=safe.jsstring(objPlaats.parms())%>"
                       + "<%=qrc ? "&qrc=1" : ""%>"
                       + "&urole=" + urole
                       + "<%=user.has('WEB_CADUSE')? '&cad=1' : ''%>";
<%
          }
          else
          {
%>
              var purl_enc = "?mld_key=-1"
                           + (pstart_key != -1 ? "&start_key=" + pstart_key : "")
                           + "&disc_key=" + disc_keys
                           + "&zoom=<%=zoom%>"
                           + "&stdm_key=" + stdm_key
                           + "<%=qrc ? "&qrc=1" : ""%>"
                           + "&urole=" + urole
              var purl = "<%=next_asp%>"
                       + "?act_key=<%=getQParamInt("act_key", -1)%>"  // fac_activiteit_key voor geplande meldingen.
                       + "&disc=" + disc_keys
                       + "&zoom=<%=zoom%>"
                       + "&stdm=" + stdm_key
                       + "<%=requiredlevel <= 2 ? "" : "&filtCode=FACMLD"%>"
                       + "<%=safe.jsstring(objPlaats.parms())%>"
                       + "<%=ruimte_key > 0 ? '&ruimte_key=' + ruimte_key : ''%>"
                       + "<%=verdieping_key > 0 ? '&verdieping_key=' + verdieping_key : ''%>"
                       + "<%=gebouw_key > 0 ? '&gebouw_key=' + gebouw_key : ''%>"
                       + "<%=locatie_key > 0 ? '&locatie_key=' + locatie_key : ''%>"
                       + "<%=ins_key > 0 ? '&ins_key=' + ins_key : ''%>"
                       + "&autlevel=<%=autlevel%>"
                       + "&startlevel=<%=startlevel%>"
                       + "&eindlevel=<%=requiredlevel%>"
                       + "<%=next_asp == "melding_new.asp" && qrc ? "&qrc=1" : ""%>"
                       + "<%=user.has('WEB_CADUSE')? '&cad=1' : ''%>"
                       + (pstart_key != -1 ? "&start_key=" + pstart_key : "")
                       + "&return_to=<%=safe.url('melding.asp')%>" + encodeURIComponent(purl_enc);
<%
          }
%>
          window.location.href = purl;
        }
    </script>
<%
  if ((next_asp == "plaatsselector.asp" || next_asp == "melding.asp") && disc_keys)
  {
    var redirect_url = "";
    if (next_asp == "plaatsselector.asp")
    {
      var return_url = "?mld_key=-1"
                     + "&start_key=" + start_key
                     + (start_key != -1 ? "&mld_continue=1" : "")
                     + "&disc_key=" + disc_keys.join(",")
                     + "&zoom=" + zoom
                     + "&stdm_key=" + stdm_key
                     + (qrc ? "&qrc=1" : "")
                     + "&urole=" + urole;
      redirect_url = "plaatsselector.asp"
                   + "?act_key=" + getQParamInt("act_key", -1)
                   + "&disc=" + disc_keys.join(",")
                   + "&zoom=" + zoom
                   + "&stdm=" + stdm_key
                   + (requiredlevel <= 2 ? "" : "&filtCode=FACMLD")
                   + safe.jsstring(objPlaats.parms())
                   + (ruimte_key > 0 ? "&ruimte_key=" + ruimte_key : "")
                   + (ins_key > 0 ? "&ins_key=" + ins_key : "")
                   + "&autlevel=" + autlevel
                   + "&startlevel=" + startlevel
                   + "&eindlevel=" + requiredlevel
                   + (user.has("WEB_CADUSE") ? "&cad=1" : "")
                   + "&return_to=" + safe.url("melding.asp") + safe.urlUTF8(return_url);
    }
    else
      redirect_url = "melding.asp"
                   + "?mld_key=-1"
                   + "&start_key=" + start_key
                   + (start_key != -1 ? "&mld_continue=1" : "")
                   + "&disc_key=" + disc_keys.join(",")
                   + "&stdm_key=" + stdm_key
                   + "&zoom=" + zoom
                   + (ruimte_key > 0 ? "&ruimte_key=" + ruimte_key : "")
                   + (ins_key > 0 ? "&ins_key=" + ins_key : "")
                   + safe.jsstring(objPlaats.parms())
                   + (qrc ? "&qrc=1" : "")
                   + "&urole=" + urole
                   + (user.has("WEB_CADUSE") ? "&cad=1" : "");
    Response.Redirect(redirect_url);
  }
%>
  </head>
  <body>
<%
  var header_title = ((srtdisc_keys.length==0) ? L("lcl_mobile_selectmeldingtype") : L("lcl_mobile_selectmelding") );

  PAGE_START({id: "page-1-"+mld_key, pclass: "melding-new"});
  HEADER({title: header_title, back:!qrc, home: !qrc });
  CONTENT_START();

    function fncolSrtLink(oRs)
    {
        var nurl = "melding_new.asp?srtdisc=" + oRs("ins_srtdiscipline_key").Value + transitParam;
        return nurl;
    };
    function fncolLink(oRs)
    {
        var disc_key = oRs("mld_ins_discipline_key").Value;
        var mresult = user.func_enabled("MLD", String(disc_key), -1, user_key, true);
        var urole = (mresult.canWrite("WEB_MLDFOF") ? "fo" : "fe");
        var nurl = "javascript:mld_new("+disc_key+","+oRs("mld_stdmelding_key").Value+",'"+urole+"')";

        return nurl;
    };
    function fncolDetail(oRs)
    {
      return (oRs("mld_stdmelding_hint").Value != null ? "<div class='listbodykop'>" + oRs("mld_stdmelding_hint").Value + "</div>" : "");
    }
    function fncolSubHeader(oRs)
    {
      return S("mld_selector_mode") == 1 ? oRs("ins_discipline_omschrijving").Value : "";
    };

    // Zoekt een plaatje onder S("mlds_image_path") met fallback naar ../Pictures
    var fso = Server.CreateObject("Scripting.FileSystemObject");
    function findImage(filename)
    {
        filename = safe.filename(filename);
        __Log(S("mlds_image_path") + filename);
        if (fso.FileExists(Server.MapPath(S("mlds_image_path")) + "/" + filename))
            return S("mlds_image_path") + filename;
        if (fso.FileExists(Server.MapPath("../Pictures/") + "/" + filename))
            return "../Pictures/" + filename;
        return "";
    }

    function fncolIcon(oRs)
    {
        var img = oRs.Fields("mld_stdmelding_image").Value;
        if (img)
        {
            if (img.match(/^fa-/)) return img;

            if (!img.match(/^http/))
            {
                var newimg = findImage(img);
                if (newimg) return newimg;
            }
            else
                return img;
        }
        return "fa-caret-right";
    }

    if (srtdisc_keys.length==0) // Eerst srtdiscipline kiezen
    {
        var filt_params = { ins_key: ins_key };
        if (action == "forward")
        {
            var this_mld = mld.func_enabled_melding(mld_key);
            var filtcode = (this_mld.canForwardKeten? "VDK" : "VD");
            var filtClause = getFiltClauseDiscipline(filtcode, { module: "MLD" } );
            filt_params.filter_from = filtClause.from;
            filt_params.filter_where = filtClause.where;
        }
        else
        {
            var filtClause = getFiltClauseDiscipline((frontend ? "FE" : "VD"), { module: "MLDP" } );
            filt_params.filter_from = filtClause.from;
            filt_params.filter_where = filtClause.where;
        }

        if (stdmgroep_keys.length)
            filt_params.filter_where += " AND sm.mld_stdmeldinggroep_key IN (" + stdmgroep_keys.join(",") + ")";
        filt_params.filter_where += " AND sm.mld_stdmelding_key = msm.mld_stdmelding_key";

        var mySRTsql = mld.srtdisc_sql(filt_params);

        var sql = "SELECT MIN(ins_srtdiscipline_key) ins_srtdiscipline_key"
                + "     , MIN(ins_srtdiscipline_image) ins_srtdiscipline_image"
                + "     , COUNT(DISTINCT ins_srtdiscipline_key) aantal"
                + "  FROM (" +  mySRTsql + ")";
        var oRs = Oracle.Execute(sql);
        if (oRs("aantal").Value == 1)
            srtdisc_keys = oRs("ins_srtdiscipline_key").Value;
        oRs.Close();
    }
    function fncolIcon1(oRs)
    {
      return oRs("ins_srtdiscipline_image").Value;
    };

    if (srtdisc_keys.length == 0 && stdmgroep_keys.length == 0 && stdm_keys.lengh == 0) // Dan écht eerst srtdiscipline kiezen
    {
        var rst = new ResultsetTable({ sql: mySRTsql
                                     , keyColumn: "ins_srtdiscipline_key"
                                     , linkColumn: fncolSrtLink
                                     , headerColumn: "ins_srtdiscipline_omschrijving"
                                     , iconColumn: fncolIcon1
                                     , ID: "mld_new_m"
                                     , showAll: true
                                     , noSearch: true
                                     , emptySetString: L("lcl_empty")
                                     });
    }
    else
    {
        var sql = "SELECT fac_functie_key"
                + "  FROM fac_functie"
                + " WHERE fac_functie_code IN (" + safe.quoted_sql_join(autfunction) + ")";
        var oRs = Oracle.Execute(sql);
        var auth_key = [];
        while (!oRs.eof)
        {
          auth_key.push(oRs("fac_functie_key").value);
          oRs.MoveNext();
        }
        oRs.Close();

        var filt_params = { disc_keys: disc_keys
                          , srtdisc_keys: srtdisc_keys
                          , stdmelding_keys: stdm_keys
                          , ins_key_arr: ins_key > 0? [ins_key] : []
                          , perslidKey: user_key // altijd voor jezelf via mobile
                          , autfunctionKeyArray: auth_key
                          , show_expired: false
                          };
        if (S("mld_mobile_place_handler") == 2) {
          filt_params.loc_key = user.alg_locatie_key({ "withcurrent": true });
          filt_params.bld_key = user.alg_gebouw_key({ "withcurrent": true });
        }
        var filtcode = urole.toUpperCase();
        if (action == "forward") {
            var this_mld = mld.func_enabled_melding(mld_key);
            filtcode = (this_mld.canForwardKeten? "VDK" : null);
        }

        var filtClause = getFiltClauseStdmelding(filtcode, filt_params);

        if (disc_keys.length==0)
        { // Alleen primaire vakgroepen
            filtClause.from += ", mld_disc_params mdpx";
            filtClause.where += " AND mdpx.mld_ins_discipline_key = di.ins_discipline_key"
                              + " AND BITAND(mdpx.mld_disc_params_srtgroep, 1) = 1";
        }
        // Voor disciplines die alleen in MLDUSE zitten moet de stdmelding gecontroleerd worden op stdmelding_notfrontend.
        var check_notfrontend = " AND sm.mld_stdmelding_notfrontend = "
                                  + " CASE WHEN EXISTS"
                                            + " (SELECT 1"
                                            + "    FROM fac_v_webgebruiker w"
                                            + "       , fac_functie        f"
                                            + "   WHERE f.fac_functie_key  = w.fac_functie_key"
                                            + "     AND f.fac_functie_code = 'WEB_MLDUSE'"
                                            + "     AND w.prs_perslid_key  = " + user_key
                                            + "     AND w.ins_discipline_key = sm.mld_ins_discipline_key"
                                            + " )"
                                            + " AND NOT EXISTS"
                                            + " (SELECT 1"
                                            + "    FROM fac_v_webgebruiker w"
                                            + "       , fac_functie        f"
                                            + "   WHERE f.fac_functie_key  = w.fac_functie_key"
                                            + "     AND f.fac_functie_code = 'WEB_MLDFOF'"
                                            + "     AND w.prs_perslid_key  = " + user_key
                                            + "     AND w.ins_discipline_key = sm.mld_ins_discipline_key"
                                            + " )"
                                  + "      THEN 0"
                                  + "      ELSE sm.mld_stdmelding_notfrontend"
                                  + " END";

        mySTDsql = "SELECT mld_stdmelding_key"
                 + ","+    lcl.xsqla('sm.mld_stdmelding_omschrijving','sm.mld_stdmelding_key')
                 + ","+    lcl.xsqla('mld_stdmelding_hint', 'sm.mld_stdmelding_key')
                 + ","+    lcl.xsqla('di.ins_discipline_omschrijving', 'di.ins_discipline_key')
                 + ",      sm.mld_ins_discipline_key"
                 + ",      sm.mld_stdmelding_image"
                 + "  FROM mld_stdmelding sm"
                 + "     , mld_v_aanwezigdiscipline di"
                 + "     , ins_srtdiscipline sd"
                 + filtClause.from
                 + " WHERE sm.mld_ins_discipline_key = di.ins_discipline_key"
                 + "   AND di.ins_srtdiscipline_key = sd.ins_srtdiscipline_key"
                 + "   AND sm.mld_stdmelding_verwijder IS NULL"
                 + ( stdmgroep_keys.length
                   ? " AND sm.mld_stdmeldinggroep_key IN (" + stdmgroep_keys.join(",") + ")"
                   : ""
                   )
                 + filtClause.where
                 + check_notfrontend;
        // Selector mode vakgroep/melding voor de frontend. {0(=default)=vakgroep en melding (beide eerst te kiezen), 1=vakgroep readonly, 2=alleen melding}
        if (S("mld_selector_mode")==0) {
            mySTDsql += " ORDER BY di.ins_discipline_volgnr, UPPER("+lcl.xsql('di.ins_discipline_omschrijving', 'di.ins_discipline_key')+"), sm.mld_stdmelding_volgnr, UPPER("+lcl.xsql('sm.mld_stdmelding_omschrijving','sm.mld_stdmelding_key')+")";
        } else {
            mySTDsql += " ORDER BY sm.mld_stdmelding_volgnr, UPPER("+lcl.xsql('sm.mld_stdmelding_omschrijving','sm.mld_stdmelding_key')+")";
        }

        var rst = new ResultsetTable({ sql: mySTDsql
                                     , keyColumn: "mld_stdmelding_key"
                                     , linkColumn: fncolLink
                                     , singleLink: true
                                     , dividerColumn: S("mld_selector_mode") == 0 && has_divider ? "ins_discipline_omschrijving" : null // Split-regel per vakgroep
                                     , headerColumn: "mld_stdmelding_omschrijving"
                                     , subheaderColumn: fncolDetail
                                     , detailColumn: fncolSubHeader
                                     , iconColumn: fncolIcon
                                     , ID: "stdmldtable"
                                     , showAll: true
                                     , emptySetString: L("lcl_empty")
                                     });
    }
    var cnt = rst.processResultset();
    if (cnt == 0)
    {
       %><script>alert(L("lcl_mobile_no_stdmelding"));window.history.back(1)</script><%
    }
  CONTENT_END();
  FOOTER();
  PAGE_END();
PDA_PAGE_END(); %>
    </body>
</html>
<% ASPPAGE_END(); %>
