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

    File:              mld_search.asp (formerly ComplainsReportAll.asp;72)
    Description:       Toont zoekvelden voor lijst van meldingen of opdrachten
    Parameters:
      urole            Gebruikers rol (fe|fo|bo|mi) REQUIRED
      accept = 1       Als ik MLDBO3 autorisatie heb, mag ik alleen accepteren
      close = 1        Als ik MLDBO2 autorisatie heb, mag ik de melding alleen afsluiten
      mld_key          Melding key van de melding
      opdr_key         Opdracht key van de opdracht
      mldstatus_str    String van meldingstatussen van de melding (multi)
      opdrstatus_str   String van opdrachtstatussen van de opdracht (multi)
      srtdisc_key_str  Vakgroeptype (Soort melding) van de melding
      disc_key_str     String van vakgroepen (Productgroep) van de melding (multi)
      meldinggrp_key   Key van meldinggroepen van de melding (multi)
      behandelgrp_key  Key van meldinggroepen van de melding (multi)
      stdm_str         String van stdmeldingen (Melding) van de melding (multi)
      primstdmfilter   Het filter op standaardmelding direct tonen (1, default 0 = pas bij Meer..)
      searchtekst      Zoektekst
      omschr           Omschrijving
      opdrtype_key     Opdrachttype van de opdracht
      perslid_key      Melder (key) van de melding
      mld_ins_discipline_key
                       Behandelteam (key) van de melding
      behandel_key     Behandelaar (key) van de melding
      behandel2_key    Behandelaar2 (key) van de melding
      handler_key      Uitvoerende (key) van de opdracht
      handleropdr_key  Behandelaar (key) van de opdracht
      contact_key      Contactpersoon van de opdracht
      hfddep_key       Hoofdafdeling/Cluster (Bussiness Unit) (key) van de melding
      comp_key         Bedrijf van de melding
      dep_key          Afdeling (Organisatie) (key) van de melding
      kp_key           Kostenplaats (key) van de melding
      tag_key          Mijlpaal/tag (key) van de melding
      regiokey         Regio (key) van de melding
      districtkey      District (key) van de melding
      locatie_key      Locatie (key) van de melding
      gebouw_key       Gebouw (key) van de melding
      verdiepingkey    Verdieping (key) van de melding
      ruimtekey        Ruimte (key) van de melding
      autosearch       Autosearch. Geeft direct een overzichtresultaat
      ins_disc_key     Objectdiscipline van objecten bij de melding
      ins_srtgroup     Objectgroep van objecten bij de melding
      ins_srtdeel_key_arr Objectsoort van objecten bij de melding
      groepering_key   Groepering
      chkAcceptEx      Checkbox overschrijding acceptatietijd
      chkRunEx         Checkbox overschrijding doorlooptijd
      chkSpoed         Checkbox Spoed
      chkAfgerond      Checkbox Afgerond
      chkShowlinked    Toon gekoppelde meldingen (standaard aan);
      chkShowRespijt   Toon meldingen met respijt (standaard aan);
      chkShowIndult    Toon meldingen met indult (standaard aan);
      chkAll           Alle statusvinkjes default aan
      datefrom         Periode van
      dateto           Periode tot
      bosort           Backoffice sortering (0=Eerste af, 1=Nieuwste eerst, default S('mld_bo_sort_descending'))
      fcltfilters      Objectstring met de gepinde waarden.
    Context:           Vanuit menu
    Note:              In principe kan voor elk veld een parameter worden gegeven (conventies hanteren!)
                       Note: Toevoegen gaat niet meer hier vandaan, dus er is heel wat verdwenen
*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/status.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/disciplineselector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="../Shared/kostenplaatsselector.inc" -->
<!-- #include file="../Shared/persoonselector.inc" -->
<!-- #include file="../Shared/plaatsselector.inc" -->
<!-- #include file="../Shared/uitvoerendeselector.inc" -->
<!-- #include file="../Shared/bedrijfselector.inc" -->
<!-- #include file="../Shared/referentieselector.inc" -->
<!-- #include file="../Shared/mldtagselector.inc" -->
<!-- #include file="../Shared/calendar.inc" -->
<!-- #include file="../Shared/xd.inc" -->
<!-- #include file="../mld/mld.inc" -->

<%
FCLTHeader.Requires({ plugins: ["jQuery", "kenmerk"],
                      js: ["../mld/mld_search.js"] });
FCLTHeader.Title(L("lcl_menu_mld_fo_overview"));

/***** Get webform parameters *****/
var urole = getQParamSafe("urole", "fe");

// LET OP: voorheen keken we of MLDBO2 of MLDBO3 wellicht gold als MLDBOF
// niet geldig was. Nu doen we dat door parameters.
// In deze twee gevallen is de eerder bepaalde urole irrelevant
var justAccept = (getQParamInt("accept", 0) == 1);
var justClose  = (getQParamInt("close", 0) == 1);
var refreshOnActivate = getQParamInt("refreshonactivate", 0) == 1;
var treat = (getQParamInt("treat", 0) == 1);
if (justClose || justAccept || treat) urole = "bo";  // dat komt beter in de buurt dan fe.

if (treat)
{ // In het deelbehandelingsoverzicht kunnen we niet accepteren of afmelden.
  justAccept = false;
  justClose = false;
}

var fronto = urole == "fo";
var backo = urole == "bo";
var minfo = urole == "mi";
var frontend = (urole == "fe" || (!fronto && !backo && !minfo));
var tiny = getQParamInt("tiny", 0) == 1;
var onlyConcepts = getQParamInt("concept", 0) == 1;
var mldlist = getQParamInt("mldlist", 1) == 1;
var mldbord = getQParamInt("mldbord", 1) == 1 && !frontend && !treat;

// PREFILL PARAMETERS:
var fcltfilters           = FCLTHeader.filters;
var mld_key               = getQParamInt("mld_key", -1); // Meldingnr
var opdr_key              = getQParamInt("opdr_key", -1); // Opdrachtnr
var mldstatus_arr         = getQParamIntArray("mldstatus_str", [-1]); // Meldingstatus
var opdrstatus_arr        = getQParamIntArray("opdrstatus_str", [-1]); // Opdrachtstatus
var srtdisc               = getQParamInt("srtdisc", -1); // Soort melding (vanuit menu bijv. voor backwards compatibility)
var srtdisc_key_arr       = getQParamIntArray("srtdisc_key_str", []); // Soort melding (0 of meer)
if (srtdisc > -1) // We werken alleen met srtdisc_key_arr
  srtdisc_key_arr.push(srtdisc);
var disc_key_arr          = getQParamIntArray("disc_key_str", []); // Productgroep
var meldinggrp_key        = getQParamInt("meldinggrp_key", -1); // Meldinggroep
var behandelgrp_key       = getQParamInt("behandelgrp_key", -1); // MLD Disc Params Behandelgroep
var stdm_arr              = getQParamIntArray("stdm_str", []); // Melding (Stdmelding)
var primstdmfilter        = getQParamInt("primstdmfilter", 0) == 1; // stdmeldingfilter als primsearch
var prio                  = getQParamInt("prio", -1); // prioriteit (1,2,3,4)
var chkSearchOR           = getQParamInt("chkSearchOR", 0) == 1; // boolean zoeken in tekst met OR
var searchtekst           = getQParam("searchtekst", ""); // Zoektekst
var omschr                = getQParam("omschr", ""); // Omschrijving
var opdrtype_key          = getQParamInt("opdrtype_key", -1); // Opdrachttype
var perslid_key           = getQParamInt("perslid_key", -1); // Melder
var mld_ins_discipline_key= getQParamInt("mld_ins_discipline", -1); // MLD Behandelteam
var behandel_key          = getQParamInt("behandel_key", -1); // Behandelaar
var behandel2_key         = getQParamInt("behandel2_key", -1); // Behandelaar2
var handler_key           = getQParamInt("handler_key", -1); // Uitvoerende
var handleropdr_key       = getQParamInt("handleropdr_key", -1); // Behandelaar opdracht
var contact_key           = getQParamInt("contact_key", -1); // Contactpersoon
var hfddep_key            = getQParamInt("hfddep_key", -1); // Bussiness Unit (Cluster/Hoofdafdeling)
var comp_key              = getQParamInt("comp_key", -1); // Bedrijf
var dep_key               = getQParamInt("dep_key", -1); // Organisatie
var kpgrp_key_arr         = getQParamIntArray("kpgrp_key", [-1]); // Kostenplaatsgroep.
var kp_key_arr            = getQParamIntArray("kp_key", []); // Kostenplaats
var tag_key_arr           = getQParamIntArray("tag_key", []); // Mijlpaal
var reg_key               = getQParamInt("regiokey", -1); // Regio
var dist_key              = getQParamInt("districtkey", -1); // District
var loc_key               = getQParamInt("locatie_key", -1); // Locatie
var bld_key               = getQParamInt("gebouw_key", -1); // Gebouw
var flr_key               = getQParamInt("verdiepingkey", -1); // Verdieping
var room_key              = getQParamInt("ruimtekey", -1); // Ruimte
var autosearch            = getQParamInt("autosearch", frontend? 1 : 0) == 1;
var disc_key              = getQParamInt("ins_disc_key", -1); // Objectdiscipline
var insgroup_key          = getQParamInt("ins_srtgroup", -1); // objectgroep
var objsrt_key_arr        = getQParamIntArray("ins_srtdeel_key_arr", []); // Objectsoort
var groepering_key        = getQParamInt("groepering_key", -1); // Groepering
var alg_startlevel        = getQParamInt("alg_startlevel", minfo? 0 : 2); // Startlevel van plaatsselector (Regio/Locatie)
var meldbron_key          = getQParamInt("meldbron_key", -1); // Meldbron
var verantw_key           = getQParamInt("verantw", -1); // Gebouw verantwoordelijke
var bosort                = getQParamInt("bosort", S('mld_bo_sort_descending'));
var alg_eindlevel         = getQParamInt("alg_eindlevel", 3); // eindlevel tbv plaatsselector. Standaard Gebouw

var chkAcceptEx     = (getQParamInt("chkAcceptEx", 0) == 1); // Overschrijding acceptatietijd
var chkRunEx        = (getQParamInt("chkRunEx", 0) == 1); // Overschrijding doorlooptijd
var chkSpoed        = (getQParamInt("chkSpoed", 0) == 1); // Spoed
var chkAfgerond     = (getQParamInt("chkAfgerond", 0) == 1); // Afgerond
var chkShowlinked   = (getQParamInt("chkShowlinked", 1) == 1); // Toon gekoppelde meldingen (standaard aan);
var chkShowRespijt  = (getQParamInt("chkShowRespijt", 1) == 1); // Toon meldingen met respijt (standaard aan);
var chkShowIndult   = (getQParamInt("chkShowIndult", 1) == 1); // Toon meldingen met indult (standaard aan);

// hier worden ook de default statusvinkjes bepaald, per stuk te overrulen
// Ze kunnen ook totaal overruled worden, bijvoorbeeld als je met een ander criterium binnenkomt (mlding_tag)
// en de status er eigenlijk niet toe doet
var chkAll = (getQParamInt("chkAll", 0) == 1);

