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

     NOTE: als hier inhoudelijk wordt gewijzigd, dan mogelijk in bes/bes_voorraad_search.asp ook.
*/ %>

<%
DOCTYPE_Disable = true;
%>

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

<%
// Build an article list
var autfunction_arr  = getQParamArray("autfunction", []); // Check of user rechten heeft op meegegeven artikelen.
var disctype  = getQParamInt("disctype", -1);             // Vakgroeptype.
var disc_key_arr = getQParamIntArray("disc_key_str", []); // Vakgroep Array.
var offerte = getQParamInt("offerte", -1);
var selectjustone =  getQParamInt("selectjustone", 0) == 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 IN (" + safe.quoted_sql_join(autfunction_arr) + ")"
                + " 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 bd.ins_discipline_key"
            + "     , " + lcl.xsqla('bd.ins_discipline_omschrijving','bd.ins_discipline_key')
            + "  FROM bes_discipline bd"
            + " WHERE bd.ins_discipline_verwijder IS NULL"
            +(disctype <= 2
              ?  " AND bd.ins_discipline_key IN (SELECT dp.bes_ins_discipline_key_inkoop"
                + "                                FROM bes_disc_params dp"
                + "                               WHERE dp.bes_ins_discipline_key_inkoop IS NOT NULL)"
              : "")
            + "   AND bd.ins_discipline_key IN (" + discsql_aut + ")"
            + (disctype >= 0
              ? " AND bd.ins_discipline_key IN (SELECT bes_ins_discipline_key"
                + "                               FROM bes_disc_params"
                + "                              WHERE bes_disc_params_bestelmode = " + disctype + ")"
              : "")
            + (disc_key_arr.length != 0
              ? " AND bd.ins_discipline_key IN (" + disc_key_arr.join(",") + ")"
              : "")
            + " ORDER BY upper("+ lcl.xsql('bd.ins_discipline_omschrijving','bd.ins_discipline_key') +")";

FCLTselectorOptions(discsql,
                    { initKey: disc_key_arr.join(","),
                      onChange: 'updateSrtGroup("' + autfunction_arr.join(",") + '");',
                      emptyOption: (disc_key_arr.length == 0 ? L("lcl_search_generic") : null), // Als een disc_key_arr is meegegeven dan geen lege optie
                      selectjustone: selectjustone? true : false
                    });
%>
mo
<% ASPPAGE_END(); %>
