<%@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          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)
      searchtekst      Zoektekst
      omschr           Omschrijving
      opdrtype_key     Opdrachttype van de opdracht
      perslid_key      Melder (key) van de melding
      behandel_key     Behandelaar (key) van de melding
      handler_key      Uitvoerende (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
      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 direcht 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
      datefrom         Periode van
      dateto           Periode tot
      bosort           Backoffice sortering (0=Eerste af, 1=Nieuwste eerst, default S('mld_bo_sort_descending')) 
    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/afdelingselector.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/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);
if (justClose || justAccept) urole = "bo";  // dat komt beter in de buurt dan fe.

var fronto = urole == "fo";
var backo = urole == "bo";
var minfo = urole == "mi"; // NOT APPLICABLE?
var frontend = (urole == "fe" || (!fronto & !backo & !minfo));


// PREFILL PARAMETERS:
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
var disc_key_arr = getQParamIntArray("disc_key_str", []); // Productgroep
var meldinggrp_key = getQParamInt("meldinggrp_key", -1); // Meldinggroep
var behandelgrp_key = getQParamInt("behandelgrp_key", -1); // Behandelgroep
var stdm_arr = getQParamIntArray("stdm_str", []); // Melding (Stdmelding)
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 behandel_key = getQParamInt("behandel_key", -1); // Behandelaar
var handler_key = getQParamInt("handler_key", -1); // Uitvoerende
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 kp_key = getQParamInt("kp_key", -1); // Kostenplaats
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 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

// hier worden ook de default vinkjes bepaald, per stuk te overrulen
var chkAfm  = (getQParamInt("chkAfm", 0) == 1);
var chkBusy = (getQParamInt("chkBusy", (fronto||frontend ? 1 : 0)) == 1);
var chkDone = (getQParamInt("chkDone", 0) == 1);
var chkNew  = (getQParamInt("chkNew", 1) == 1);  // default aan, fronto heeft geen New
var chkRej  = (getQParamInt("chkRej", 0) == 1);
var chkSelf = (getQParamInt("chkSelf", (fronto ? 1 : 0)) == 1);
var chkVer  = (getQParamInt("chkVer", 0) == 1);

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);
var fromdate = new Date(todate.getFullYear(), todate.getMonth(), 1);

var date_from = (!datefrom? fromdate : datefrom);
var date_to = (!dateto? todate : dateto);

if (srtdisc > 0)
    lcl.set_dialect(srtdisc, "MLD_SRTDISCIPLINE_KEY");

if (disc_key_arr.length > 0 && srtdisc < 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 = 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 == -1) {
    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 = 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 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
sql= "SELECT 1 FROM ins_srtdiscipline WHERE (ins_srtdiscipline_alg=1 OR ins_srtdiscipline_ins=1 OR ins_srtdiscipline_bes=1) AND ROWNUM = 1";
oRs = Oracle.Execute(sql);
var anygeo = !oRs.eof;
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 orders
// 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();


// 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 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").toggle(doxd);
        iface_toggleSecondarySearchblock(false); // altijd uitschakelen
      }
<% } %>
      function doSubmit(pimode)
      {
<% 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");
        }
<% } %>
        // 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 (!validateForm("u2"))
          return false;

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

