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

<%
DOCTYPE_Disable = true;
%>

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

<%
// Build a group list
var autfunction = getQParam("autfunction", ""); // Check of user rechten heeft op meegegeven discipline
var disc_key_arr = getQParamIntArray("disc_key_arr", []);
var srtgroup_arr = getQParamIntArray("srtgroup", []);
var module = getQParam("module", ""); // Module die de ins_srtgroep-en opvraagt
var multi = (getQParamInt("multi", 0) == 1);
var size = getQParamInt("size", 4);
var emptyOption = getQParam("emptyOption", null);
var selectjustone =  getQParamInt("selectjustone", 0) == 1;
var selectfirstone = (getQParamInt("selectfirstone", 0) == 1);
var onChange = getQParam("onChange", "");
var required = (getQParamInt("required", 0) == 1);

var sql_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);

var sql = "";

if (module.toUpperCase() == 'BES') {
    var sql = "SELECT sg.bes_srtgroep_key"
            + ", "+lcl.xsqla('sg.bes_srtgroep_omschrijving', 'sg.bes_srtgroep_key')
            + " FROM bes_v_aanwezigsrtgroep sg"
            + " WHERE ins_discipline_key IN (" + sql_aut + ")"
            + (disc_key_arr.length!=0 ? " AND sg.ins_discipline_key IN (" + disc_key_arr.join(",") + ")" : " AND 1=0")
            + " ORDER BY 2 ASC";
} else {
    var sql = "SELECT sg.ins_srtgroep_key"
            + ", "+lcl.xsqla('sg.ins_srtgroep_omschrijving', 'sg.ins_srtgroep_key')
            + " FROM ins_v_aanwezigsrtgroep sg"
            + " WHERE ins_discipline_key IN (" + sql_aut + ")"
            + (disc_key_arr.length!=0 ? " AND sg.ins_discipline_key IN (" + disc_key_arr.join(",") + ")" : " AND 1=0")
            + " ORDER BY 2 ASC";
}

var params = { initKey: srtgroup_arr.join(","),
               multi: (multi? true : false),
               size: (multi? size : 1),
               required: required
             }

if (emptyOption != null)
  params.emptyOption = emptyOption;
if (selectjustone)
  params.selectjustone = selectjustone;
if (selectfirstone)
  params.selectfirstone = selectfirstone;

FCLTselectorOptions(sql,
                    params);
%>
<% ASPPAGE_END(); %>