var chkAfm  = chkAll||(getQParamInt("chkAfm", 0) == 1);
var chkBusy = chkAll||(getQParamInt("chkBusy", (fronto||frontend ? 1 : 0)) == 1);
var chkDone = chkAll||(getQParamInt("chkDone", 0) == 1);
var chkNew  = chkAll||(getQParamInt("chkNew", 1) == 1);  // default aan, fronto heeft geen New
var chkRej  = chkAll||(getQParamInt("chkRej", 0) == 1);
var chkSelf = chkAll||(getQParamInt("chkSelf", (fronto ? 1 : 0)) == 1);
var chkVer  = chkAll||(getQParamInt("chkVer", 0) == 1);

var public = (getQParamInt("public", 0));

var datefrom_empty = getQParam("date_from", null) == "-1" || !minfo;  // -1 betekent leeglaten maar dat is geen Date, dus als String bekijken (omdat het ook &date_to=Wn1 mag zijn)
var dateto_empty = getQParam("date_to", null) == "-1" || !minfo;      // en standaard is die alleen bij minfo initieel gevuld
var datefrom = getQParamDate("date_from", null);
var dateto = getQParamDate("date_to", null);

var today = new Date ();
var todate = new Date(today.getFullYear(), today.getMonth(), 1);
todate.setDate(0);
todate.setHours(23,59);
var fromdate = new Date(todate.getFullYear(), todate.getMonth(), 1);
todate = convertToServerTime(todate);
fromdate = convertToServerTime(fromdate);
todate.setSeconds(59); // consistent met calendar onClick

var date_from = (datefrom ? datefrom : fromdate);
var date_to = (dateto ? dateto : todate);
var enddate_from = getQParamDate("enddate_from", null);
var enddate_to = getQParamDate("enddate_to", null);

var fcltfilters_data = (fcltfilters ? JSON.parse(fcltfilters) : null);

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

if (disc_key_arr.length > 0 && srtdisc_key_arr.length == 0)
{
  var sql = "SELECT ins_srtdiscipline_key FROM mld_v_aanwezigdiscipline WHERE ins_discipline_key IN (" + disc_key_arr.join(",") + ")";
  oRs = Oracle.Execute(sql);
  if (!oRs.eof)
    srtdisc_key_arr = [oRs("ins_srtdiscipline_key").value];
}

// TODO: stdm parameter goed interpreteren (naar groep en discipline, of naar mld_list toe
if (stdm_arr.length != 0 && disc_key_arr.length == 0 && srtdisc_key_arr.length == 0) {
    sql= "SELECT mld_ins_discipline_key, ins_srtdiscipline_key"
       + " FROM mld_stdmelding s, mld_discipline m "
       + " WHERE s.mld_ins_discipline_key = m.ins_discipline_key"
       + " AND mld_stdmelding_key IN (" + stdm_arr.join(",") + ")";
    oRs = Oracle.Execute(sql);
    if (!oRs.eof) {
        disc_key_arr = [oRs("mld_ins_discipline_key").value];
        srtdisc_key_arr = [oRs("ins_srtdiscipline_key").value];
    }
}
/***** End get webform parameters *****/

// So what authorization must we check?
var autfunction = "";
if (justAccept)
  autfunction = "WEB_MLDBO3";
else if (justClose)
  autfunction = "WEB_MLDBO2";
else if (backo)
  autfunction = "WEB_MLDBOF"
else if (fronto)
  autfunction = "WEB_MLDFOF";
else if (minfo)
  autfunction = "WEB_MLDBAC";
else
  autfunction = "WEB_MLDUSE";

var dis_autfunction = [autfunction];

var authparams = user.checkAutorisation(autfunction);

// ------------------------------------------------
// Some analysis to check relevance of some filters
//
// Fast check to see if we have anything to do with orders
sql= "SELECT 1 FROM mld_opdr WHERE ROWNUM = 1";
oRs = Oracle.Execute(sql);
var anyorders = !oRs.eof;
oRs.close();

// Fast check to see if we have anything to do with geographics
var min_plaats = -1;
sql= "SELECT MIN (ins_srtdiscipline_alg) min_plaats FROM ins_srtdiscipline WHERE ins_srtdiscipline_alg > 0 AND ins_srtdiscipline_verwijder IS NULL";
oRs = Oracle.Execute(sql);
min_plaats = oRs("min_plaats").Value;
oRs.close();

// Fast check to see if we have anything to do with objects
sql= "SELECT 1 FROM ins_srtdiscipline WHERE (ins_srtdiscipline_ins=1) AND ROWNUM = 1";
oRs = Oracle.Execute(sql);
var anyobj = !oRs.eof;
oRs.close();

// Fast check to see if we have anything to do with call groups
// If not, we can suppress a few filters.
sql= "SELECT 1 FROM mld_stdmeldinggroep WHERE ROWNUM = 1";
oRs = Oracle.Execute(sql);
var anymldgroup = !oRs.eof;
oRs.close();


// Fast check to see if we have any costcentres
// if not, suppress filter
sql= "SELECT 1 FROM prs_kostenplaats WHERE prs_kostenplaats_verwijder IS NULL AND ROWNUM = 1";
oRs = Oracle.Execute(sql);
var anykpn = !oRs.eof;
oRs.close();

// Fast check to see if we have we have more than one costcentregroup
sql= "SELECT 1 FROM (SELECT COUNT (prs_kostenplaatsgrp_key) aantal FROM prs_kostenplaatsgrp) WHERE aantal > 1";
oRs = Oracle.Execute(sql);
var anykpngrp = !oRs.eof;
oRs.close();

// Fast check to see if we have anything to do with FO-BO handling (doorzetten)
sql= "SELECT 1 FROM "
   + "(SELECT 1 FROM mld_disc_params dp, mld_discipline d "
   + "WHERE d.ins_discipline_key = dp.mld_ins_discipline_key AND mld_disc_params_directklaar>0 AND d.ins_discipline_verwijder IS NULL "
   + "UNION ALL "
   + "SELECT 1 FROM mld_stdmelding std, mld_discipline d "
   + "WHERE mld_stdmelding_directklaar>0 AND mld_stdmelding_verwijder IS NULL "
   + "  AND (   std.mld_stdmelding_vervaldatum IS NULL"
   + "       OR std.mld_stdmelding_vervaldatum > SYSDATE) "
   + "AND std.mld_ins_discipline_key = d.ins_discipline_key AND d.ins_discipline_verwijder IS NULL) "
   + "WHERE ROWNUM = 1";
oRs = Oracle.Execute(sql);
var anyfobodiscs = !oRs.eof;
oRs.close();

// Fast check to see if we have anything to do with tags
sql= "SELECT 1 FROM mld_melding_tag WHERE mld_melding_tag_verwijder IS NULL AND ROWNUM = 1";
oRs = Oracle.Execute(sql);
var anymldtags = !oRs.eof;
oRs.close();


// VALIDATE AND PREPARE
%>
<html>
  <head>
    <% FCLTHeader.Generate(); %>

    <script type="text/javascript">
      minfo = <%=minfo? 1 : 0%> == 1;
      function getSrtdeelString()
      {
        // stdmelding waarden ophalen (multi selectbox)
        var lstdm_key_str = new Array();
        $('#sm :selected').each(function(i, selected)
                                         {
                                           lstdm_key_str[i] = $(selected).val();
                                         });
        return lstdm_key_str;
      }

      function getSrtDiscString()
      {
        // SrtDiscipline waarden ophalen (multi selectbox)
        var lsrtdisc_key_str = new Array();
        $('#srtdiscmulti :selected').each(function(i, selected)
                                       {
                                         lsrtdisc_key_str[i] = $(selected).val();
                                       });
        return lsrtdisc_key_str;
      }

      function getDiscString()
      {
        // Discipline waarden ophalen (multi selectbox)
        var ldisc_key_str = new Array();
        $('#discmulti :selected').each(function(i, selected)
                                       {
                                         ldisc_key_str[i] = $(selected).val();
                                       });
        return ldisc_key_str;
      }

<%    if (xd.enabled())
      { %>
        function xdclicked()
        {
          var doxd = document.getElementById("xd").checked;
          $(".noxd").toggle(!doxd);
          $(".onlyxd").toggleClass('hidden', !doxd);
          iface_toggleSecondarySearchblock(false); // altijd uitschakelen
        }
<%    } %>

      async function doSubmit(pimode, showAll, mode)
      {
<%      if (xd.enabled())
        { %>
          if ($("#xd").is(":checked"))
          {
            $("form[name=u2]").attr("action", "mld_search_list_xd.asp");
          }
          else
          {
            $("form[name=u2]").attr("action", "mld_search_list.asp");
          }
<%      } %>

        // Wordt gebruikt in mld_bord.inc
        $("#showAll").val(showAll ? 1 : 0);
        $("#searchmode").val(mode || "list");
        await Promise.all(window.finishBeforeSubmit || []);
        if (mode === "bord") {
          var kenmerk_omschrijving = $("#mldbord-columns :selected").attr("descr");
          $("#bord_descr").val(kenmerk_omschrijving);
        }

        // pimode = 0 voor lijst en 1 voor PPI.
        // Beetje lui, maar voor de groepringen 1,2 en 16 is PPI niet van toepassing,
        //  ook al wordt er 1 meegegeven. We maken er dan gewoon 0 van om foutmeldingen te
        // vermijden. Disablen van buttons doen we i.h.a. niet.
        if (pimode == 1 && ($("#groupby").val() == 1 || $("#groupby").val() == 2 || $("#groupby").val() == 16))
            pimode = 0;

        $("#perform").val(pimode);
        if (!await validateForm("u2")){
          return false;
        }

<%      if (!frontend)
        { %>
          // Submitten met kenmerken
          doSubmitWithKenmerken();
<%      }
        else
        { %>
          document.forms.u2.submit();
<%      } %>
      }