<%    if (!frontend)
      { %>
        function myModal()
        {
          var groupby = $("#groupby").val();
          var lastmodal = -1; // Unieke modal key zodat inhoud scherm met ingevulde waarden onthouden worden
          if (!minfo || 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)
          { // Meldingen
            if ($("#srtdisc").val() == -1)
            {
              alert(L("lcl_mld_select_nosrtdisc_selected"));
              return;
            }

            var lsrtdisc_key = $("#srtdisc").val()||<%=srtdisc%>;
            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
                    + "&urole=<%=urole%>"
                    + "&advanced=1"
            var titel = "<%=L("lcl_mld_kenmerken")%>";
          }
          else if (groupby == 2 || groupby == 10 || groupby == 16 || groupby == 17)
          { // Opdrachten
            if ($('#opdrtype').val() == -1)
            {
              alert(L("lcl_select_notypeopdr_selected"));
              return;
            }

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

  <body id="searchbody">
    <div id="search">
      <form name="u2" method="get" action="mld_search_list.asp" target="workFrame" onsubmit='doSubmit(0);return false'>
        <input type="hidden" name="urole" value="<%=urole%>">
        <input type="hidden" name="user_key" value="<%=user_key%>">
        <input type="hidden" name="perform" id="perform" value="0">
<%      if (srtdisc > -1 || disc_key_arr.length != 0) {  %>
           <input type='hidden' id='srtdisc' name='srtdisc' value='<%=srtdisc%>'>
<%      } %>
<%      if (justClose) { %>
          <input type="hidden" name="justclose" value="1">
<%      } %>
<%      if (justAccept) { %>
          <input type="hidden" name="justaccept" value="1">
<%      } %>
<%      BLOCK_START("searchtable", L("lcl_filterblok")); %>
        <tr>
          <td class="searchkolom1">
            <table><!-- x rijen, 2 kolommen: label + veld -->
            <!-- Meldingnummer -->
<%
            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="fldmldnum<%=justClose?' required': ''%>" name="mldnum" <%=(mld_key != -1) ? "value='" + mld_key + "'" : ""%>>
              </td>
            </tr>

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

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

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

              if (!justClose)
              { %>
                <!-- Zoektekst -->
                <tr class="primsearch">
                  <td class="label"><label for="searchtekst"><%=L("lcl_search_diff_fields")%>:</label></td>
                  <td>
                    <input type="text" class="fldsrch wildcard" name="searchtekst" value="<%=safe.htmlattr(searchtekst)%>">
                  </td>
                </tr>
<%              if (backo && anyorders)
                { // alleen back kan kiezen uit opdrachten
%>                <!-- Resultaat meldingen/opdrachten -->
                  <tr class="primsearch noxd">
                    <td class="label"><label><%=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)
               {

if (srtdisc == -1) {  // 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 van hiervoor effectief
                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_stdmelding ms"
                      + ", mld_v_aanwezigdiscipline m1"
                      + " WHERE m1.ins_discipline_key = ms.mld_ins_discipline_key"
                      + " AND ms.mld_stdmelding_verwijder IS NULL)"
                    + " AND EXISTS (SELECT 'y'"
                      + " FROM fac_v_my_disciplines md"
                      + " , mld_v_aanwezigdiscipline m1"
                      + " WHERE fac_functie_code = " + safe.quoted_sql(autfunction) + " "
                      + " AND prs_perslid_key = " + user_key
                      + " AND m1.ins_srtdiscipline_key = sd.ins_srtdiscipline_key"
                      + " AND md.ins_discipline_key = m1.ins_discipline_key"
                      + ") "
                      + " ORDER BY 2";

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

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

                     oRs.close();
                  }
                  oRs2.close();

                if (srtdisc == -1)
                {
                  FCLTselector("srtdisc",
                               sql,
                               { initKey: srtdisc,
                                 label: L("lcl_vakgroup_type"),
                                 trclass:"primsearch noxd",
                                 onChange: 'updateDisc("' + urole + '", "' + autfunction + '");',
                                 emptyOption: (srtdisc == -1? L("lcl_all") : null), // Als een srtdisc is meegegeven dan geen lege optie,
                                 readonly: srtdisc > -1 || disc_key_arr.length != 0
                               })
                }
}

if (!frontend && srtdisc > -1)
{
  %><input type='hidden' id='srtdisc' name='srtdisc' value='<%=srtdisc%>'><%
}

               // <!-- 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.
// TODO: als er maar 1 waarde is dan die kiezen; het is zinloos dan Alle/De ene keuze als selectie te bieden, fixed De ene keuze is dan beter (ruimte!)
                // 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 = " + safe.quoted_sql(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"
                        + " 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 + ")"
                        + (srtdisc != -1
                          ? " AND m1.ins_discipline_key IN (SELECT ins_discipline_key"
                            + " FROM mld_discipline"
                            + " WHERE ins_srtdiscipline_key = " + srtdisc + ")"
                          : "")
                        + (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: 'updateStdm("' + urole + '", "' + autfunction + '");',
                               trclass: "primsearch noxd",
                               multi: true,
                               emptyOption: (disc_key_arr.length == 0? L("lcl_all") : 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 = " + safe.quoted_sql(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"
                              : "")
                            + (srtdisc != -1
                              ? " AND ins_srtdiscipline_key = " + srtdisc
                              : "")
                            + (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"),
                               trclass: (minfo ? "primsearch" : "secsearch")+ " noxd",
                               multi: true,
                               emptyOption: L("lcl_all")
                             });

                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'});
                }

                // 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 = " + safe.quoted_sql(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 != -1
                             ? " AND mld_ins_discipline_key IN (SELECT ins_discipline_key"
                               + " FROM mld_discipline"
                               + " WHERE ins_srtdiscipline_key = " + srtdisc + ")"
                             : "")
                           + (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: ""
                                  });
                }
                
                if (backo)
                {
                sortsql = "SELECT 0, " + safe.qL("lcl_mld_behandeling") + ", 0 FROM DUAL"
                      + " UNION SELECT 1, " + safe.qL("lcl_mld_newfirst") + ", 1 FROM DUAL"
                      + " ORDER BY 3";
                  oRs = Oracle.Execute(sortsql);
                  if (!oRs.eof) {
                      FCLTselector("bosort",
                                    sortsql,
                                    { initKey: bosort,
                                      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  'MLDBEH', " + safe.quoted_sql(L("lcl_mld_trackprefixmld")+L("lcl_mld_is_mldbeh")) + " 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  '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: ""
                             });
                    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_all")
                             });

