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

     NOTE: als hier inhoudelijk wordt gewijzigd, dan mogelijk in mld/mld-search.asp ook.
*/ %>

<%
DOCTYPE_Disable = true;
%>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/selector.inc" -->

<%
// Build an article list
var urole = getQParamSafe("urole");
var fronto = urole == "fo";
var backo = urole == "bo";
var minfo = urole == "mi"; // NOT APPLICABLE?
var frontend = (urole == "fe" || (!fronto & !backo & !minfo));

var autfunction  = getQParam("autfunction", ""); // Check of user rechten heeft op meegegeven artikelen
var srtdisc_arr  = getQParamIntArray("srtdisc_key",  []); // Soort Melding
var disc_key_arr = getQParamIntArray("disc_key_str", []); // Productgroep (discipline) array
var offerte = getQParamInt("offerte", -1);

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 DISTINCT 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"
        + (offerte >= 0
          ? "   , mld_typeopdr_srtdiscipline tsd"
            + " , mld_typeopdr mto"
          : "")
        + " WHERE m1.ins_srtdiscipline_key = sd.ins_srtdiscipline_key"
        + (offerte >= 0
          ? " AND sd.ins_srtdiscipline_key = tsd.ins_srtdiscipline_key"
            + " AND tsd.mld_typeopdr_key = mto.mld_typeopdr_key"
            + " AND (tsd.ins_discipline_key IS NULL OR tsd.ins_discipline_key = m1.ins_discipline_key)"
            + " AND mto.mld_typeopdr_isofferte = " + offerte
          : "")
        + " AND 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_discipline_key IN (" + discsql_aut + ")"
        + (srtdisc_arr.length != 0
          ? " AND m1.ins_discipline_key IN (SELECT ins_discipline_key"
            + " FROM mld_discipline"
            + " WHERE ins_srtdiscipline_key IN (" + srtdisc_arr.join(",") + "))"
          : "")
        + (disc_key_arr.length != 0
          ? " AND m1.ins_discipline_key IN (" + disc_key_arr.join(",") + ")"
          : "")
        + " ORDER BY 2"

FCLTselectorOptions(discsql,
                    { initKey:  disc_key_arr.join(","),
                       onChange: 'updateStdm("' + urole + '", "' + autfunction + '");',
                      multi: true,
                      size: 3,
                      emptyOption: (disc_key_arr.length == 0 ? L("lcl_all") : null) // Als een disc_key_arr is meegegeven dan geen lege optie
                    });
%>