<%    if (!frontend)
      { %>
        async function myModal(init)
        {
          var groupby = $("#groupby").val();
          var result_opdr = $("#mld_opdr_o").is(":checked");
          var lastmodal = -1; // Unieke modal key zodat inhoud scherm met ingevulde waarden onthouden worden
          if ((!minfo && !result_opdr) || groupby ==  1 || groupby ==  3 || groupby ==  4 || groupby ==  5 || groupby ==  6 || groupby ==  7 || groupby == 8
                                       || groupby ==  9 || groupby == 11 || groupby == 12 || groupby == 13 || groupby == 14 || groupby == 15
                                       || groupby == 18 || groupby == 19 || groupby == 20 || groupby == 21 || groupby == 22 || groupby == 23)
          { // Meldingen
            var lsrtdisc_key_str = getSrtDiscString();
            var ldisc_key_str = getDiscString();
            var lstdm_key_str = getSrtdeelString();
            var url = "load_kenmerk.asp?stdm_str=" + lstdm_key_str
                    + "&disc_str=" + ldisc_key_str
                    + "&srtdisc_key=" + lsrtdisc_key_str
                    + "&urole=<%=urole%>"
                    + "&advanced=1"
                    + "&niveau=M"
                    + "&hasFilter=1";
            var titel = L("lcl_mld_kenmerken");
          }
          else if ((!minfo && result_opdr) || groupby == 2 || groupby == 10 || groupby == 16 || groupby == 17)
          { // Opdrachten
            if ($('#opdrtype').val() == -1)
            {
              FcltMgr.alert(L("lcl_select_notypeopdr_selected"));
              return;
            }

            var key = $('#opdrtype').val();
            var url = "load_kenmerk.asp?opdr_type=" + $('#opdrtype').val()
                    + "&urole=<%=urole%>"
                    + "&advanced=1"
                    + "&niveau=O"
                    + "&hasFilter=1";
            var titel = L("lcl_mld_ord_kenmerken");
          }
          await showKenmerkModal(url, titel, init);
        }
<%    } %>
    </script>
  </head>

  <body id="searchbody">
    <form name="u2" method="post" action="mld_search_list.asp" target="workFrame" onsubmit='doSubmit(0);return false'>
      <%
      SEARCH_PAGE_START({ header: L("lcl_filterblok")});
        SEARCH_BLOCK_START();
      %>
        <input type="hidden" name="urole" value="<%=urole%>">
        <input type="hidden" name="user_key" value="<%=user_key%>">
        <input type="hidden" name="public" value="<%=public%>">
        <input type="hidden" name="tiny" value="<%=tiny?1:0%>">
        <input type="hidden" name="perform" id="perform" value="0">
        <input type="hidden" name="treat" id="treat" value="<%=treat?1:0%>">
        <input type="hidden" name="onlyConcepts" id="onlyConcepts" value="<%=onlyConcepts?1:0%>">
        <input type="hidden" name="showAll" id="showAll" value="0">
        <input type="hidden" name="searchmode" id="searchmode" value="<%=mldlist ? "list" : "bord"%>">

<%      if (srtdisc_key_arr.length > 0 || disc_key_arr.length > 0) {  %>
           <input type="hidden" id="srtdiscmulti" name="srtdiscmulti" value="<%=srtdisc_key_arr.join(",")%>">
<%      } %>
<%      if (justClose) { %>
          <input type="hidden" name="justclose" value="1">
<%      } %>
<%      if (justAccept) { %>
          <input type="hidden" name="justaccept" value="1">
<%      }

        if (xd.enabled())
            RWCHECKBOXTR("xd", "fldxd", L("lcl_xd_crossdomain"), false, {html: "onclick='xdclicked()'"});
%>
            <tr class="primsearch">
              <td class="label"><label for="mldnum"><%=L("lcl_call_number")%></label></td>
              <td>
                <input type="text" class="fldshort<%=justClose?' required': ''%>" name="mldnum" <%=(mld_key != -1) ? "value='" + mld_key + "'" : ""%>>
              </td>
            </tr>