%>

                  <!-- Group by -->
<%                sql = "SELECT         1, " + safe.quoted_sql(L("lcl_complains")) + ", 1 FROM DUAL"
                      + " UNION SELECT  2, " + safe.quoted_sql(L("lcl_orders")) + ", 2 FROM DUAL"
                      + " UNION SELECT 16, " + safe.quoted_sql(L("lcl_orders") + ' + ' + L("lcl_opdr_kosten")) + ", 3 FROM DUAL"
                      + " UNION SELECT  3, " + safe.quoted_sql(L("lcl_complain") + ' ' + L("lcl_status")) + ", 4 FROM DUAL"
                      + " UNION SELECT  4, " + safe.quoted_sql(L("lcl_vakgroup_type")) + ", 5 FROM DUAL"
                      + " UNION SELECT  5, " + safe.quoted_sql(L("lcl_vakgroup_type") + ' + ' + L("lcl_vakgroup")) + ", 6 FROM DUAL"
                      + " UNION SELECT 13, " + safe.quoted_sql(L("lcl_district") + ' + ' + L("lcl_vakgroup_type") + ' + ' + L("lcl_vakgroup")) + ", 7 FROM DUAL"
                      + " UNION SELECT 14, " + safe.quoted_sql(L("lcl_location") + ' + ' + L("lcl_vakgroup_type") + ' + ' + L("lcl_vakgroup")) + ", 8 FROM DUAL"
                      + " UNION SELECT  6, " + safe.quoted_sql(L("lcl_vakgroup_type") + ' + ' + L("lcl_vakgroup") + ' + ' + L("lcl_complain")) + ", 9 FROM DUAL"
                      + " UNION SELECT 12, " + safe.quoted_sql(L("lcl_charge_type")) + ", 10 FROM DUAL"
                      + " UNION SELECT 15, " + safe.quoted_sql(L("lcl_charge_type_group")) + ", 11 FROM DUAL"
                      + " UNION SELECT  7, " + safe.quoted_sql(L("lcl_mld_kosten")) + ", 12 FROM DUAL"
                      + " UNION SELECT  8, " + safe.quoted_sql(L("lcl_district")) + ", 13 FROM DUAL"
                      + " UNION SELECT  9, " + safe.quoted_sql(L("lcl_location")) + ", 14 FROM DUAL"
                      + " UNION SELECT 10, " + safe.quoted_sql(L("lcl_mld_opdrachtstatus")) + ", 15 FROM DUAL"
                      + " UNION SELECT 11, " + safe.quoted_sql(L("lcl_handler")) + ", 16 FROM DUAL"
                      + " UNION SELECT 17, " + safe.quoted_sql(L("lcl_mld_typeopdr")) + ", 17 FROM DUAL"
                      + " UNION SELECT 18, " + safe.quoted_sql(L("lcl_mld_meldinggroep")) + ", 18 FROM DUAL"
                      + " UNION SELECT 19, " + safe.quoted_sql(L("lcl_vakgroup_type") + ' + ' + L("lcl_mld_meldinggroep")) + ", 19 FROM DUAL"
                      + " UNION SELECT 20, " + safe.quoted_sql(L("lcl_mld_meldinggroep") + ' + ' + L("lcl_mld_kosten")) + ", 20 FROM DUAL"
                      + " UNION SELECT 21, " + safe.quoted_sql(L("lcl_mld_meldbron")) + ", 21 FROM DUAL"
                      + " UNION SELECT 22, " + safe.quoted_sql(L("lcl_mld_urg")) + ", 22 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 > -1)
            { // Wordt soms meegegeven in frontend mode. Dus extra, anders wordt deze niet gesubmit.
              %><input type='hidden' id='srtdisc' name='srtdisc' value='<%=srtdisc%>'><%
            }

            if (!justClose && S('mld_melding_flags') > 1 && !frontend) // Flags checkboxen -->
            {
%>
              <tr>
                <td class="label"><label><%=L("lcl_mld_flags")%>:&nbsp;</label></td>
                <td id="mldFlags">
<%                  for (flagkey=0; flagkey < S('mld_melding_flags'); flagkey++)
                    {
                      if (flagkey == 0)
                      {
                        %><label for="flag0"><input type="checkbox" name="flag0" checked>&nbsp;<%=safe.html(L("lcl_mld_flag0"))%></label><br>
<%                    } 
                      else
                      {    
                        %><label for="flag<%=flagkey%>"><input type="checkbox" name="flag<%=flagkey%>" checked><img src='../Pictures/mldflag<%=flagkey%>.png'>&nbsp;<%=safe.html(L("lcl_mld_flag"+flagkey))%></label><br>
<%                    }
                    } %>
                </td>
              </tr>
<%          } %>
          </table>
          </td><!-- end column 1 -->

          <!-- Second column -->
          <td class="searchkolom2">
            <table><!-- x rijen, 2 kolommen: label + veld -->
            <!-- Datum van -->
