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

    File:               SuggestSrtgroep.asp
    Description:        Suggereer Srtgroepen
    Parameters:         k             De eerste paar letters
                        filtcode beperk de lijst met getoonde locaties TO BE DEFINED
                        perslidKey  : verplicht  Voor wie is de Srtgroep
                        autfunctionKey: verplicht fac_function_key of -1 als alles toegestaan
                        autfunction : verplicht:
    Globals:
    Context:
    Note:
*/ %>

<%
JSON_Result = true;
%>

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

<%
var chars = getQParam("k", "");
var autfunction = getQParam("autfunction");
var bAll = getQParamInt("SuggestAll", 0) == 1;
var disc_key = getQParamInt("disc_key", -1);
var extracode = getQParam("extracode", "");
var filtcode = getQParam("filtcode", "");
var module = getQParamSafe("module", "INS");

if (module != "INS" && module != "BES")
  shared.internal_error(L("lcl_obj_bad_value") + " module={0}.".format(module));

var chars = chars.replace(/\*/g,"%");

var params = { autfunction: autfunction,
               disc_key: disc_key,
               module: module };

var filtClause = getFiltClauseSrtgroep(filtcode, params);

var sql = "SELECT sg." + module + "_srtgroep_key srtgroep_key"
        + ", " + lcl.xsql("sg." + module + "_srtgroep_omschrijving", "sg." + module + "_srtgroep_key") + " srtgroep_omschrijving"
        + ", " + lcl.xsqla("td.ins_discipline_omschrijving", "td.ins_discipline_key")
        + ", td.ins_discipline_key extra"
        + " FROM " + module + "_v_aanwezigsrtgroep sg"
        + ", ins_tab_discipline td"
        + " WHERE td.ins_discipline_key = sg.ins_discipline_key"
        + "   AND td.ins_discipline_verwijder IS NULL"
        + " AND (UPPER(" + lcl.xsql("sg." + module + "_srtgroep_omschrijving", "sg." + module + "_srtgroep_key") +") LIKE " + safe.quoted_sql_wild2(chars)
          + " OR UPPER(" + lcl.xsql("td.ins_discipline_omschrijving", "td.ins_discipline_key") + ") LIKE " + safe.quoted_sql_wild2(chars) + ")"
        + filtClause
        + " ORDER BY " + module + "_srtgroep_omschrijving ASC";



WriteResult(sql, bAll, "srtgroep_omschrijving", "srtgroep_key", "ins_discipline_omschrijving", "extra");
%>
<% ASPPAGE_END(); %>