<%          if (minfo)
            { %>
              <!-- Meldingstatusen -->
<%            sql = (anyfobodiscs ? "SELECT 0, " + safe.quoted_sql(mld.getmldstatustext(0)) + ",1 FROM DUAL UNION " : "")
                  + "       SELECT  2, " + safe.quoted_sql(mld.getmldstatustext(2)) + ",2 FROM DUAL"
                  + " UNION SELECT  4, " + safe.quoted_sql(mld.getmldstatustext(4)) + ",4 FROM DUAL"
                  + " UNION SELECT  7, " + safe.quoted_sql(mld.getmldstatustext(7)) + ",5 FROM DUAL"
                  + " UNION SELECT 99, " + safe.quoted_sql(mld.getmldstatustext(99))+ ",6 FROM DUAL"
                  + " UNION SELECT  5, " + safe.quoted_sql(mld.getmldstatustext(5)) + ",7 FROM DUAL"
                  + " UNION SELECT  6, " + safe.quoted_sql(mld.getmldstatustext(6)) + ",8 FROM DUAL"
                  + " UNION SELECT  1, " + safe.quoted_sql(mld.getmldstatustext(1)) + ",9 FROM DUAL"
                  + " ORDER BY 3";
              FCLTselector("mldstatusmulti",
                           sql,
                           { initKey: mldstatus_arr.join(","),
                             label: L("lcl_mld_mldstatus"),
                             trclass:"primsearch",
                             multi: true,
                             emptyOption: L("lcl_search_generic")
                           }); %>

              <!-- Opdrachtnummer -->
              <tr class="secsearch">
                <td class="label"><label for="opdrnum"><%=L("lcl_mld_opdr_number")%></label></td>
                <td>
                  <input type="text" class="fldshort<%=justClose?' required': ''%>" name="opdrnum" <%=(opdr_key != -1) ? "value='" + opdr_key + "'" : ""%>>
                </td>
              </tr>

              <!-- Opdrachtstatusen -->
<%            sql = " SELECT       10, " + safe.quoted_sql(status.getopdrstatustext(10))+ ",1 FROM DUAL"
                  + " UNION SELECT  3, " + safe.quoted_sql(status.getopdrstatustext(3)) + ",2 FROM DUAL"
                  + " UNION SELECT  4, " + safe.quoted_sql(status.getopdrstatustext(4)) + ",3 FROM DUAL"
                  + " UNION SELECT  5, " + safe.quoted_sql(status.getopdrstatustext(5)) + ",4 FROM DUAL"
                  + " UNION SELECT  8, " + safe.quoted_sql(status.getopdrstatustext(8)) + ",5 FROM DUAL"
                  + " UNION SELECT  6, " + safe.quoted_sql(status.getopdrstatustext(6)) + ",6 FROM DUAL"
                  + " UNION SELECT  9, " + safe.quoted_sql(status.getopdrstatustext(9)) + ",7 FROM DUAL"
                  + " UNION SELECT  7, " + safe.quoted_sql(status.getopdrstatustext(7)) + ",8 FROM DUAL"
                  + " UNION SELECT  2, " + safe.quoted_sql(status.getopdrstatustext(2)) + ",9 FROM DUAL"
                  + " UNION SELECT  1, " + safe.quoted_sql(status.getopdrstatustext(1)) + ",10 FROM DUAL"
                  + " ORDER BY 3";
              FCLTselector("opdrstatusmulti",
                           sql,
                           { initKey: opdrstatus_arr.join(","),
                             label: L("lcl_mld_opdr_status"),
                             trclass:"secsearch",
                             multi: true,
                             emptyOption: L("lcl_search_generic")
                           });
            }  // minfo

            if (!justClose)
            { %>
              <!-- Zoektekst -->
              <tr class="primsearch">
                <td class="label"><label for="searchtekst"><%=L("lcl_search_diff_fields")%></label>
                  <div class="secsearch" style="display:none;">
                      <input type="checkbox" class="fldcheck" name="chkSearchOR" id="chkSearchOR" value="1" <%=chkSearchOR? "checked" : ""%>>
                      <label for="chkSearchOR"><%=L("lcl_search_or_fields")%></label>
                  </div>
                </td>
                <td>
                  <input type="text" class="fld wildcard" name="searchtekst" value="<%=safe.htmlattr(searchtekst)%>">
                </td>
              </tr>
<%            if (mldlist && backo && anyorders) { // alleen back kan kiezen uit opdrachten
%>              <!-- Resultaat meldingen/opdrachten -->
                <tr class="primsearch noxd">
                  <td class="label"><label for="mld_opdr_c"><%=L("lcl_mld_result")%></label></td>
                  <td>
                    <label for="mld_opdr_c">
                      <input type="radio" name="mld_or_opdr" id="mld_opdr_c" value="0" checked><%=L("lcl_complains")%>
                    </label>
                    <label for="mld_opdr_o">
                      <input type="radio" name="mld_or_opdr" id="mld_opdr_o" value="1"><%=L("lcl_orders")%>
                    </label>
                 </td>
                </tr>
<%            }
              if (!frontend)
              {
                // Kijk of er (behandel)teams gebruikt -kunnen- worden
                sql = "SELECT 1"
                    + "  FROM DUAL"
                    + " WHERE EXISTS"
                    + "           (SELECT 1"
                    + "              FROM mld_disc_params dp1, mld_discipline d1"
                    + "             WHERE d1.ins_discipline_key = dp1.mld_ins_discipline_key"
                    + "               AND d1.ins_discipline_verwijder IS NULL"
                    + "               AND BITAND (dp1.mld_disc_params_srtgroep, 2) = 2)" // Is team
                    + "   AND EXISTS"
                    + "           (SELECT 1"
                    + "              FROM mld_disc_params dp2, mld_discipline d2"
                    + "             WHERE d2.ins_discipline_key = dp2.mld_ins_discipline_key"
                    + "               AND d2.ins_discipline_verwijder IS NULL"
                    + "               AND BITAND (dp2.mld_disc_params_srtgroep, 4) = 4)" // Has team
                    + "   AND ROWNUM <= 1";
                var oRs = Oracle.Execute(sql);
                var canUseTeams = !oRs.EoF;
                oRs.Close();

                if (canUseTeams && (fronto || backo))
                  dis_autfunction = ["WEB_MLDFOF", "WEB_MLDBOF"];

                if (srtdisc_key_arr.length == 0) // TODO netjes afmaken: als het readonly is want meegegeven, dan hoef ik het niet te tonen ook
                {
                  // <!-- Soort melding -->
                  // Als een srtdisc meegegeven dan geen lege optie
                  // en dan is hidden field srtdisc_key_arr van hiervoor effectief.

                  // srtdisciplines met bestaande stdm
                  sql = "  SELECT sd.ins_srtdiscipline_key"
                      + ", " + lcl.xsqla("sd.ins_srtdiscipline_omschrijving", "ins_srtdiscipline_key")
                      + "    FROM ins_srtdiscipline sd"
                      + "   WHERE EXISTS"
                      + "             (SELECT 'x'"
                      + "                FROM mld_v_aanwezigdiscipline m1, mld_stdmelding ms"
                      + "               WHERE m1.ins_srtdiscipline_key = sd.ins_srtdiscipline_key"
                      + "                 AND m1.ins_discipline_key = ms.mld_ins_discipline_key"
                      + "                 AND ms.mld_stdmelding_verwijder IS NULL)";

                  var aut_scope_sql = "     AND EXISTS"
                                    + "             (SELECT 'y'"
                                    + "                FROM mld_v_aanwezigdiscipline m1, fac_v_my_disciplines md"
                                    + "               WHERE m1.ins_srtdiscipline_key = sd.ins_srtdiscipline_key"
                                    + "                 AND md.ins_discipline_key = m1.ins_discipline_key"
                                    + "                 AND fac_functie_code IN (" + safe.quoted_sql_join(dis_autfunction) + ")"
                                    + "                 AND prs_perslid_key = " + user_key + ")";

                  if (!canUseTeams)
                      sql += aut_scope_sql;

                  var sqlcnt = "SELECT COUNT (1) nrsrtdisc"
                             + "  FROM (" + sql + ")";

                  var oRs2 = Oracle.Execute(sqlcnt);
                  if (oRs2("nrsrtdisc").Value == 1)
                  {
                    var oRs = Oracle.Execute(sql);
                    srtdisc_key_arr = [oRs("ins_srtdiscipline_key").Value];

                    oRs.Close();
                  }
                  oRs2.Close();

                  if (srtdisc_key_arr.length == 0)
                  {
                    if (canUseTeams) // Scoping alsnog toevoegen
                        sql += aut_scope_sql;
                    sql += " ORDER BY 2";

                    FCLTselector("srtdiscmulti",
                                 sql,
                                 { initKey: -1,
                                   label: L("lcl_vakgroup_type"),
                                   trclass: "primsearch noxd",
                                   onChange: "return updateDisc('" + urole + "', '" + dis_autfunction + "');",
                                   emptyOption: L("lcl_search_generic"),
                                   readonly: disc_key_arr.length != 0,
                                   multi: true,
                                   sgRelType: "discmulti" // Wijzigen van srtdiscipline heeft effect op de discipline selector.
                                 });
                  }
                }

                if (!frontend && srtdisc_key_arr.length > 0)
                {
                  %><input type="hidden" id="srtdisc_key_arr" name="srtdisc_key_arr" value="<%=srtdisc_key_arr.join(",")%>"><%
                }

                // <!-- Productgroep -->
                // LET OP!!
                // De options van deze selector wordt on-change dynamisch vervangen door ../shared/loadDisc.asp!
                // Wat hier staat is dus alleen de initiele situatie.
                // SQL-queries uit loadDisc:
                var discsql_aut = "SELECT ins_discipline_key"
                                + "  FROM fac_v_webgebruiker g"
                                + ", fac_functie f"
                                + " WHERE g.prs_perslid_key = " + user_key
                                + " AND f.fac_functie_key = g.fac_functie_key"
                                + " AND f.fac_functie_code IN (" + safe.quoted_sql_join(dis_autfunction) + ")"
                                + " AND g.fac_gebruiker_alg_level_read < 9"; // MGE: Als alg_level_read = 9 dan komt waarde niet meer voor in fac_v_webgebruiker. Regel zou dus weg kunnen

                var discsql = " SELECT m1.ins_discipline_key"
                            + ", CASE "
                            + "   WHEN sd.ins_srtdiscipline_prefix IS NULL"
                            + "   THEN ''"
                            + "   ELSE sd.ins_srtdiscipline_prefix || '-'"
                            + "   END"
                            + "   || "+ lcl.xsqla('m1.ins_discipline_omschrijving', 'm1.ins_discipline_key')
                            + " FROM mld_v_aanwezigdiscipline m1"
                            + ", ins_srtdiscipline sd"
                            + ", mld_disc_params dp"
                            + " WHERE EXISTS (SELECT 'x'"
                            + "                 FROM mld_stdmelding ms"
                            + "                WHERE m1.ins_discipline_key = ms.mld_ins_discipline_key"
                            + "                  AND ms.mld_stdmelding_verwijder IS NULL)"
                            + "   AND m1.ins_srtdiscipline_key = sd.ins_srtdiscipline_key(+)"
                            + "   AND m1.ins_discipline_key IN (" + discsql_aut + ")"
                            + "   AND dp.mld_ins_discipline_key = m1.ins_discipline_key"
                            + "   AND BITAND(dp.mld_disc_params_srtgroep, 1) = 1" // Alleen primaire
                            + ( fcltfilters_data && fcltfilters_data.srtdiscmulti.length != -1
                              ? " AND sd.ins_srtdiscipline_key IN (" + fcltfilters_data.srtdiscmulti.join(",") + ")"
                              : ( srtdisc_key_arr.length > 0
                                ? " AND m1.ins_discipline_key IN (SELECT ins_discipline_key"
                                + "                                 FROM mld_discipline"
                                + "                                WHERE ins_srtdiscipline_key IN (" + srtdisc_key_arr.join(",") + "))"
                                : ""
                                )
                              )
                            + ( fcltfilters_data && fcltfilters_data.discmulti != -1
                              ? " AND m1.ins_discipline_key IN (" + fcltfilters_data.discmulti + ")"
                              : ( disc_key_arr.length != 0
                                ? " AND m1.ins_discipline_key IN (" + disc_key_arr.join(",") + ")"
                                : ""
                                )
                              )
                            + " ORDER BY 2"

                FCLTselector("discmulti",
                             discsql,
                             { initKey: disc_key_arr.join(","),
                               label: L("lcl_vakgroup"),
                               onChange: "return updateStdm('" + urole + "', '" + dis_autfunction + "');",
                               trclass: "primsearch noxd",
                               multi: true,
                               emptyOption: (disc_key_arr.length == 0? L("lcl_search_generic") : null) // Als een disc_key_arr is meegegeven dan geen lege optie
                             })

                // <!-- Melding (Stdmelding) -->
                // LET OP!!
                // deze selector wordt on-change dynamisch en totaal vervangen door ../Shared/loadStdmelding.asp!
                // Wat hier staat is dus alleen de initiele situatie.
                // SQL-queries uit loadStdmelding:
                var stdmsql_aut = "SELECT ins_discipline_key"
                                + "  FROM fac_v_webgebruiker g"
                                + ", fac_functie f"
                                + " WHERE g.prs_perslid_key = " + user_key
                                + " AND f.fac_functie_key = g.fac_functie_key"
                                + " AND f.fac_functie_code IN (" + safe.quoted_sql_join(dis_autfunction) + ")"
                                + " AND g.fac_gebruiker_alg_level_read < 9"; // MGE: Als alg_level_read = 9 dan komt waarde niet meer voor in fac_v_webgebruiker. Regel zou dus weg kunnen

                var stdmsql = "SELECT mld_stdmelding_key"
                            + ", " + lcl.xsqla("stdm.mld_stdmelding_omschrijving", "stdm.mld_stdmelding_key")
                            + ", mld_ins_discipline_key"
                            + " FROM mld_stdmelding stdm"
                            + ", mld_discipline"
                            + " WHERE mld_ins_discipline_key = ins_discipline_key"
                            + " AND mld_stdmelding_verwijder IS NULL"
                            + " AND ins_discipline_verwijder IS NULL"
                            + (frontend
                              ? " AND mld_stdmelding_notfrontend = 0"
                              : "")
                            + ( fcltfilters_data && fcltfilters_data.srtdiscmulti.length != -1
                              ? " AND ins_srtdiscipline_key IN (" + fcltfilters_data.srtdiscmulti.join(",") + ")"
                              : ( srtdisc_key_arr.length > 0
                                ? " AND ins_srtdiscipline_key IN (" + srtdisc_key_arr.join(",") + ")"
                                : ""
                                )
                              )
                            + ( fcltfilters_data && fcltfilters_data.discmulti != -1
                              ? " AND mld_ins_discipline_key IN (" + fcltfilters_data.discmulti + ")"
                              : ( disc_key_arr.length != 0
                                ? " AND mld_ins_discipline_key IN (" + disc_key_arr.join(",") + ")"
                                : ""
                                )
                              )
                            + " AND mld_ins_discipline_key IN (" + stdmsql_aut + ")"
                            + " ORDER BY " + lcl.xsql("stdm.mld_stdmelding_omschrijving", "stdm.mld_stdmelding_key");

                FCLTselector("sm", // heette stdmmulti maar nu korte naam om url kort te houden
                             stdmsql,
                             { initKey: stdm_arr.join(","),
                               label: L("lcl_complain"),
                               onChange: "return updateBoardColumns('" + urole + "', '" + dis_autfunction + "');",
                               trclass: (minfo||primstdmfilter ? "primsearch" : "secsearch") + " noxd",
                               multi: true,
                               emptyOption: L("lcl_search_generic")
                             });

                if (backo && anyorders)
                {
                  // Zijn er opdrachttypen van het type offerte?
                  sql = "SELECT mto.mld_typeopdr_key"
                      + "  FROM mld_typeopdr mto"
                      + " WHERE mto.mld_typeopdr_isofferte = 1"
                  oRs = Oracle.Execute(sql);
                  if (!oRs.eof)
                    RWCHECKBOXTR("offertes", "fldoffertes", L("lcl_mld_offertes"), false, { html: " value='1' ", trclass: "noxd"});
                  oRs.Close();
                }

                // Meldinggroep
                // Laat alle meldinggroepen zien die voorkomen onder de disciplines die ik mag zien.
		            if (anymldgroup)
		            {
                  var grpsql_aut = "SELECT ins_discipline_key"
                                 + "  FROM fac_v_webgebruiker g"
                                 + ", fac_functie f"
                                 + " WHERE g.prs_perslid_key = " + user_key
                                 + " AND f.fac_functie_key = g.fac_functie_key"
                                 + " AND f.fac_functie_code IN (" + safe.quoted_sql_join(dis_autfunction) + ")"
                                 + " AND g.fac_gebruiker_alg_level_read < 9"; // MGE: Als alg_level_read = 9 dan komt waarde niet meer voor in fac_v_webgebruiker. Regel zou dus weg kunnen

                  var grpsql = "SELECT G.mld_stdmeldinggroep_key akey"
                             + ", " + lcl.xsqla("G.mld_stdmeldinggroep_naam", "G.mld_stdmeldinggroep_key")
                             + " FROM mld_stdmelding M"
                             + "    , mld_stdmeldinggroep G"
                             + " WHERE M.mld_stdmeldinggroep_key = G.mld_stdmeldinggroep_key"
                             + "   AND M.mld_stdmelding_verwijder IS NULL"
                             + " AND M.mld_stdmeldinggroep_key IS NOT NULL"
                             + (srtdisc_key_arr.length > 0
                               ? " AND mld_ins_discipline_key IN (SELECT ins_discipline_key"
                                 + " FROM mld_discipline"
                                 + " WHERE ins_srtdiscipline_key IN (" + srtdisc_key_arr.join(",") + "))"
                               : "")
                             + (disc_key_arr != 0
                               ? " AND mld_ins_discipline_key IN (" + disc_key_arr.join(",") + ")"
                               : "")
                             + " AND mld_ins_discipline_key IN (" + grpsql_aut + ")"
                             + " GROUP BY G.mld_stdmeldinggroep_key, mld_stdmeldinggroep_naam"
                             + " ORDER BY 2";

                  FCLTselector("meldinggrp_key",
                                grpsql,
                                { initKey: meldinggrp_key,
                                  label: L("lcl_mld_meldinggroep"),
                                  trclass: "secsearch noxd",
                                  emptyOption: ""
                                });
		            }
                // Behandelgroep-filter (indien die er zijn)
                var behsql = "SELECT mld_behandelgroep_key,"
                           + lcl.xsqla('mld_behandelgroep_naam', 'mld_behandelgroep_key')+", "
                           + lcl.xsqla('mld_behandelgroep_oms', 'mld_behandelgroep_key')
                           + "  FROM mld_behandelgroep";
                oRs = Oracle.Execute(behsql);
                if (!oRs.eof) {
                    FCLTselector("behandelgrp_key",
                                  behsql,
                                  { initKey: behandelgrp_key,
                                    label: L("lcl_mld_behandelgroep"),
                                    trclass: "secsearch noxd",
                                    emptyOption: ""
                                  });
                }
                oRs.Close();

                // Vervolgmelding-filter
                if (backo || minfo || fronto)
                {
                  sortsql = "SELECT -1, " + safe.qL("lcl_mld_vervolgfilter_both") + ", 0 FROM DUAL"       // geen filter
                          + " UNION SELECT 1, " + safe.qL("lcl_mld_vervolgfilter_none") + ", 1 FROM DUAL" // zonder vervolgmeldingen
                          + " UNION SELECT 2, " + safe.qL("lcl_mld_vervolgfilter_only") + ", 2 FROM DUAL" // alleen vervolgmeldingen
                          + " ORDER BY 3";
                  FCLTselector("vervolgmld",
                                sortsql,
                                { label: L("lcl_mld_vervolgfilter"),
                                  trclass: "secsearch noxd"
                                });
                }

                if (backo)
                {
                  sortsql = "SELECT -1, '', 0 FROM DUAL"  // Alle
                          + " UNION SELECT 1, " + safe.qL("lcl_mld_completed") + ", 1 FROM DUAL"     // Afgerond
                          + " UNION SELECT 2, " + safe.qL("lcl_mld_not_completed") + ", 2 FROM DUAL" // Niet afgerond
                          + " ORDER BY 3";
                  FCLTselector("completed",
                                sortsql,
                                { label: L("lcl_mld_afgerond"),
                                  trclass: "secsearch noxd"
                                });
                }

                if (!minfo)
                {
                  sortsql = "SELECT 0, " + safe.qL("lcl_mld_firstready") + ", 0 FROM DUAL"
                          + " UNION SELECT 1, " + safe.qL("lcl_mld_newfirst") + ", 1 FROM DUAL"
                          + " UNION SELECT 2, " + safe.qL("lcl_mld_laatste_actie") + ", 2 FROM DUAL"
                          + " ORDER BY 3";
                  FCLTselector("bosort",
                                sortsql,
                                { initKey: (fronto ? 1 : bosort), // initieel voor fo sortering op laatste eerst.
                                  label: L("lcl_mld_sort"),
                                  trclass: "secsearch noxd"
                                });
                }

                if (minfo)
                { %>
                  <!-- BackOfficetype -->
                  <tr class="secsearch">
                    <td align="right"><b></b></td>
                    <td>
                      <input type="checkbox" class="fldcheck" name="chkAcceptEx" id="chkAcceptEx" value="1" <%=chkAcceptEx? "checked" : ""%>>
                      <label for="chkAcceptEx"><%=L("lcl_mld_accept_time_exceed")%></label>
                      <br>
                      <input type="checkbox" class="fldcheck" name="chkRunEx" id="chkRunEx" value="1" <%=chkRunEx? "checked" : ""%>>
                      <label for="chkRunEx"><%=L("lcl_mld_run_time_exceed")%></label>
                      <br>
                      <input type="checkbox" class="fldcheck" name="chkSpoed" id="chkSpoed" value="1" <%=chkSpoed? "checked" : ""%>>
                      <label for="chkSpoed"><%=L("lcl_mld_spoed")%></label>
                      <br>
                      <input type="checkbox" class="fldcheck" name="chkAfgerond" id="chkAfgerond" value="1" <%=chkAfgerond? "checked" : ""%>>
                      <label for="chkAfgerond"><%=L("lcl_mld_afgerond")%></label>
                  </tr>

<%
                  sql = "    SELECT 'MLDNEW' noticode, " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldnew")) + " notitext FROM DUAL"
                      + "  UNION ALL SELECT  'MLDDOO', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mlddoo")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'MLDFWD', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldfwd")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'MLDBWD', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldbwd")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'MLDUPD', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldupd")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'MLDACP', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldacp")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'MLDBHG', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldbhg")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'MLDBEH', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldbeh")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'MLDABH', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldabh")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'MLDREJ', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldrej")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'MLDAFM', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldafm")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'MLDVER', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldver")) + " FROM DUAL"

                      + "  UNION ALL SELECT  'ORDACP', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordacp")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDHLT', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordhlt")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDRSM', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordrsm")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDAFM', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordafm")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDAFR', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordafr")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDCAN', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordcan")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDFIA', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordfia")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDFNO', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordfno")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDFOK', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordfok")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDMLE', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordmle")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDMLI', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordmli")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDNEW', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordnew")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDONO', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordono")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDOOK', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordook")) + " FROM DUAL"
                      // ooit? xcase "ORDREJ', '" +L("lcl_ord_is_ordrejOPDR"):  + "' FROM DUAL"
                      + "  UNION ALL SELECT  'ORDSNT', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordsnt")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDUPD', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordupd")) + " FROM DUAL"
                      + "  UNION ALL SELECT  'ORDVER', " + safe.quoted_sql(L("lcl_mld_trackprefixord")+L("lcl_ord_is_ordver")) + " FROM DUAL"

                      + "  ORDER BY 2";

                  FCLTselector("srt_tracking",
                           sql,
                           {
                             label: L("lcl_mld_trackcol"),
                             trclass: "primsearch",
                             emptyOption: "",
                             multi: true
                           });
                  FCLTpersoonselector("prs_tracking",
                          "sgTrackPerson",
                          { perslidKey: perslid_key,
                            label: L("lcl_mld_trackby"),
                            filtercode: "TRCK", // ooit in tracking
                            trclass: "primsearch noxd",
                            whenEmpty: L("lcl_search_generic")  // want filter
                          });
                  // periode van actie
                  FCLTcalendar("actiondate_from",
                               { label : L("lcl_mld_action_from"),
                                 initEmpty: true,
                                 trclass: "secsearch"
                               });
                  FCLTcalendar("actiondate_to",
                               { label: L("lcl_mld_action_to"),
                                 initEmpty: true,
                                 trclass: "secsearch"
                               });


                  sql = "SELECT 'fe'," + safe.quoted_sql(L("lcl_fe")) + " FROM DUAL"
                      + " UNION SELECT 'fo'," + safe.quoted_sql(L("lcl_fo")) + " FROM DUAL";
                  FCLTselector("ingevoerd",
                           sql,
                           {
                             label: L("lcl_mld_starter"),
                             trclass: "primsearch",
                             emptyOption: L("lcl_search_generic")
                           });