<%          if (frontend || minfo)
            {
              FCLTcalendar("date_from",
                           { label : L("lcl_period_from"),
                             datum: date_from,
                             initEmpty: (frontend ? true : false),
                             trclass: "primsearch",
                             volgnr: 1
                           }); %>
              <!-- Datum tot -->
<%            FCLTcalendar("date_to",
                           { label: L("lcl_period_to"),
                             datum: date_to,
                             initEmpty: (frontend ? true : false),
                             trclass: "primsearch",
                             volgnr: 2
                           });
            }
            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 (anygeo) {
%>
                <!-- Locatie en gebouw -->
                <tr class="primsearch onlyxd hidden">
                  <td class="label"><label for="loctekst"><%=L("lcl_location")%>:</label></td>
                  <td>
                    <input type="text" class="fldsrch 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,
                                                              startlevel: alg_startlevel,
                                                              eindlevel: (minfo? 5 : 3), // Voor minfo Ruimte, anders maximaal Gebouw.
                                                              filtercode: (minfo?null:"FAC"),
                                                              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_alg_bld_verantw"),
                                    filtercode: "GV", // Gebouw Verantwoordelijke
                                    trclass: "primsearch noxd",
                                    suppressNoValues: true,
                                    whenEmpty: L("lcl_search_generic")  // want filter
                                  });
                } // anygeo
                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="fldsrch 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="fldsrch wildcard" name="handlertekst" value="">
                  </td>
                </tr>
<%
                  FCLTpersoonselector("sBehandel_key",
                                        "sgBehandelaar",
                                        { perslidKey: behandel_key,
                                          label: L("lcl_mld_behandelaar"),
                                          filtercode: "BEHS",
                                          trclass: "primsearch noxd", /* als wel xd: _self zou leuk zijn */
                                          autlevel: authparams.PRSreadlevel,
                                          autlevelALG: authparams.ALGreadlevel,
                                          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,
                                      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)
                {                
%>              <tr class="primsearch noxd">
                  <td class="label"><label for="kostenplaats"><%=L("lcl_mld_kosten")%>:</label></td>
<%                // Let op: dit is bewust een wildcardfilter
                  var kpstr = "";
                  if (kp_key != -1)
                  {
                    sql = "SELECT " + S("prs_kpn_string") + " kpstring"
                        + " FROM prs_kostenplaats k"
                        + " WHERE prs_kostenplaats_key = " + kp_key;
                    var oRs = Oracle.Execute(sql);
                    if (!oRs.eof)
                      kpstr = oRs("kpstring").Value;
                  }
                  // in principe in kp_key voldoende voor de selectie en hoeft de string niet mee. Disabled maken dan?
%>
                  <td>
                    <input class="fldkp wildcard" type="text"  value="<%=safe.htmlattr(kpstr)%>" name="kp">
                  </td>
                </tr>
<%              }
                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_srtdis"
                      + "     , SUM(sd.ins_srtdiscipline_bes) aantal_besgeg"
                      + "  FROM ins_v_aanwezigsrtdiscipline sd";
                  var oRs = Oracle.Execute(sql);
                  var aantal_srtdis = oRs("aantal_srtdis").Value;
                  var aantal_besgeg = oRs("aantal_besgeg").Value;
                  var lutype = (aantal_besgeg == 0 // Zijn alle vakgroeptypen zonder bestelgegevens?
                               ? "U" // Uitvoerenden.
                               : (aantal_besgeg == aantal_srtdis // 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.
                                });

                  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
                    $(document).ready(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)
%>
            </table>
          </td><!-- end column 2-->
        </tr>
<%
        if     (!justClose)
        { %>
          <!-- 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")%>:&nbsp;</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")%>:&nbsp;</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="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")%>:&nbsp;</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="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>
<%      } // if (!justClose) 3
        BLOCK_END();

        var buttons =  [];
        buttons.push ( {title: L("lcl_overview_list"),  action:"doSubmit(0)" } ); // Overzicht
        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"} ); // Overzicht Prestatie Performance Indicatoren (PPI)
        if (!frontend && !justClose)
        {
            buttons.push ( {title: L("lcl_shared_more"),  action:"iface_toggleSecondarySearchblock()", id : "btnMoreLess", xclass: "noxd" } );
            buttons.push ( {title: L("lcl_obj_advanced"),  action:"myModal()", xclass: "noxd"} );
        }
        CreateButtons(buttons, { entersubmit: true} );
%>
      </form>
    </div> <!-- search -->

    <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
%>      $(document).ready(function()
                          {
                            iface_toggleSecondarySearchblock();doSubmit();
                          });
<%    } %>
    </script>
    <div id="result">
      <iframe width="100%" height="100%"
              src="../Shared/empty.asp"
              name="workFrame" id="workFrame"
              onload='FcltMgr.iframeLoaded(this)'
              frameborder="0" scrolling="no">
      </iframe>
    </div>
  </body>
</html>