%>

                  <!-- Group by -->
<%                sql = "SELECT         1, " + safe.quoted_sql(L("lcl_complains")) + ", 1 FROM DUAL"
                      + " UNION SELECT  2, " + safe.quoted_sql(L("lcl_orders")) + ", 3 FROM DUAL"
                      + " UNION SELECT 16, " + safe.quoted_sql(L("lcl_orders") + ' + ' + L("lcl_opdr_kosten")) + ", 5 FROM DUAL"
                      + " UNION SELECT  3, " + safe.quoted_sql(L("lcl_mld_mldstatus")) + ", 7 FROM DUAL"
                      + " UNION SELECT  4, " + safe.quoted_sql(L("lcl_vakgroup_type")) + ", 9 FROM DUAL"
                      + " UNION SELECT  5, " + safe.quoted_sql(L("lcl_vakgroup_type") + ' + ' + L("lcl_vakgroup")) + ", 11 FROM DUAL"
                      + " UNION SELECT  6, " + safe.quoted_sql(L("lcl_vakgroup_type") + ' + ' + L("lcl_vakgroup") + ' + ' + L("lcl_complain")) + ", 12 FROM DUAL"
                      + " UNION SELECT 18, " + safe.quoted_sql(L("lcl_mld_meldinggroep")) + ", 13 FROM DUAL"
                      + " UNION SELECT 19, " + safe.quoted_sql(L("lcl_vakgroup_type") + ' + ' + L("lcl_mld_meldinggroep")) + ", 15 FROM DUAL"
                      + " UNION SELECT 22, " + safe.quoted_sql(L("lcl_mld_urg")) + ", 19 FROM DUAL"
                      + " UNION SELECT 30, " + safe.quoted_sql(L("mld_melding_tag")) + ", 20 FROM DUAL"
                      + (min_plaats > 0 ? " UNION SELECT  8, " + safe.quoted_sql(L("lcl_district")) + ", 21 FROM DUAL" : "")
                      + (min_plaats > 0 ? " UNION SELECT 13, " + safe.quoted_sql(L("lcl_district") + ' + ' + L("lcl_vakgroup_type") + ' + ' + L("lcl_vakgroup")) + ", 23 FROM DUAL" : "")
                      + (min_plaats > 0 ? " UNION SELECT  9, " + safe.quoted_sql(L("lcl_location")) + ", 25 FROM DUAL" : "")
                      + (min_plaats > 0 ? " UNION SELECT 14, " + safe.quoted_sql(L("lcl_location") + ' + ' + L("lcl_vakgroup_type") + ' + ' + L("lcl_vakgroup")) + ", 27 FROM DUAL" : "")
                      + (min_plaats > 0 ? " UNION SELECT 23, " + safe.quoted_sql(L("lcl_building")) + ", 29 FROM DUAL" : "")
                      + " UNION SELECT 15, " + safe.quoted_sql(L("lcl_charge_type_group")) + ", 33 FROM DUAL"
                      + " UNION SELECT 12, " + safe.quoted_sql(L("lcl_charge_type")) + ", 35 FROM DUAL"
                      + " UNION SELECT 29, " + safe.quoted_sql(L("lcl_prs_kostenpl_group")) + ", 36 FROM DUAL"
                      + " UNION SELECT  7, " + safe.quoted_sql(L("lcl_account")) + ", 37 FROM DUAL"
                      + " UNION SELECT 20, " + safe.quoted_sql(L("lcl_mld_meldinggroep") + ' + ' + L("lcl_account")) + ", 38 FROM DUAL"
                      + " UNION SELECT 21, " + safe.quoted_sql(L("lcl_mld_meldbron")) + ", 41 FROM DUAL"
                      + " UNION SELECT 27, " + safe.quoted_sql(L("lcl_caller")) + ", 43 FROM DUAL"
                      + " UNION SELECT 28, " + safe.quoted_sql(L("lcl_mld_behandelaar")) + ", 45 FROM DUAL"
                      + (canUseTeams ? " UNION SELECT 24, " + safe.quoted_sql(L("mld_processing_group")) + ", 47 FROM DUAL" : "")
                      + (canUseTeams ? " UNION SELECT 25, " + safe.quoted_sql(L("lcl_mld_processor")) + ", 49 FROM DUAL" : "")
                      + (canUseTeams ? " UNION SELECT 26, " + safe.quoted_sql(L("mld_processing_group") + ' + '+ L("lcl_mld_processor")) + ", 51 FROM DUAL" : "")
                      + " UNION SELECT 11, " + safe.quoted_sql(L("lcl_handler")) + ", 53 FROM DUAL"
                      + " UNION SELECT 10, " + safe.quoted_sql(L("lcl_mld_opdrachtstatus")) + ", 54 FROM DUAL"
                      + " UNION SELECT 17, " + safe.quoted_sql(L("lcl_mld_typeopdr")) + ", 55 FROM DUAL"
                      + " ORDER BY 3";
                  FCLTselector("groupby",
                               sql,
                               { initKey: groepering_key,
                                 label: L("lcl_mld_groepering"),
                                 trclass: "primsearch noxd"
                               });
                }
              }
            } // if (!justClose) 1
            else if (frontend && srtdisc_key_arr.length > 0)
            { // Wordt soms meegegeven in frontend mode. Dus extra, anders wordt deze niet gesubmit.
              %><input type='hidden' id='srtdisc_key_arr' name='srtdisc_key_arr' value='<%=srtdisc_key_arr.join(",")%>'><%
            }

            // prioriteit
            if (!justClose)
            {
                sql = "SELECT -1, '' FROM DUAL UNION "
                    + "SELECT 1, " + safe.quoted_sql(L("lcl_mld_urg_kritiek")) + " FROM DUAL UNION "
                    + "SELECT 2, " + safe.quoted_sql(L("lcl_mld_urg_hoog"))    + " FROM DUAL UNION "
                    + "SELECT 3, " + safe.quoted_sql(L("lcl_mld_urg_normaal")) + " FROM DUAL UNION "
                    + "SELECT 4, " + safe.quoted_sql(L("lcl_mld_urg_laag"))    + " FROM DUAL";
                FCLTselector("priority",
                             sql,
                             { initKey: prio,
                               label: L("lcl_mld_urg"),
                               trclass: "secsearch noxd",
                               multi: true
                             });
            }

            if (mldbord) {
              var initKey = getQParamInt("bordKey", 0);
              var params = {
                srtdisc_key_arr: srtdisc_key_arr,
                disc_key_arr: disc_key_arr,
                stdm_key_arr: stdm_arr
              };
              var colSql = mld.getBoardColumns_sql(params);
              FCLTselector( "mldbord-columns",
                            colSql, {
                              initKey: getQParamInt("bordKey", 0),
                              label: L("lcl_mld_board_group"),
                              data: { "depends-on": "sm" },
                              extraParamValue: "descr",
                              required: true
                            }
              );
%>            <input type='hidden' id='bord_descr' name='bord_descr'><%
            }

            if (!justClose && S('mld_melding_flags') > 1 && !frontend) // Flags checkboxen -->
            {
                for (flagkey=0; flagkey < S("mld_melding_flags"); flagkey++)
                {
                    var label = "<label for='flag" + flagkey + "'>"
                              + "  <span class='mldflag" + flagkey + " mlds'>"
                              +      I("fa-fclt-flag" + (flagkey == 0 ? "0" : ""))
                              + "  </span> " + safe.html(L("lcl_mld_flag" + flagkey))
                              + "</label>";
                    RWCHECKBOXTR("flag" + flagkey, "fldcheck", (flagkey == 0 ? L("lcl_mld_flags") : ""), 1, { twocols: true, posthtml: label });
                }
            }
            if (!frontend)
            {
                RWCHECKBOXTR("actiecodeFE", "fldcheck", "", 1,   { trclass: "primsearch noxd", twocols: true, posthtml: "<label for='actiecodeFE'> " + I("fa-user-circle", { fastyle: "fas" }) + " " + L("lcl_mld_actiecodeFEchk") + "</label>" });
                RWCHECKBOXTR("actiecodeATT", "fldcheck", "", 0, { trclass: "primsearch noxd", twocols: true, posthtml: "<label for='actiecodeATT'> " + I("fa-bell", { fastyle: "fas" }) + " " + L("lcl_mld_actiecodeATTchk") + "</label>" });
                RWCHECKBOXTR("linked",  "fldcheck", "", (chkShowlinked?1:0),  { trclass: "secsearch", twocols: true, posthtml: "<label for='linked'> " + L("lcl_mld_showlinked") + "</label>"});
                RWCHECKBOXTR("respijt", "fldcheck", "", (chkShowRespijt?1:0), { trclass: "secsearch", twocols: true, posthtml: "<label for='respijt'> " + L("lcl_mld_showrespijt") + "</label>"});
                RWCHECKBOXTR("indult",  "fldcheck", "", (chkShowIndult?1:0),  { trclass: "secsearch", twocols: true, posthtml: "<label for='indult'> " + L("lcl_mld_showindult") + "</label>"});
            } else {
              // frontend
%>
              <input type='hidden' id='linked' name='linked' value='on'>
              <input type='hidden' id='respijt' name='respijt' value='on'>
              <input type='hidden' id='indult' name='indult' value='on'>
<%
                // Hier zou je zo willen kunnen filteren dat je alleen de "actie vereist" meldingen ziet. Dat is dus de bij-BO (&2) uitzetten
                RWCHECKBOXTR("actiecodeBO",  "fldcheck", L("lcl_mld_actiecodeBOchk"), 1,   { trclass: "primsearch noxd", boxfirst: true, twocols: true });
            }
            SEARCH_BLOCK_END();
            // Start responsive search_column 2
            SEARCH_BLOCK_START();
              // Datum van
              FCLTcalendar("date_from",
                           { label : L("lcl_period_from"),
                             datum: date_from,
                             initEmpty: (datefrom_empty ? true : false),
                             trclass: (frontend || minfo ? "primsearch" : "secsearch"),
                             volgnr: 1
                           });
              // Datum tot
              FCLTcalendar("date_to",
                           { label: L("lcl_period_to"),
                             datum: date_to,
                             initEmpty: (dateto_empty ? true : false),
                             trclass: (frontend || minfo ? "primsearch" : "secsearch"),
                             volgnr: 2
                           });
              // Einddatum van
              FCLTcalendar("enddate_from",
                           { label : L("lcl_end_date_plan_from"),
                             datum: enddate_from,
                             initEmpty: true,
                             trclass: "secsearch",
                             volgnr: 1
                           });
              // Einddatum tot
              FCLTcalendar("enddate_to",
                           { label: L("lcl_end_date_plan_to"),
                             datum: enddate_to,
                             initEmpty: true,
                             trclass: "secsearch",
                             volgnr: 2
                           });

            // Tags (mijlpalen)
            if (anymldtags && !frontend) {
              // TODO leuk zou zijn: ondersteuning van multivalue. Ik weet nog niet hoe. Moet je dan ook kunnen pinnen voor de backlog
              FCLTmldtagselector("tag_key", "sgMldTag",
                          {  initKeyArr: tag_key_arr,
                             label: L("mld_melding_tag_naam"),
                             multitoggle: true,
                             srtdisc_key : (srtdisc_key_arr.length > 0 ? srtdisc_key_arr[0] : null),
                             trclass: "noxd",
                             filtercode: "Z", // alles, ook inactieve
                             addfixedoption: { txt: L("lcl_suggestemptytxtMPL"), desc: L("lcl_suggestemptydesc"), key: -2 },
                             whenEmpty:  L("lcl_search_generic")
                          });
            }

            if (!justClose && backo)
            {
              // Referentie type
              // Alleen de referenties tonen die ooit bij een melding zijn gebruikt.
              // Als er geen meldingen zijn met een referentie, dan heeft dit filterveld geen zin en wordt het niet getoond.
              var refsql = mld.reference_sql();
              var ref_oRs = Oracle.Execute(refsql);
              if (!ref_oRs.eof)
                FCLTselector("referencetype",
                             refsql,
                             { initKey: -1,
                               label: L("lcl_mld_ref_type"),
                               trclass: "noxd",  /* supported? */
                               emptyOption: ""
                             })
              ref_oRs.Close();
            }

            if (minfo)
            {
              // Referentie
              FCLTreferentieselector("ref_key",
                                     "sgRef",
                                     { label: L("lcl_reference"),
                                       referenceKey: -1,
                                       referenceType: "",
                                       filtercode: "F",
                                       trclass: "noxd",  /* supported? */
                                       whenEmpty: L("lcl_search_generic")
                                       //urlAdd: [{urlParam: "stdm_key", field: "stdm", init: stdm_arr.join(",")}] // MIGHTDO???: Invoer stdmelding van invloed op de referentie.
                                     });
            }

            if (!frontend)
            {
              if (!justClose)
              {
                if (min_plaats > 0) {

                switch(min_plaats)
                {
                  case 7: alg_eindlevel = 2; break; // Locatie
                  case 5: alg_eindlevel = 3; break; // Gebouw
                  case 3: alg_eindlevel = (minfo?4:alg_eindlevel); break; // Voor minfo Verdieping, anders maximaal Gebouw.
                  case 1: alg_eindlevel = (minfo?5:alg_eindlevel); break; // Voor minfo Ruimte, anders maximaal Gebouw.
                }
%>
                <!-- Locatie en gebouw -->
                <tr class="primsearch onlyxd hidden">
                  <td class="label"><label for="loctekst"><%=L("lcl_location")%></label></td>
                  <td>
                    <input type="text" class="fld wildcard" name="loctekst" value="">
                  </td>
                </tr>



<%              FCLTplaatsselector(authparams.ALGreadlevel, { regiokey: reg_key,
                                                              districtkey: dist_key,
                                                              locatiekey: loc_key,
                                                              gebouwkey: bld_key,
                                                              verdiepingkey: flr_key,
                                                              ruimtekey: room_key,
                                                              multitoggle: 5,
                                                              multionchange: true,
                                                              startlevel: alg_startlevel,
                                                              eindlevel: alg_eindlevel,
                                                              filtercode: (alg_eindlevel <= 2 ? "" : (minfo?"EXPMLD":"FACMLD")),
                                                              trclass: "noxd",
                                                              terrein: true,
                                                              whenEmpty: L("lcl_search_generic")  // want filter
                                                            });


                  // Gebouw verantwoordelijke
                  // Dit veld is alleen zichtbaar indien er minimaal één gebouwverantwoordelijke geconfigureerd is (suppressNoValues).
                  FCLTpersoonselector("verantw",
                                  "sgVerantw",
                                  { perslidKey: verantw_key,
                                    label: L("lcl_bld_ter_verantw"),
                                    filtercode: "GTV", // Gebouw/Terrein Verantwoordelijke
                                    trclass: "primsearch noxd",
                                    suppressNoValues: true,
                                    whenEmpty: L("lcl_search_generic")  // want filter
                                  });
                } // min_plaats
                if (minfo)
                { %>

                  <!-- Omschrijving -->
                  <tr class="primsearch">
                    <td class="label"><label for="omschr"><%=L("lcl_descr")%></label></td>
                    <td>
                      <input class="fld wildcard" type="text"  value="<%=safe.htmlattr(omschr)%>" name="omschr">
                    </td>
                  </tr>
<%              } %>

<%              if (fronto || backo || minfo)
                { %>
                  <!-- Melder -->
                <tr class="primsearch onlyxd hidden">
                  <td class="label"><label for="meldertekst"><%=L("lcl_caller")%></label></td>
                  <td>
                    <input type="text" class="fld wildcard" name="meldertekst" value="">
                  </td>
                </tr>
<%                // alleen voor zij die zelf behandelaars kunnen zijn
                  FCLTpersoonselector("sName_key",
                                      "sgPerson",
                                      { perslidKey: perslid_key,
                                        label: L("lcl_caller"),
                                        filtercode: "M",
                                        trclass: "primsearch noxd",
                                        autlevel: authparams.PRSreadlevel,
                                        whenEmpty: L("lcl_search_generic")  // want filter
                                      });

                  // <!-- Meldbron, keuze uit gebruikten -->
                  sql = "SELECT mld_meldbron_key, "+lcl.xsqla('mld_meldbron_omschrijving', 'mld_meldbron_key')
                      + "  FROM mld_meldbron mb"
                      + "  WHERE EXISTS (SELECT '' FROM mld_melding mm WHERE mm.mld_meldbron_key = mb.mld_meldbron_key)"
                      + " ORDER BY "+ lcl.xsql('mld_meldbron_omschrijving', 'mld_meldbron_key');
                  FCLTselector("meldbronkey",
                               sql,
                               { initKey: meldbron_key,
                                 label: L("lcl_mld_meldbron"),
                                 trclass:"secsearch noxd",
                                 emptyOption : "",
                                 initEmpty: true // Altijd lege waarde tonen, ook als er maar 1 waarde is.
                               });


                  // <!-- Behandelaar -->
                  // NB: Gekozen gedrag is hier (en wacht op feedback uit praktijk)
                  //   in fronto filter ik frontofficebehandelaars
                  //   in backo filter ik backofficehandelaars
                  //  een melding met status>2 is hooguit aan een bo toegewezen
                  //  dus filteren op fo-collegas heeft geen zin
                  //  Vraag: moet een fo op BO-mensen kunnen filteren  en andersom?
                  //  Ik zeg van niet, dus is het zo goed.
                  //  Je kunt overwegen om de BO-behandelaars voor FO-ers te verstoppen v.v.
                  //  ook in het overzicht. Voor de transparantie zeggen we van niet.
                  //  Voor FE is het afhankelijk van mld_fe_show_statusnames
%>
                <tr class="primsearch onlyxd hidden">
                  <td class="label"><label for="handlertekst"><%=L("lcl_mld_behandelaar")%></label></td>
                  <td>
                    <input type="text" class="fld wildcard" name="handlertekst" value="">
                  </td>
                </tr>
<%
                  FCLTpersoonselector("sBehandel_key",
                                      "sgBehandelaar",
                                      { perslidKey: (fcltfilters ? null : behandel_key),
                                        label: L("lcl_mld_behandelaar"),
                                        filtercode: "BEHS",
                                        trclass: "primsearch noxd", /* als wel xd: _self zou leuk zijn */
                                        multitoggle: true,
                                        autlevel: authparams.PRSreadlevel,
                                        autlevelALG: authparams.ALGreadlevel,
                                        addfixedoption: { txt: L("lcl_suggestemptytxtBEH"), desc: L("lcl_suggestemptydesc"), key: -2 },
                                        whenEmpty: L("lcl_search_generic")  // want filter
                                      });
                  if (canUseTeams)
                  {
                    var urlAdd;
                    if (!S("mld_processing_group_all"))
                    { // Scope
                        urlAdd = [{urlParam: "srtdisc_key", field: "srtdiscmulti", init: srtdisc_key_arr[0]}];
                    }

                    FCLTdisciplineselector("mld_ins_discipline",
                                           "sgDisc",
                                           { idadd: 2,
                                             label: L("mld_processing_group"),
                                             disc_key: mld_ins_discipline_key,
                                             noJustOne: true,
                                             module: "MLDB",
                                             perslidKey: user_key,
                                             urlAdd: urlAdd,
                                             multitoggle: true,
                                             autfunctionKey: -1, // alles is toegestaan! authparams.autfunctionkey,
                                             addfixedoption: { txt: L("lcl_suggestemptytxtBHT"), desc: L("lcl_suggestemptydesc"), key: -2 },
                                             whenEmpty: L("lcl_search_generic")  // want filter
                                           });
                    FCLTpersoonselector("sBehandel2_key",
                                          "sgBehandelaar",
                                          { perslidKey: behandel2_key,
                                            idadd: 2,
                                            label: L("lcl_mld_processor"),
                                            filtercode: "BH2S",
                                            trclass: "primsearch noxd", /* als wel xd: _self zou leuk zijn */
                                            multitoggle: true,
                                            autlevel: authparams.PRSreadlevel,
                                            autlevelALG: authparams.ALGreadlevel,
                                            addfixedoption: { txt: L("lcl_suggestemptytxtTBH"), desc: L("lcl_suggestemptydesc"), key: -2 },
                                            whenEmpty: L("lcl_search_generic")  // want filter
                                          });
                  }
                }

                if (!minfo)
                { %>
                  <!-- Bussiness Unit (Cluster/Hoofdafdeling) -->
<%                FCLTafdelingselector("sDeptH_key", // TODO: Wellicht deze suggest Custer (Alleen hoofdafdelingen) afhankelijk maken van organisatie suggest (Alle afdelingen)
                                       "sgDeptH",
                                       { departmentKey: hfddep_key,
                                         label: L("lcl_dep_name_level1"),
                                         filtercode: "P",
                                         trclass: "secsearch noxd",
                                         autlevel: authparams.PRSreadlevel,
                                         whenEmpty: L("lcl_search_generic")  // want filter
                                       });
                } %>

                <!-- Bedrijf -->
<%              FCLTbedrijfselector("sComp_key",
                                    "sgComp",
                                    { companyKey: comp_key,
                                      label: L("lcl_company"),
                                      trclass: "primsearch noxd",
                                      filtercode: "I", // Interne bedrijven
                                      autlevel: authparams.PRSreadlevel,
                                      startempty: true, // heeft deze selector kennelijk nodig
                                      whenEmpty: L("lcl_search_generic")  // want filter
                                    });


                // <!-- Organisatie -->
                FCLTafdelingselector("sDept_key",
                                      "sgDept",
                                      { departmentKey: dep_key,
                                        label: L("lcl_prs_organisatie"),
                                        trclass: "primsearch noxd",
                                        autlevel: authparams.PRSreadlevel,
                                        whenEmpty: L("lcl_search_generic")  // want filter
                                      });

                // <!-- Kostenplaats -->
                if (anykpn)
                {
                  if (anykpngrp)
                      {
                      // Kostenplaatsgroep.
                      sql = "SELECT prs_kostenplaatsgrp_key"
                          + "     , DECODE (prs_kostenplaatsgrp_nr, NULL, '', prs_kostenplaatsgrp_nr || ' - ') || prs_kostenplaatsgrp_oms oms"
                          + "  FROM prs_kostenplaatsgrp";
                      FCLTselector("kpgrp_key",
                                   sql,
                                   { initKey: kpgrp_key_arr.join(","),
                                     label: L("lcl_prs_kostenpl_group"),
                                     trclass: "primsearch noxd",
                                     onChange: "onChangeKpgroep()", // kpgroepChanged
                                     emptyOption: "",
                                     multi: true,
                                     initEmpty: true
                                   });
                      }
                  FCLTkostenplaatsselector("kp",
                                           "sgKp",
                                           user_key,
                                           { kostenplaatsKey: kp_key_arr.join(","),
                                             trclass: "noxd",
                                             label: L("lcl_mld_inf_Kostenplaats"),
                                             filtercode: "AA", // Alleen actieve kostenplaatsen kunnen selecteren "All Active". Huidige waarde als initiële waarde kan bij kostenplaatsen altijd.
                                             urlAdd: [{ urlParam: "kpgrp_key_arr", field: "kpgrp_key" }],
                                             inzage: true,
                                             multitoggle: true,
                                             whenEmpty: L("lcl_search_generic")  // want filter
                                           });
                }

                if ((backo || minfo) && anyorders)
                { // wat opdrachtfilters
                  // Zijn er vakgroeptypen met bestelgegevens? (Nee, Ja maar niet allemaal, Ja allemaal)
                  sql = "SELECT COUNT(sd.ins_srtdiscipline_key) aantal_srtdisc"
                      + "     , SUM(sd.ins_srtdiscipline_bes) aantal_besgeg"
                      + "  FROM ins_v_aanwezigsrtdiscipline sd";
                  var oRs = Oracle.Execute(sql);
                  var aantal_srtdisc = oRs("aantal_srtdisc").Value;
                  var aantal_besgeg = oRs("aantal_besgeg").Value;
                  oRs.Close();

                  var lutype = (aantal_besgeg == 0 // Zijn alle vakgroeptypen zonder bestelgegevens?
                               ? "OU" // Uitvoerenden according to mld_opdr.
                               : (aantal_besgeg == aantal_srtdisc // Zijn alle vakgroeptypen met bestelgegevens?
                                 ? "L" // Leveranciers.
                                 : "LU")); // Levereanciers en Uitvoerenden.

                  // <!-- Uitvoerende -->
                  FCLTuitvoerendeselector("handler",
                                           "sgUitv",
                                           { uitvoerendekey: handler_key,
                                             label: L("lcl_handler"),
                                             trclass:"primsearch noxd",
                                             autlevel: authparams.PRSreadlevel,
                                             whenEmpty: L("lcl_search_generic"),  // want filter
                                             initEmpty: true, // Altijd lege waarde tonen, ook als er maar 1 waarde is.
                                             lutype: lutype // Leveranciers en/of Uitvoerenden.
                                           });

                  // <!-- Behandelaar Opdracht -->
                  // Ben ik toevallig een contactpersoon van een extern bedrijf? Dan mag ik automatisch
                  // alleen de opdrachten van mijn bedrijf/bedrijven zien (AADS#)
                  var exhandler = user.iamContact();
                  FCLTpersoonselector("uitvopdr_key",
                                        "sgPersonOpdr",
                                        { perslidKey: handleropdr_key,
                                          label: L("lcl_mld_behandelaar")+" "+L("lcl_opdr_info"),
                                          trclass: "secsearch noxd",
                                          autlevel: authparams.PRSreadlevel,
                                          filtercode: justClose && exhandler? "BEHOC" : "BEHO",
                                          urlAdd: [{urlParam: "pbtype", field: "pbtype", init: "BI"},
                                                   {urlParam: "uitv_key", field: "uitvoerende", init: -1}],
                                          disc_key: -1,
                                          initEmpty: true, // Altijd lege waarde tonen, ook als er maar 1 waarde is.
                                          whenEmpty: L("lcl_search_generic")  // want filter
                                        });

                  if (minfo)
                  {
                    // <!-- Contactpersoon -->
                    FCLTpersoonselector("sContact_key",
                                        "sgContact",
                                        { perslidKey: contact_key,
                                          label: L("lcl_contact_pers"),
                                          filtercode: "CPO", // Contactpersonen van bestaande opdrachten
                                          trclass: "secsearch noxd",
                                          autlevel: authparams.PRSreadlevel,
                                          initEmpty: true, // Altijd lege waarde tonen, ook als er maar 1 waarde is.,
                                          whenEmpty: L("lcl_search_generic")  // want filter
                                        });
                  }

                  // <!-- Opdrachttype -->
                  sql = "SELECT mld_typeopdr_key"
                        + ", "+ lcl.xsqla('t.mld_typeopdr_omschrijving', 't.mld_typeopdr_key')
                        + " FROM mld_typeopdr t"
                        + " ORDER BY 2";
                    FCLTselector("opdrtype",
                                 sql,
                                 { initKey: opdrtype_key,
                                   label: L("lcl_mld_typeopdr"),
                                   trclass:"primsearch noxd",
                                   emptyOption : "",
                                   initEmpty: true // Altijd lege waarde tonen, ook als er maar 1 waarde is.
                                 })
                }
		 if (anyobj) {
                if (minfo)
                {
                  //<!-- Objectdiscipline -->
                  sql = "SELECT ins_discipline_key"
                      + ", "+lcl.xsqla('ins_discipline_omschrijving', 'ins_discipline_key')
                      + " FROM ins_v_aanwezigdiscipline"
                      + " WHERE ins_discipline_key IN"
                        + " (SELECT ins_discipline_key"
                        + " FROM fac_v_webgebruiker g"
                        + ", fac_functie f"
                        + " WHERE g.prs_perslid_key = " + user_key
                        + " AND f.fac_functie_key = g.fac_functie_key "
                        + " AND f.fac_functie_code = 'WEB_INSMAN'"
                        + " AND (g.fac_gebruiker_alg_level_read < 9 AND g.fac_gebruiker_prs_level_read < 9)" + ")"
                      + " ORDER BY "+lcl.xsql('ins_discipline_omschrijving', 'ins_discipline_key');  // is by 2 niet goedkoper?
                  FCLTselector("insdisc",
                               sql,
                               { initKey: disc_key,
                                 label: L("lcl_discipline"),
                                 onChange: 'updateInsSrtGroup("WEB_INSMAN");', // disgroupChanged
                                 trclass: "secsearch noxd",
                                 emptyOption: (disc_key > 0? null : "")
                               }); %>

                  <!-- Objectgroup -->
<%                FCLTselector("inssrtgroup",
                               "", // sql: lege selectbox die onload wordt geladen
                               { initKey: insgroup_key,
                                 label: L("lcl_obj_group"),
                                 onChange: 'updateInsSrtDeel("WEB_INSMAN");', // srtgroupChanged
                                 trclass: "secsearch noxd",
                                 emptyOption: ""
                               }); %>

                  <!-- Objectsoort -->
<%                FCLTselector("inssrtdeelmulti",
                               "", // sql: lege selectbox die onload wordt geladen
                               { initKey: objsrt_key_arr.join(","),
                                 label: L("lcl_obj_sort"),
                                 multi: true,
                                 trclass:"secsearch noxd",
                                 emptyOption: ""
                               }); %>
                  <script type="text/javascript">
                    // Laad de groupen en de items
                    // Selecteer eventueel de initiële groepen en items die meegegeven kunnen worden
                    $(function()
                    {
                      updateInsSrtGroup("<%=autfunction%>", "<%=insgroup_key%>", "<%=objsrt_key_arr%>");
                    });
                  </script>
<%              }  // minfo
                // Object omschrijving
                RWFIELDTR("objectoms", "fld wildcard", L("lcl_mld_object_oms"), safe.htmlattr(omschr), { trclass: "secsearch", datatype: "text" });
              } // anyobj
              } // if (!justClose) 2
            } // if (!frontend)

        SEARCH_BLOCK_END();
        if     (!justClose)
        { SEARCH_BLOCK_START({wide: true});
        %>
          <!-- Status checkboxen -->
          <tr>
            <td colspan="2">
              <div id="statusboxes">
<%              // Statusfilters:
                // FE: nog niks mee gedaan (2), mee bezig (0,3,4,7), afgewezen (1), klaar (5,6)
                // FO: zelf mee bezig (0), bij BO (2,3,4,7), afgewezen (1), afgemeld (5), archief (6)
                // BO :te behandelen (2,3) zelf mee bezig (4,7), bij FO (0), afgewezen (1), afgemeld (5), archief (6)
                // Merk op: de ids kunnen afhankelijk van de urole andere betekenis hebben, dus.
                if (frontend)
                { %>
                  <label><%=L("lcl_mld_mldstatus")%></label>
                  <input type="checkbox" class="fldcheck" name="mldNew"  id="mldNew" value="1" <%=chkNew? "checked" : ""%>><label for="mldNew"><%=L("lcl_mld_chk_fe_mldNew")%></label>
                  <input type="checkbox" class="fldcheck" name="mldBusy" id="mldBusy" value="1" <%=chkBusy? "checked" : ""%>><label for="mldBusy"><%=L("lcl_mld_chk_fe_mldBusy")%></label>
                  <input type="checkbox" class="fldcheck" name="mldRej"  id="mldRej" value="1" <%=chkRej? "checked" : ""%>><label for="mldRej"><%=L("lcl_mld_chk_fe_mldRej")%></label>
                  <input type="checkbox" class="fldcheck" name="mldDone" id="mldDone" value="1" <%=chkDone? "checked" : ""%>><label for="mldDone"><%=L("lcl_mld_chk_fe_mldDone")%></label>
<%              }
                else if (fronto)
                {
                %>
                  <label><%=L("lcl_mld_mldstatus")%></label>
                  <input type="checkbox" class="fldcheck" name="mldSelf" id="mldSelf" value="1" <%=chkSelf? "checked" : ""%>><label for="mldSelf"><%=L("lcl_mld_chk_fo_mldSelf")%></label>
                  <input type="checkbox" class="fldcheck" name="mldBusy" id="mldBusy" value="1" <%=chkBusy? "checked" : ""%>><label for="mldBusy"><%=L("lcl_mld_chk_fo_mldBusy")%></label>
                  <input type="checkbox" class="fldcheck" name="mldUitg" id="mldUitg" value="1" <%=chkSelf? "checked" : ""%>><label for="mldUitg"><%=L("lcl_mld_chk_fo_mldUitg")%></label>
                  <input type="checkbox" class="fldcheck" name="mldRej"  id="mldRej" value="1" <%=S("mld_rejected_is_open")||chkRej ? "checked" : " "%>><label for="mldRej"><%=L("lcl_mld_chk_fo_mldRej")%></label>
                  <input type="checkbox" class="fldcheck" name="mldAfm"  id="mldAfm" value="1" <%=chkAfm? "checked" : ""%>><label for="mldAfm"><%=L("lcl_mld_chk_fo_mldAfm")%></label>
                  <input type="checkbox" class="fldcheck" name="mldVer"  id="mldVer" value="1" <%=chkVer? "checked" : ""%>><label for="mldVer"><%=L("lcl_mld_chk_fo_mldVer")%></label>
<%              }
                else if (backo)
                { %>
                  <label><%=L("lcl_mld_mldstatus")%></label>
                  <input type="checkbox" class="fldcheck" name="mldNew"  id="mldNew" value="1" <%=chkNew? "checked" : ""%>><label for="mldNew"><%=L("lcl_mld_chk_bo_mldNew")%></label>
                  <input type="checkbox" class="fldcheck" name="mldSelf" id="mldSelf" value="1" <%=chkSelf? "checked" : ""%>><label for="mldSelf"><%=L("lcl_mld_chk_bo_mldSelf")%></label>
                  <input type="checkbox" class="fldcheck" name="mldUitg" id="mldUitg" value="1" <%=chkSelf? "checked" : ""%>><label for="mldUitg"><%=L("lcl_mld_chk_bo_mldUitg")%></label>
               <% if (anyfobodiscs) { %>
                  <input type="checkbox" class="fldcheck" name="mldBusy" id="mldBusy" value="1" <%=chkBusy? "checked" : ""%>><label for="mldBusy"><%=L("lcl_mld_chk_bo_mldBusy")%></label>
               <% } %>
                  <input type="checkbox" class="fldcheck" name="mldRej"  id="mldRej" value="1" <%=chkRej? "checked" : ""%>><label for="mldRej"><%=L("lcl_mld_chk_bo_mldRej")%></label>
                  <input type="checkbox" class="fldcheck" name="mldAfm"  id="mldAfm" value="1" <%=chkAfm? "checked" : ""%>><label for="mldAfm"><%=L("lcl_mld_chk_bo_mldAfm")%></label>
                  <input type="checkbox" class="fldcheck" name="mldVer"  id="mldVer" value="1" <%=chkVer? "checked" : ""%>><label for="mldVer"><%=L("lcl_mld_chk_bo_mldVer")%></label>
<%
                } %>
              </div>
            </td>
          </tr>
<%        SEARCH_BLOCK_END();
        } // if (!justClose) 3

        SIMPLE_BLOCK_START();
        var buttons =  [];
        if (mldlist)
          buttons.push ( { title: L("lcl_overview_list"), action: "doSubmit(0);", importance: 1, icon: "fa-clipboard-list"} ); // Overzichtslijst
        if (mldbord)
          buttons.push ( { title: L("lcl_mld_board"), action: "doSubmit(0, null, 'bord');", xclass: "noxd", importance: 1, icon: "fa-chart-tree-map"} ); // Meldingenbord

        if (minfo) // TODO nog te togglen met xd, html: "class='noxd'" werkt niet vanzelf
          buttons.push ( {title: L("lcl_mld_PPI"), action:"doSubmit(1)", xclass: "noxd", importance: 1, icon: "fa-chart-bar"} ); // Overzicht Prestatie Performance Indicatoren (PPI)
        if (!frontend && !justClose)
        {
            buttons.push ( {title: L("lcl_shared_more"),  action:"iface_toggleSecondarySearchblock()", id : "btnMoreLess", xclass: "noxd", importance: 3, icon: "fa-chevron-right" } );
            buttons.push ( {title: L("lcl_shared_advanced"),  action:"myModal()", xclass: "noxd", importance: 3, icon: "fa-filter"} );
        }
        CreateButtons(buttons, { entersubmit: true, showIcons: true} );
        SIMPLE_BLOCK_END();
      SEARCH_PAGE_END();
%>
      </form>

    <script type="text/javascript">
<%
      if (autosearch)
      {
        // klap de More open om ook evt. verborgen filters te tonen
        // zou je nog eens kunnen verfijnen , maar hoeft van mij niet
%>      $(function()
        {
          iface_toggleSecondarySearchblock();
        });
        window.afterfiltersready = function () { doSubmit() };
<%    } %>
    </script>
    <div id="result">
      <iframe width="100%" height="100%"
              src="../Shared/empty.asp"
              name="workFrame" id="workFrame"
              onload="FcltMgr.iframeLoaded(this)"
<%=refreshOnActivate ? " data-refresh-on-activate='1'" : ""%>
              frameborder="0" scrolling="no">
      </iframe>
    </div>
  </body>
</html><% ASPPAGE_END(); %>
